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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.358   ! raeburn     4: # $Id: domainprefs.pm,v 1.357 2019/04/26 23:46:19 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.1       raeburn   179: 
1.155     raeburn   180: my $registered_cleanup;
                    181: my $modified_urls;
                    182: 
1.1       raeburn   183: sub handler {
                    184:     my $r=shift;
                    185:     if ($r->header_only) {
                    186:         &Apache::loncommon::content_type($r,'text/html');
                    187:         $r->send_http_header;
                    188:         return OK;
                    189:     }
                    190: 
1.91      raeburn   191:     my $context = 'domain';
1.1       raeburn   192:     my $dom = $env{'request.role.domain'};
1.5       albertel  193:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   194:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    195:         &Apache::loncommon::content_type($r,'text/html');
                    196:         $r->send_http_header;
                    197:     } else {
                    198:         $env{'user.error.msg'}=
                    199:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    200:         return HTTP_NOT_ACCEPTABLE;
                    201:     }
1.155     raeburn   202: 
                    203:     $registered_cleanup=0;
                    204:     @{$modified_urls}=();
                    205: 
1.1       raeburn   206:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    207:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   208:                                             ['phase','actions']);
1.30      raeburn   209:     my $phase = 'pickactions';
1.3       raeburn   210:     if ( exists($env{'form.phase'}) ) {
                    211:         $phase = $env{'form.phase'};
                    212:     }
1.150     raeburn   213:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   214:     my %domconfig =
1.6       raeburn   215:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   216:                 'quotas','autoenroll','autoupdate','autocreate',
                    217:                 'directorysrch','usercreation','usermodification',
                    218:                 'contacts','defaults','scantron','coursecategories',
                    219:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   220:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   221:                 'requestauthor','selfenrollment','inststatus',
1.357     raeburn   222:                 'ltitools','ssl','trust','lti','privacy','passwords'],$dom);
1.320     raeburn   223:     my %encconfig =
                    224:         &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
1.297     raeburn   225:     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    226:         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    227:             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320     raeburn   228:                 if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
                    229:                     (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.297     raeburn   230:                     foreach my $item ('key','secret') {
                    231:                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    232:                     }
                    233:                 }
                    234:             }
                    235:         }
                    236:     }
1.320     raeburn   237:     if (ref($domconfig{'lti'}) eq 'HASH') {
                    238:         if (ref($encconfig{'lti'}) eq 'HASH') {
                    239:             foreach my $id (keys(%{$domconfig{'lti'}})) {
                    240:                 if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
                    241:                     (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
                    242:                     foreach my $item ('key','secret') {
                    243:                         $domconfig{'lti'}{$id}{$item} = $encconfig{'lti'}{$id}{$item};
                    244:                     }
                    245:                 }
                    246:             }
                    247:         }
                    248:     }
1.354     raeburn   249:     my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.357     raeburn   250:                        'autoupdate','autocreate','directorysrch','contacts','privacy',
1.224     raeburn   251:                        'usercreation','selfcreation','usermodification','scantron',
1.163     raeburn   252:                        'requestcourses','requestauthor','coursecategories',
1.267     raeburn   253:                        'serverstatuses','helpsettings','coursedefaults',
1.320     raeburn   254:                        'ltitools','selfenrollment','usersessions','ssl','trust','lti');
1.171     raeburn   255:     my %existing;
                    256:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    257:         %existing = %{$domconfig{'loadbalancing'}};
                    258:     }
                    259:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   260:         push(@prefs_order,'loadbalancing');
                    261:     }
1.30      raeburn   262:     my %prefs = (
                    263:         'rolecolors' =>
                    264:                    { text => 'Default color schemes',
1.67      raeburn   265:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   266:                      header => [{col1 => 'Student Settings',
                    267:                                  col2 => '',},
                    268:                                 {col1 => 'Coordinator Settings',
                    269:                                  col2 => '',},
                    270:                                 {col1 => 'Author Settings',
                    271:                                  col2 => '',},
                    272:                                 {col1 => 'Administrator Settings',
                    273:                                  col2 => '',}],
1.230     raeburn   274:                       print => \&print_rolecolors,
                    275:                       modify => \&modify_rolecolors,
1.30      raeburn   276:                     },
1.110     raeburn   277:         'login' =>
1.30      raeburn   278:                     { text => 'Log-in page options',
1.67      raeburn   279:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   280:                       header => [{col1 => 'Log-in Page Items',
                    281:                                   col2 => '',},
                    282:                                  {col1 => 'Log-in Help',
1.256     raeburn   283:                                   col2 => 'Value'},
                    284:                                  {col1 => 'Custom HTML in document head',
1.168     raeburn   285:                                   col2 => 'Value'}],
1.230     raeburn   286:                       print => \&print_login,
                    287:                       modify => \&modify_login,
1.30      raeburn   288:                     },
1.43      raeburn   289:         'defaults' => 
1.236     raeburn   290:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   291:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   292:                       header => [{col1 => 'Setting',
1.236     raeburn   293:                                   col2 => 'Value'},
                    294:                                  {col1 => 'Institutional user types',
1.305     raeburn   295:                                   col2 => 'Name displayed'}],
1.230     raeburn   296:                       print => \&print_defaults,
                    297:                       modify => \&modify_defaults,
1.43      raeburn   298:                     },
1.354     raeburn   299:         'passwords' =>
                    300:                     { text => 'Passwords (Internal authentication)',
                    301:                       help => 'Domain_Configuration_Passwords',
                    302:                       header => [{col1 => 'Resetting Forgotten Password',
                    303:                                   col2 => 'Settings'},
                    304:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    305:                                   col2 => 'Settings'},
                    306:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    307:                                   col2 => 'Settings'},
                    308:                                  {col1 => 'Course Owner Changing Student Passwords',
                    309:                                   col2 => 'Settings'}],
                    310:                       print => \&print_passwords,
                    311:                       modify => \&modify_passwords,
                    312:                     },
1.30      raeburn   313:         'quotas' => 
1.197     raeburn   314:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   315:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   316:                       header => [{col1 => 'User affiliation',
1.72      raeburn   317:                                   col2 => 'Available tools',
1.213     raeburn   318:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   319:                       print => \&print_quotas,
                    320:                       modify => \&modify_quotas,
1.30      raeburn   321:                     },
                    322:         'autoenroll' =>
                    323:                    { text => 'Auto-enrollment settings',
1.67      raeburn   324:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   325:                      header => [{col1 => 'Configuration setting',
                    326:                                  col2 => 'Value(s)'}],
1.230     raeburn   327:                      print => \&print_autoenroll,
                    328:                      modify => \&modify_autoenroll,
1.30      raeburn   329:                    },
                    330:         'autoupdate' => 
                    331:                    { text => 'Auto-update settings',
1.67      raeburn   332:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   333:                      header => [{col1 => 'Setting',
                    334:                                  col2 => 'Value',},
1.131     raeburn   335:                                 {col1 => 'Setting',
                    336:                                  col2 => 'Affiliation'},
1.43      raeburn   337:                                 {col1 => 'User population',
1.227     bisitz    338:                                  col2 => 'Updatable user data'}],
1.230     raeburn   339:                      print => \&print_autoupdate,
                    340:                      modify => \&modify_autoupdate,
1.30      raeburn   341:                   },
1.125     raeburn   342:         'autocreate' => 
                    343:                   { text => 'Auto-course creation settings',
                    344:                      help => 'Domain_Configuration_Auto_Creation',
                    345:                      header => [{col1 => 'Configuration Setting',
                    346:                                  col2 => 'Value',}],
1.230     raeburn   347:                      print => \&print_autocreate,
                    348:                      modify => \&modify_autocreate,
1.125     raeburn   349:                   },
1.30      raeburn   350:         'directorysrch' => 
1.277     raeburn   351:                   { text => 'Directory searches',
1.67      raeburn   352:                     help => 'Domain_Configuration_InstDirectory_Search',
1.277     raeburn   353:                     header => [{col1 => 'Institutional Directory Setting',
                    354:                                 col2 => 'Value',},
                    355:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   356:                                 col2 => 'Value',}],
1.230     raeburn   357:                     print => \&print_directorysrch,
                    358:                     modify => \&modify_directorysrch,
1.30      raeburn   359:                   },
                    360:         'contacts' =>
1.286     raeburn   361:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   362:                     help => 'Domain_Configuration_Contact_Info',
1.286     raeburn   363:                     header => [{col1 => 'Default e-mail addresses',
                    364:                                 col2 => 'Value',},
                    365:                                {col1 => 'Recipient(s) for notifications',
                    366:                                 col2 => 'Value',},
1.340     raeburn   367:                                {col1 => 'Nightly status check e-mail',
                    368:                                 col2 => 'Settings',},
1.286     raeburn   369:                                {col1 => 'Ask helpdesk form settings',
                    370:                                 col2 => 'Value',},],
1.230     raeburn   371:                     print => \&print_contacts,
                    372:                     modify => \&modify_contacts,
1.30      raeburn   373:                   },
                    374:         'usercreation' => 
                    375:                   { text => 'User creation',
1.67      raeburn   376:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   377:                     header => [{col1 => 'Format rule type',
                    378:                                 col2 => 'Format rules in force'},
1.34      raeburn   379:                                {col1 => 'User account creation',
                    380:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   381:                                {col1 => 'Context',
1.43      raeburn   382:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   383:                     print => \&print_usercreation,
                    384:                     modify => \&modify_usercreation,
1.30      raeburn   385:                   },
1.224     raeburn   386:         'selfcreation' => 
                    387:                   { text => 'Users self-creating accounts',
                    388:                     help => 'Domain_Configuration_Self_Creation', 
                    389:                     header => [{col1 => 'Self-creation with institutional username',
                    390:                                 col2 => 'Enabled?'},
                    391:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    392:                                 col2 => 'Information user can enter'},
1.303     raeburn   393:                                {col1 => 'Self-creation with e-mail verification',
1.224     raeburn   394:                                 col2 => 'Settings'}],
1.230     raeburn   395:                     print => \&print_selfcreation,
                    396:                     modify => \&modify_selfcreation,
1.224     raeburn   397:                   },
1.69      raeburn   398:         'usermodification' =>
1.33      raeburn   399:                   { text => 'User modification',
1.67      raeburn   400:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   401:                     header => [{col1 => 'Target user has role',
1.227     bisitz    402:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   403:                                {col1 => 'Target user has role',
1.227     bisitz    404:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   405:                     print => \&print_usermodification,
                    406:                     modify => \&modify_usermodification,
1.33      raeburn   407:                   },
1.69      raeburn   408:         'scantron' =>
1.346     raeburn   409:                   { text => 'Bubblesheet format',
1.67      raeburn   410:                     help => 'Domain_Configuration_Scantron_Format',
1.346     raeburn   411:                     header => [ {col1 => 'Bubblesheet format file',
                    412:                                  col2 => ''},
                    413:                                 {col1 => 'Bubblesheet data upload formats',
                    414:                                  col2 => 'Settings'}],
1.230     raeburn   415:                     print => \&print_scantron,
                    416:                     modify => \&modify_scantron,
1.46      raeburn   417:                   },
1.86      raeburn   418:         'requestcourses' => 
                    419:                  {text => 'Request creation of courses',
                    420:                   help => 'Domain_Configuration_Request_Courses',
                    421:                   header => [{col1 => 'User affiliation',
1.102     raeburn   422:                               col2 => 'Availability/Processing of requests',},
                    423:                              {col1 => 'Setting',
1.216     raeburn   424:                               col2 => 'Value'},
                    425:                              {col1 => 'Available textbooks',
1.235     raeburn   426:                               col2 => ''},
1.242     raeburn   427:                              {col1 => 'Available templates',
                    428:                               col2 => ''},
1.235     raeburn   429:                              {col1 => 'Validation (not official courses)',
                    430:                               col2 => 'Value'},],
1.230     raeburn   431:                   print => \&print_quotas,
                    432:                   modify => \&modify_quotas,
1.86      raeburn   433:                  },
1.163     raeburn   434:         'requestauthor' =>
1.223     bisitz    435:                  {text => 'Request Authoring Space',
1.163     raeburn   436:                   help => 'Domain_Configuration_Request_Author',
                    437:                   header => [{col1 => 'User affiliation',
                    438:                               col2 => 'Availability/Processing of requests',},
                    439:                              {col1 => 'Setting',
                    440:                               col2 => 'Value'}],
1.230     raeburn   441:                   print => \&print_quotas,
                    442:                   modify => \&modify_quotas,
1.163     raeburn   443:                  },
1.69      raeburn   444:         'coursecategories' =>
1.120     raeburn   445:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   446:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   447:                     header => [{col1 => 'Catalog type/availability',
                    448:                                 col2 => '',},
                    449:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   450:                                 col2 => '',},
                    451:                                {col1 => 'Categories',
                    452:                                 col2 => '',
                    453:                                }],
1.230     raeburn   454:                     print => \&print_coursecategories,
                    455:                     modify => \&modify_coursecategories,
1.69      raeburn   456:                   },
                    457:         'serverstatuses' =>
1.77      raeburn   458:                  {text   => 'Access to server status pages',
1.69      raeburn   459:                   help   => 'Domain_Configuration_Server_Status',
                    460:                   header => [{col1 => 'Status Page',
                    461:                               col2 => 'Other named users',
                    462:                               col3 => 'Specific IPs',
                    463:                             }],
1.230     raeburn   464:                   print => \&print_serverstatuses,
                    465:                   modify => \&modify_serverstatuses,
1.69      raeburn   466:                  },
1.118     jms       467:         'helpsettings' =>
1.282     raeburn   468:                  {text   => 'Support settings',
1.118     jms       469:                   help   => 'Domain_Configuration_Help_Settings',
1.282     raeburn   470:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    471:                               col2 => 'Value'},
                    472:                              {col1 => 'Helpdesk Roles',
                    473:                               col2 => 'Settings'},],
1.230     raeburn   474:                   print  => \&print_helpsettings,
                    475:                   modify => \&modify_helpsettings,
1.118     jms       476:                  },
1.121     raeburn   477:         'coursedefaults' => 
                    478:                  {text => 'Course/Community defaults',
                    479:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   480:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    481:                               col2 => 'Value',},
                    482:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    483:                               col2 => 'Value',},],
1.230     raeburn   484:                   print => \&print_coursedefaults,
                    485:                   modify => \&modify_coursedefaults,
1.121     raeburn   486:                  },
1.231     raeburn   487:         'selfenrollment' => 
                    488:                  {text   => 'Self-enrollment in Course/Community',
                    489:                   help   => 'Domain_Configuration_Selfenrollment',
                    490:                   header => [{col1 => 'Configuration Rights',
                    491:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    492:                              {col1 => 'Defaults',
                    493:                               col2 => 'Value'},
                    494:                              {col1 => 'Self-enrollment validation (optional)',
                    495:                               col2 => 'Value'},],
                    496:                   print => \&print_selfenrollment,
                    497:                   modify => \&modify_selfenrollment,
                    498:                  },
1.120     raeburn   499:         'privacy' => 
1.357     raeburn   500:                  {text   => 'Availability of User Information',
1.120     raeburn   501:                   help   => 'Domain_Configuration_User_Privacy',
1.357     raeburn   502:                   header => [{col1 => 'Role assigned in different domain',
                    503:                               col2 => 'Approval options'},
                    504:                              {col1 => 'Role assigned in different domain to user of type',
                    505:                               col2 => 'User information available in that domain'},
                    506:                              {col1 => "Role assigned in user's domain",
                    507:                               col2 => 'Information viewable by privileged user'},
                    508:                              {col1 => "Role assigned in user's domain",
                    509:                               col2 => 'Information viewable by unprivileged user'}],
1.230     raeburn   510:                   print => \&print_privacy,
                    511:                   modify => \&modify_privacy,
1.120     raeburn   512:                  },
1.141     raeburn   513:         'usersessions' =>
1.145     raeburn   514:                  {text  => 'User session hosting/offloading',
1.137     raeburn   515:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   516:                   header => [{col1 => 'Domain server',
                    517:                               col2 => 'Servers to offload sessions to when busy'},
                    518:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   519:                               col2 => 'Rules'},
                    520:                              {col1 => "Hosting domain's own users elsewhere",
                    521:                               col2 => 'Rules'}],
1.230     raeburn   522:                   print => \&print_usersessions,
                    523:                   modify => \&modify_usersessions,
1.137     raeburn   524:                  },
1.279     raeburn   525:         'loadbalancing' =>
1.185     raeburn   526:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   527:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   528:                   header => [{col1 => 'Balancers',
1.150     raeburn   529:                               col2 => 'Default destinations',
1.183     bisitz    530:                               col3 => 'User affiliation',
1.150     raeburn   531:                               col4 => 'Overrides'},
                    532:                             ],
1.230     raeburn   533:                   print => \&print_loadbalancing,
                    534:                   modify => \&modify_loadbalancing,
1.150     raeburn   535:                  },
1.279     raeburn   536:         'ltitools' => 
1.267     raeburn   537:                  {text => 'External Tools (LTI)',
1.296     raeburn   538:                   help => 'Domain_Configuration_LTI_Tools',
1.267     raeburn   539:                   header => [{col1 => 'Setting',
                    540:                               col2 => 'Value',}],
                    541:                   print => \&print_ltitools,
                    542:                   modify => \&modify_ltitools,
                    543:                  },
1.279     raeburn   544:         'ssl' =>
1.275     raeburn   545:                  {text  => 'LON-CAPA Network (SSL)',
                    546:                   help  => 'Domain_Configuration_Network_SSL',
                    547:                   header => [{col1 => 'Server',
                    548:                               col2 => 'Certificate Status'},
                    549:                              {col1 => 'Connections to other servers',
                    550:                               col2 => 'Rules'},
1.293     raeburn   551:                              {col1 => 'Connections from other servers',
                    552:                               col2 => 'Rules'},
1.275     raeburn   553:                              {col1 => "Replicating domain's published content",
                    554:                               col2 => 'Rules'}],
                    555:                   print => \&print_ssl,
                    556:                   modify => \&modify_ssl,
                    557:                  },
1.279     raeburn   558:         'trust' =>
                    559:                  {text   => 'Trust Settings',
                    560:                   help   => 'Domain_Configuration_Trust',
                    561:                   header => [{col1 => "Access to this domain's content by others",
                    562:                               col2 => 'Rules'},
                    563:                              {col1 => "Access to other domain's content by this domain",
                    564:                               col2 => 'Rules'},
                    565:                              {col1 => "Enrollment in this domain's courses by others",
                    566:                               col2 => 'Rules',},
                    567:                              {col1 => "Co-author roles in this domain for others",
                    568:                               col2 => 'Rules',},
                    569:                              {col1 => "Co-author roles for this domain's users elsewhere",
                    570:                               col2 => 'Rules',},
                    571:                              {col1 => "Domain roles in this domain assignable to others",
                    572:                               col2 => 'Rules'},
                    573:                              {col1 => "Course catalog for this domain displayed elsewhere",
                    574:                               col2 => 'Rules'},
                    575:                              {col1 => "Requests for creation of courses in this domain by others",
                    576:                               col2 => 'Rules'},
                    577:                              {col1 => "Users in other domains can send messages to this domain",
                    578:                               col2 => 'Rules'},],
                    579:                   print => \&print_trust,
                    580:                   modify => \&modify_trust,
                    581:                  },
1.320     raeburn   582:           'lti' =>
                    583:                  {text => 'LTI Provider',
                    584:                   help => 'Domain_Configuration_LTI_Provider',
                    585:                   header => [{col1 => 'Setting',
                    586:                               col2 => 'Value',}],
                    587:                   print => \&print_lti,
                    588:                   modify => \&modify_lti,
                    589:                  },
1.3       raeburn   590:     );
1.110     raeburn   591:     if (keys(%servers) > 1) {
                    592:         $prefs{'login'}  = { text   => 'Log-in page options',
                    593:                              help   => 'Domain_Configuration_Login_Page',
                    594:                             header => [{col1 => 'Log-in Service',
                    595:                                         col2 => 'Server Setting',},
                    596:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   597:                                         col2 => ''},
                    598:                                        {col1 => 'Log-in Help',
1.256     raeburn   599:                                         col2 => 'Value'},
                    600:                                        {col1 => 'Custom HTML in document head',
1.168     raeburn   601:                                         col2 => 'Value'}],
1.230     raeburn   602:                             print => \&print_login,
                    603:                             modify => \&modify_login,
1.110     raeburn   604:                            };
                    605:     }
1.174     foxr      606: 
1.6       raeburn   607:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   608:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   609:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   610:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   611:       text=>"Settings to display/modify"});
1.9       raeburn   612:     my $confname = $dom.'-domainconfig';
1.174     foxr      613: 
1.3       raeburn   614:     if ($phase eq 'process') {
1.212     raeburn   615:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    616:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   617:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   618:             $r->rflush();
1.212     raeburn   619:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   620:         }
1.30      raeburn   621:     } elsif ($phase eq 'display') {
1.192     raeburn   622:         my $js = &recaptcha_js().
1.236     raeburn   623:                  &toggle_display_js();
1.171     raeburn   624:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   625:             my ($othertitle,$usertypes,$types) =
                    626:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   627:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    628:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   629:                    &new_spares_js().
                    630:                    &common_domprefs_js().
                    631:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   632:         }
1.216     raeburn   633:         if (grep(/^requestcourses$/,@actions)) {
                    634:             my $javascript_validations;
                    635:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    636:             $js .= <<END;
                    637: <script type="text/javascript">
                    638: $javascript_validations
                    639: </script>
                    640: $coursebrowserjs
                    641: END
                    642:         }
1.305     raeburn   643:         if (grep(/^selfcreation$/,@actions)) {
                    644:             $js .= &selfcreate_javascript();
                    645:         }
1.286     raeburn   646:         if (grep(/^contacts$/,@actions)) {
                    647:             $js .= &contacts_javascript();
                    648:         }
1.346     raeburn   649:         if (grep(/^scantron$/,@actions)) {
                    650:             $js .= &scantron_javascript();
                    651:         }
1.150     raeburn   652:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   653:     } else {
1.180     raeburn   654: # check if domconfig user exists for the domain.
                    655:         my $servadm = $r->dir_config('lonAdmEMail');
                    656:         my ($configuserok,$author_ok,$switchserver) =
                    657:             &config_check($dom,$confname,$servadm);
                    658:         unless ($configuserok eq 'ok') {
1.181     raeburn   659:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    660:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   661:                           $confname).
1.181     raeburn   662:                       '<br />'
                    663:             );
1.180     raeburn   664:             if ($switchserver) {
1.181     raeburn   665:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    666:                           '<br />'.
                    667:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    668:                           '<br />'.
                    669:                           &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).
                    670:                           '<br />'.
                    671:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    672:                 );
                    673:             } else {
                    674:                 $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.').
                    675:                           '<br />'.
                    676:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    677:                 );
1.180     raeburn   678:             }
                    679:             $r->print(&Apache::loncommon::end_page());
                    680:             return OK;
                    681:         }
1.21      raeburn   682:         if (keys(%domconfig) == 0) {
                    683:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   684:             my @ids=&Apache::lonnet::current_machine_ids();
                    685:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   686:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   687:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   688:                 my $custom_img_count = 0;
                    689:                 foreach my $img (@loginimages) {
                    690:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    691:                         $custom_img_count ++;
                    692:                     }
                    693:                 }
                    694:                 foreach my $role (@roles) {
                    695:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    696:                         $custom_img_count ++;
                    697:                     }
                    698:                 }
                    699:                 if ($custom_img_count > 0) {
1.94      raeburn   700:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   701:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   702:                     $r->print(
                    703:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    704:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    705:     &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 />'.
                    706:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    707:                     if ($switch_server) {
1.30      raeburn   708:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   709:                     }
1.91      raeburn   710:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   711:                     return OK;
                    712:                 }
                    713:             }
                    714:         }
1.91      raeburn   715:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   716:     }
                    717:     return OK;
                    718: }
                    719: 
                    720: sub process_changes {
1.205     raeburn   721:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   722:     my %domconfig;
                    723:     if (ref($values) eq 'HASH') {
                    724:         %domconfig = %{$values};
                    725:     }
1.3       raeburn   726:     my $output;
                    727:     if ($action eq 'login') {
1.205     raeburn   728:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   729:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   730:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   731:                                      $lastactref,%domconfig);
1.3       raeburn   732:     } elsif ($action eq 'quotas') {
1.216     raeburn   733:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   734:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   735:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   736:     } elsif ($action eq 'autoupdate') {
                    737:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   738:     } elsif ($action eq 'autocreate') {
                    739:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   740:     } elsif ($action eq 'directorysrch') {
1.295     raeburn   741:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   742:     } elsif ($action eq 'usercreation') {
1.28      raeburn   743:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   744:     } elsif ($action eq 'selfcreation') {
1.305     raeburn   745:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   746:     } elsif ($action eq 'usermodification') {
                    747:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   748:     } elsif ($action eq 'contacts') {
1.205     raeburn   749:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   750:     } elsif ($action eq 'defaults') {
1.212     raeburn   751:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   752:     } elsif ($action eq 'scantron') {
1.205     raeburn   753:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   754:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   755:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   756:     } elsif ($action eq 'serverstatuses') {
                    757:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   758:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   759:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   760:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   761:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       762:     } elsif ($action eq 'helpsettings') {
1.285     raeburn   763:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121     raeburn   764:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   765:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   766:     } elsif ($action eq 'selfenrollment') {
                    767:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   768:     } elsif ($action eq 'usersessions') {
1.212     raeburn   769:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   770:     } elsif ($action eq 'loadbalancing') {
                    771:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   772:     } elsif ($action eq 'ltitools') {
                    773:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.275     raeburn   774:     } elsif ($action eq 'ssl') {
                    775:         $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279     raeburn   776:     } elsif ($action eq 'trust') {
                    777:         $output = &modify_trust($dom,$lastactref,%domconfig);
1.320     raeburn   778:     } elsif ($action eq 'lti') {
                    779:         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357     raeburn   780:     } elsif ($action eq 'privacy') {
                    781:         $output = &modify_privacy($dom,%domconfig);
1.354     raeburn   782:     } elsif ($action eq 'passwords') {
                    783:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3       raeburn   784:     }
                    785:     return $output;
                    786: }
                    787: 
                    788: sub print_config_box {
1.9       raeburn   789:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   790:     my $rowtotal = 0;
1.49      raeburn   791:     my $output;
                    792:     if ($action eq 'coursecategories') {
                    793:         $output = &coursecategories_javascript($settings);
1.236     raeburn   794:     } elsif ($action eq 'defaults') {
                    795:         $output = &defaults_javascript($settings); 
1.354     raeburn   796:     } elsif ($action eq 'passwords') {
                    797:         $output = &passwords_javascript();
1.282     raeburn   798:     } elsif ($action eq 'helpsettings') {
                    799:         my (%privs,%levelscurrent);
                    800:         my %full=();
                    801:         my %levels=(
                    802:                      course => {},
                    803:                      domain => {},
                    804:                      system => {},
                    805:                    );
                    806:         my $context = 'domain';
                    807:         my $crstype = 'Course';
                    808:         my $formname = 'display';
                    809:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    810:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    811:         $output =
                    812:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                    813:                                                       \@templateroles);
1.334     raeburn   814:     } elsif ($action eq 'ltitools') {
                    815:         $output .= &ltitools_javascript($settings);
                    816:     } elsif ($action eq 'lti') {
                    817:         $output .= &lti_javascript($settings);
1.91      raeburn   818:     }
1.236     raeburn   819:     $output .=
1.30      raeburn   820:          '<table class="LC_nested_outer">
1.3       raeburn   821:           <tr>
1.306     raeburn   822:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   823:            &mt($item->{text}).'&nbsp;'.
                    824:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    825:           '</tr>';
1.30      raeburn   826:     $rowtotal ++;
1.110     raeburn   827:     my $numheaders = 1;
                    828:     if (ref($item->{'header'}) eq 'ARRAY') {
                    829:         $numheaders = scalar(@{$item->{'header'}});
                    830:     }
                    831:     if ($numheaders > 1) {
1.64      raeburn   832:         my $colspan = '';
1.145     raeburn   833:         my $rightcolspan = '';
1.238     raeburn   834:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   835:             ($action eq 'directorysrch') ||
1.256     raeburn   836:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   837:             $colspan = ' colspan="2"';
                    838:         }
1.145     raeburn   839:         if ($action eq 'usersessions') {
                    840:             $rightcolspan = ' colspan="3"'; 
                    841:         }
1.30      raeburn   842:         $output .= '
1.3       raeburn   843:           <tr>
                    844:            <td>
                    845:             <table class="LC_nested">
                    846:              <tr class="LC_info_row">
1.59      bisitz    847:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   848:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   849:              </tr>';
1.69      raeburn   850:         $rowtotal ++;
1.230     raeburn   851:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   852:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   853:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   854:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.357     raeburn   855:             ($action eq 'contacts') || ($action eq 'privacy')) {
1.230     raeburn   856:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   857:         } elsif ($action eq 'passwords') {
                    858:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   859:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   860:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn   861:         } elsif ($action eq 'scantron') {
                    862:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   863:         } elsif ($action eq 'login') {
1.256     raeburn   864:             if ($numheaders == 4) {
1.168     raeburn   865:                 $colspan = ' colspan="2"';
                    866:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    867:             } else {
                    868:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    869:             }
1.230     raeburn   870:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   871:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       872:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   873:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   874:         }
1.30      raeburn   875:         $output .= '
1.6       raeburn   876:            </table>
                    877:           </td>
                    878:          </tr>
                    879:          <tr>
                    880:            <td>
                    881:             <table class="LC_nested">
                    882:              <tr class="LC_info_row">
1.230     raeburn   883:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    884:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   885:              </tr>';
                    886:             $rowtotal ++;
1.230     raeburn   887:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    888:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   889:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.357     raeburn   890:             ($action eq 'trust') || ($action eq 'contacts') ||
                    891:             ($action eq 'privacy') || ($action eq 'passwords')) {
1.238     raeburn   892:             if ($action eq 'coursecategories') {
                    893:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    894:                 $colspan = ' colspan="2"';
1.279     raeburn   895:             } elsif ($action eq 'trust') {
                    896:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn   897:             } elsif ($action eq 'passwords') {
                    898:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238     raeburn   899:             } else {
                    900:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    901:             }
1.279     raeburn   902:             if ($action eq 'trust') {
                    903:                 $output .= '
                    904:             </table>
                    905:           </td>
                    906:          </tr>';
                    907:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    908:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    909:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    910:                     $output .= '
                    911:          <tr>
                    912:            <td>
                    913:             <table class="LC_nested">
                    914:              <tr class="LC_info_row">
                    915:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    916:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    917:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    918:             </table>
                    919:           </td>
                    920:          </tr>';
                    921:                 }
                    922:                 $output .= '
                    923:          <tr>
                    924:            <td>
                    925:             <table class="LC_nested">
                    926:              <tr class="LC_info_row">
                    927:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                    928:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                    929:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    930:             } else {
                    931:                 $output .= '
1.63      raeburn   932:            </table>
                    933:           </td>
                    934:          </tr>
                    935:          <tr>
                    936:            <td>
                    937:             <table class="LC_nested">
                    938:              <tr class="LC_info_row">
                    939:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   940:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn   941:              </tr>'."\n";
1.279     raeburn   942:                 if ($action eq 'coursecategories') {
                    943:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357     raeburn   944:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354     raeburn   945:                     if ($action eq 'passwords') {
                    946:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                    947:                     } else {
                    948:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                    949:                     }
                    950:                     $output .= '
1.340     raeburn   951:              </tr>
                    952:             </table>
                    953:            </td>
                    954:           </tr>
                    955:           <tr>
                    956:            <td>
                    957:             <table class="LC_nested">
                    958:              <tr class="LC_info_row">
                    959:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354     raeburn   960:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                    961:                     if ($action eq 'passwords') {
                    962:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                    963:                     } else {
                    964:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    965:                     }
                    966:                     $output .= '
1.340     raeburn   967:             </table>
                    968:           </td>
                    969:          </tr>
                    970:          <tr>';
1.279     raeburn   971:                 } else {
                    972:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    973:                 }
1.238     raeburn   974:             }
1.63      raeburn   975:             $rowtotal ++;
1.236     raeburn   976:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn   977:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    978:                  ($action eq 'helpsettings')) {
1.230     raeburn   979:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn   980:         } elsif ($action eq 'scantron') {
                    981:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn   982:         } elsif ($action eq 'ssl') {
                    983:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                    984:             </table>
                    985:           </td>
                    986:          </tr>
                    987:          <tr>
                    988:            <td>
                    989:             <table class="LC_nested">
                    990:              <tr class="LC_info_row">
                    991:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    992:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                    993:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                    994:             </table>
                    995:           </td>
                    996:          </tr>
                    997:          <tr>
                    998:            <td>
                    999:             <table class="LC_nested">
                   1000:              <tr class="LC_info_row">
                   1001:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1002:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1003:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1004:         } elsif ($action eq 'login') {
1.256     raeburn  1005:             if ($numheaders == 4) {
1.168     raeburn  1006:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1007:            </table>
                   1008:           </td>
                   1009:          </tr>
                   1010:          <tr>
                   1011:            <td>
                   1012:             <table class="LC_nested">
                   1013:              <tr class="LC_info_row">
                   1014:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1015:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1016:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1017:                 $rowtotal ++;
                   1018:             } else {
                   1019:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1020:             }
1.256     raeburn  1021:             $output .= '
                   1022:            </table>
                   1023:           </td>
                   1024:          </tr>
                   1025:          <tr>
                   1026:            <td>
                   1027:             <table class="LC_nested">
                   1028:              <tr class="LC_info_row">';
                   1029:             if ($numheaders == 4) {
                   1030:                 $output .= '
                   1031:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1032:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1033:              </tr>';
                   1034:             } else {
                   1035:                 $output .= '
                   1036:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1037:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1038:              </tr>';
                   1039:             }
                   1040:             $rowtotal ++;
                   1041:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1042:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1043:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1044:             $rowtotal ++;
                   1045:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1046:            </table>
                   1047:           </td>
                   1048:          </tr>
                   1049:          <tr>
                   1050:            <td>
                   1051:             <table class="LC_nested">
                   1052:              <tr class="LC_info_row">
                   1053:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1054:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1055:                        &textbookcourses_javascript($settings).
                   1056:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1057:             </table>
                   1058:            </td>
                   1059:           </tr>
                   1060:          <tr>
                   1061:            <td>
                   1062:             <table class="LC_nested">
                   1063:              <tr class="LC_info_row">
                   1064:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1065:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1066:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1067:             </table>
                   1068:            </td>
                   1069:           </tr>
                   1070:           <tr>
                   1071:            <td>
                   1072:             <table class="LC_nested">
                   1073:              <tr class="LC_info_row">
1.306     raeburn  1074:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1075:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1076:              </tr>'.
                   1077:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1078:         } elsif ($action eq 'requestauthor') {
                   1079:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1080:             $rowtotal ++;
1.122     jms      1081:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1082:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1083:            </table>
                   1084:           </td>
                   1085:          </tr>
                   1086:          <tr>
                   1087:            <td>
                   1088:             <table class="LC_nested">
                   1089:              <tr class="LC_info_row">
1.306     raeburn  1090:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1091:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1092:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1093:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1094:              </tr>'.
1.30      raeburn  1095:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1096:            </table>
                   1097:           </td>
                   1098:          </tr>
                   1099:          <tr>
                   1100:            <td>
                   1101:             <table class="LC_nested">
                   1102:              <tr class="LC_info_row">
1.59      bisitz   1103:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1104:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1105:              </tr>'.
1.30      raeburn  1106:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1107:             $rowtotal += 2;
1.6       raeburn  1108:         }
1.3       raeburn  1109:     } else {
1.30      raeburn  1110:         $output .= '
1.3       raeburn  1111:           <tr>
                   1112:            <td>
                   1113:             <table class="LC_nested">
1.30      raeburn  1114:              <tr class="LC_info_row">';
1.277     raeburn  1115:         if ($action eq 'login') {
1.30      raeburn  1116:             $output .= '  
1.59      bisitz   1117:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1118:         } elsif ($action eq 'serverstatuses') {
                   1119:             $output .= '
1.306     raeburn  1120:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1121:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1122: 
1.6       raeburn  1123:         } else {
1.30      raeburn  1124:             $output .= '
1.306     raeburn  1125:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1126:         }
1.72      raeburn  1127:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1128:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1129:                        &mt($item->{'header'}->[0]->{'col2'});
                   1130:             if ($action eq 'serverstatuses') {
                   1131:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1132:             } 
1.69      raeburn  1133:         } else {
1.306     raeburn  1134:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1135:                        &mt($item->{'header'}->[0]->{'col2'});
                   1136:         }
                   1137:         $output .= '</td>';
                   1138:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1139:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1140:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1141:                             &mt($item->{'header'}->[0]->{'col3'});
                   1142:             } else {
1.306     raeburn  1143:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1144:                            &mt($item->{'header'}->[0]->{'col3'});
                   1145:             }
1.69      raeburn  1146:             if ($action eq 'serverstatuses') {
                   1147:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1148:             }
                   1149:             $output .= '</td>';
1.6       raeburn  1150:         }
1.150     raeburn  1151:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1152:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1153:                        &mt($item->{'header'}->[0]->{'col4'});
                   1154:         }
1.69      raeburn  1155:         $output .= '</tr>';
1.48      raeburn  1156:         $rowtotal ++;
1.168     raeburn  1157:         if ($action eq 'quotas') {
1.86      raeburn  1158:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1159:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1160:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.320     raeburn  1161:                  ($action eq 'ltitools') || ($action eq 'lti')) {
1.230     raeburn  1162:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1163:         }
1.3       raeburn  1164:     }
1.30      raeburn  1165:     $output .= '
1.3       raeburn  1166:    </table>
                   1167:   </td>
                   1168:  </tr>
1.30      raeburn  1169: </table><br />';
                   1170:     return ($output,$rowtotal);
1.1       raeburn  1171: }
                   1172: 
1.3       raeburn  1173: sub print_login {
1.168     raeburn  1174:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1175:     my ($css_class,$datatable);
1.6       raeburn  1176:     my %choices = &login_choices();
1.110     raeburn  1177: 
1.168     raeburn  1178:     if ($caller eq 'service') {
1.149     raeburn  1179:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1180:         my $choice = $choices{'disallowlogin'};
                   1181:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1182:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1183:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1184:                       '<th>'.$choices{'server'}.'</th>'.
                   1185:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1186:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1187:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1188:         my %disallowed;
                   1189:         if (ref($settings) eq 'HASH') {
                   1190:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1191:                %disallowed = %{$settings->{'loginvia'}};
                   1192:             }
                   1193:         }
                   1194:         foreach my $lonhost (sort(keys(%servers))) {
                   1195:             my $direct = 'selected="selected"';
1.128     raeburn  1196:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1197:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1198:                     $direct = '';
                   1199:                 }
1.110     raeburn  1200:             }
1.115     raeburn  1201:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1202:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1203:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1204:                           '</option>';
1.184     raeburn  1205:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1206:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1207:                 my $selected = '';
1.128     raeburn  1208:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1209:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1210:                         $selected = 'selected="selected"';
                   1211:                     }
1.110     raeburn  1212:                 }
                   1213:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1214:                               $servers{$hostid}.'</option>';
                   1215:             }
1.128     raeburn  1216:             $datatable .= '</select></td>'.
                   1217:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1218:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1219:                 my $pathname = $path;
                   1220:                 if ($path eq 'custom') {
                   1221:                     $pathname = &mt('Custom Path').' ->';
                   1222:                 }
                   1223:                 my $selected = '';
                   1224:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1225:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1226:                         $selected = 'selected="selected"';
                   1227:                     }
                   1228:                 } elsif ($path eq '') {
                   1229:                     $selected = 'selected="selected"';
                   1230:                 }
                   1231:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1232:             }
                   1233:             $datatable .= '</select></td>';
                   1234:             my ($custom,$exempt);
                   1235:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1236:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1237:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1238:             }
                   1239:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1240:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1241:                           '</tr>';
1.110     raeburn  1242:         }
                   1243:         $datatable .= '</table></td></tr>';
                   1244:         return $datatable;
1.168     raeburn  1245:     } elsif ($caller eq 'page') {
                   1246:         my %defaultchecked = ( 
                   1247:                                'coursecatalog' => 'on',
1.188     raeburn  1248:                                'helpdesk'      => 'on',
1.168     raeburn  1249:                                'adminmail'     => 'off',
                   1250:                                'newuser'       => 'off',
                   1251:                              );
1.188     raeburn  1252:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1253:         my (%checkedon,%checkedoff);
1.42      raeburn  1254:         foreach my $item (@toggles) {
1.168     raeburn  1255:             if ($defaultchecked{$item} eq 'on') { 
                   1256:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1257:                 $checkedoff{$item} = ' ';
1.168     raeburn  1258:             } elsif ($defaultchecked{$item} eq 'off') {
                   1259:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1260:                 $checkedon{$item} = ' ';
                   1261:             }
1.1       raeburn  1262:         }
1.168     raeburn  1263:         my @images = ('img','logo','domlogo','login');
                   1264:         my @logintext = ('textcol','bgcol');
                   1265:         my @bgs = ('pgbg','mainbg','sidebg');
                   1266:         my @links = ('link','alink','vlink');
                   1267:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1268:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1269:         my (%is_custom,%designs);
                   1270:         my %defaults = (
                   1271:                        font => $defaultdesign{'login.font'},
                   1272:                        );
1.6       raeburn  1273:         foreach my $item (@images) {
1.168     raeburn  1274:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1275:             $defaults{'showlogo'}{$item} = 1;
                   1276:         }
                   1277:         foreach my $item (@bgs) {
                   1278:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1279:         }
1.41      raeburn  1280:         foreach my $item (@logintext) {
1.168     raeburn  1281:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1282:         }
1.168     raeburn  1283:         foreach my $item (@links) {
                   1284:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1285:         }
1.168     raeburn  1286:         if (ref($settings) eq 'HASH') {
                   1287:             foreach my $item (@toggles) {
                   1288:                 if ($settings->{$item} eq '1') {
                   1289:                     $checkedon{$item} =  ' checked="checked" ';
                   1290:                     $checkedoff{$item} = ' ';
                   1291:                 } elsif ($settings->{$item} eq '0') {
                   1292:                     $checkedoff{$item} =  ' checked="checked" ';
                   1293:                     $checkedon{$item} = ' ';
                   1294:                 }
                   1295:             }
                   1296:             foreach my $item (@images) {
                   1297:                 if (defined($settings->{$item})) {
                   1298:                     $designs{$item} = $settings->{$item};
                   1299:                     $is_custom{$item} = 1;
                   1300:                 }
                   1301:                 if (defined($settings->{'showlogo'}{$item})) {
                   1302:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1303:                 }
                   1304:             }
                   1305:             foreach my $item (@logintext) {
                   1306:                 if ($settings->{$item} ne '') {
                   1307:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1308:                     $is_custom{$item} = 1;
                   1309:                 }
                   1310:             }
                   1311:             if ($settings->{'font'} ne '') {
                   1312:                 $designs{'font'} = $settings->{'font'};
                   1313:                 $is_custom{'font'} = 1;
                   1314:             }
                   1315:             foreach my $item (@bgs) {
                   1316:                 if ($settings->{$item} ne '') {
                   1317:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1318:                     $is_custom{$item} = 1;
                   1319:                 }
                   1320:             }
                   1321:             foreach my $item (@links) {
                   1322:                 if ($settings->{$item} ne '') {
                   1323:                     $designs{'links'}{$item} = $settings->{$item};
                   1324:                     $is_custom{$item} = 1;
                   1325:                 }
                   1326:             }
                   1327:         } else {
                   1328:             if ($designhash{$dom.'.login.font'} ne '') {
                   1329:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1330:                 $is_custom{'font'} = 1;
                   1331:             }
                   1332:             foreach my $item (@images) {
                   1333:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1334:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1335:                     $is_custom{$item} = 1;
                   1336:                 }
                   1337:             }
                   1338:             foreach my $item (@bgs) {
                   1339:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1340:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1341:                     $is_custom{$item} = 1;
                   1342:                 }
1.6       raeburn  1343:             }
1.168     raeburn  1344:             foreach my $item (@links) {
                   1345:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1346:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1347:                     $is_custom{$item} = 1;
                   1348:                 }
1.6       raeburn  1349:             }
                   1350:         }
1.168     raeburn  1351:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1352:                                                       logo => 'Institution Logo',
                   1353:                                                       domlogo => 'Domain Logo',
                   1354:                                                       login => 'Login box');
                   1355:         my $itemcount = 1;
                   1356:         foreach my $item (@toggles) {
                   1357:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1358:             $datatable .=  
                   1359:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1360:                 '</td><td>'.
                   1361:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1362:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1363:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1364:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1365:                 '</tr>';
                   1366:             $itemcount ++;
1.6       raeburn  1367:         }
1.168     raeburn  1368:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1369:         $datatable .= '</tr></table></td></tr>';
                   1370:     } elsif ($caller eq 'help') {
                   1371:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1372:         my $switchserver = &check_switchserver($dom,$confname);
                   1373:         my $itemcount = 1;
                   1374:         $defaulturl = '/adm/loginproblems.html';
                   1375:         $defaulttype = 'default';
                   1376:         %lt = &Apache::lonlocal::texthash (
                   1377:                      del     => 'Delete?',
                   1378:                      rep     => 'Replace:',
                   1379:                      upl     => 'Upload:',
                   1380:                      default => 'Default',
                   1381:                      custom  => 'Custom',
                   1382:                                              );
                   1383:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1384:         my @currlangs;
                   1385:         if (ref($settings) eq 'HASH') {
                   1386:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1387:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1388:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1389:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1390:                     $type{$key} = 'custom';
                   1391:                     unless ($key eq 'nolang') {
                   1392:                         push(@currlangs,$key);
                   1393:                     }
                   1394:                 }
                   1395:             } elsif ($settings->{'helpurl'} ne '') {
                   1396:                 $type{'nolang'} = 'custom';
                   1397:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1398:             }
                   1399:         }
1.168     raeburn  1400:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1401:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1402:             $datatable .= '<tr'.$css_class.'>';
                   1403:             if ($url{$lang} eq '') {
                   1404:                 $url{$lang} = $defaulturl;
                   1405:             }
                   1406:             if ($type{$lang} eq '') {
                   1407:                 $type{$lang} = $defaulttype;
                   1408:             }
                   1409:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1410:             if ($lang eq 'nolang') {
                   1411:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1412:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1413:             } else {
                   1414:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1415:                                   $langchoices{$lang},
                   1416:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1417:             }
                   1418:             $datatable .= '</span></td>'."\n".
                   1419:                           '<td class="LC_left_item">';
                   1420:             if ($type{$lang} eq 'custom') {
                   1421:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1422:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1423:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1424:             } else {
                   1425:                 $datatable .= $lt{'upl'};
                   1426:             }
                   1427:             $datatable .='<br />';
                   1428:             if ($switchserver) {
                   1429:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1430:             } else {
                   1431:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1432:             }
1.168     raeburn  1433:             $datatable .= '</td></tr>';
                   1434:             $itemcount ++;
1.6       raeburn  1435:         }
1.168     raeburn  1436:         my @addlangs;
                   1437:         foreach my $lang (sort(keys(%langchoices))) {
                   1438:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1439:             push(@addlangs,$lang);
                   1440:         }
                   1441:         if (@addlangs > 0) {
                   1442:             my %toadd;
                   1443:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1444:             $toadd{''} = &mt('Select');
                   1445:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1446:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1447:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1448:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1449:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1450:             if ($switchserver) {
                   1451:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1452:             } else {
                   1453:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1454:             }
1.168     raeburn  1455:             $datatable .= '</td></tr>';
1.169     raeburn  1456:             $itemcount ++;
1.6       raeburn  1457:         }
1.169     raeburn  1458:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1459:     } elsif ($caller eq 'headtag') {
                   1460:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1461:         my $choice = $choices{'headtag'};
                   1462:         $css_class = ' class="LC_odd_row"';
                   1463:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1464:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1465:                       '<th>'.$choices{'current'}.'</th>'.
                   1466:                       '<th>'.$choices{'action'}.'</th>'.
                   1467:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1468:         my (%currurls,%currexempt);
                   1469:         if (ref($settings) eq 'HASH') {
                   1470:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1471:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1472:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1473:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1474:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1475:                     }
                   1476:                 }
                   1477:             }
                   1478:         }
                   1479:         my %lt = &Apache::lonlocal::texthash(
                   1480:                                                del  => 'Delete?',
                   1481:                                                rep  => 'Replace:',
                   1482:                                                upl  => 'Upload:',
                   1483:                                                curr => 'View contents',
                   1484:                                                none => 'None',
                   1485:         );
                   1486:         my $switchserver = &check_switchserver($dom,$confname);
                   1487:         foreach my $lonhost (sort(keys(%domservers))) {
                   1488:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1489:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1490:             if ($currurls{$lonhost}) {
                   1491:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1492:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1493:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1494:                               '">'.$lt{'curr'}.'</a></td>'.
                   1495:                               '<td><span class="LC_nobreak"><label>'.
                   1496:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1497:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1498:             } else {
                   1499:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1500:             }
                   1501:             $datatable .='<br />';
                   1502:             if ($switchserver) {
                   1503:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1504:             } else {
                   1505:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1506:             }
1.330     raeburn  1507:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1508:         }
                   1509:         $datatable .= '</table></td></tr>';
1.1       raeburn  1510:     }
1.6       raeburn  1511:     return $datatable;
                   1512: }
                   1513: 
                   1514: sub login_choices {
                   1515:     my %choices =
                   1516:         &Apache::lonlocal::texthash (
1.116     bisitz   1517:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1518:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1519:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1520:             disallowlogin => "Login page requests redirected",
                   1521:             hostid        => "Server",
1.128     raeburn  1522:             server        => "Redirect to:",
                   1523:             serverpath    => "Path",
                   1524:             custompath    => "Custom", 
                   1525:             exempt        => "Exempt IP(s)",
1.110     raeburn  1526:             directlogin   => "No redirect",
                   1527:             newuser       => "Link to create a user account",
                   1528:             img           => "Header",
                   1529:             logo          => "Main Logo",
                   1530:             domlogo       => "Domain Logo",
                   1531:             login         => "Log-in Header", 
                   1532:             textcol       => "Text color",
                   1533:             bgcol         => "Box color",
                   1534:             bgs           => "Background colors",
                   1535:             links         => "Link colors",
                   1536:             font          => "Font color",
                   1537:             pgbg          => "Header",
                   1538:             mainbg        => "Page",
                   1539:             sidebg        => "Login box",
                   1540:             link          => "Link",
                   1541:             alink         => "Active link",
                   1542:             vlink         => "Visited link",
1.256     raeburn  1543:             headtag       => "Custom markup",
                   1544:             action        => "Action",
                   1545:             current       => "Current",
1.6       raeburn  1546:         );
                   1547:     return %choices;
                   1548: }
                   1549: 
                   1550: sub print_rolecolors {
1.30      raeburn  1551:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1552:     my %choices = &color_font_choices();
                   1553:     my @bgs = ('pgbg','tabbg','sidebg');
                   1554:     my @links = ('link','alink','vlink');
                   1555:     my @images = ('img');
                   1556:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1557:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1558:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1559:     my (%is_custom,%designs);
1.200     raeburn  1560:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1561:     if (ref($settings) eq 'HASH') {
                   1562:         if (ref($settings->{$role}) eq 'HASH') {
                   1563:             if ($settings->{$role}->{'img'} ne '') {
                   1564:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1565:                 $is_custom{'img'} = 1;
                   1566:             }
                   1567:             if ($settings->{$role}->{'font'} ne '') {
                   1568:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1569:                 $is_custom{'font'} = 1;
                   1570:             }
1.97      tempelho 1571:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1572:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1573:                 $is_custom{'fontmenu'} = 1;
                   1574:             }
1.6       raeburn  1575:             foreach my $item (@bgs) {
                   1576:                 if ($settings->{$role}->{$item} ne '') {
                   1577:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1578:                     $is_custom{$item} = 1;
                   1579:                 }
                   1580:             }
                   1581:             foreach my $item (@links) {
                   1582:                 if ($settings->{$role}->{$item} ne '') {
                   1583:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1584:                     $is_custom{$item} = 1;
                   1585:                 }
                   1586:             }
                   1587:         }
                   1588:     } else {
                   1589:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1590:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1591:             $is_custom{'img'} = 1;
                   1592:         }
1.97      tempelho 1593:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1594:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1595:             $is_custom{'fontmenu'} = 1; 
                   1596:         }
1.6       raeburn  1597:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1598:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1599:             $is_custom{'font'} = 1;
                   1600:         }
                   1601:         foreach my $item (@bgs) {
                   1602:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1603:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1604:                 $is_custom{$item} = 1;
                   1605:             
                   1606:             }
                   1607:         }
                   1608:         foreach my $item (@links) {
                   1609:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1610:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1611:                 $is_custom{$item} = 1;
                   1612:             }
                   1613:         }
                   1614:     }
                   1615:     my $itemcount = 1;
1.30      raeburn  1616:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1617:     $datatable .= '</tr></table></td></tr>';
                   1618:     return $datatable;
                   1619: }
                   1620: 
1.200     raeburn  1621: sub role_defaults {
                   1622:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1623:     my %defaults;
                   1624:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1625:         return %defaults;
                   1626:     }
                   1627:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1628:     if ($role eq 'login') {
                   1629:         %defaults = (
                   1630:                        font => $defaultdesign{$role.'.font'},
                   1631:                     );
                   1632:         if (ref($logintext) eq 'ARRAY') {
                   1633:             foreach my $item (@{$logintext}) {
                   1634:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1635:             }
                   1636:         }
                   1637:         foreach my $item (@{$images}) {
                   1638:             $defaults{'showlogo'}{$item} = 1;
                   1639:         }
                   1640:     } else {
                   1641:         %defaults = (
                   1642:                        img => $defaultdesign{$role.'.img'},
                   1643:                        font => $defaultdesign{$role.'.font'},
                   1644:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1645:                     );
                   1646:     }
                   1647:     foreach my $item (@{$bgs}) {
                   1648:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1649:     }
                   1650:     foreach my $item (@{$links}) {
                   1651:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1652:     }
                   1653:     foreach my $item (@{$images}) {
                   1654:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1655:     }
                   1656:     return %defaults;
                   1657: }
                   1658: 
1.6       raeburn  1659: sub display_color_options {
1.9       raeburn  1660:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1661:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1662:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1663:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1664:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1665:         '<td>'.$choices->{'font'}.'</td>';
                   1666:     if (!$is_custom->{'font'}) {
1.329     raeburn  1667:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1668:     } else {
                   1669:         $datatable .= '<td>&nbsp;</td>';
                   1670:     }
1.174     foxr     1671:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1672: 
1.8       raeburn  1673:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1674:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1675:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  1676:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1677:     unless ($role eq 'login') { 
                   1678:         $datatable .= '<tr'.$css_class.'>'.
                   1679:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1680:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  1681:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1682:         } else {
                   1683:             $datatable .= '<td>&nbsp;</td>';
                   1684:         }
1.202     raeburn  1685: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1686: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1687:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1688:                       '<input class="colorchooser" type="text" size="10" name="'
                   1689: 		      .$role.'_fontmenu"'.
                   1690:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  1691:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1692:     }
1.9       raeburn  1693:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1694:     foreach my $img (@{$images}) {
1.18      albertel 1695: 	$itemcount ++;
1.6       raeburn  1696:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1697:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1698:                       '<td>'.$choices->{$img};
1.41      raeburn  1699:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1700:         if ($role eq 'login') {
                   1701:             if ($img eq 'login') {
                   1702:                 $login_hdr_pick =
1.135     bisitz   1703:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1704:                 $logincolors =
                   1705:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1706:                                        $designs,$defaults);
1.70      raeburn  1707:             } elsif ($img ne 'domlogo') {
                   1708:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1709:             }
                   1710:         }
                   1711:         $datatable .= '</td>';
1.6       raeburn  1712:         if ($designs->{$img} ne '') {
                   1713:             $imgfile = $designs->{$img};
1.18      albertel 1714: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1715:         } else {
                   1716:             $imgfile = $defaults->{$img};
                   1717:         }
                   1718:         if ($imgfile) {
1.9       raeburn  1719:             my ($showfile,$fullsize);
                   1720:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1721:                 my $urldir = $1;
                   1722:                 my $filename = $2;
                   1723:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1724:                 if (@info) {
                   1725:                     my $thumbfile = 'tn-'.$filename;
                   1726:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1727:                     if (@thumb) {
                   1728:                         $showfile = $urldir.'/'.$thumbfile;
                   1729:                     } else {
                   1730:                         $showfile = $imgfile;
                   1731:                     }
                   1732:                 } else {
                   1733:                     $showfile = '';
                   1734:                 }
                   1735:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1736:                 $showfile = $imgfile;
1.6       raeburn  1737:                 my $imgdir = $1;
                   1738:                 my $filename = $2;
1.159     raeburn  1739:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1740:                     $showfile = "/$imgdir/tn-".$filename;
                   1741:                 } else {
1.159     raeburn  1742:                     my $input = $londocroot.$imgfile;
                   1743:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1744:                     if (!-e $output) {
1.9       raeburn  1745:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1746:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1747:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1748:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1749:                                 my $size = $width.'x'.$height;
1.316     raeburn  1750:                                 my @args = ('convert','-sample',$size,$input,$output);
                   1751:                                 system({$args[0]} @args);
1.159     raeburn  1752:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1753:                             }
                   1754:                         }
1.6       raeburn  1755:                     }
                   1756:                 }
1.16      raeburn  1757:             }
1.6       raeburn  1758:             if ($showfile) {
1.40      raeburn  1759:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1760:                     if ($showfile =~ m{^/res/}) {
                   1761:                         my $local_showfile =
                   1762:                             &Apache::lonnet::filelocation('',$showfile);
                   1763:                         &Apache::lonnet::repcopy($local_showfile);
                   1764:                     }
                   1765:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1766:                 }
                   1767:                 if ($imgfile) {
                   1768:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1769:                         if ($imgfile =~ m{^/res/}) {
                   1770:                             my $local_imgfile =
                   1771:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1772:                             &Apache::lonnet::repcopy($local_imgfile);
                   1773:                         }
                   1774:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1775:                     } else {
                   1776:                         $fullsize = $imgfile;
                   1777:                     }
                   1778:                 }
1.41      raeburn  1779:                 $datatable .= '<td>';
                   1780:                 if ($img eq 'login') {
1.135     bisitz   1781:                     $datatable .= $login_hdr_pick;
                   1782:                 } 
1.41      raeburn  1783:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1784:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1785:             } else {
1.201     raeburn  1786:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1787:                               &mt('Upload:').'<br />';
1.6       raeburn  1788:             }
                   1789:         } else {
1.201     raeburn  1790:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1791:                           &mt('Upload:').'<br />';
1.6       raeburn  1792:         }
1.9       raeburn  1793:         if ($switchserver) {
                   1794:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1795:         } else {
1.135     bisitz   1796:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1797:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1798:             }
1.9       raeburn  1799:         }
                   1800:         $datatable .= '</td></tr>';
1.6       raeburn  1801:     }
                   1802:     $itemcount ++;
                   1803:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1804:     $datatable .= '<tr'.$css_class.'>'.
                   1805:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1806:     my $bgs_def;
                   1807:     foreach my $item (@{$bgs}) {
                   1808:         if (!$is_custom->{$item}) {
1.329     raeburn  1809:             $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  1810:         }
                   1811:     }
                   1812:     if ($bgs_def) {
1.8       raeburn  1813:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1814:     } else {
                   1815:         $datatable .= '<td>&nbsp;</td>';
                   1816:     }
                   1817:     $datatable .= '<td class="LC_right_item">'.
                   1818:                   '<table border="0"><tr>';
1.174     foxr     1819: 
1.6       raeburn  1820:     foreach my $item (@{$bgs}) {
1.306     raeburn  1821:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     1822: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1823:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1824:             $datatable .= '&nbsp;';
1.6       raeburn  1825:         }
1.174     foxr     1826:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1827:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1828:     }
                   1829:     $datatable .= '</tr></table></td></tr>';
                   1830:     $itemcount ++;
                   1831:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1832:     $datatable .= '<tr'.$css_class.'>'.
                   1833:                   '<td>'.$choices->{'links'}.'</td>';
                   1834:     my $links_def;
                   1835:     foreach my $item (@{$links}) {
                   1836:         if (!$is_custom->{$item}) {
1.329     raeburn  1837:             $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  1838:         }
                   1839:     }
                   1840:     if ($links_def) {
1.8       raeburn  1841:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1842:     } else {
                   1843:         $datatable .= '<td>&nbsp;</td>';
                   1844:     }
                   1845:     $datatable .= '<td class="LC_right_item">'.
                   1846:                   '<table border="0"><tr>';
                   1847:     foreach my $item (@{$links}) {
1.234     raeburn  1848: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  1849:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  1850:         if ($designs->{'links'}{$item}) {
1.174     foxr     1851:             $datatable.='&nbsp;';
1.6       raeburn  1852:         }
1.174     foxr     1853:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1854:                       '" /></td>';
                   1855:     }
1.30      raeburn  1856:     $$rowtotal += $itemcount;
1.3       raeburn  1857:     return $datatable;
                   1858: }
                   1859: 
1.70      raeburn  1860: sub logo_display_options {
                   1861:     my ($img,$defaults,$designs) = @_;
                   1862:     my $checkedon;
                   1863:     if (ref($defaults) eq 'HASH') {
                   1864:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1865:             if ($defaults->{'showlogo'}{$img}) {
                   1866:                 $checkedon = 'checked="checked" ';     
                   1867:             }
                   1868:         } 
                   1869:     }
                   1870:     if (ref($designs) eq 'HASH') {
                   1871:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1872:             if (defined($designs->{'showlogo'}{$img})) {
                   1873:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1874:                     $checkedon = '';
                   1875:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1876:                     $checkedon = 'checked="checked" ';
                   1877:                 }
                   1878:             }
                   1879:         }
                   1880:     }
                   1881:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1882:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1883:            &mt('show').'</label>'."\n";
                   1884: }
                   1885: 
1.41      raeburn  1886: sub login_header_options  {
1.135     bisitz   1887:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1888:     my $output = '';
1.41      raeburn  1889:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1890:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1891:         if (!$is_custom->{'textcol'}) {
                   1892:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1893:                        '&nbsp;&nbsp;&nbsp;';
                   1894:         }
                   1895:         if (!$is_custom->{'bgcol'}) {
                   1896:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1897:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1898:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1899:         }
                   1900:         $output .= '<br />';
                   1901:     }
                   1902:     $output .='<br />';
                   1903:     return $output;
                   1904: }
                   1905: 
                   1906: sub login_text_colors {
1.201     raeburn  1907:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1908:     my $color_menu = '<table border="0"><tr>';
                   1909:     foreach my $item (@{$logintext}) {
1.306     raeburn  1910:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  1911:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1912:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1913:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1914:     }
                   1915:     $color_menu .= '</tr></table><br />';
                   1916:     return $color_menu;
                   1917: }
                   1918: 
                   1919: sub image_changes {
                   1920:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1921:     my $output;
1.135     bisitz   1922:     if ($img eq 'login') {
1.331     raeburn  1923:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   1924:     } elsif (!$is_custom) {
1.70      raeburn  1925:         if ($img ne 'domlogo') {
1.331     raeburn  1926:             $output = &mt('Default image:').'<br />';
1.41      raeburn  1927:         } else {
1.331     raeburn  1928:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  1929:         }
                   1930:     }
1.331     raeburn  1931:     if ($img ne 'login') {
1.135     bisitz   1932:         if ($img_import) {
                   1933:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1934:         }
                   1935:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1936:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1937:         if ($is_custom) {
                   1938:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1939:                        '<input type="checkbox" name="'.
                   1940:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1941:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1942:         } else {
1.306     raeburn  1943:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1944:         }
1.41      raeburn  1945:     }
                   1946:     return $output;
                   1947: }
                   1948: 
1.3       raeburn  1949: sub print_quotas {
1.86      raeburn  1950:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1951:     my $context;
                   1952:     if ($action eq 'quotas') {
                   1953:         $context = 'tools';
                   1954:     } else {
                   1955:         $context = $action;
                   1956:     }
1.197     raeburn  1957:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1958:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1959:     my $typecount = 0;
1.101     raeburn  1960:     my ($css_class,%titles);
1.86      raeburn  1961:     if ($context eq 'requestcourses') {
1.325     raeburn  1962:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  1963:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1964:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1965:         %titles = &courserequest_titles();
1.163     raeburn  1966:     } elsif ($context eq 'requestauthor') {
                   1967:         @usertools = ('author');
                   1968:         @options = ('norequest','approval','automatic');
1.210     raeburn  1969:         %titles = &authorrequest_titles();
1.86      raeburn  1970:     } else {
1.162     raeburn  1971:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1972:         %titles = &tool_titles();
1.86      raeburn  1973:     }
1.26      raeburn  1974:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1975:         foreach my $type (@{$types}) {
1.197     raeburn  1976:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1977:             unless (($context eq 'requestcourses') ||
                   1978:                     ($context eq 'requestauthor')) {
1.86      raeburn  1979:                 if (ref($settings) eq 'HASH') {
                   1980:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1981:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1982:                     } else {
                   1983:                         $currdefquota = $settings->{$type};
                   1984:                     }
1.197     raeburn  1985:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1986:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1987:                     }
1.78      raeburn  1988:                 }
1.72      raeburn  1989:             }
1.3       raeburn  1990:             if (defined($usertypes->{$type})) {
                   1991:                 $typecount ++;
                   1992:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1993:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1994:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1995:                               '<td class="LC_left_item">';
1.101     raeburn  1996:                 if ($context eq 'requestcourses') {
                   1997:                     $datatable .= '<table><tr>';
                   1998:                 }
                   1999:                 my %cell;  
1.72      raeburn  2000:                 foreach my $item (@usertools) {
1.101     raeburn  2001:                     if ($context eq 'requestcourses') {
                   2002:                         my ($curroption,$currlimit);
                   2003:                         if (ref($settings) eq 'HASH') {
                   2004:                             if (ref($settings->{$item}) eq 'HASH') {
                   2005:                                 $curroption = $settings->{$item}->{$type};
                   2006:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2007:                                     $currlimit = $1; 
                   2008:                                 }
                   2009:                             }
                   2010:                         }
                   2011:                         if (!$curroption) {
                   2012:                             $curroption = 'norequest';
                   2013:                         }
                   2014:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2015:                         foreach my $option (@options) {
                   2016:                             my $val = $option;
                   2017:                             if ($option eq 'norequest') {
                   2018:                                 $val = 0;  
                   2019:                             }
                   2020:                             if ($option eq 'validate') {
                   2021:                                 my $canvalidate = 0;
                   2022:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2023:                                     if ($validations{$item}{$type}) {
                   2024:                                         $canvalidate = 1;
                   2025:                                     }
                   2026:                                 }
                   2027:                                 next if (!$canvalidate);
                   2028:                             }
                   2029:                             my $checked = '';
                   2030:                             if ($option eq $curroption) {
                   2031:                                 $checked = ' checked="checked"';
                   2032:                             } elsif ($option eq 'autolimit') {
                   2033:                                 if ($curroption =~ /^autolimit/) {
                   2034:                                     $checked = ' checked="checked"';
                   2035:                                 }                       
                   2036:                             } 
                   2037:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2038:                                   '<input type="radio" name="crsreq_'.$item.
                   2039:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2040:                                   $titles{$option}.'</label>';
1.101     raeburn  2041:                             if ($option eq 'autolimit') {
1.127     raeburn  2042:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2043:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2044:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2045:                             }
1.127     raeburn  2046:                             $cell{$item} .= '</span> ';
1.103     raeburn  2047:                             if ($option eq 'autolimit') {
1.127     raeburn  2048:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2049:                             }
1.101     raeburn  2050:                         }
1.163     raeburn  2051:                     } elsif ($context eq 'requestauthor') {
                   2052:                         my $curroption;
                   2053:                         if (ref($settings) eq 'HASH') {
                   2054:                             $curroption = $settings->{$type};
                   2055:                         }
                   2056:                         if (!$curroption) {
                   2057:                             $curroption = 'norequest';
                   2058:                         }
                   2059:                         foreach my $option (@options) {
                   2060:                             my $val = $option;
                   2061:                             if ($option eq 'norequest') {
                   2062:                                 $val = 0;
                   2063:                             }
                   2064:                             my $checked = '';
                   2065:                             if ($option eq $curroption) {
                   2066:                                 $checked = ' checked="checked"';
                   2067:                             }
                   2068:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2069:                                   '<input type="radio" name="authorreq_'.$type.
                   2070:                                   '" value="'.$val.'"'.$checked.' />'.
                   2071:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2072:                         }
1.101     raeburn  2073:                     } else {
                   2074:                         my $checked = 'checked="checked" ';
                   2075:                         if (ref($settings) eq 'HASH') {
                   2076:                             if (ref($settings->{$item}) eq 'HASH') {
                   2077:                                 if ($settings->{$item}->{$type} == 0) {
                   2078:                                     $checked = '';
                   2079:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2080:                                     $checked =  'checked="checked" ';
                   2081:                                 }
1.78      raeburn  2082:                             }
1.72      raeburn  2083:                         }
1.101     raeburn  2084:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2085:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2086:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2087:                                       '</label></span>&nbsp; ';
1.72      raeburn  2088:                     }
1.101     raeburn  2089:                 }
                   2090:                 if ($context eq 'requestcourses') {
                   2091:                     $datatable .= '</tr><tr>';
                   2092:                     foreach my $item (@usertools) {
1.106     raeburn  2093:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2094:                     }
                   2095:                     $datatable .= '</tr></table>';
1.72      raeburn  2096:                 }
1.86      raeburn  2097:                 $datatable .= '</td>';
1.163     raeburn  2098:                 unless (($context eq 'requestcourses') ||
                   2099:                         ($context eq 'requestauthor')) {
1.86      raeburn  2100:                     $datatable .= 
1.197     raeburn  2101:                               '<td class="LC_right_item">'.
                   2102:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2103:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2104:                               '" value="'.$currdefquota.
1.197     raeburn  2105:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2106:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2107:                               '<input type="text" name="authorquota_'.$type.
                   2108:                               '" value="'.$currauthorquota.
                   2109:                               '" size="5" /></span></td>';
1.86      raeburn  2110:                 }
                   2111:                 $datatable .= '</tr>';
1.3       raeburn  2112:             }
                   2113:         }
                   2114:     }
1.163     raeburn  2115:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2116:         $defaultquota = '20';
1.197     raeburn  2117:         $authorquota = '500';
1.86      raeburn  2118:         if (ref($settings) eq 'HASH') {
                   2119:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2120:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2121:             } elsif (defined($settings->{'default'})) {
                   2122:                 $defaultquota = $settings->{'default'};
                   2123:             }
1.197     raeburn  2124:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2125:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2126:             }
1.3       raeburn  2127:         }
                   2128:     }
                   2129:     $typecount ++;
                   2130:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2131:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2132:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2133:                   '<td class="LC_left_item">';
1.101     raeburn  2134:     if ($context eq 'requestcourses') {
                   2135:         $datatable .= '<table><tr>';
                   2136:     }
                   2137:     my %defcell;
1.72      raeburn  2138:     foreach my $item (@usertools) {
1.101     raeburn  2139:         if ($context eq 'requestcourses') {
                   2140:             my ($curroption,$currlimit);
                   2141:             if (ref($settings) eq 'HASH') {
                   2142:                 if (ref($settings->{$item}) eq 'HASH') {
                   2143:                     $curroption = $settings->{$item}->{'default'};
                   2144:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2145:                         $currlimit = $1;
                   2146:                     }
                   2147:                 }
                   2148:             }
                   2149:             if (!$curroption) {
                   2150:                 $curroption = 'norequest';
                   2151:             }
                   2152:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2153:             foreach my $option (@options) {
                   2154:                 my $val = $option;
                   2155:                 if ($option eq 'norequest') {
                   2156:                     $val = 0;
                   2157:                 }
                   2158:                 if ($option eq 'validate') {
                   2159:                     my $canvalidate = 0;
                   2160:                     if (ref($validations{$item}) eq 'HASH') {
                   2161:                         if ($validations{$item}{'default'}) {
                   2162:                             $canvalidate = 1;
                   2163:                         }
                   2164:                     }
                   2165:                     next if (!$canvalidate);
                   2166:                 }
                   2167:                 my $checked = '';
                   2168:                 if ($option eq $curroption) {
                   2169:                     $checked = ' checked="checked"';
                   2170:                 } elsif ($option eq 'autolimit') {
                   2171:                     if ($curroption =~ /^autolimit/) {
                   2172:                         $checked = ' checked="checked"';
                   2173:                     }
                   2174:                 }
                   2175:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2176:                                   '<input type="radio" name="crsreq_'.$item.
                   2177:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2178:                                   $titles{$option}.'</label>';
                   2179:                 if ($option eq 'autolimit') {
1.127     raeburn  2180:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2181:                                        $item.'_limit_default" size="1" '.
                   2182:                                        'value="'.$currlimit.'" />';
                   2183:                 }
1.127     raeburn  2184:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2185:                 if ($option eq 'autolimit') {
1.127     raeburn  2186:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2187:                 }
1.101     raeburn  2188:             }
1.163     raeburn  2189:         } elsif ($context eq 'requestauthor') {
                   2190:             my $curroption;
                   2191:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2192:                 $curroption = $settings->{'default'};
1.163     raeburn  2193:             }
                   2194:             if (!$curroption) {
                   2195:                 $curroption = 'norequest';
                   2196:             }
                   2197:             foreach my $option (@options) {
                   2198:                 my $val = $option;
                   2199:                 if ($option eq 'norequest') {
                   2200:                     $val = 0;
                   2201:                 }
                   2202:                 my $checked = '';
                   2203:                 if ($option eq $curroption) {
                   2204:                     $checked = ' checked="checked"';
                   2205:                 }
                   2206:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2207:                               '<input type="radio" name="authorreq_default"'.
                   2208:                               ' value="'.$val.'"'.$checked.' />'.
                   2209:                               $titles{$option}.'</label></span>&nbsp; ';
                   2210:             }
1.101     raeburn  2211:         } else {
                   2212:             my $checked = 'checked="checked" ';
                   2213:             if (ref($settings) eq 'HASH') {
                   2214:                 if (ref($settings->{$item}) eq 'HASH') {
                   2215:                     if ($settings->{$item}->{'default'} == 0) {
                   2216:                         $checked = '';
                   2217:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2218:                         $checked = 'checked="checked" ';
                   2219:                     }
1.78      raeburn  2220:                 }
1.72      raeburn  2221:             }
1.101     raeburn  2222:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2223:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2224:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2225:                           '</label></span>&nbsp; ';
                   2226:         }
                   2227:     }
                   2228:     if ($context eq 'requestcourses') {
                   2229:         $datatable .= '</tr><tr>';
                   2230:         foreach my $item (@usertools) {
1.106     raeburn  2231:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2232:         }
1.101     raeburn  2233:         $datatable .= '</tr></table>';
1.72      raeburn  2234:     }
1.86      raeburn  2235:     $datatable .= '</td>';
1.163     raeburn  2236:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2237:         $datatable .= '<td class="LC_right_item">'.
                   2238:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2239:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2240:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2241:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2242:                       '<input type="text" name="authorquota" value="'.
                   2243:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2244:     }
                   2245:     $datatable .= '</tr>';
1.72      raeburn  2246:     $typecount ++;
                   2247:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2248:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2249:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2250:     if ($context eq 'requestcourses') {
1.109     raeburn  2251:         $datatable .= &mt('(overrides affiliation, if set)').
                   2252:                       '</td>'.
                   2253:                       '<td class="LC_left_item">'.
                   2254:                       '<table><tr>';
1.101     raeburn  2255:     } else {
1.109     raeburn  2256:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2257:                       '</td>'.
                   2258:                       '<td class="LC_left_item" colspan="2">'.
                   2259:                       '<br />';
1.101     raeburn  2260:     }
                   2261:     my %advcell;
1.72      raeburn  2262:     foreach my $item (@usertools) {
1.101     raeburn  2263:         if ($context eq 'requestcourses') {
                   2264:             my ($curroption,$currlimit);
                   2265:             if (ref($settings) eq 'HASH') {
                   2266:                 if (ref($settings->{$item}) eq 'HASH') {
                   2267:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2268:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2269:                         $currlimit = $1;
                   2270:                     }
                   2271:                 }
                   2272:             }
                   2273:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2274:             my $checked = '';
                   2275:             if ($curroption eq '') {
                   2276:                 $checked = ' checked="checked"';
                   2277:             }
                   2278:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2279:                                '<input type="radio" name="crsreq_'.$item.
                   2280:                                '__LC_adv" value=""'.$checked.' />'.
                   2281:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2282:             foreach my $option (@options) {
                   2283:                 my $val = $option;
                   2284:                 if ($option eq 'norequest') {
                   2285:                     $val = 0;
                   2286:                 }
                   2287:                 if ($option eq 'validate') {
                   2288:                     my $canvalidate = 0;
                   2289:                     if (ref($validations{$item}) eq 'HASH') {
                   2290:                         if ($validations{$item}{'_LC_adv'}) {
                   2291:                             $canvalidate = 1;
                   2292:                         }
                   2293:                     }
                   2294:                     next if (!$canvalidate);
                   2295:                 }
                   2296:                 my $checked = '';
1.104     raeburn  2297:                 if ($val eq $curroption) {
1.101     raeburn  2298:                     $checked = ' checked="checked"';
                   2299:                 } elsif ($option eq 'autolimit') {
                   2300:                     if ($curroption =~ /^autolimit/) {
                   2301:                         $checked = ' checked="checked"';
                   2302:                     }
                   2303:                 }
                   2304:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2305:                                   '<input type="radio" name="crsreq_'.$item.
                   2306:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2307:                                   $titles{$option}.'</label>';
                   2308:                 if ($option eq 'autolimit') {
1.127     raeburn  2309:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2310:                                        $item.'_limit__LC_adv" size="1" '.
                   2311:                                        'value="'.$currlimit.'" />';
                   2312:                 }
1.127     raeburn  2313:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2314:                 if ($option eq 'autolimit') {
1.127     raeburn  2315:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2316:                 }
1.101     raeburn  2317:             }
1.163     raeburn  2318:         } elsif ($context eq 'requestauthor') {
                   2319:             my $curroption;
                   2320:             if (ref($settings) eq 'HASH') {
                   2321:                 $curroption = $settings->{'_LC_adv'};
                   2322:             }
                   2323:             my $checked = '';
                   2324:             if ($curroption eq '') {
                   2325:                 $checked = ' checked="checked"';
                   2326:             }
                   2327:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2328:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2329:                           ' value=""'.$checked.' />'.
                   2330:                           &mt('No override set').'</label></span>&nbsp; ';
                   2331:             foreach my $option (@options) {
                   2332:                 my $val = $option;
                   2333:                 if ($option eq 'norequest') {
                   2334:                     $val = 0;
                   2335:                 }
                   2336:                 my $checked = '';
                   2337:                 if ($val eq $curroption) {
                   2338:                     $checked = ' checked="checked"';
                   2339:                 }
                   2340:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2341:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2342:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2343:                               $titles{$option}.'</label></span>&nbsp; ';
                   2344:             }
1.101     raeburn  2345:         } else {
                   2346:             my $checked = 'checked="checked" ';
                   2347:             if (ref($settings) eq 'HASH') {
                   2348:                 if (ref($settings->{$item}) eq 'HASH') {
                   2349:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2350:                         $checked = '';
                   2351:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2352:                         $checked = 'checked="checked" ';
                   2353:                     }
1.79      raeburn  2354:                 }
1.72      raeburn  2355:             }
1.101     raeburn  2356:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2357:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2358:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2359:                           '</label></span>&nbsp; ';
                   2360:         }
                   2361:     }
                   2362:     if ($context eq 'requestcourses') {
                   2363:         $datatable .= '</tr><tr>';
                   2364:         foreach my $item (@usertools) {
1.106     raeburn  2365:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2366:         }
1.101     raeburn  2367:         $datatable .= '</tr></table>';
1.72      raeburn  2368:     }
1.98      raeburn  2369:     $datatable .= '</td></tr>';
1.30      raeburn  2370:     $$rowtotal += $typecount;
1.3       raeburn  2371:     return $datatable;
                   2372: }
                   2373: 
1.163     raeburn  2374: sub print_requestmail {
1.305     raeburn  2375:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2376:     my ($now,$datatable,%currapp);
1.102     raeburn  2377:     $now = time;
                   2378:     if (ref($settings) eq 'HASH') {
                   2379:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2380:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2381:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2382:             }
                   2383:         }
                   2384:     }
1.191     raeburn  2385:     my $numinrow = 2;
1.224     raeburn  2386:     my $css_class;
1.305     raeburn  2387:     if ($$rowtotal%2) {
                   2388:         $css_class = 'LC_odd_row';
                   2389:     }
                   2390:     if ($customcss) {
                   2391:         $css_class .= " $customcss";
                   2392:     }
                   2393:     $css_class =~ s/^\s+//;
                   2394:     if ($css_class) {
                   2395:         $css_class = ' class="'.$css_class.'"';
                   2396:     }
                   2397:     if ($rowstyle) {
                   2398:         $css_class .= ' style="'.$rowstyle.'"';
                   2399:     }
1.163     raeburn  2400:     my $text;
                   2401:     if ($action eq 'requestcourses') {
                   2402:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2403:     } elsif ($action eq 'requestauthor') {
                   2404:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2405:     } else {
1.224     raeburn  2406:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2407:     }
1.224     raeburn  2408:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2409:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2410:                  ' <td class="LC_left_item">';
1.191     raeburn  2411:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2412:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2413:     if ($numdc > 0) {
                   2414:         $datatable .= $table;
1.102     raeburn  2415:     } else {
                   2416:         $datatable .= &mt('There are no active Domain Coordinators');
                   2417:     }
                   2418:     $datatable .='</td></tr>';
                   2419:     return $datatable;
                   2420: }
                   2421: 
1.216     raeburn  2422: sub print_studentcode {
                   2423:     my ($settings,$rowtotal) = @_;
                   2424:     my $rownum = 0; 
1.218     raeburn  2425:     my ($output,%current);
1.325     raeburn  2426:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2427:     if (ref($settings) eq 'HASH') {
                   2428:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2429:             foreach my $type (@crstypes) {
                   2430:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2431:             }
1.218     raeburn  2432:         }
                   2433:     }
                   2434:     $output .= '<tr>'.
                   2435:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2436:                '<td class="LC_left_item">';
                   2437:     foreach my $type (@crstypes) {
                   2438:         my $check = ' ';
                   2439:         if ($current{$type}) {
                   2440:             $check = ' checked="checked" ';
                   2441:         }
                   2442:         $output .= '<span class="LC_nobreak"><label>'.
                   2443:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2444:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2445:     }
                   2446:     $output .= '</td></tr>';
                   2447:     $$rowtotal ++;
                   2448:     return $output;
1.216     raeburn  2449: }
                   2450: 
                   2451: sub print_textbookcourses {
1.242     raeburn  2452:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2453:     my $rownum = 0;
                   2454:     my $css_class;
                   2455:     my $itemcount = 1;
                   2456:     my $maxnum = 0;
                   2457:     my $bookshash;
                   2458:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2459:         $bookshash = $settings->{$type};
1.216     raeburn  2460:     }
                   2461:     my %ordered;
                   2462:     if (ref($bookshash) eq 'HASH') {
                   2463:         foreach my $item (keys(%{$bookshash})) {
                   2464:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2465:                 my $num = $bookshash->{$item}{'order'};
                   2466:                 $ordered{$num} = $item;
                   2467:             }
                   2468:         }
                   2469:     }
                   2470:     my $confname = $dom.'-domainconfig';
                   2471:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2472:     my $maxnum = scalar(keys(%ordered));
                   2473:     my $datatable;
1.216     raeburn  2474:     if (keys(%ordered)) {
                   2475:         my @items = sort { $a <=> $b } keys(%ordered);
                   2476:         for (my $i=0; $i<@items; $i++) {
                   2477:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2478:             my $key = $ordered{$items[$i]};
                   2479:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2480:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2481:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2482:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2483:                 $subject = $bookshash->{$key}->{'subject'};
                   2484:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2485:                 if ($type eq 'textbooks') {
1.243     raeburn  2486:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2487:                     $author = $bookshash->{$key}->{'author'};
                   2488:                     $image = $bookshash->{$key}->{'image'};
                   2489:                     if ($image ne '') {
                   2490:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2491:                         my $imagethumb = "$path/tn-".$imagefile;
                   2492:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2493:                     }
1.216     raeburn  2494:                 }
                   2495:             }
1.242     raeburn  2496:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2497:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2498:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2499:             for (my $k=0; $k<=$maxnum; $k++) {
                   2500:                 my $vpos = $k+1;
                   2501:                 my $selstr;
                   2502:                 if ($k == $i) {
                   2503:                     $selstr = ' selected="selected" ';
                   2504:                 }
                   2505:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2506:             }
                   2507:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2508:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2509:                 &mt('Delete?').'</label></span></td>'.
                   2510:                 '<td colspan="2">'.
1.242     raeburn  2511:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2512:                 ('&nbsp;'x2).
1.242     raeburn  2513:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2514:             if ($type eq 'textbooks') {
                   2515:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2516:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2517:                               ('&nbsp;'x2).
1.242     raeburn  2518:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2519:                               ('&nbsp;'x2).
                   2520:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2521:                 if ($image) {
1.267     raeburn  2522:                     $datatable .= $imgsrc.
1.242     raeburn  2523:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2524:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2525:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2526:                 }
                   2527:                 if ($switchserver) {
                   2528:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2529:                 } else {
                   2530:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2531:                 }
1.216     raeburn  2532:             }
1.242     raeburn  2533:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2534:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2535:                           $coursetitle.'</span></td></tr>'."\n";
                   2536:             $itemcount ++;
                   2537:         }
                   2538:     }
                   2539:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2540:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2541:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2542:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2543:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2544:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2545:         my $vpos = $k+1;
                   2546:         my $selstr;
                   2547:         if ($k == $maxnum) {
                   2548:             $selstr = ' selected="selected" ';
                   2549:         }
                   2550:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2551:     }
                   2552:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2553:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2554:                   '<td colspan="2">'.
1.242     raeburn  2555:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2556:                   ('&nbsp;'x2).
1.242     raeburn  2557:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2558:                   ('&nbsp;'x2);
                   2559:     if ($type eq 'textbooks') {
1.243     raeburn  2560:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2561:                       ('&nbsp;'x2).
                   2562:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2563:                       ('&nbsp;'x2).
                   2564:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2565:         if ($switchserver) {
                   2566:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2567:         } else {
                   2568:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2569:         }
1.334     raeburn  2570:         $datatable .= '</span>'."\n";
1.216     raeburn  2571:     }
1.334     raeburn  2572:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2573:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2574:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2575:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2576:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2577:                   '</span></td>'."\n".
                   2578:                   '</tr>'."\n";
                   2579:     $itemcount ++;
                   2580:     return $datatable;
                   2581: }
                   2582: 
1.217     raeburn  2583: sub textbookcourses_javascript {
1.242     raeburn  2584:     my ($settings) = @_;
                   2585:     return unless(ref($settings) eq 'HASH');
                   2586:     my (%ordered,%total,%jstext);
                   2587:     foreach my $type ('textbooks','templates') {
                   2588:         $total{$type} = 0;
                   2589:         if (ref($settings->{$type}) eq 'HASH') {
                   2590:             foreach my $item (keys(%{$settings->{$type}})) {
                   2591:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2592:                     my $num = $settings->{$type}->{$item}{'order'};
                   2593:                     $ordered{$type}{$num} = $item;
                   2594:                 }
                   2595:             }
                   2596:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2597:         }
                   2598:         my @jsarray = ();
                   2599:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2600:             push(@jsarray,$ordered{$type}{$item});
                   2601:         }
                   2602:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2603:     }
                   2604:     return <<"ENDSCRIPT";
                   2605: <script type="text/javascript">
                   2606: // <![CDATA[
1.242     raeburn  2607: function reorderBooks(form,item,caller) {
1.217     raeburn  2608:     var changedVal;
1.242     raeburn  2609: $jstext{'textbooks'};
                   2610: $jstext{'templates'};
                   2611:     var newpos;
                   2612:     var maxh;
                   2613:     if (caller == 'textbooks') {  
                   2614:         newpos = 'textbooks_addbook_pos';
                   2615:         maxh = 1 + $total{'textbooks'};
                   2616:     } else {
                   2617:         newpos = 'templates_addbook_pos';
                   2618:         maxh = 1 + $total{'templates'};
                   2619:     }
1.217     raeburn  2620:     var current = new Array;
                   2621:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2622:     if (item == newpos) {
                   2623:         changedVal = newitemVal;
                   2624:     } else {
                   2625:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2626:         current[newitemVal] = newpos;
                   2627:     }
1.242     raeburn  2628:     if (caller == 'textbooks') {
                   2629:         for (var i=0; i<textbooks.length; i++) {
                   2630:             var elementName = 'textbooks_'+textbooks[i];
                   2631:             if (elementName != item) {
                   2632:                 if (form.elements[elementName]) {
                   2633:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2634:                     current[currVal] = elementName;
                   2635:                 }
                   2636:             }
                   2637:         }
                   2638:     }
                   2639:     if (caller == 'templates') {
                   2640:         for (var i=0; i<templates.length; i++) {
                   2641:             var elementName = 'templates_'+templates[i];
                   2642:             if (elementName != item) {
                   2643:                 if (form.elements[elementName]) {
                   2644:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2645:                     current[currVal] = elementName;
                   2646:                 }
1.217     raeburn  2647:             }
                   2648:         }
                   2649:     }
                   2650:     var oldVal;
                   2651:     for (var j=0; j<maxh; j++) {
                   2652:         if (current[j] == undefined) {
                   2653:             oldVal = j;
                   2654:         }
                   2655:     }
                   2656:     if (oldVal < changedVal) {
                   2657:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2658:            var elementName = current[k];
                   2659:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2660:         }
                   2661:     } else {
                   2662:         for (var k=changedVal; k<oldVal; k++) {
                   2663:             var elementName = current[k];
                   2664:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2665:         }
                   2666:     }
                   2667:     return;
                   2668: }
                   2669: 
                   2670: // ]]>
                   2671: </script>
                   2672: 
                   2673: ENDSCRIPT
                   2674: }
                   2675: 
1.267     raeburn  2676: sub ltitools_javascript {
                   2677:     my ($settings) = @_;
1.319     raeburn  2678:     my $togglejs = &ltitools_toggle_js();
                   2679:     unless (ref($settings) eq 'HASH') {
                   2680:         return $togglejs;
                   2681:     }
1.267     raeburn  2682:     my (%ordered,$total,%jstext);
                   2683:     $total = 0;
                   2684:     foreach my $item (keys(%{$settings})) {
                   2685:         if (ref($settings->{$item}) eq 'HASH') {
                   2686:             my $num = $settings->{$item}{'order'};
                   2687:             $ordered{$num} = $item;
                   2688:         }
                   2689:     }
                   2690:     $total = scalar(keys(%{$settings}));
                   2691:     my @jsarray = ();
                   2692:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2693:         push(@jsarray,$ordered{$item});
                   2694:     }
                   2695:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2696:     return <<"ENDSCRIPT";
                   2697: <script type="text/javascript">
                   2698: // <![CDATA[
1.319     raeburn  2699: function reorderLTITools(form,item) {
1.267     raeburn  2700:     var changedVal;
                   2701: $jstext
                   2702:     var newpos = 'ltitools_add_pos';
                   2703:     var maxh = 1 + $total;
                   2704:     var current = new Array;
                   2705:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2706:     if (item == newpos) {
                   2707:         changedVal = newitemVal;
                   2708:     } else {
                   2709:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2710:         current[newitemVal] = newpos;
                   2711:     }
                   2712:     for (var i=0; i<ltitools.length; i++) {
                   2713:         var elementName = 'ltitools_'+ltitools[i];
                   2714:         if (elementName != item) {
                   2715:             if (form.elements[elementName]) {
                   2716:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2717:                 current[currVal] = elementName;
                   2718:             }
                   2719:         }
                   2720:     }
                   2721:     var oldVal;
                   2722:     for (var j=0; j<maxh; j++) {
                   2723:         if (current[j] == undefined) {
                   2724:             oldVal = j;
                   2725:         }
                   2726:     }
                   2727:     if (oldVal < changedVal) {
                   2728:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2729:            var elementName = current[k];
                   2730:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2731:         }
                   2732:     } else {
                   2733:         for (var k=changedVal; k<oldVal; k++) {
                   2734:             var elementName = current[k];
                   2735:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2736:         }
                   2737:     }
                   2738:     return;
                   2739: }
                   2740: 
                   2741: // ]]>
                   2742: </script>
                   2743: 
1.319     raeburn  2744: $togglejs
                   2745: 
                   2746: ENDSCRIPT
                   2747: }
                   2748: 
                   2749: sub ltitools_toggle_js {
                   2750:     return <<"ENDSCRIPT";
                   2751: <script type="text/javascript">
                   2752: // <![CDATA[
                   2753: 
                   2754: function toggleLTITools(form,setting,item) {
                   2755:     var radioname = '';
                   2756:     var divid = '';
                   2757:     if ((setting == 'passback') || (setting == 'roster')) {
                   2758:         radioname = 'ltitools_'+setting+'_'+item;
                   2759:         divid = 'ltitools_'+setting+'time_'+item;
                   2760:         var num = form.elements[radioname].length;
                   2761:         if (num) {
                   2762:             var setvis = '';
                   2763:             for (var i=0; i<num; i++) {
                   2764:                 if (form.elements[radioname][i].checked) {
                   2765:                     if (form.elements[radioname][i].value == '1') {
                   2766:                         if (document.getElementById(divid)) {
                   2767:                             document.getElementById(divid).style.display = 'inline-block';
                   2768:                         }
                   2769:                         setvis = 1;
                   2770:                     }
                   2771:                     break;
                   2772:                 }
                   2773:             }
                   2774:         }
                   2775:         if (!setvis) {
                   2776:             if (document.getElementById(divid)) {
                   2777:                 document.getElementById(divid).style.display = 'none';
                   2778:             }
                   2779:         }
                   2780:     }
1.324     raeburn  2781:     if (setting == 'user') {
                   2782:         divid = 'ltitools_'+setting+'_div_'+item;
                   2783:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   2784:         if (document.getElementById(divid)) {
                   2785:             if (document.getElementById(checkid)) {
                   2786:                 if (document.getElementById(checkid).checked) {
                   2787:                     document.getElementById(divid).style.display = 'inline-block';
                   2788:                 } else {
                   2789:                     document.getElementById(divid).style.display = 'none';
                   2790:                 }
                   2791:             }
                   2792:         }
                   2793:     }
1.319     raeburn  2794:     return;
                   2795: }
                   2796: // ]]>
                   2797: </script>
                   2798: 
1.267     raeburn  2799: ENDSCRIPT
                   2800: }
                   2801: 
1.320     raeburn  2802: sub lti_javascript {
                   2803:     my ($settings) = @_;
                   2804:     my $togglejs = &lti_toggle_js();
                   2805:     unless (ref($settings) eq 'HASH') {
                   2806:         return $togglejs;
                   2807:     }
                   2808:     my (%ordered,$total,%jstext);
                   2809:     $total = 0;
                   2810:     foreach my $item (keys(%{$settings})) {
                   2811:         if (ref($settings->{$item}) eq 'HASH') {
                   2812:             my $num = $settings->{$item}{'order'};
                   2813:             $ordered{$num} = $item;
                   2814:         }
                   2815:     }
                   2816:     $total = scalar(keys(%{$settings}));
                   2817:     my @jsarray = ();
                   2818:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2819:         push(@jsarray,$ordered{$item});
                   2820:     }
                   2821:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2822:     return <<"ENDSCRIPT";
                   2823: <script type="text/javascript">
                   2824: // <![CDATA[
                   2825: function reorderLTI(form,item) {
                   2826:     var changedVal;
                   2827: $jstext
                   2828:     var newpos = 'lti_pos_add';
                   2829:     var maxh = 1 + $total;
                   2830:     var current = new Array;
                   2831:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2832:     if (item == newpos) {
                   2833:         changedVal = newitemVal;
                   2834:     } else {
                   2835:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2836:         current[newitemVal] = newpos;
                   2837:     }
                   2838:     for (var i=0; i<lti.length; i++) {
                   2839:         var elementName = 'lti_pos_'+lti[i];
                   2840:         if (elementName != item) {
                   2841:             if (form.elements[elementName]) {
                   2842:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2843:                 current[currVal] = elementName;
                   2844:             }
                   2845:         }
                   2846:     }
                   2847:     var oldVal;
                   2848:     for (var j=0; j<maxh; j++) {
                   2849:         if (current[j] == undefined) {
                   2850:             oldVal = j;
                   2851:         }
                   2852:     }
                   2853:     if (oldVal < changedVal) {
                   2854:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2855:            var elementName = current[k];
                   2856:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2857:         }
                   2858:     } else {
                   2859:         for (var k=changedVal; k<oldVal; k++) {
                   2860:             var elementName = current[k];
                   2861:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2862:         }
                   2863:     }
                   2864:     return;
                   2865: }
                   2866: // ]]>
                   2867: </script>
                   2868: 
                   2869: $togglejs
                   2870: 
                   2871: ENDSCRIPT
                   2872: }
                   2873: 
                   2874: sub lti_toggle_js {
1.325     raeburn  2875:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   2876:                             localauth => 'Local auth argument',
                   2877:                             krb       => 'Kerberos domain',
                   2878:                          );
1.320     raeburn  2879:     return <<"ENDSCRIPT";
                   2880: <script type="text/javascript">
                   2881: // <![CDATA[
                   2882: 
                   2883: function toggleLTI(form,setting,item) {
1.345     raeburn  2884:     if (setting == 'requser') {
                   2885:         var fieldsets = document.getElementsByClassName('ltioption_'+item);
                   2886:         if (fieldsets.length) {
                   2887:             var radioname = 'lti_'+setting+'_'+item;
                   2888:             var num = form.elements[radioname].length;
                   2889:             if (num) {
                   2890:                 var setvis = '';
                   2891:                 for (var i=0; i<num; i++) {
                   2892:                     if (form.elements[radioname][i].checked) {
                   2893:                         if (form.elements[radioname][i].value == '1') {
                   2894:                            setvis = 1;
                   2895:                            break;
                   2896:                         }
                   2897:                     }
                   2898:                 }
1.352     raeburn  2899:                 for (var j=0; j<fieldsets.length; j++) {
1.345     raeburn  2900:                     if (setvis) {
                   2901:                         fieldsets[j].style.display = 'block';
                   2902:                     } else {
                   2903:                         fieldsets[j].style.display = 'none';
                   2904:                     }
                   2905:                 }
                   2906:             }
                   2907:         }
                   2908:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback')) {
1.320     raeburn  2909:         var radioname = '';
                   2910:         var divid = '';
                   2911:         if (setting == 'user') {
                   2912:             radioname = 'lti_mapuser_'+item;
                   2913:             divid = 'lti_userfield_'+item;
1.343     raeburn  2914:         } else if (setting == 'crs') {
1.320     raeburn  2915:             radioname = 'lti_mapcrs_'+item;
                   2916:             divid = 'lti_crsfield_'+item;
1.337     raeburn  2917:         } else {
1.351     raeburn  2918:             radioname = 'lti_passback_'+item;
1.337     raeburn  2919:             divid =  'lti_passback_'+item;
1.320     raeburn  2920:         }
                   2921:         var num = form.elements[radioname].length;
                   2922:         if (num) {
                   2923:             var setvis = '';
                   2924:             for (var i=0; i<num; i++) {
                   2925:                if (form.elements[radioname][i].checked) {
1.337     raeburn  2926:                    if (setting == 'passback') {
                   2927:                        if (form.elements[radioname][i].value == '1') {
                   2928:                            if (document.getElementById(divid)) {
                   2929:                                document.getElementById(divid).style.display = 'inline-block';
                   2930:                            }
                   2931:                            setvis = 1;
                   2932:                            break;
                   2933:                        }
                   2934:                    } else {
                   2935:                        if (form.elements[radioname][i].value == 'other') {
                   2936:                            if (document.getElementById(divid)) {
                   2937:                                document.getElementById(divid).style.display = 'inline-block';
                   2938:                            }
                   2939:                            setvis = 1;
                   2940:                            break;
1.320     raeburn  2941:                        }
                   2942:                    }
                   2943:                } 
                   2944:             }
                   2945:             if (!setvis) {
                   2946:                 if (document.getElementById(divid)) {
                   2947:                     document.getElementById(divid).style.display = 'none';
                   2948:                 }
                   2949:             }
                   2950:         }
                   2951:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   2952:         var numsec = form.elements['lti_crssec_'+item].length;
                   2953:         if (numsec) {
                   2954:             var setvis = '';
                   2955:             for (var i=0; i<numsec; i++) {
                   2956:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   2957:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   2958:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   2959:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   2960:                             setvis = 1;
                   2961:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   2962:                             if (numsrcsec) {
                   2963:                                 var setsrcvis = '';
                   2964:                                 for (var j=0; j<numsrcsec; j++) {
                   2965:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   2966:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   2967:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   2968:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   2969:                                                 setsrcvis = 1;
                   2970:                                             }
                   2971:                                         }
                   2972:                                     }
                   2973:                                 }
                   2974:                                 if (!setsrcvis) {
                   2975:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   2976:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   2977:                                     }
                   2978:                                 }
                   2979:                             }
                   2980:                         }
                   2981:                     }
                   2982:                 }
                   2983:             }
                   2984:             if (!setvis) {
                   2985:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   2986:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   2987:                 }
                   2988:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   2989:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   2990:                 }
                   2991:             }
                   2992:         }
1.325     raeburn  2993:     } else if (setting == 'lcauth') {
                   2994:         var numauth = form.elements['lti_lcauth_'+item].length;
                   2995:         if (numauth) {
                   2996:             for (var i=0; i<numauth; i++) {
                   2997:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   2998:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   2999:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3000:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3001:                         } else {
                   3002:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3003:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3004:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3005:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3006:                                 } else {
                   3007:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3008:                                 }
                   3009:                             }
                   3010:                         }
                   3011:                     }
                   3012:                 }
                   3013:             }
                   3014:         }
1.326     raeburn  3015:     } else if (setting == 'lcmenu') {
                   3016:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3017:         var divid = 'lti_menufield_'+item;
                   3018:         var setvis = '';
                   3019:         for (var i=0; i<menus.length; i++) {
                   3020:             var radioname = menus[i];  
                   3021:             var num = form.elements[radioname].length;
                   3022:             if (num) {
                   3023:                 for (var j=0; j<num; j++) {
                   3024:                     if (form.elements[radioname][j].checked) {
                   3025:                         if (form.elements[radioname][j].value == '1') {
                   3026:                             if (document.getElementById(divid)) {
                   3027:                                 document.getElementById(divid).style.display = 'inline-block';
                   3028:                             }
                   3029:                             setvis = 1;
                   3030:                             break;
                   3031:                         }
                   3032:                     }
                   3033:                 }
                   3034:             }
                   3035:             if (setvis == 1) {
                   3036:                 break;
                   3037:             }
                   3038:         }
                   3039:         if (!setvis) {
                   3040:             if (document.getElementById(divid)) {
                   3041:                 document.getElementById(divid).style.display = 'none';
                   3042:             }
                   3043:         }
1.320     raeburn  3044:     }
                   3045:     return;
                   3046: }
                   3047: // ]]>
                   3048: </script>
                   3049: 
                   3050: ENDSCRIPT
                   3051: }
                   3052: 
1.3       raeburn  3053: sub print_autoenroll {
1.30      raeburn  3054:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3055:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274     raeburn  3056:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  3057:     if (ref($settings) eq 'HASH') {
                   3058:         if (exists($settings->{'run'})) {
                   3059:             if ($settings->{'run'} eq '0') {
                   3060:                 $runoff = ' checked="checked" ';
                   3061:                 $runon = ' ';
                   3062:             } else {
                   3063:                 $runon = ' checked="checked" ';
                   3064:                 $runoff = ' ';
                   3065:             }
                   3066:         } else {
                   3067:             if ($autorun) {
                   3068:                 $runon = ' checked="checked" ';
                   3069:                 $runoff = ' ';
                   3070:             } else {
                   3071:                 $runoff = ' checked="checked" ';
                   3072:                 $runon = ' ';
                   3073:             }
                   3074:         }
1.129     raeburn  3075:         if (exists($settings->{'co-owners'})) {
                   3076:             if ($settings->{'co-owners'} eq '0') {
                   3077:                 $coownersoff = ' checked="checked" ';
                   3078:                 $coownerson = ' ';
                   3079:             } else {
                   3080:                 $coownerson = ' checked="checked" ';
                   3081:                 $coownersoff = ' ';
                   3082:             }
                   3083:         } else {
                   3084:             $coownersoff = ' checked="checked" ';
                   3085:             $coownerson = ' ';
                   3086:         }
1.3       raeburn  3087:         if (exists($settings->{'sender_domain'})) {
                   3088:             $defdom = $settings->{'sender_domain'};
                   3089:         }
1.274     raeburn  3090:         if (exists($settings->{'autofailsafe'})) {
                   3091:             $failsafe = $settings->{'autofailsafe'};
                   3092:         }
1.14      raeburn  3093:     } else {
                   3094:         if ($autorun) {
                   3095:             $runon = ' checked="checked" ';
                   3096:             $runoff = ' ';
                   3097:         } else {
                   3098:             $runoff = ' checked="checked" ';
                   3099:             $runon = ' ';
                   3100:         }
1.3       raeburn  3101:     }
                   3102:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3103:     my $notif_sender;
                   3104:     if (ref($settings) eq 'HASH') {
                   3105:         $notif_sender = $settings->{'sender_uname'};
                   3106:     }
1.3       raeburn  3107:     my $datatable='<tr class="LC_odd_row">'.
                   3108:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3109:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3110:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3111:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3112:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3113:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3114:                   '</tr><tr>'.
                   3115:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3116:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3117:                   &mt('username').':&nbsp;'.
                   3118:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3119:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3120:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3121:                   '<tr class="LC_odd_row">'.
                   3122:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3123:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3124:                   '<input type="radio" name="autoassign_coowners"'.
                   3125:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3126:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3127:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  3128:                   '</tr><tr>'.
                   3129:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   3130:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3131:                   '<input type="text" name="autoenroll_failsafe"'.
1.333     raeburn  3132:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274     raeburn  3133:     $$rowtotal += 4;
1.3       raeburn  3134:     return $datatable;
                   3135: }
                   3136: 
                   3137: sub print_autoupdate {
1.30      raeburn  3138:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  3139:     my $datatable;
                   3140:     if ($position eq 'top') {
                   3141:         my $updateon = ' ';
                   3142:         my $updateoff = ' checked="checked" ';
                   3143:         my $classlistson = ' ';
                   3144:         my $classlistsoff = ' checked="checked" ';
                   3145:         if (ref($settings) eq 'HASH') {
                   3146:             if ($settings->{'run'} eq '1') {
                   3147:                 $updateon = $updateoff;
                   3148:                 $updateoff = ' ';
                   3149:             }
                   3150:             if ($settings->{'classlists'} eq '1') {
                   3151:                 $classlistson = $classlistsoff;
                   3152:                 $classlistsoff = ' ';
                   3153:             }
                   3154:         }
                   3155:         my %title = (
                   3156:                    run => 'Auto-update active?',
                   3157:                    classlists => 'Update information in classlists?',
                   3158:                     );
                   3159:         $datatable = '<tr class="LC_odd_row">'. 
                   3160:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  3161:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3162:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  3163:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3164:                   '<label><input type="radio" name="autoupdate_run"'.
                   3165:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3166:                   '</tr><tr>'.
                   3167:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  3168:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3169:                   '<label><input type="radio" name="classlists"'.
                   3170:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3171:                   '<label><input type="radio" name="classlists"'.
                   3172:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3173:                   '</tr>';
1.30      raeburn  3174:         $$rowtotal += 2;
1.131     raeburn  3175:     } elsif ($position eq 'middle') {
                   3176:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3177:         my $numinrow = 3;
                   3178:         my $locknamesettings;
                   3179:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   3180:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  3181:                                     'lockablenames',$rowtotal);
1.131     raeburn  3182:         $$rowtotal ++;
1.3       raeburn  3183:     } else {
1.44      raeburn  3184:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  3185:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  3186:                       'permanentemail','id');
1.33      raeburn  3187:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  3188:         my $numrows = 0;
1.26      raeburn  3189:         if (ref($types) eq 'ARRAY') {
                   3190:             if (@{$types} > 0) {
                   3191:                 $datatable = 
                   3192:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   3193:                                          \@fields,$types,\$numrows);
1.30      raeburn  3194:                     $$rowtotal += @{$types}; 
1.26      raeburn  3195:             }
1.3       raeburn  3196:         }
                   3197:         $datatable .= 
                   3198:             &usertype_update_row($settings,{'default' => $othertitle},
                   3199:                                  \%fieldtitles,\@fields,['default'],
                   3200:                                  \$numrows);
1.30      raeburn  3201:         $$rowtotal ++;     
1.3       raeburn  3202:     }
                   3203:     return $datatable;
                   3204: }
                   3205: 
1.125     raeburn  3206: sub print_autocreate {
                   3207:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  3208:     my (%createon,%createoff,%currhash);
1.125     raeburn  3209:     my @types = ('xml','req');
                   3210:     if (ref($settings) eq 'HASH') {
                   3211:         foreach my $item (@types) {
                   3212:             $createoff{$item} = ' checked="checked" ';
                   3213:             $createon{$item} = ' ';
                   3214:             if (exists($settings->{$item})) {
                   3215:                 if ($settings->{$item}) {
                   3216:                     $createon{$item} = ' checked="checked" ';
                   3217:                     $createoff{$item} = ' ';
                   3218:                 }
                   3219:             }
                   3220:         }
1.210     raeburn  3221:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  3222:             $currhash{$settings->{'xmldc'}} = 1;
                   3223:         }
1.125     raeburn  3224:     } else {
                   3225:         foreach my $item (@types) {
                   3226:             $createoff{$item} = ' checked="checked" ';
                   3227:             $createon{$item} = ' ';
                   3228:         }
                   3229:     }
                   3230:     $$rowtotal += 2;
1.191     raeburn  3231:     my $numinrow = 2;
1.125     raeburn  3232:     my $datatable='<tr class="LC_odd_row">'.
                   3233:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   3234:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3235:                   '<input type="radio" name="autocreate_xml"'.
                   3236:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3237:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  3238:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   3239:                   '</td></tr><tr>'.
                   3240:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   3241:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3242:                   '<input type="radio" name="autocreate_req"'.
                   3243:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3244:                   '<label><input type="radio" name="autocreate_req"'.
                   3245:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  3246:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   3247:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  3248:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  3249:     if ($numdc > 1) {
1.247     raeburn  3250:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   3251:                       '</td><td class="LC_left_item">';
1.125     raeburn  3252:     } else {
1.247     raeburn  3253:         $datatable .= &mt('Course creation processed as:').
                   3254:                       '</td><td class="LC_right_item">';
1.125     raeburn  3255:     }
1.247     raeburn  3256:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  3257:     $$rowtotal += $rows;
1.125     raeburn  3258:     return $datatable;
                   3259: }
                   3260: 
1.23      raeburn  3261: sub print_directorysrch {
1.277     raeburn  3262:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3263:     my $datatable;
                   3264:     if ($position eq 'top') {
                   3265:         my $instsrchon = ' ';
                   3266:         my $instsrchoff = ' checked="checked" ';
                   3267:         my ($exacton,$containson,$beginson);
                   3268:         my $instlocalon = ' ';
                   3269:         my $instlocaloff = ' checked="checked" ';
                   3270:         if (ref($settings) eq 'HASH') {
                   3271:             if ($settings->{'available'} eq '1') {
                   3272:                 $instsrchon = $instsrchoff;
                   3273:                 $instsrchoff = ' ';
                   3274:             }
                   3275:             if ($settings->{'localonly'} eq '1') {
                   3276:                 $instlocalon = $instlocaloff;
                   3277:                 $instlocaloff = ' ';
                   3278:             }
                   3279:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   3280:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   3281:                     if ($type eq 'exact') {
                   3282:                         $exacton = ' checked="checked" ';
                   3283:                     } elsif ($type eq 'contains') {
                   3284:                         $containson = ' checked="checked" ';
                   3285:                     } elsif ($type eq 'begins') {
                   3286:                         $beginson = ' checked="checked" ';
                   3287:                     }
                   3288:                 }
                   3289:             } else {
                   3290:                 if ($settings->{'searchtypes'} eq 'exact') {
                   3291:                     $exacton = ' checked="checked" ';
                   3292:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   3293:                     $containson = ' checked="checked" ';
                   3294:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  3295:                     $exacton = ' checked="checked" ';
                   3296:                     $containson = ' checked="checked" ';
                   3297:                 }
                   3298:             }
1.277     raeburn  3299:         }
                   3300:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   3301:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3302: 
                   3303:         my $numinrow = 4;
                   3304:         my $cansrchrow = 0;
                   3305:         $datatable='<tr class="LC_odd_row">'.
                   3306:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   3307:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3308:                    '<input type="radio" name="dirsrch_available"'.
                   3309:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3310:                    '<label><input type="radio" name="dirsrch_available"'.
                   3311:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3312:                    '</tr><tr>'.
                   3313:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   3314:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3315:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   3316:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3317:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   3318:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3319:                    '</tr>';
                   3320:         $$rowtotal += 2;
                   3321:         if (ref($usertypes) eq 'HASH') {
                   3322:             if (keys(%{$usertypes}) > 0) {
                   3323:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  3324:                                              $numinrow,$othertitle,'cansearch',
                   3325:                                              $rowtotal);
1.277     raeburn  3326:                 $cansrchrow = 1;
1.25      raeburn  3327:             }
1.23      raeburn  3328:         }
1.277     raeburn  3329:         if ($cansrchrow) {
                   3330:             $$rowtotal ++;
                   3331:             $datatable .= '<tr>';
                   3332:         } else {
                   3333:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  3334:         }
1.277     raeburn  3335:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   3336:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   3337:         foreach my $title (@{$titleorder}) {
                   3338:             if (defined($searchtitles->{$title})) {
                   3339:                 my $check = ' ';
                   3340:                 if (ref($settings) eq 'HASH') {
                   3341:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   3342:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   3343:                             $check = ' checked="checked" ';
                   3344:                         }
1.39      raeburn  3345:                     }
1.25      raeburn  3346:                 }
1.277     raeburn  3347:                 $datatable .= '<td class="LC_left_item">'.
                   3348:                               '<span class="LC_nobreak"><label>'.
                   3349:                               '<input type="checkbox" name="searchby" '.
                   3350:                               'value="'.$title.'"'.$check.'/>'.
                   3351:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  3352:             }
                   3353:         }
1.277     raeburn  3354:         $datatable .= '</tr></table></td></tr>';
                   3355:         $$rowtotal ++;
                   3356:         if ($cansrchrow) {
                   3357:             $datatable .= '<tr class="LC_odd_row">';
                   3358:         } else {
                   3359:             $datatable .= '<tr>';
                   3360:         }
                   3361:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   3362:                       '<td class="LC_left_item" colspan="2">'.
                   3363:                       '<span class="LC_nobreak"><label>'.
                   3364:                       '<input type="checkbox" name="searchtypes" '.
                   3365:                       $exacton.' value="exact" />'.&mt('Exact match').
                   3366:                       '</label>&nbsp;'.
                   3367:                       '<label><input type="checkbox" name="searchtypes" '.
                   3368:                       $beginson.' value="begins" />'.&mt('Begins with').
                   3369:                       '</label>&nbsp;'.
                   3370:                       '<label><input type="checkbox" name="searchtypes" '.
                   3371:                       $containson.' value="contains" />'.&mt('Contains').
                   3372:                       '</label></span></td></tr>';
                   3373:         $$rowtotal ++;
1.26      raeburn  3374:     } else {
1.277     raeburn  3375:         my $domsrchon = ' checked="checked" ';
                   3376:         my $domsrchoff = ' ';
                   3377:         my $domlocalon = ' ';
                   3378:         my $domlocaloff = ' checked="checked" ';
                   3379:         if (ref($settings) eq 'HASH') {
                   3380:             if ($settings->{'lclocalonly'} eq '1') {
                   3381:                 $domlocalon = $domlocaloff;
                   3382:                 $domlocaloff = ' ';
                   3383:             }
                   3384:             if ($settings->{'lcavailable'} eq '0') {
                   3385:                 $domsrchoff = $domsrchon;
                   3386:                 $domsrchon = ' ';
                   3387:             }
                   3388:         }
                   3389:         $datatable='<tr class="LC_odd_row">'.
                   3390:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   3391:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3392:                       '<input type="radio" name="dirsrch_domavailable"'.
                   3393:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3394:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   3395:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3396:                       '</tr><tr>'.
                   3397:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   3398:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3399:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   3400:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3401:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   3402:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3403:                       '</tr>';
                   3404:         $$rowtotal += 2;
1.26      raeburn  3405:     }
1.25      raeburn  3406:     return $datatable;
                   3407: }
                   3408: 
1.28      raeburn  3409: sub print_contacts {
1.286     raeburn  3410:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  3411:     my $datatable;
                   3412:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  3413:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  3414:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  3415:     if ($position eq 'top') {
                   3416:         if (ref($settings) eq 'HASH') {
                   3417:             foreach my $item (@contacts) {
                   3418:                 if (exists($settings->{$item})) {
                   3419:                     $to{$item} = $settings->{$item};
                   3420:                 }
                   3421:             }
                   3422:         }
                   3423:     } elsif ($position eq 'middle') {
                   3424:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  3425:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  3426:         foreach my $type (@mailings) {
                   3427:             $otheremails{$type} = '';
                   3428:         }
1.340     raeburn  3429:     } elsif ($position eq 'lower') {
                   3430:         if (ref($settings) eq 'HASH') {
                   3431:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   3432:                 %lonstatus = %{$settings->{'lonstatus'}};
                   3433:             }
                   3434:         }
1.286     raeburn  3435:     } else {
                   3436:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  3437:         foreach my $type (@mailings) {
                   3438:             $otheremails{$type} = '';
                   3439:         }
1.286     raeburn  3440:         $bccemails{'helpdeskmail'} = '';
                   3441:         $bccemails{'otherdomsmail'} = '';
                   3442:         $includestr{'helpdeskmail'} = '';
                   3443:         $includestr{'otherdomsmail'} = '';
                   3444:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   3445:     }
1.28      raeburn  3446:     if (ref($settings) eq 'HASH') {
1.340     raeburn  3447:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  3448:             foreach my $type (@mailings) {
                   3449:                 if (exists($settings->{$type})) {
                   3450:                     if (ref($settings->{$type}) eq 'HASH') {
                   3451:                         foreach my $item (@contacts) {
                   3452:                             if ($settings->{$type}{$item}) {
                   3453:                                 $checked{$type}{$item} = ' checked="checked" ';
                   3454:                             }
                   3455:                         }
                   3456:                         $otheremails{$type} = $settings->{$type}{'others'};
                   3457:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3458:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   3459:                             if ($settings->{$type}{'include'} ne '') {
                   3460:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3461:                                 $includestr{$type} = &unescape($includestr{$type});
                   3462:                             }
                   3463:                         }
                   3464:                     }
                   3465:                 } elsif ($type eq 'lonstatusmail') {
                   3466:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3467:                 }
1.28      raeburn  3468:             }
                   3469:         }
1.286     raeburn  3470:         if ($position eq 'bottom') {
                   3471:             foreach my $type (@mailings) {
                   3472:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   3473:                 if ($settings->{$type}{'include'} ne '') {
                   3474:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3475:                     $includestr{$type} = &unescape($includestr{$type});
                   3476:                 }
                   3477:             }
                   3478:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   3479:                 if (ref($fields) eq 'ARRAY') {
                   3480:                     foreach my $field (@{$fields}) {
                   3481:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  3482:                     }
1.286     raeburn  3483:                 }
                   3484:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   3485:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   3486:                 } else {
1.289     raeburn  3487:                     $maxsize = '1.0';
1.286     raeburn  3488:                 }
                   3489:             } else {
                   3490:                 if (ref($fields) eq 'ARRAY') {
                   3491:                     foreach my $field (@{$fields}) {
                   3492:                         $currfield{$field} = 'yes';
1.134     raeburn  3493:                     }
1.28      raeburn  3494:                 }
1.286     raeburn  3495:                 $maxsize = '1.0';
1.28      raeburn  3496:             }
                   3497:         }
                   3498:     } else {
1.286     raeburn  3499:         if ($position eq 'top') {
                   3500:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   3501:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   3502:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   3503:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  3504:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  3505:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   3506:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   3507:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  3508:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  3509:         } elsif ($position eq 'bottom') {
                   3510:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   3511:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   3512:             if (ref($fields) eq 'ARRAY') {
                   3513:                 foreach my $field (@{$fields}) {
                   3514:                     $currfield{$field} = 'yes';
                   3515:                 }
                   3516:             }
                   3517:             $maxsize = '1.0';
                   3518:         }
1.28      raeburn  3519:     }
                   3520:     my ($titles,$short_titles) = &contact_titles();
                   3521:     my $rownum = 0;
                   3522:     my $css_class;
1.286     raeburn  3523:     if ($position eq 'top') {
                   3524:         foreach my $item (@contacts) {
                   3525:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3526:             $datatable .= '<tr'.$css_class.'>'. 
                   3527:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3528:                           '</span></td><td class="LC_right_item">'.
                   3529:                           '<input type="text" name="'.$item.'" value="'.
                   3530:                           $to{$item}.'" /></td></tr>';
                   3531:             $rownum ++;
                   3532:         }
1.315     raeburn  3533:     } elsif ($position eq 'bottom') {
                   3534:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3535:         $datatable .= '<tr'.$css_class.'>'.
                   3536:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   3537:                       &mt('(e-mail, subject, and description always shown)').
                   3538:                       '</td><td class="LC_left_item">';
                   3539:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3540:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3541:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3542:             foreach my $field (@{$fields}) {
                   3543:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3544:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3545:                     $datatable .= ' '.&mt('(logged-in users)');
                   3546:                 }
                   3547:                 $datatable .='</td><td>';
                   3548:                 my $clickaction;
                   3549:                 if ($field eq 'screenshot') {
                   3550:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3551:                 }
                   3552:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3553:                     foreach my $option (@{$possoptions->{$field}}) {
                   3554:                         my $checked;
                   3555:                         if ($currfield{$field} eq $option) {
                   3556:                             $checked = ' checked="checked"';
                   3557:                         }
                   3558:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3559:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3560:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3561:                                       '</label></span>'.('&nbsp;'x2);
                   3562:                     }
                   3563:                 }
                   3564:                 if ($field eq 'screenshot') {
                   3565:                     my $display;
                   3566:                     if ($currfield{$field} eq 'no') {
                   3567:                         $display = ' style="display:none"';
                   3568:                     }
1.334     raeburn  3569:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  3570:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3571:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3572:                 }
                   3573:                 $datatable .= '</td></tr>';
                   3574:             }
                   3575:             $datatable .= '</table>';
                   3576:         }
                   3577:         $datatable .= '</td></tr>'."\n";
                   3578:         $rownum ++;
                   3579:     }
1.340     raeburn  3580:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  3581:         foreach my $type (@mailings) {
                   3582:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3583:             $datatable .= '<tr'.$css_class.'>'.
                   3584:                           '<td><span class="LC_nobreak">'.
                   3585:                           $titles->{$type}.': </span></td>'.
                   3586:                           '<td class="LC_left_item">';
                   3587:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3588:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3589:             }
                   3590:             $datatable .= '<span class="LC_nobreak">';
                   3591:             foreach my $item (@contacts) {
                   3592:                 $datatable .= '<label>'.
                   3593:                               '<input type="checkbox" name="'.$type.'"'.
                   3594:                               $checked{$type}{$item}.
                   3595:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3596:                               '</label>&nbsp;';
                   3597:             }
                   3598:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3599:                           '<input type="text" name="'.$type.'_others" '.
                   3600:                           'value="'.$otheremails{$type}.'"  />';
                   3601:             my %locchecked;
                   3602:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3603:                 foreach my $loc ('s','b') {
                   3604:                     if ($includeloc{$type} eq $loc) {
                   3605:                         $locchecked{$loc} = ' checked="checked"';
                   3606:                         last;
                   3607:                     }
                   3608:                 }
                   3609:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3610:                               '<input type="text" name="'.$type.'_bcc" '.
                   3611:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3612:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3613:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  3614:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  3615:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3616:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3617:                               ('&nbsp;'x2).
                   3618:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3619:                               '</span></fieldset>';
                   3620:             }
                   3621:             $datatable .= '</td></tr>'."\n";
                   3622:             $rownum ++;
                   3623:         }
1.28      raeburn  3624:     }
1.286     raeburn  3625:     if ($position eq 'middle') {
                   3626:         my %choices;
1.340     raeburn  3627:         my $corelink = &core_link_msu();
                   3628:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  3629:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  3630:                                         $corelink);
                   3631:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   3632:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  3633:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  3634:                               'reportupdates' => 'on',
                   3635:                               'reportstatus'  => 'on');
1.286     raeburn  3636:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3637:                                                    \%choices,$rownum);
                   3638:         $datatable .= $reports;
1.340     raeburn  3639:     } elsif ($position eq 'lower') {
                   3640:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3641:         my ($threshold,$sysmail,%excluded,%weights);
                   3642:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   3643:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
                   3644:             $threshold = $lonstatus{'threshold'};
                   3645:         } else {
                   3646:             $threshold = $defaults->{'threshold'};
                   3647:         }
                   3648:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
                   3649:             $sysmail = $lonstatus{'sysmail'};
                   3650:         } else {
                   3651:             $sysmail = $defaults->{'sysmail'};
                   3652:         }
                   3653:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  3654:             foreach my $type ('E','W','N','U') {
1.340     raeburn  3655:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   3656:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   3657:                 } else {
                   3658:                     $weights{$type} = $defaults->{$type};
                   3659:                 }
                   3660:             }
                   3661:         } else {
1.341     raeburn  3662:             foreach my $type ('E','W','N','U') {
1.340     raeburn  3663:                 $weights{$type} = $defaults->{$type};
                   3664:             }
                   3665:         }
                   3666:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   3667:             if (@{$lonstatus{'excluded'}} > 0) {
                   3668:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   3669:             }
                   3670:         }
                   3671:         $datatable .= '<tr'.$css_class.'>'.
                   3672:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3673:                       $titles->{'errorthreshold'}.
                   3674:                       '</span></td><td class="LC_left_item">'.
                   3675:                       '<input type="text" name="errorthreshold" value="'.
                   3676:                       $threshold.'" size="5" /></td></tr>';
                   3677:         $rownum ++;
                   3678:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3679:         $datatable .= '<tr'.$css_class.'>'.
                   3680:                       '<td class="LC_left_item">'.
                   3681:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   3682:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  3683:         foreach my $type ('E','W','N','U') {
1.340     raeburn  3684:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   3685:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   3686:                           $weights{$type}.'" size="5" /></td>';
                   3687:         }
                   3688:         $datatable .= '</tr></table></tr>';
                   3689:         $rownum ++;
                   3690:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3691:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   3692:                       $titles->{'errorexcluded'}.'</td>'.
                   3693:                       '<td class="LC_left_item"><table>';
                   3694:         my $numinrow = 4;
                   3695:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   3696:         for (my $i=0; $i<@ids; $i++) {
                   3697:             my $rem = $i%($numinrow);
                   3698:             if ($rem == 0) {
                   3699:                 if ($i > 0) {
                   3700:                     $datatable .= '</tr>';
                   3701:                 }
                   3702:                 $datatable .= '<tr>';
                   3703:             }
                   3704:             my $check;
                   3705:             if ($excluded{$ids[$i]}) {
                   3706:                 $check = ' checked="checked" ';
                   3707:             }
                   3708:             $datatable .= '<td class="LC_left_item">'.
                   3709:                           '<span class="LC_nobreak"><label>'.
                   3710:                           '<input type="checkbox" name="errorexcluded" '.
                   3711:                           'value="'.$ids[$i].'"'.$check.' />'.
                   3712:                           $ids[$i].'</label></span></td>';
                   3713:         }
                   3714:         my $colsleft = $numinrow - @ids%($numinrow);
                   3715:         if ($colsleft > 1 ) {
                   3716:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3717:                           '&nbsp;</td>';
                   3718:         } elsif ($colsleft == 1) {
                   3719:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   3720:         }
                   3721:         $datatable .= '</tr></table></td></tr>';
                   3722:         $rownum ++;
                   3723:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3724:         $datatable .= '<tr'.$css_class.'>'.
                   3725:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3726:                       $titles->{'errorsysmail'}.
                   3727:                       '</span></td><td class="LC_left_item">'.
                   3728:                       '<input type="text" name="errorsysmail" value="'.
                   3729:                       $sysmail.'" size="5" /></td></tr>';
                   3730:         $rownum ++;
1.286     raeburn  3731:     } elsif ($position eq 'bottom') {
1.315     raeburn  3732:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3733:         my (@posstypes,%usertypeshash);
                   3734:         if (ref($types) eq 'ARRAY') {
                   3735:             @posstypes = @{$types};
                   3736:         }
                   3737:         if (@posstypes) {
                   3738:             if (ref($usertypes) eq 'HASH') {
                   3739:                 %usertypeshash = %{$usertypes};
                   3740:             }
                   3741:             my @overridden;
                   3742:             my $numinrow = 4;
                   3743:             if (ref($settings) eq 'HASH') {
                   3744:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   3745:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   3746:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   3747:                             push(@overridden,$key);
                   3748:                             foreach my $item (@contacts) {
                   3749:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   3750:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   3751:                                 }
                   3752:                             }
                   3753:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   3754:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   3755:                             $includeloc{'override_'.$key} = '';
                   3756:                             $includestr{'override_'.$key} = '';
                   3757:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   3758:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   3759:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   3760:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   3761:                             }
1.286     raeburn  3762:                         }
                   3763:                     }
                   3764:                 }
1.315     raeburn  3765:             }
                   3766:             my $customclass = 'LC_helpdesk_override';
                   3767:             my $optionsprefix = 'LC_options_helpdesk_';
                   3768: 
                   3769:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   3770:  
                   3771:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   3772:                                          $numinrow,$othertitle,'overrides',
                   3773:                                          \$rownum,$onclicktypes,$customclass);
                   3774:             $rownum ++;
                   3775:             $usertypeshash{'default'} = $othertitle;
                   3776:             foreach my $status (@posstypes) {
                   3777:                 my $css_class;
                   3778:                 if ($rownum%2) {
                   3779:                     $css_class = 'LC_odd_row ';
                   3780:                 }
                   3781:                 $css_class .= $customclass;
                   3782:                 my $rowid = $optionsprefix.$status;
                   3783:                 my $hidden = 1;
                   3784:                 my $currstyle = 'display:none';
                   3785:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   3786:                     $currstyle = 'display:table-row';
                   3787:                     $hidden = 0;
                   3788:                 }
                   3789:                 my $key = 'override_'.$status;
                   3790:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   3791:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   3792:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   3793:                                                   \@contacts,$short_titles);
                   3794:                 unless ($hidden) {
                   3795:                     $rownum ++;
1.286     raeburn  3796:                 }
                   3797:             }
1.134     raeburn  3798:         }
1.28      raeburn  3799:     }
1.30      raeburn  3800:     $$rowtotal += $rownum;
1.28      raeburn  3801:     return $datatable;
                   3802: }
                   3803: 
1.340     raeburn  3804: sub core_link_msu {
                   3805:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3806:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   3807: }
                   3808: 
1.315     raeburn  3809: sub overridden_helpdesk {
                   3810:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   3811:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   3812:     my $class = 'LC_left_item';
                   3813:     if ($css_class) {
                   3814:         $css_class = ' class="'.$css_class.'"';
                   3815:     }
                   3816:     if ($rowid) {
                   3817:         $rowid = ' id="'.$rowid.'"';
                   3818:     }
                   3819:     if ($rowstyle) {
                   3820:         $rowstyle = ' style="'.$rowstyle.'"';
                   3821:     }
                   3822:     my ($output,$description);
                   3823:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   3824:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   3825:               "<td>$description</td>\n".
                   3826:               '<td class="'.$class.'" colspan="2">'.
                   3827:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   3828:               '<span class="LC_nobreak">';
                   3829:     if (ref($contacts) eq 'ARRAY') {
                   3830:         foreach my $item (@{$contacts}) {
                   3831:             my $check;
                   3832:             if (ref($checked) eq 'HASH') {
                   3833:                $check = $checked->{$item};
                   3834:             }
                   3835:             my $title;
                   3836:             if (ref($short_titles) eq 'HASH') {
                   3837:                 $title = $short_titles->{$item}; 
                   3838:             }
                   3839:             $output .= '<label>'.
                   3840:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   3841:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   3842:         }
                   3843:     }
                   3844:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3845:                '<input type="text" name="override_'.$type.'_others" '.
                   3846:                'value="'.$otheremails.'"  />';
                   3847:     my %locchecked;
                   3848:     foreach my $loc ('s','b') {
                   3849:         if ($includeloc eq $loc) {
                   3850:             $locchecked{$loc} = ' checked="checked"';
                   3851:             last;
                   3852:         }
                   3853:     }
                   3854:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3855:                '<input type="text" name="override_'.$type.'_bcc" '.
                   3856:                'value="'.$bccemails.'"  /></fieldset>'.
                   3857:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3858:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  3859:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  3860:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3861:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3862:                ('&nbsp;'x2).
                   3863:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3864:                '</span></fieldset>'.
                   3865:                '</td></tr>'."\n";
                   3866:     return $output;
                   3867: }
                   3868: 
1.286     raeburn  3869: sub contacts_javascript {
                   3870:     return <<"ENDSCRIPT";
                   3871: 
                   3872: <script type="text/javascript">
                   3873: // <![CDATA[
                   3874: 
                   3875: function screenshotSize(field) {
                   3876:     if (document.getElementById('help_screenshotsize')) {
                   3877:         if (field.value == 'no') {
1.289     raeburn  3878:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  3879:         } else {
                   3880:             document.getElementById('help_screenshotsize').style.display="";
                   3881:         }
                   3882:     }
                   3883:     return;
                   3884: }
                   3885: 
1.315     raeburn  3886: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   3887:     if (form.elements[checkbox].length != undefined) {
                   3888:         var count = 0;
                   3889:         if (docount) {
                   3890:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   3891:                 if (form.elements[checkbox][i].checked) {
                   3892:                     count ++;
                   3893:                 }
                   3894:             }
                   3895:         }
                   3896:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3897:             var type = form.elements[checkbox][i].value;
                   3898:             if (document.getElementById(prefix+type)) {
                   3899:                 if (form.elements[checkbox][i].checked) {
                   3900:                     document.getElementById(prefix+type).style.display = 'table-row';
                   3901:                     if (count % 2 == 1) {
                   3902:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   3903:                     } else {
                   3904:                         document.getElementById(prefix+type).className = target;
                   3905:                     }
                   3906:                     count ++;
                   3907:                 } else {
                   3908:                     document.getElementById(prefix+type).style.display = 'none';
                   3909:                 }
                   3910:             }
                   3911:         }
                   3912:     }
                   3913:     return;
                   3914: }
                   3915: 
                   3916: 
1.286     raeburn  3917: // ]]>
                   3918: </script>
                   3919: 
                   3920: ENDSCRIPT
                   3921: }
                   3922: 
1.118     jms      3923: sub print_helpsettings {
1.282     raeburn  3924:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3925:     my $confname = $dom.'-domainconfig';
1.285     raeburn  3926:     my $formname = 'display';
1.168     raeburn  3927:     my ($datatable,$itemcount);
1.282     raeburn  3928:     if ($position eq 'top') {
                   3929:         $itemcount = 1;
                   3930:         my (%choices,%defaultchecked,@toggles);
                   3931:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3932:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3933:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3934:         %defaultchecked = ('submitbugs' => 'on');
                   3935:         @toggles = ('submitbugs');
                   3936:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3937:                                                      \%choices,$itemcount);
                   3938:         $$rowtotal ++;
                   3939:     } else {
                   3940:         my $css_class;
                   3941:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  3942:         my (%customroles,%ordered,%current);
1.301     raeburn  3943:         if (ref($settings) eq 'HASH') {
                   3944:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3945:                 %current = %{$settings->{'adhoc'}};
                   3946:             }
1.285     raeburn  3947:         }
                   3948:         my $count = 0;
                   3949:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  3950:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3951:                 my $rolename = $1;
1.285     raeburn  3952:                 my (%privs,$order);
1.282     raeburn  3953:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3954:                 $customroles{$rolename} = \%privs;
1.285     raeburn  3955:                 if (ref($current{$rolename}) eq 'HASH') {
                   3956:                     $order = $current{$rolename}{'order'};
                   3957:                 }
                   3958:                 if ($order eq '') {
                   3959:                     $order = $count;
                   3960:                 }
                   3961:                 $ordered{$order} = $rolename;
                   3962:                 $count++;
                   3963:             }
                   3964:         }
                   3965:         my $maxnum = scalar(keys(%ordered));
                   3966:         my @roles_by_num = ();
                   3967:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3968:             push(@roles_by_num,$item);
                   3969:         }
                   3970:         my $context = 'domprefs';
                   3971:         my $crstype = 'Course';
                   3972:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  3973:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  3974:         my ($numstatustypes,@jsarray);
                   3975:         if (ref($types) eq 'ARRAY') {
                   3976:             if (@{$types} > 0) {
                   3977:                 $numstatustypes = scalar(@{$types});
                   3978:                 push(@accesstypes,'status');
                   3979:                 @jsarray = ('bystatus');
1.282     raeburn  3980:             }
                   3981:         }
1.290     raeburn  3982:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  3983:         if (keys(%domhelpdesk)) {
                   3984:             push(@accesstypes,('inc','exc'));
                   3985:             push(@jsarray,('notinc','notexc'));
                   3986:         }
                   3987:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  3988:         my $context = 'domprefs';
                   3989:         my $crstype = 'Course';
1.285     raeburn  3990:         my $prefix = 'helproles_';
                   3991:         my $add_class = 'LC_hidden';
                   3992:         foreach my $num (@roles_by_num) {
                   3993:             my $role = $ordered{$num};
                   3994:             my ($desc,$access,@statuses);
                   3995:             if (ref($current{$role}) eq 'HASH') {
                   3996:                 $desc = $current{$role}{'desc'};
                   3997:                 $access = $current{$role}{'access'};
                   3998:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3999:                     @statuses = @{$current{$role}{'insttypes'}};
                   4000:                 }
                   4001:             }
                   4002:             if ($desc eq '') {
                   4003:                 $desc = $role;
                   4004:             }
                   4005:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4006:             my %full=();
                   4007:             my %levels= (
                   4008:                          course => {},
                   4009:                          domain => {},
                   4010:                          system => {},
                   4011:                         );
                   4012:             my %levelscurrent=(
                   4013:                                course => {},
                   4014:                                domain => {},
                   4015:                                system => {},
                   4016:                               );
                   4017:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4018:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4019:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  4020:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  4021:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  4022:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4023:             for (my $k=0; $k<=$maxnum; $k++) {
                   4024:                 my $vpos = $k+1;
                   4025:                 my $selstr;
                   4026:                 if ($k == $num) {
                   4027:                     $selstr = ' selected="selected" ';
                   4028:                 }
                   4029:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4030:             }
                   4031:             $datatable .= '</select>'.('&nbsp;'x2).
                   4032:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4033:                           '</td>'.
                   4034:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4035:                           &mt('Name shown to users:').
                   4036:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4037:                           '</fieldset>'.
                   4038:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4039:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4040:                           '<fieldset>'.
                   4041:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  4042:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  4043:                                                                    \%levelscurrent,$identifier,
                   4044:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4045:                           '</fieldset></td>';
1.282     raeburn  4046:             $itemcount ++;
                   4047:         }
                   4048:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4049:         my $newcust = 'custhelp'.$count;
                   4050:         my (%privs,%levelscurrent);
                   4051:         my %full=();
                   4052:         my %levels= (
                   4053:                      course => {},
                   4054:                      domain => {},
                   4055:                      system => {},
                   4056:                     );
                   4057:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4058:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  4059:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  4060:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  4061:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4062:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4063:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4064:             my $vpos = $k+1;
                   4065:             my $selstr;
                   4066:             if ($k == $maxnum) {
                   4067:                 $selstr = ' selected="selected" ';
                   4068:             }
                   4069:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4070:         }
                   4071:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  4072:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4073:                       '</label></span></td>'.
1.285     raeburn  4074:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4075:                       '<span class="LC_nobreak">'.
                   4076:                       &mt('Internal name:').
                   4077:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4078:                       '</span>'.('&nbsp;'x4).
                   4079:                       '<span class="LC_nobreak">'.
                   4080:                       &mt('Name shown to users:').
                   4081:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4082:                       '</span></fieldset>'.
                   4083:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4084:                                              $usertypes,$types,\%domhelpdesk).
                   4085:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  4086:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4087:                                                                 \@templateroles,$newcust).
                   4088:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4089:                                                                \%levelscurrent,$newcust).
1.334     raeburn  4090:                       '</fieldset>'.
                   4091:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4092:                       '</td></tr>';
1.282     raeburn  4093:         $count ++;
                   4094:         $$rowtotal += $count;
                   4095:     }
1.166     raeburn  4096:     return $datatable;
1.121     raeburn  4097: }
                   4098: 
1.285     raeburn  4099: sub adhocbutton {
                   4100:     my ($prefix,$num,$field,$visibility) = @_;
                   4101:     my %lt = &Apache::lonlocal::texthash(
                   4102:                                           show => 'Show details',
                   4103:                                           hide => 'Hide details',
                   4104:                                         );
                   4105:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4106:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4107:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4108:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4109: }
                   4110: 
                   4111: sub helpsettings_javascript {
                   4112:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4113:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4114:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4115:                                           show => 'Show details',
                   4116:                                           hide => 'Hide details',
                   4117:                                         );
                   4118:     &html_escape(\%html_js_lt);
                   4119:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4120:     return <<"ENDSCRIPT";
                   4121: <script type="text/javascript">
                   4122: // <![CDATA[
                   4123: 
                   4124: function reorderHelpRoles(form,item) {
                   4125:     var changedVal;
                   4126: $jstext
                   4127:     var newpos = 'helproles_${total}_pos';
                   4128:     var maxh = 1 + $total;
                   4129:     var current = new Array();
                   4130:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4131:     if (item == newpos) {
                   4132:         changedVal = newitemVal;
                   4133:     } else {
                   4134:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4135:         current[newitemVal] = newpos;
                   4136:     }
                   4137:     for (var i=0; i<helproles.length; i++) {
                   4138:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4139:         if (elementName != item) {
                   4140:             if (form.elements[elementName]) {
                   4141:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4142:                 current[currVal] = elementName;
                   4143:             }
                   4144:         }
                   4145:     }
                   4146:     var oldVal;
                   4147:     for (var j=0; j<maxh; j++) {
                   4148:         if (current[j] == undefined) {
                   4149:             oldVal = j;
                   4150:         }
                   4151:     }
                   4152:     if (oldVal < changedVal) {
                   4153:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4154:            var elementName = current[k];
                   4155:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4156:         }
                   4157:     } else {
                   4158:         for (var k=changedVal; k<oldVal; k++) {
                   4159:             var elementName = current[k];
                   4160:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4161:         }
                   4162:     }
                   4163:     return;
                   4164: }
                   4165: 
                   4166: function helpdeskAccess(num) {
                   4167:     var curraccess = null;
                   4168:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   4169:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   4170:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   4171:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   4172:             }
                   4173:         }
                   4174:     }
                   4175:     var shown = Array();
                   4176:     var hidden = Array();
                   4177:     if (curraccess == 'none') {
                   4178:         hidden = Array('$hiddenstr');
                   4179:     } else {
                   4180:         if (curraccess == 'status') {
                   4181:             shown = Array('bystatus');
                   4182:             hidden = Array('notinc','notexc');
                   4183:         } else {
                   4184:             if (curraccess == 'exc') {
                   4185:                 shown = Array('notexc');
                   4186:                 hidden = Array('notinc','bystatus');
                   4187:             }
                   4188:             if (curraccess == 'inc') {
                   4189:                 shown = Array('notinc');
                   4190:                 hidden = Array('notexc','bystatus');
                   4191:             }
1.293     raeburn  4192:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  4193:                 hidden = Array('notinc','notexc','bystatus');
                   4194:             }
                   4195:         }
                   4196:     }
                   4197:     if (hidden.length > 0) {
                   4198:         for (var i=0; i<hidden.length; i++) {
                   4199:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   4200:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   4201:             }
                   4202:         }
                   4203:     }
                   4204:     if (shown.length > 0) {
                   4205:         for (var i=0; i<shown.length; i++) {
                   4206:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   4207:                 if (shown[i] == 'privs') {
                   4208:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   4209:                 } else {
                   4210:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   4211:                 }
                   4212:             }
                   4213:         }
                   4214:     }
                   4215:     return;
                   4216: }
                   4217: 
                   4218: function toggleHelpdeskItem(num,field) {
                   4219:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   4220:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  4221:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  4222:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   4223:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4224:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   4225:             }
                   4226:         } else {
                   4227:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   4228:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4229:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   4230:             }
                   4231:         }
                   4232:     }
                   4233:     return;
                   4234: }
                   4235: 
                   4236: // ]]>
                   4237: </script>
                   4238: 
                   4239: ENDSCRIPT
                   4240: }
                   4241: 
                   4242: sub helpdeskroles_access {
                   4243:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   4244:         $usertypes,$types,$domhelpdesk) = @_;
                   4245:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   4246:     my %lt = &Apache::lonlocal::texthash(
                   4247:                     'rou'    => 'Role usage',
                   4248:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  4249:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   4250:                     'dh'     => 'All with domain helpdesk role',
                   4251:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  4252:                     'none'   => 'None',
                   4253:                     'status' => 'Determined based on institutional status',
                   4254:                     'inc'    => 'Include all, but exclude specific personnel',
                   4255:                     'exc'    => 'Exclude all, but include specific personnel',
                   4256:                   );
                   4257:     my %usecheck = (
                   4258:                      all => ' checked="checked"',
                   4259:                    );
                   4260:     my %displaydiv = (
                   4261:                       status => 'none',
                   4262:                       inc    => 'none',
                   4263:                       exc    => 'none',
                   4264:                       priv   => 'block',
                   4265:                      );
                   4266:     my $output;
                   4267:     if (ref($current) eq 'HASH') {
                   4268:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   4269:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   4270:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   4271:                 delete($usecheck{'all'});
                   4272:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   4273:                     my $access = $1;
                   4274:                     $displaydiv{$access} = 'inline';
                   4275:                 } elsif ($current->{access} eq 'none') {
                   4276:                     $displaydiv{'priv'} = 'none';
                   4277:                 }
                   4278:             }
                   4279:         }
                   4280:     }
                   4281:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   4282:               '<p>'.$lt{'whi'}.'</p>';
                   4283:     foreach my $access (@{$accesstypes}) {
                   4284:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   4285:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   4286:                    $lt{$access}.'</label>';
                   4287:         if ($access eq 'status') {
                   4288:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   4289:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   4290:                                                                  $othertitle,$usertypes,$types).
                   4291:                        '</div>';
                   4292:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   4293:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   4294:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4295:                        '</div>';
                   4296:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   4297:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   4298:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4299:                        '</div>';
                   4300:         }
                   4301:         $output .= '</p>';
                   4302:     }
                   4303:     $output .= '</fieldset>';
                   4304:     return $output;
                   4305: }
                   4306: 
1.121     raeburn  4307: sub radiobutton_prefs {
1.192     raeburn  4308:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257     raeburn  4309:         $additional,$align) = @_;
1.121     raeburn  4310:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   4311:                    (ref($choices) eq 'HASH'));
                   4312: 
1.170     raeburn  4313:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  4314: 
                   4315:     foreach my $item (@{$toggles}) {
                   4316:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      4317:             $checkedon{$item} = ' checked="checked" ';
                   4318:             $checkedoff{$item} = ' ';
1.121     raeburn  4319:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      4320:             $checkedoff{$item} = ' checked="checked" ';
                   4321:             $checkedon{$item} = ' ';
                   4322:         }
                   4323:     }
                   4324:     if (ref($settings) eq 'HASH') {
1.121     raeburn  4325:         foreach my $item (@{$toggles}) {
1.118     jms      4326:             if ($settings->{$item} eq '1') {
                   4327:                 $checkedon{$item} =  ' checked="checked" ';
                   4328:                 $checkedoff{$item} = ' ';
                   4329:             } elsif ($settings->{$item} eq '0') {
                   4330:                 $checkedoff{$item} =  ' checked="checked" ';
                   4331:                 $checkedon{$item} = ' ';
                   4332:             }
                   4333:         }
1.121     raeburn  4334:     }
1.192     raeburn  4335:     if ($onclick) {
                   4336:         $onclick = ' onclick="'.$onclick.'"';
                   4337:     }
1.121     raeburn  4338:     foreach my $item (@{$toggles}) {
1.118     jms      4339:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  4340:         $datatable .=
1.306     raeburn  4341:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  4342:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  4343:             '</span></td>';
                   4344:         if ($align eq 'left') {
                   4345:             $datatable .= '<td class="LC_left_item">';
                   4346:         } else {
                   4347:             $datatable .= '<td class="LC_right_item">';
                   4348:         }
1.289     raeburn  4349:         $datatable .=
1.257     raeburn  4350:             '<span class="LC_nobreak">'.
1.118     jms      4351:             '<label><input type="radio" name="'.
1.192     raeburn  4352:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      4353:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  4354:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4355:             '</span>'.$additional.
                   4356:             '</td>'.
1.118     jms      4357:             '</tr>';
                   4358:         $itemcount ++;
1.121     raeburn  4359:     }
                   4360:     return ($datatable,$itemcount);
                   4361: }
                   4362: 
1.267     raeburn  4363: sub print_ltitools {
                   4364:     my ($dom,$settings,$rowtotal) = @_;
                   4365:     my $rownum = 0;
                   4366:     my $css_class;
                   4367:     my $itemcount = 1;
                   4368:     my $maxnum = 0;
                   4369:     my %ordered;
                   4370:     if (ref($settings) eq 'HASH') {
                   4371:         foreach my $item (keys(%{$settings})) {
                   4372:             if (ref($settings->{$item}) eq 'HASH') {
                   4373:                 my $num = $settings->{$item}{'order'};
                   4374:                 $ordered{$num} = $item;
                   4375:             }
                   4376:         }
                   4377:     }
                   4378:     my $confname = $dom.'-domainconfig';
                   4379:     my $switchserver = &check_switchserver($dom,$confname);
                   4380:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  4381:     my $datatable;
1.267     raeburn  4382:     my %lt = &ltitools_names();
                   4383:     my @courseroles = ('cc','in','ta','ep','st');
                   4384:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  4385:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  4386:     if (keys(%ordered)) {
                   4387:         my @items = sort { $a <=> $b } keys(%ordered);
                   4388:         for (my $i=0; $i<@items; $i++) {
                   4389:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4390:             my $item = $ordered{$items[$i]};
1.323     raeburn  4391:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  4392:             if (ref($settings->{$item}) eq 'HASH') {
                   4393:                 $title = $settings->{$item}->{'title'};
                   4394:                 $url = $settings->{$item}->{'url'};
                   4395:                 $key = $settings->{$item}->{'key'};
                   4396:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  4397:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  4398:                 my $image = $settings->{$item}->{'image'};
                   4399:                 if ($image ne '') {
                   4400:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   4401:                 }
1.323     raeburn  4402:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   4403:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   4404:                 } else {
                   4405:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   4406:                 }
1.267     raeburn  4407:             }
1.319     raeburn  4408:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  4409:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4410:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   4411:             for (my $k=0; $k<=$maxnum; $k++) {
                   4412:                 my $vpos = $k+1;
                   4413:                 my $selstr;
                   4414:                 if ($k == $i) {
                   4415:                     $selstr = ' selected="selected" ';
                   4416:                 }
                   4417:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4418:             }
                   4419:             $datatable .= '</select>'.('&nbsp;'x2).
                   4420:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   4421:                 &mt('Delete?').'</label></span></td>'.
                   4422:                 '<td colspan="2">'.
                   4423:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  4424:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  4425:                 ('&nbsp;'x2).
                   4426:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   4427:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   4428:                 ('&nbsp;'x2).
                   4429:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   4430:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  4431:                 ('&nbsp;'x2).
                   4432:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   4433:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   4434:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  4435:                 '<br /><br />'.
1.323     raeburn  4436:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  4437:                 ' value="'.$url.'" /></span>'.
                   4438:                 ('&nbsp;'x2).
1.319     raeburn  4439:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  4440:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   4441:                 ('&nbsp;'x2).
1.322     raeburn  4442:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   4443:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   4444:                 ('&nbsp;'x2).
1.267     raeburn  4445:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   4446:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   4447:                 '<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>'.
                   4448:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   4449:                 '</fieldset>'.
                   4450:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4451:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   4452:             my %currdisp;
                   4453:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   4454:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   4455:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  4456:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   4457:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  4458:                 } else {
                   4459:                     $currdisp{'iframe'} = ' checked="checked"';
                   4460:                 }
                   4461:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   4462:                     $currdisp{'width'} = $1;
                   4463:                 }
                   4464:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   4465:                      $currdisp{'height'} = $1;
                   4466:                 }
1.296     raeburn  4467:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   4468:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  4469:             } else {
                   4470:                 $currdisp{'iframe'} = ' checked="checked"';
                   4471:             }
1.298     raeburn  4472:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  4473:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   4474:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4475:             }
                   4476:             $datatable .= ('&nbsp;'x4);
                   4477:             foreach my $dimen ('width','height') {
                   4478:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4479:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   4480:                               ('&nbsp;'x2);
                   4481:             }
1.334     raeburn  4482:             $datatable .= '</span><br />'.
1.296     raeburn  4483:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  4484:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  4485:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   4486:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   4487:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  4488:             my %units = (
                   4489:                           'passback' => 'days',
                   4490:                           'roster'   => 'seconds',
                   4491:                         );
1.267     raeburn  4492:             foreach my $extra ('passback','roster') {
1.319     raeburn  4493:                 my $validsty = 'none';
                   4494:                 my $currvalid;
1.267     raeburn  4495:                 my $checkedon = '';
                   4496:                 my $checkedoff = ' checked="checked"';
                   4497:                 if ($settings->{$item}->{$extra}) {
                   4498:                     $checkedon = $checkedoff;
                   4499:                     $checkedoff = '';
1.319     raeburn  4500:                     $validsty = 'inline-block';
                   4501:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   4502:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   4503:                     }
                   4504:                 }
                   4505:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   4506:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   4507:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   4508:                               &mt('No').'</label>'.('&nbsp;'x2).
                   4509:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   4510:                               &mt('Yes').'</label></span></div>'.
                   4511:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   4512:                               '<span class="LC_nobreak">'.
                   4513:                               &mt("at least [_1] $units{$extra} after launch",
                   4514:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   4515:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  4516:             }
1.319     raeburn  4517:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  4518:             if ($imgsrc) {
                   4519:                 $datatable .= $imgsrc.
                   4520:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   4521:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   4522:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   4523:             } else {
                   4524:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4525:             }
                   4526:             if ($switchserver) {
                   4527:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4528:             } else {
                   4529:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   4530:             }
                   4531:             $datatable .= '</span></fieldset>';
1.324     raeburn  4532:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  4533:             if (ref($settings->{$item}) eq 'HASH') {
                   4534:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   4535:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   4536:                 }
1.324     raeburn  4537:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  4538:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   4539:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   4540:                     $checkedfields{'roles'} = 1;
                   4541:                 }
                   4542:             }
                   4543:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4544:                           '<span class="LC_nobreak">';
1.324     raeburn  4545:             my $userfieldstyle = 'display:none;';
                   4546:             my $seluserdom = '';
                   4547:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  4548:             foreach my $field (@fields) {
1.324     raeburn  4549:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  4550:                 if ($checkedfields{$field}) {
                   4551:                     $checked = ' checked="checked"';
                   4552:                 }
1.324     raeburn  4553:                 if ($field eq 'user') {
                   4554:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   4555:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   4556:                     if ($checked) {
                   4557:                         $userfieldstyle = 'display:inline-block';
                   4558:                         if ($userincdom) {
                   4559:                             $seluserdom = $unseluserdom;
                   4560:                             $unseluserdom = '';
                   4561:                         }
                   4562:                     }
                   4563:                 } else {
                   4564:                     $spacer = ('&nbsp;' x2);
                   4565:                 }
1.267     raeburn  4566:                 $datatable .= '<label>'.
1.324     raeburn  4567:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   4568:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  4569:             }
1.324     raeburn  4570:             $datatable .= '</span>';
                   4571:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   4572:                           '<span class="LC_nobreak"> : '.
                   4573:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   4574:                           '<option value="">'.&mt('Select').'</option>'.
                   4575:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   4576:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   4577:                           '</select></span></div>';
                   4578:             $datatable .= '</fieldset>'.
1.267     raeburn  4579:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   4580:             foreach my $role (@courseroles) {
                   4581:                 my ($selected,$selectnone);
                   4582:                 if (!$rolemaps{$role}) {
                   4583:                     $selectnone = ' selected="selected"';
                   4584:                 }
1.306     raeburn  4585:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  4586:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4587:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   4588:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   4589:                 foreach my $ltirole (@ltiroles) {
                   4590:                     unless ($selectnone) {
                   4591:                         if ($rolemaps{$role} eq $ltirole) {
                   4592:                             $selected = ' selected="selected"';
                   4593:                         } else {
                   4594:                             $selected = '';
                   4595:                         }
                   4596:                     }
                   4597:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   4598:                 }
                   4599:                 $datatable .= '</select></td>';
                   4600:             }
1.273     raeburn  4601:             $datatable .= '</tr></table></fieldset>';
                   4602:             my %courseconfig;
                   4603:             if (ref($settings->{$item}) eq 'HASH') {
                   4604:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   4605:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   4606:                 }
                   4607:             }
                   4608:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  4609:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  4610:                 my $checked;
                   4611:                 if ($courseconfig{$item}) {
                   4612:                     $checked = ' checked="checked"';
                   4613:                 }
                   4614:                 $datatable .= '<label>'.
                   4615:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   4616:                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   4617:             }
                   4618:             $datatable .= '</span></fieldset>'.
1.267     raeburn  4619:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4620:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   4621:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   4622:                 my %custom = %{$settings->{$item}->{'custom'}};
                   4623:                 if (keys(%custom) > 0) {
                   4624:                     foreach my $key (sort(keys(%custom))) {
                   4625:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4626:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   4627:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   4628:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   4629:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   4630:                     }
                   4631:                 }
                   4632:             }
                   4633:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4634:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   4635:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   4636:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   4637:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   4638:             $itemcount ++;
                   4639:         }
                   4640:     }
                   4641:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  4642:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  4643:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4644:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   4645:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   4646:     for (my $k=0; $k<$maxnum+1; $k++) {
                   4647:         my $vpos = $k+1;
                   4648:         my $selstr;
                   4649:         if ($k == $maxnum) {
                   4650:             $selstr = ' selected="selected" ';
                   4651:         }
                   4652:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4653:     }
                   4654:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  4655:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  4656:                   '<td colspan="2">'.
                   4657:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  4658:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  4659:                   ('&nbsp;'x2).
                   4660:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   4661:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4662:                   ('&nbsp;'x2).
                   4663:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   4664:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  4665:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   4666:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   4667:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  4668:                   '<br />'.
1.323     raeburn  4669:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  4670:                   ('&nbsp;'x2).
                   4671:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   4672:                   ('&nbsp;'x2).
1.322     raeburn  4673:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   4674:                   ('&nbsp;'x2).
1.267     raeburn  4675:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   4676:                   '<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".
                   4677:                   '</fieldset>'.
                   4678:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4679:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   4680:     my %defaultdisp;
                   4681:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  4682:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  4683:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   4684:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4685:     }
                   4686:     $datatable .= ('&nbsp;'x4);
                   4687:     foreach my $dimen ('width','height') {
                   4688:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4689:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   4690:                       ('&nbsp;'x2);
                   4691:     }
1.334     raeburn  4692:     $datatable .= '</span><br />'.
1.296     raeburn  4693:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  4694:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  4695:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  4696:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  4697:                   '</div><div style=""></div><br />';
1.319     raeburn  4698:     my %units = (
                   4699:                   'passback' => 'days',
                   4700:                   'roster'   => 'seconds',
                   4701:                 );
                   4702:     my %defaulttimes = (
                   4703:                      'passback' => '7',
1.322     raeburn  4704:                      'roster'   => '300',
1.319     raeburn  4705:                    );
1.267     raeburn  4706:     foreach my $extra ('passback','roster') {
1.319     raeburn  4707:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   4708:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   4709:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   4710:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   4711:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   4712:                       &mt('Yes').'</label></span></div>'.
                   4713:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   4714:                       '<span class="LC_nobreak">'.
                   4715:                       &mt("at least [_1] $units{$extra} after launch",
                   4716:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   4717:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  4718:     }
1.319     raeburn  4719:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  4720:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4721:     if ($switchserver) {
                   4722:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4723:     } else {
                   4724:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   4725:     }
                   4726:     $datatable .= '</span></fieldset>'.
                   4727:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4728:                   '<span class="LC_nobreak">';
                   4729:     foreach my $field (@fields) {
1.324     raeburn  4730:         my ($id,$onclick,$spacer);
                   4731:         if ($field eq 'user') {
                   4732:             $id = ' id="ltitools_user_field_add"';
                   4733:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   4734:         } else {
                   4735:             $spacer = ('&nbsp;' x2);
                   4736:         }
1.267     raeburn  4737:         $datatable .= '<label>'.
1.324     raeburn  4738:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   4739:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  4740:     }
1.324     raeburn  4741:     $datatable .= '</span>'.
                   4742:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   4743:                   '<span class="LC_nobreak"> : '.
                   4744:                   '<select name="ltitools_userincdom_add">'.
                   4745:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   4746:                   '<option value="0">'.&mt('username').'</option>'.
                   4747:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   4748:                   '</select></span></div></fieldset>';
                   4749:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  4750:     foreach my $role (@courseroles) {
                   4751:         my ($checked,$checkednone);
1.306     raeburn  4752:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  4753:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4754:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   4755:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   4756:         foreach my $ltirole (@ltiroles) {
                   4757:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   4758:         }
                   4759:         $datatable .= '</select></td>';
                   4760:     }
                   4761:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  4762:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  4763:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  4764:         $datatable .= '<label>'.
                   4765:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   4766:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  4767:     }
                   4768:     $datatable .= '</span></fieldset>'.
1.267     raeburn  4769:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4770:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   4771:                   '<tr><td><span class="LC_nobreak">'.
                   4772:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   4773:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   4774:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  4775:                   '</table></fieldset>'."\n".
1.267     raeburn  4776:                   '</td>'."\n".
                   4777:                   '</tr>'."\n";
                   4778:     $itemcount ++;
                   4779:     return $datatable;
                   4780: }
                   4781: 
                   4782: sub ltitools_names {
                   4783:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  4784:                                           'title'          => 'Title',
                   4785:                                           'version'        => 'Version',
                   4786:                                           'msgtype'        => 'Message Type',
1.323     raeburn  4787:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  4788:                                           'url'            => 'URL',
                   4789:                                           'key'            => 'Key',
1.322     raeburn  4790:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  4791:                                           'secret'         => 'Secret',
                   4792:                                           'icon'           => 'Icon',   
1.324     raeburn  4793:                                           'user'           => 'User',
1.296     raeburn  4794:                                           'fullname'       => 'Full Name',
                   4795:                                           'firstname'      => 'First Name',
                   4796:                                           'lastname'       => 'Last Name',
                   4797:                                           'email'          => 'E-mail',
                   4798:                                           'roles'          => 'Role',
1.298     raeburn  4799:                                           'window'         => 'Window',
                   4800:                                           'tab'            => 'Tab',
1.296     raeburn  4801:                                           'iframe'         => 'iFrame',
                   4802:                                           'height'         => 'Height',
                   4803:                                           'width'          => 'Width',
                   4804:                                           'linktext'       => 'Default Link Text',
                   4805:                                           'explanation'    => 'Default Explanation',
                   4806:                                           'passback'       => 'Tool can return grades:',
                   4807:                                           'roster'         => 'Tool can retrieve roster:',
                   4808:                                           'crstarget'      => 'Display target',
                   4809:                                           'crslabel'       => 'Course label',
                   4810:                                           'crstitle'       => 'Course title', 
                   4811:                                           'crslinktext'    => 'Link Text',
                   4812:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  4813:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  4814:                                         );
                   4815:     return %lt;
                   4816: }
                   4817: 
1.320     raeburn  4818: sub print_lti {
                   4819:     my ($dom,$settings,$rowtotal) = @_;
                   4820:     my $itemcount = 1;
                   4821:     my $maxnum = 0;
                   4822:     my $css_class;
                   4823:     my %ordered;
                   4824:     if (ref($settings) eq 'HASH') {
                   4825:         foreach my $item (keys(%{$settings})) {
                   4826:             if (ref($settings->{$item}) eq 'HASH') {
                   4827:                 my $num = $settings->{$item}{'order'};
                   4828:                 $ordered{$num} = $item;
                   4829:             }
                   4830:         }
                   4831:     }
                   4832:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  4833:     my $datatable;
1.320     raeburn  4834:     my %lt = &lti_names();
                   4835:     if (keys(%ordered)) {
                   4836:         my @items = sort { $a <=> $b } keys(%ordered);
                   4837:         for (my $i=0; $i<@items; $i++) {
                   4838:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4839:             my $item = $ordered{$items[$i]};
1.345     raeburn  4840:             my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320     raeburn  4841:             if (ref($settings->{$item}) eq 'HASH') {
                   4842:                 $key = $settings->{$item}->{'key'};
                   4843:                 $secret = $settings->{$item}->{'secret'};
                   4844:                 $lifetime = $settings->{$item}->{'lifetime'};
                   4845:                 $consumer = $settings->{$item}->{'consumer'};
1.345     raeburn  4846:                 $requser = $settings->{$item}->{'requser'};
1.320     raeburn  4847:                 $current = $settings->{$item};
                   4848:             }
1.345     raeburn  4849:             my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   4850:             my %checkedrequser = (
                   4851:                                    yes => ' checked="checked"',
                   4852:                                    no  => '',
                   4853:                                  );
                   4854:             if (!$requser) {
                   4855:                 $checkedrequser{'no'} = $checkedrequser{'yes'};
                   4856:                 $checkedrequser{'yes'} = '';
1.352     raeburn  4857:             }
1.320     raeburn  4858:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   4859:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4860:                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   4861:             for (my $k=0; $k<=$maxnum; $k++) {
                   4862:                 my $vpos = $k+1;
                   4863:                 my $selstr;
                   4864:                 if ($k == $i) {
                   4865:                     $selstr = ' selected="selected" ';
                   4866:                 }
                   4867:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4868:             }
                   4869:             $datatable .= '</select>'.('&nbsp;'x2).
                   4870:                 '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   4871:                 &mt('Delete?').'</label></span></td>'.
                   4872:                 '<td colspan="2">'.
                   4873:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4874:                 '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  4875:                 ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320     raeburn  4876:                 ('&nbsp;'x2).
                   4877:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   4878:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   4879:                 ('&nbsp;'x2).
                   4880:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345     raeburn  4881:                 'value="'.$lifetime.'" size="3" /></span>'.
                   4882:                 ('&nbsp;'x2).
                   4883:                  '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   4884:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   4885:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  4886:                 '<br /><br />'.
                   4887:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   4888:                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   4889:                 ('&nbsp;'x2).
                   4890:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   4891:                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   4892:                 '<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>'.
                   4893:                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325     raeburn  4894:                 '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320     raeburn  4895:             $itemcount ++;
                   4896:         }
                   4897:     }
                   4898:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4899:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   4900:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4901:                   '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   4902:                   '<select name="lti_pos_add"'.$chgstr.'>';
                   4903:     for (my $k=0; $k<$maxnum+1; $k++) {
                   4904:         my $vpos = $k+1;
                   4905:         my $selstr;
                   4906:         if ($k == $maxnum) {
                   4907:             $selstr = ' selected="selected" ';
                   4908:         }
                   4909:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4910:     }
                   4911:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  4912:                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320     raeburn  4913:                   '<td colspan="2">'.
                   4914:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4915:                   '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  4916:                   ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320     raeburn  4917:                   ('&nbsp;'x2).
                   4918:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   4919:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4920:                   ('&nbsp;'x2).
1.345     raeburn  4921:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   4922:                   ('&nbsp;'x2).
                   4923:                   '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   4924:                   '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   4925:                   '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  4926:                   '<br /><br />'.
                   4927:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   4928:                   ('&nbsp;'x2).
                   4929:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   4930:                   '<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  4931:                   '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
1.320     raeburn  4932:                   '</td>'."\n".
                   4933:                   '</tr>'."\n";
                   4934:     $$rowtotal ++;
                   4935:     return $datatable;;
                   4936: }
                   4937: 
                   4938: sub lti_names {
                   4939:     my %lt = &Apache::lonlocal::texthash(
                   4940:                                           'version'   => 'LTI Version',
                   4941:                                           'url'       => 'URL',
                   4942:                                           'key'       => 'Key',
1.322     raeburn  4943:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  4944:                                           'consumer'  => 'Consumer',
1.320     raeburn  4945:                                           'secret'    => 'Secret',
1.345     raeburn  4946:                                           'requser'   => "User's identity sent",
1.320     raeburn  4947:                                           'email'     => 'Email address',
                   4948:                                           'sourcedid' => 'User ID',
                   4949:                                           'other'     => 'Other',
                   4950:                                           'passback'  => 'Can return grades to Consumer:',
                   4951:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  4952:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  4953:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  4954:                                         );
                   4955:     return %lt;
                   4956: }
                   4957: 
                   4958: sub lti_options {
1.325     raeburn  4959:     my ($num,$current,$itemcount,%lt) = @_;
1.320     raeburn  4960:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);
                   4961:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   4962:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
                   4963:     $checked{'makecrs'}{'N'} = '  checked="checked"';
                   4964:     $checked{'mapcrstype'} = {};
                   4965:     $checked{'makeuser'} = {};
                   4966:     $checked{'selfenroll'} = {};
                   4967:     $checked{'crssec'} = {};
                   4968:     $checked{'crssecsrc'} = {};
1.325     raeburn  4969:     $checked{'lcauth'} = {};
1.326     raeburn  4970:     $checked{'menuitem'} = {};
1.325     raeburn  4971:     if ($num eq 'add') {
                   4972:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   4973:     }
1.320     raeburn  4974:     my $userfieldsty = 'none';
                   4975:     my $crsfieldsty = 'none';
                   4976:     my $crssecfieldsty = 'none';
                   4977:     my $secsrcfieldsty = 'none';
1.337     raeburn  4978:     my $passbacksty = 'none';
1.345     raeburn  4979:     my $optionsty = 'block';
1.325     raeburn  4980:     my $lcauthparm;
                   4981:     my $lcauthparmstyle = 'display:none';
                   4982:     my $lcauthparmtext;
1.326     raeburn  4983:     my $menusty;
1.325     raeburn  4984:     my $numinrow = 4;
1.326     raeburn  4985:     my %menutitles = &ltimenu_titles();
1.320     raeburn  4986: 
                   4987:     if (ref($current) eq 'HASH') {
1.345     raeburn  4988:         if (!$current->{'requser'}) {
                   4989:             $optionsty = 'none';
                   4990:         }
1.320     raeburn  4991:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   4992:             $checked{'mapuser'}{'sourcedid'} = '';
                   4993:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   4994:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   4995:             } else {
                   4996:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   4997:                 $userfield = $current->{'mapuser'};
                   4998:                 $userfieldsty = 'inline-block';
                   4999:             }
                   5000:         }
                   5001:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   5002:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   5003:             if ($current->{'mapcrs'} eq 'context_id') {
                   5004:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   5005:             } else {
                   5006:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   5007:                 $cidfield = $current->{'mapcrs'};
                   5008:                 $crsfieldsty = 'inline-block';
                   5009:             }
                   5010:         }
                   5011:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   5012:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   5013:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   5014:             }
                   5015:         }
1.345     raeburn  5016:         if ($current->{'makecrs'}) {
1.320     raeburn  5017:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  5018:         }
1.320     raeburn  5019:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   5020:             foreach my $role (@{$current->{'makeuser'}}) {
                   5021:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   5022:             }
                   5023:         }
1.325     raeburn  5024:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   5025:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   5026:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   5027:                 $lcauthparm = $current->{'lcauthparm'};
                   5028:                 $lcauthparmstyle = 'display:table-row'; 
                   5029:                 if ($current->{'lcauth'} eq 'localauth') {
                   5030:                     $lcauthparmtext = &mt('Local auth argument');
                   5031:                 } else {
                   5032:                     $lcauthparmtext = &mt('Kerberos domain');
                   5033:                 }
                   5034:             }
                   5035:         }
1.320     raeburn  5036:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   5037:             foreach my $role (@{$current->{'selfenroll'}}) {
                   5038:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   5039:             }
                   5040:         }
                   5041:         if (ref($current->{'maproles'}) eq 'HASH') {
                   5042:             %rolemaps = %{$current->{'maproles'}};
                   5043:         }
                   5044:         if ($current->{'section'} ne '') {
                   5045:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   5046:             $crssecfieldsty = 'inline-block';
                   5047:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   5048:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   5049:             } else {
                   5050:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   5051:                 $crssecsrc = $current->{'section'};
                   5052:                 $secsrcfieldsty = 'inline-block';
                   5053:             }
                   5054:         } else {
                   5055:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   5056:         }
1.326     raeburn  5057:         if ($current->{'topmenu'}) {
                   5058:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   5059:         } else {
                   5060:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   5061:         }
                   5062:         if ($current->{'inlinemenu'}) {
                   5063:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   5064:         } else {
                   5065:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   5066:         }
                   5067:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   5068:             $menusty = 'inline-block';
                   5069:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   5070:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   5071:                     if (exists($menutitles{$item})) {
                   5072:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   5073:                     }
                   5074:                 }
                   5075:             }
                   5076:         } else {
                   5077:             $menusty = 'none';
                   5078:         }
1.320     raeburn  5079:     } else {
                   5080:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   5081:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.326     raeburn  5082:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   5083:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   5084:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   5085:         $menusty = 'inline-block'; 
1.320     raeburn  5086:     }
1.325     raeburn  5087:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  5088:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   5089:                                official   => 'Official',
                   5090:                                unofficial => 'Unofficial',
                   5091:                                community  => 'Community',
                   5092:                                textbook   => 'Textbook',
                   5093:                                placement  => 'Placement Test',
1.325     raeburn  5094:                                lti        => 'LTI Provider',
1.320     raeburn  5095:     );
1.325     raeburn  5096:     my @authtypes = ('internal','krb4','krb5','localauth');
                   5097:     my %shortauth = (
                   5098:                      internal => 'int',
                   5099:                      krb4 => 'krb4',
                   5100:                      krb5 => 'krb5',
                   5101:                      localauth  => 'loc'
                   5102:                     );
                   5103:     my %authnames = &authtype_names();
1.320     raeburn  5104:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   5105:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   5106:     my @courseroles = ('cc','in','ta','ep','st');
                   5107:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   5108:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   5109:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
                   5110:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  5111:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  5112:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345     raeburn  5113:     my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  5114:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   5115:     foreach my $option ('sourcedid','email','other') {
                   5116:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   5117:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   5118:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   5119:     }
                   5120:     $output .= '</span></div>'.
                   5121:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   5122:                '<input type="text" name="lti_customuser_'.$num.'" '.
                   5123:                'value="'.$userfield.'" /></div></fieldset>'. 
1.345     raeburn  5124:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320     raeburn  5125:     foreach my $ltirole (@lticourseroles) {
                   5126:         my ($selected,$selectnone);
                   5127:         if ($rolemaps{$ltirole} eq '') {
                   5128:             $selectnone = ' selected="selected"';
                   5129:         }
                   5130:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   5131:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   5132:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5133:         foreach my $role (@courseroles) {
                   5134:             unless ($selectnone) {
                   5135:                 if ($rolemaps{$ltirole} eq $role) {
                   5136:                     $selected = ' selected="selected"';
                   5137:                 } else {
                   5138:                     $selected = '';
                   5139:                 }
                   5140:             }
                   5141:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   5142:                        &Apache::lonnet::plaintext($role,'Course').
                   5143:                        '</option>';
                   5144:         }
                   5145:         $output .= '</select></td>';
                   5146:     }
                   5147:     $output .= '</tr></table></fieldset>'.
1.345     raeburn  5148:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  5149:     foreach my $ltirole (@ltiroles) {
                   5150:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   5151:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   5152:     }
                   5153:     $output .= '</fieldset>'.
1.345     raeburn  5154:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  5155:                '<table>'.
                   5156:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   5157:                '</table>'.
                   5158:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   5159:                '<td class="LC_left_item">';
                   5160:     foreach my $auth ('lti',@authtypes) {
                   5161:         my $authtext;
                   5162:         if ($auth eq 'lti') {
                   5163:             $authtext = &mt('None');
                   5164:         } else {
                   5165:             $authtext = $authnames{$shortauth{$auth}};
                   5166:         }
                   5167:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   5168:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   5169:                    $authtext.'</label></span> &nbsp;';
                   5170:     }
                   5171:     $output .= '</td></tr>'.
                   5172:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   5173:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   5174:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   5175:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   5176:                '</table></fieldset>'.
1.345     raeburn  5177:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  5178:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   5179:                &mt('Unique course identifier').':&nbsp;';
                   5180:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   5181:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   5182:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   5183:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   5184:     }
1.334     raeburn  5185:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  5186:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   5187:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   5188:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   5189:     foreach my $type (@coursetypes) {
                   5190:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   5191:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   5192:                    ('&nbsp;'x2);
                   5193:     }
                   5194:     $output .= '</span></fieldset>'.
1.345     raeburn  5195:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  5196:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   5197:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   5198:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5199:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   5200:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   5201:                '</fieldset>'.
1.345     raeburn  5202:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  5203:     foreach my $lticrsrole (@lticourseroles) {
                   5204:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   5205:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   5206:     }
                   5207:     $output .= '</fieldset>'.
1.345     raeburn  5208:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  5209:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   5210:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   5211:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5212:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  5213:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  5214:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   5215:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   5216:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   5217:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   5218:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   5219:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   5220:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  5221:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  5222:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  5223:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   5224:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   5225:     foreach my $extra ('roster','passback') {
1.320     raeburn  5226:         my $checkedon = '';
                   5227:         my $checkedoff = ' checked="checked"';
1.337     raeburn  5228:         if ($extra eq 'passback') {
                   5229:             $pb1p1chk = ' checked="checked"';
                   5230:             $pb1p0chk = '';
                   5231:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   5232:         } else {
                   5233:             $onclickpb = ''; 
                   5234:         }
1.320     raeburn  5235:         if (ref($current) eq 'HASH') {
                   5236:             if (($current->{$extra})) {
                   5237:                 $checkedon = $checkedoff;
                   5238:                 $checkedoff = '';
1.337     raeburn  5239:                 if ($extra eq 'passback') {
                   5240:                     $passbacksty = 'inline-block';
                   5241:                 }
                   5242:                 if ($current->{'passbackformat'} eq '1.0') {
                   5243:                     $pb1p0chk =  ' checked="checked"';
                   5244:                     $pb1p1chk = '';
                   5245:                 }
1.320     raeburn  5246:             }
                   5247:         }
                   5248:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  5249:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  5250:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  5251:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  5252:                    &mt('Yes').'</label><br />';
                   5253:     }
1.337     raeburn  5254:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   5255:                '<span class="LC_nobreak">'.&mt('Grade format').
                   5256:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   5257:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   5258:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
                   5259:                &mt('Outcomes Extension (1.0)').'</label></span></div></fieldset>'.
1.345     raeburn  5260:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326     raeburn  5261:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   5262:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   5263:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5264:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334     raeburn  5265:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326     raeburn  5266:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   5267:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   5268:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   5269:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5270:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334     raeburn  5271:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326     raeburn  5272:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'. 
                   5273:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   5274:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   5275:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   5276:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   5277:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   5278:                    ('&nbsp;'x2);
                   5279:     }
1.334     raeburn  5280:     $output .= '</span></div></fieldset>';
1.320     raeburn  5281: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   5282: #
                   5283: #    $output .= '</fieldset>'.
                   5284: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   5285:     return $output;
                   5286: }
                   5287: 
1.326     raeburn  5288: sub ltimenu_titles {
                   5289:     return &Apache::lonlocal::texthash(
                   5290:                                         fullname    => 'Full name',
                   5291:                                         coursetitle => 'Course title',
                   5292:                                         role        => 'Role',
                   5293:                                         logout      => 'Logout',
                   5294:                                         grades      => 'Grades',
                   5295:     );
                   5296: }
                   5297: 
1.121     raeburn  5298: sub print_coursedefaults {
1.139     raeburn  5299:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  5300:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  5301:     my $itemcount = 1;
1.192     raeburn  5302:     my %choices =  &Apache::lonlocal::texthash (
                   5303:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  5304:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  5305:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   5306:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  5307:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   5308:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314     raeburn  5309:         texengine            => 'Default method to display mathematics',
1.257     raeburn  5310:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  5311:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   5312:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  5313:     );
1.198     raeburn  5314:     my %staticdefaults = (
                   5315:                            anonsurvey_threshold => 10,
                   5316:                            uploadquota          => 500,
1.257     raeburn  5317:                            postsubmit           => 60,
1.276     raeburn  5318:                            mysqltables          => 172800,
1.198     raeburn  5319:                          );
1.139     raeburn  5320:     if ($position eq 'top') {
1.257     raeburn  5321:         %defaultchecked = (
                   5322:                             'canuse_pdfforms' => 'off',
                   5323:                             'uselcmath'       => 'on',
                   5324:                             'usejsme'         => 'on',
1.289     raeburn  5325:                             'canclone'        => 'none',
1.257     raeburn  5326:                           );
                   5327:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349     raeburn  5328:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  5329:         if (ref($settings) eq 'HASH') {
                   5330:             if ($settings->{'texengine'}) {
                   5331:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   5332:                     $deftex = $settings->{'texengine'};
                   5333:                 }
                   5334:             }
                   5335:         }
                   5336:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5337:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   5338:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   5339:                        '</span></td><td class="LC_right_item">'.
                   5340:                        '<select name="texengine">'."\n";
                   5341:         my %texoptions = (
                   5342:                             MathJax  => 'MathJax',
                   5343:                             mimetex  => &mt('Convert to Images'),
                   5344:                             tth      => &mt('TeX to HTML'),
                   5345:                          );
                   5346:         foreach my $renderer ('MathJax','mimetex','tth') {
                   5347:             my $selected = '';
                   5348:             if ($renderer eq $deftex) {
                   5349:                 $selected = ' selected="selected"';
                   5350:             }
                   5351:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   5352:         }
                   5353:         $mathdisp .= '</select></td></tr>'."\n";
                   5354:         $itemcount ++;
1.139     raeburn  5355:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  5356:                                                      \%choices,$itemcount);
1.314     raeburn  5357:         $datatable = $mathdisp.$datatable;
1.264     raeburn  5358:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5359:         $datatable .=
1.306     raeburn  5360:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  5361:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   5362:             '</span></td><td class="LC_left_item">';
                   5363:         my $currcanclone = 'none';
                   5364:         my $onclick;
                   5365:         my @cloneoptions = ('none','domain');
                   5366:         my %clonetitles = (
                   5367:                              none     => 'No additional course requesters',
                   5368:                              domain   => "Any course requester in course's domain",
                   5369:                              instcode => 'Course requests for official courses ...',
                   5370:                           );
                   5371:         my (%codedefaults,@code_order,@posscodes);
                   5372:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   5373:                                                     \@code_order) eq 'ok') {
                   5374:             if (@code_order > 0) {
                   5375:                 push(@cloneoptions,'instcode');
                   5376:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   5377:             }
                   5378:         }
                   5379:         if (ref($settings) eq 'HASH') {
                   5380:             if ($settings->{'canclone'}) {
                   5381:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   5382:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   5383:                         if (@code_order > 0) {
                   5384:                             $currcanclone = 'instcode';
                   5385:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   5386:                         }
                   5387:                     }
                   5388:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   5389:                     $currcanclone = $settings->{'canclone'};
                   5390:                 }
                   5391:             }
1.289     raeburn  5392:         }
1.264     raeburn  5393:         foreach my $option (@cloneoptions) {
                   5394:             my ($checked,$additional);
                   5395:             if ($currcanclone eq $option) {
                   5396:                 $checked = ' checked="checked"';
                   5397:             }
                   5398:             if ($option eq 'instcode') {
                   5399:                 if (@code_order) {
                   5400:                     my $show = 'none';
                   5401:                     if ($checked) {
                   5402:                         $show = 'block';
                   5403:                     }
1.317     raeburn  5404:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  5405:                                   &mt('Institutional codes for new and cloned course have identical:').
                   5406:                                   '<br />';
                   5407:                     foreach my $item (@code_order) {
                   5408:                         my $codechk;
                   5409:                         if ($checked) {
                   5410:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   5411:                                 $codechk = ' checked="checked"';
                   5412:                             }
                   5413:                         }
                   5414:                         $additional .= '<label>'.
                   5415:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   5416:                                        $item.'</label>';
                   5417:                     }
                   5418:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   5419:                 }
                   5420:             }
                   5421:             $datatable .=
                   5422:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   5423:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   5424:                 '</label>&nbsp;'.$additional.'</span><br />';
                   5425:         }
                   5426:         $datatable .= '</td>'.
                   5427:                       '</tr>';
                   5428:         $itemcount ++;
1.139     raeburn  5429:     } else {
                   5430:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  5431:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  5432:         my $currusecredits = 0;
1.257     raeburn  5433:         my $postsubmitclient = 1;
1.271     raeburn  5434:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  5435:         if (ref($settings) eq 'HASH') {
                   5436:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  5437:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   5438:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   5439:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   5440:                 }
                   5441:             }
1.192     raeburn  5442:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  5443:                 foreach my $type (@types) {
                   5444:                     next if ($type eq 'community');
                   5445:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   5446:                     if ($defcredits{$type} ne '') {
                   5447:                         $currusecredits = 1;
                   5448:                     }
                   5449:                 }
                   5450:             }
                   5451:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   5452:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   5453:                     $postsubmitclient = 0;
                   5454:                     foreach my $type (@types) {
                   5455:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5456:                     }
                   5457:                 } else {
                   5458:                     foreach my $type (@types) {
                   5459:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   5460:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  5461:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  5462:                             } else {
                   5463:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5464:                             }
                   5465:                         } else {
                   5466:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5467:                         }
                   5468:                     }
                   5469:                 }
                   5470:             } else {
                   5471:                 foreach my $type (@types) {
                   5472:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  5473:                 }
                   5474:             }
1.276     raeburn  5475:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   5476:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   5477:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   5478:                 }
                   5479:             } else {
                   5480:                 foreach my $type (@types) {
                   5481:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   5482:                 }
                   5483:             }
1.258     raeburn  5484:         } else {
                   5485:             foreach my $type (@types) {
                   5486:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5487:             }
1.139     raeburn  5488:         }
                   5489:         if (!$currdefresponder) {
1.198     raeburn  5490:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  5491:         } elsif ($currdefresponder < 1) {
                   5492:             $currdefresponder = 1;
                   5493:         }
1.198     raeburn  5494:         foreach my $type (@types) {
                   5495:             if ($curruploadquota{$type} eq '') {
                   5496:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   5497:             }
                   5498:         }
1.139     raeburn  5499:         $datatable .=
1.192     raeburn  5500:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5501:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  5502:                 '</span></td>'.
                   5503:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5504:                 '<input type="text" name="anonsurvey_threshold"'.
                   5505:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  5506:                 '</td></tr>'."\n";
                   5507:         $itemcount ++;
                   5508:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5509:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5510:                       $choices{'uploadquota'}.
                   5511:                       '</span></td>'.
1.306     raeburn  5512:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  5513:                       '<table><tr>';
1.198     raeburn  5514:         foreach my $type (@types) {
1.306     raeburn  5515:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  5516:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   5517:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   5518:         }
                   5519:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  5520:         $itemcount ++;
1.236     raeburn  5521:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  5522:         my $display = 'none';
1.192     raeburn  5523:         if ($currusecredits) {
                   5524:             $display = 'block';
                   5525:         }
                   5526:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  5527:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   5528:         foreach my $type (@types) {
                   5529:             next if ($type eq 'community');
1.306     raeburn  5530:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  5531:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  5532:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  5533:         }
                   5534:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  5535:         %defaultchecked = ('coursecredits' => 'off');
                   5536:         @toggles = ('coursecredits');
                   5537:         my $current = {
                   5538:                         'coursecredits' => $currusecredits,
                   5539:                       };
                   5540:         (my $table,$itemcount) =
                   5541:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  5542:                                \%choices,$itemcount,$onclick,$additional,'left');
                   5543:         $datatable .= $table;
                   5544:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   5545:         my $display = 'none';
                   5546:         if ($postsubmitclient) {
                   5547:             $display = 'block';
                   5548:         }
                   5549:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  5550:                       &mt('Number of seconds submit is disabled').'<br />'.
                   5551:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   5552:                       '<table><tr>';
1.257     raeburn  5553:         foreach my $type (@types) {
1.306     raeburn  5554:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  5555:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   5556:                            $deftimeout{$type}.'" size="5" /></td>';
                   5557:         }
                   5558:         $additional .= '</tr></table></div>'."\n";
                   5559:         %defaultchecked = ('postsubmit' => 'on');
                   5560:         @toggles = ('postsubmit');
1.280     raeburn  5561:         $current = {
                   5562:                        'postsubmit' => $postsubmitclient,
                   5563:                    };
1.257     raeburn  5564:         ($table,$itemcount) =
                   5565:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   5566:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  5567:         $datatable .= $table;
1.276     raeburn  5568:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5569:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5570:                       $choices{'mysqltables'}.
                   5571:                       '</span></td>'.
1.306     raeburn  5572:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  5573:                       '<table><tr>';
                   5574:         foreach my $type (@types) {
1.306     raeburn  5575:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  5576:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  5577:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  5578:         }
                   5579:         $datatable .= '</tr></table></td></tr>'."\n";
                   5580:         $itemcount ++;
                   5581: 
1.139     raeburn  5582:     }
1.192     raeburn  5583:     $$rowtotal += $itemcount;
1.121     raeburn  5584:     return $datatable;
1.118     jms      5585: }
                   5586: 
1.231     raeburn  5587: sub print_selfenrollment {
                   5588:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5589:     my ($css_class,$datatable);
                   5590:     my $itemcount = 1;
1.271     raeburn  5591:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  5592:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  5593:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   5594:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  5595:         my @rows;
                   5596:         my $key;
                   5597:         if ($position eq 'top') {
                   5598:             $key = 'admin'; 
                   5599:             if (ref($rowsref) eq 'ARRAY') {
                   5600:                 @rows = @{$rowsref};
                   5601:             }
                   5602:         } elsif ($position eq 'middle') {
                   5603:             $key = 'default';
                   5604:             @rows = ('types','registered','approval','limit');
                   5605:         }
                   5606:         foreach my $row (@rows) {
                   5607:             if (defined($titlesref->{$row})) {
                   5608:                 $itemcount ++;
                   5609:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5610:                 $datatable .= '<tr'.$css_class.'>'.
                   5611:                               '<td>'.$titlesref->{$row}.'</td>'.
                   5612:                               '<td class="LC_left_item">'.
                   5613:                               '<table><tr>';
                   5614:                 my (%current,%currentcap);
                   5615:                 if (ref($settings) eq 'HASH') {
                   5616:                     if (ref($settings->{$key}) eq 'HASH') {
                   5617:                         foreach my $type (@types) {
                   5618:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5619:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   5620:                             }
                   5621:                             if (($row eq 'limit') && ($key eq 'default')) {
                   5622:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5623:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   5624:                                 }
                   5625:                             }
                   5626:                         }
                   5627:                     }
                   5628:                 }
                   5629:                 my %roles = (
                   5630:                              '0' => &Apache::lonnet::plaintext('dc'),
                   5631:                             ); 
                   5632:             
                   5633:                 foreach my $type (@types) {
                   5634:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   5635:                         $datatable .= '<th>'.&mt($type).'</th>';
                   5636:                     }
                   5637:                 }
                   5638:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   5639:                     $datatable .= '</tr><tr>';
                   5640:                 }
                   5641:                 foreach my $type (@types) {
                   5642:                     if ($type eq 'community') {
                   5643:                         $roles{'1'} = &mt('Community personnel');
                   5644:                     } else {
                   5645:                         $roles{'1'} = &mt('Course personnel');
                   5646:                     }
                   5647:                     $datatable .= '<td style="vertical-align: top">';
                   5648:                     if ($position eq 'top') {
                   5649:                         my %checked;
                   5650:                         if ($current{$type} eq '0') {
                   5651:                             $checked{'0'} = ' checked="checked"';
                   5652:                         } else {
                   5653:                             $checked{'1'} = ' checked="checked"';
                   5654:                         }
                   5655:                         foreach my $role ('1','0') {
                   5656:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   5657:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   5658:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   5659:                                           $roles{$role}.'</label></span> ';
                   5660:                         }
                   5661:                     } else {
                   5662:                         if ($row eq 'types') {
                   5663:                             my %checked;
                   5664:                             if ($current{$type} =~ /^(all|dom)$/) {
                   5665:                                 $checked{$1} = ' checked="checked"';
                   5666:                             } else {
                   5667:                                 $checked{''} = ' checked="checked"';
                   5668:                             }
                   5669:                             foreach my $val ('','dom','all') {
                   5670:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5671:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5672:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5673:                             }
                   5674:                         } elsif ($row eq 'registered') {
                   5675:                             my %checked;
                   5676:                             if ($current{$type} eq '1') {
                   5677:                                 $checked{'1'} = ' checked="checked"';
                   5678:                             } else {
                   5679:                                 $checked{'0'} = ' checked="checked"';
                   5680:                             }
                   5681:                             foreach my $val ('0','1') {
                   5682:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5683:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5684:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5685:                             }
                   5686:                         } elsif ($row eq 'approval') {
                   5687:                             my %checked;
                   5688:                             if ($current{$type} =~ /^([12])$/) {
                   5689:                                 $checked{$1} = ' checked="checked"';
                   5690:                             } else {
                   5691:                                 $checked{'0'} = ' checked="checked"';
                   5692:                             }
                   5693:                             for my $val (0..2) {
                   5694:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5695:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5696:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5697:                             }
                   5698:                         } elsif ($row eq 'limit') {
                   5699:                             my %checked;
                   5700:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   5701:                                 $checked{$1} = ' checked="checked"';
                   5702:                             } else {
                   5703:                                 $checked{'none'} = ' checked="checked"';
                   5704:                             }
                   5705:                             my $cap;
                   5706:                             if ($currentcap{$type} =~ /^\d+$/) {
                   5707:                                 $cap = $currentcap{$type};
                   5708:                             }
                   5709:                             foreach my $val ('none','allstudents','selfenrolled') {
                   5710:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5711:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5712:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5713:                             }
                   5714:                             $datatable .= '<br />'.
                   5715:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   5716:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   5717:                                           '</span>'; 
                   5718:                         }
                   5719:                     }
                   5720:                     $datatable .= '</td>';
                   5721:                 }
                   5722:                 $datatable .= '</tr>';
                   5723:             }
                   5724:             $datatable .= '</table></td></tr>';
                   5725:         }
                   5726:     } elsif ($position eq 'bottom') {
1.235     raeburn  5727:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   5728:     }
                   5729:     $$rowtotal += $itemcount;
                   5730:     return $datatable;
                   5731: }
                   5732: 
                   5733: sub print_validation_rows {
                   5734:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   5735:     my ($itemsref,$namesref,$fieldsref);
                   5736:     if ($caller eq 'selfenroll') { 
                   5737:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   5738:     } elsif ($caller eq 'requestcourses') {
                   5739:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   5740:     }
                   5741:     my %currvalidation;
                   5742:     if (ref($settings) eq 'HASH') {
                   5743:         if (ref($settings->{'validation'}) eq 'HASH') {
                   5744:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  5745:         }
1.235     raeburn  5746:     }
                   5747:     my $datatable;
                   5748:     my $itemcount = 0;
                   5749:     foreach my $item (@{$itemsref}) {
                   5750:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5751:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5752:                       $namesref->{$item}.
                   5753:                       '</span></td>'.
                   5754:                       '<td class="LC_left_item">';
                   5755:         if (($item eq 'url') || ($item eq 'button')) {
                   5756:             $datatable .= '<span class="LC_nobreak">'.
                   5757:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   5758:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   5759:         } elsif ($item eq 'fields') {
                   5760:             my @currfields;
                   5761:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   5762:                 @currfields = @{$currvalidation{$item}};
                   5763:             }
                   5764:             foreach my $field (@{$fieldsref}) {
                   5765:                 my $check = '';
                   5766:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   5767:                     $check = ' checked="checked"';
                   5768:                 }
                   5769:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5770:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   5771:                               ' value="'.$field.'"'.$check.' />'.$field.
                   5772:                               '</label></span> ';
                   5773:             }
                   5774:         } elsif ($item eq 'markup') {
1.334     raeburn  5775:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  5776:                            $currvalidation{$item}.
1.231     raeburn  5777:                               '</textarea>';
1.235     raeburn  5778:         }
                   5779:         $datatable .= '</td></tr>'."\n";
                   5780:         if (ref($rowtotal)) {
1.231     raeburn  5781:             $itemcount ++;
                   5782:         }
                   5783:     }
1.235     raeburn  5784:     if ($caller eq 'requestcourses') {
                   5785:         my %currhash;
1.248     raeburn  5786:         if (ref($settings) eq 'HASH') {
                   5787:             if (ref($settings->{'validation'}) eq 'HASH') {
                   5788:                 if ($settings->{'validation'}{'dc'} ne '') {
                   5789:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   5790:                 }
1.235     raeburn  5791:             }
                   5792:         }
                   5793:         my $numinrow = 2;
                   5794:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   5795:                                                        'validationdc',%currhash);
1.247     raeburn  5796:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  5797:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  5798:         if ($numdc > 1) {
1.247     raeburn  5799:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  5800:         } else {
1.247     raeburn  5801:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  5802:         }
1.247     raeburn  5803:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  5804:         $itemcount ++;
                   5805:     }
                   5806:     if (ref($rowtotal)) {
                   5807:         $$rowtotal += $itemcount;
                   5808:     }
1.231     raeburn  5809:     return $datatable;
                   5810: }
                   5811: 
1.357     raeburn  5812: sub print_privacy {
                   5813:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5814:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   5815:     my $itemcount = 0;
                   5816:     unless ($position eq 'top') {
                   5817:         @items = ('domain','author','course','community');
                   5818:         %names = &Apache::lonlocal::texthash (
                   5819:                      domain => 'Assigned domain role(s)',
                   5820:                      author => 'Assigned co-author role(s)',
                   5821:                      course => 'Assigned course role(s)',
                   5822:                      community => 'Assigned community role',
                   5823:                  );
                   5824:         $numinrow = 4;
                   5825:         ($othertitle,$usertypes,$types) =
                   5826:             &Apache::loncommon::sorted_inst_types($dom);
                   5827:     }
                   5828:     if (($position eq 'top') || ($position eq 'middle')) {
                   5829:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   5830:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   5831:         if ($position eq 'top') {
                   5832:             my %curr;
                   5833:             my @options = ('none','user','domain','auto');
                   5834:             my %titles = &Apache::lonlocal::texthash (
                   5835:                 none   => 'Not allowed',
                   5836:                 user   => 'User authorizes',
                   5837:                 domain => 'DC authorizes',
                   5838:                 auto   => 'Unrestricted',
                   5839:                 instdom => 'Other domain shares institution/provider',
                   5840:                 extdom => 'Other domain has different institution/provider',
                   5841:             );
                   5842:             my %names = &Apache::lonlocal::texthash (
                   5843:                 domain => 'Domain role',
                   5844:                 author => 'Co-author role',
                   5845:                 course => 'Course role',
                   5846:                 community => 'Community role',
                   5847:             );
                   5848:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5849:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5850:             foreach my $domtype ('instdom','extdom') {
                   5851:                 my (%checked,$skip);
                   5852:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5853:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   5854:                               '<td class="LC_left_item">';
                   5855:                 if ($domtype eq 'instdom') {
                   5856:                     unless (@instdoms > 1) {
                   5857:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   5858:                         $skip = 1;
                   5859:                     }
                   5860:                 } elsif ($domtype eq 'extdom') {
                   5861:                     if (keys(%by_location) == 0) {
                   5862:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   5863:                         $skip = 1;
                   5864:                     }
                   5865:                 }
                   5866:                 unless ($skip) {
                   5867:                     foreach my $roletype ('domain','author','course','community') {
                   5868:                         $checked{'auto'} = ' checked="checked"';
                   5869:                         if (ref($settings) eq 'HASH') {
                   5870:                             if (ref($settings->{approval}) eq 'HASH') {
                   5871:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   5872:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   5873:                                         $checked{$1} = ' checked="checked"';
                   5874:                                         $checked{'auto'} = '';
                   5875:                                     }
                   5876:                                 }
                   5877:                             }
                   5878:                         }
                   5879:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   5880:                         foreach my $option (@options) {
                   5881:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   5882:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   5883:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   5884:                                           '</label></span>&nbsp; ';
                   5885:                         }
                   5886:                         $datatable .= '</fieldset>';
                   5887:                     }
                   5888:                 }
                   5889:                 $datatable .= '</td></tr>';
                   5890:                 $itemcount ++;
                   5891:             }
                   5892:         } elsif ($position eq 'middle') {
                   5893:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   5894:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   5895:                     foreach my $item (@{$types}) {
                   5896:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   5897:                                                                $numinrow,$itemcount,'','','','','',
                   5898:                                                                '',$usertypes->{$item});
                   5899:                         $itemcount ++;
                   5900:                     }
                   5901:                 }
                   5902:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   5903:                                                        $numinrow,$itemcount,'','','','','',
                   5904:                                                        '',$othertitle);
                   5905:                 $itemcount ++;
                   5906:             } else {
                   5907:                 $datatable .= &mt('Nothing to set here, as there are no other domains');
                   5908:             }
                   5909:         }
                   5910:     } else {
                   5911:         my $prefix;
                   5912:         if ($position eq 'lower') {
                   5913:             $prefix = 'priv';
                   5914:         } else {
                   5915:             $prefix = 'unpriv';
                   5916:         }
                   5917:         foreach my $item (@items) {
                   5918:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   5919:                                                    $numinrow,$itemcount,'','','','','',
                   5920:                                                    '',$names{$item});
                   5921:             $itemcount ++;
                   5922:         }
                   5923:     }
                   5924:     if (ref($rowtotal)) {
                   5925:         $$rowtotal += $itemcount;
                   5926:     }
                   5927:     return $datatable;
                   5928: }
                   5929: 
1.354     raeburn  5930: sub print_passwords {
                   5931:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   5932:     my ($datatable,$css_class);
                   5933:     my $itemcount = 0;
                   5934:     my %titles = &Apache::lonlocal::texthash (
                   5935:         captcha        => '"Forgot Password" CAPTCHA validation',
                   5936:         link           => 'Reset link expiration (hours)',
                   5937:         case           => 'Case-sensitive usernames/e-mail',
                   5938:         prelink        => 'Information required (form 1)',
                   5939:         postlink       => 'Information required (form 2)',
                   5940:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   5941:         customtext     => 'Domain specific text (HTML)',
                   5942:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   5943:         intauth_check  => 'Check bcrypt cost if authenticated',
                   5944:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   5945:         permanent      => 'Permanent e-mail address',
                   5946:         critical       => 'Critical notification address',
                   5947:         notify         => 'Notification address',
                   5948:         min            => 'Minimum password length',
                   5949:         max            => 'Maximum password length',
                   5950:         chars          => 'Required characters',
                   5951:         expire         => 'Password expiration (days)',
1.356     raeburn  5952:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  5953:     );
                   5954:     if ($position eq 'top') {
                   5955:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5956:         my $shownlinklife = 2;
                   5957:         my $prelink = 'both';
                   5958:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   5959:         if (ref($settings) eq 'HASH') {
                   5960:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   5961:                 $shownlinklife = $settings->{resetlink};
                   5962:             }
                   5963:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   5964:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   5965:             }
                   5966:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   5967:                 $prelink = $settings->{resetprelink};
                   5968:             }
                   5969:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   5970:                 %postlink = %{$settings->{resetpostlink}};
                   5971:             }
                   5972:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   5973:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   5974:             }
                   5975:             if ($settings->{resetremove}) {
                   5976:                 $nostdtext = 1;
                   5977:             }
                   5978:             if ($settings->{resetcustom}) {
                   5979:                 $customurl = $settings->{resetcustom};
                   5980:             }
                   5981:         } else {
                   5982:             if (ref($types) eq 'ARRAY') {
                   5983:                 foreach my $item (@{$types}) {
                   5984:                     $casesens{$item} = 1;
                   5985:                     $postlink{$item} = ['username','email'];
                   5986:                 }
                   5987:             }
                   5988:             $casesens{'default'} = 1;
                   5989:             $postlink{'default'} = ['username','email'];
                   5990:             $prelink = 'both';
                   5991:             %emailsrc = (
                   5992:                           permanent => 1,
                   5993:                           critical  => 1,
                   5994:                           notify    => 1,
                   5995:             );
                   5996:         }
                   5997:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   5998:         $itemcount ++;
                   5999:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6000:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   6001:                       '<td class="LC_left_item">'.
                   6002:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   6003:                       'name="passwords_link" size="3" /></td></tr>';
                   6004:         $itemcount ++;
                   6005:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6006:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   6007:                       '<td class="LC_left_item">';
                   6008:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6009:             foreach my $item (@{$types}) {
                   6010:                 my $checkedcase;
                   6011:                 if ($casesens{$item}) {
                   6012:                     $checkedcase = ' checked="checked"';
                   6013:                 }
                   6014:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   6015:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   6016:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
                   6017:                               '<span>&nbsp;&nbsp; ';
                   6018:             }
                   6019:         }
                   6020:         my $checkedcase;
                   6021:         if ($casesens{'default'}) {
                   6022:             $checkedcase = ' checked="checked"';
                   6023:         }
                   6024:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   6025:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   6026:                       $othertitle.'</label></span></td>';
                   6027:         $itemcount ++;
                   6028:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6029:         my %checkedpre = (
                   6030:                              both => ' checked="checked"',
                   6031:                              either => '',
                   6032:                          );
                   6033:         if ($prelink eq 'either') {
                   6034:             $checkedpre{either} = ' checked="checked"';
                   6035:             $checkedpre{both} = '';
                   6036:         }
                   6037:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   6038:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6039:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   6040:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   6041:                       '<span class="LC_nobreak"><label>'.
                   6042:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   6043:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   6044:         $itemcount ++;
                   6045:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6046:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   6047:                       '<td class="LC_left_item">';
                   6048:         my %postlinked;
                   6049:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6050:             foreach my $item (@{$types}) {
                   6051:                 undef(%postlinked);
                   6052:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   6053:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   6054:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   6055:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   6056:                 }
                   6057:                 foreach my $field ('email','username') {
                   6058:                     my $checked;
                   6059:                     if ($postlinked{$field}) {
                   6060:                         $checked = ' checked="checked"';
                   6061:                     }
                   6062:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   6063:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   6064:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   6065:                                   '<span>&nbsp;&nbsp; ';
                   6066:                 }
                   6067:                 $datatable .= '</fieldset>';
                   6068:             }
                   6069:         }
                   6070:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   6071:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   6072:         }
                   6073:         $datatable .= '<fieldset style="display: inline-block;">'.
                   6074:                       '<legend>'.$othertitle.'</legend>';
                   6075:         foreach my $field ('email','username') {
                   6076:             my $checked;
                   6077:             if ($postlinked{$field}) {
                   6078:                 $checked = ' checked="checked"';
                   6079:             }
                   6080:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6081:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   6082:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   6083:                           '<span>&nbsp;&nbsp; ';
                   6084:         }
                   6085:         $datatable .= '</fieldset></td></tr>';
                   6086:         $itemcount ++;
                   6087:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6088:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   6089:                       '<td class="LC_left_item">';
                   6090:         foreach my $type ('permanent','critical','notify') {
                   6091:             my $checkedemail;
                   6092:             if ($emailsrc{$type}) {
                   6093:                 $checkedemail = ' checked="checked"';
                   6094:             }
                   6095:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6096:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   6097:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   6098:                           '<span>&nbsp;&nbsp; ';
                   6099:         }
                   6100:         $datatable .= '</td></tr>';
                   6101:         $itemcount ++;
                   6102:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6103:         my $switchserver = &check_switchserver($dom,$confname);
                   6104:         my ($showstd,$noshowstd);
                   6105:         if ($nostdtext) {
                   6106:             $noshowstd = ' checked="checked"';
                   6107:         } else {
                   6108:             $showstd = ' checked="checked"';
                   6109:         }
                   6110:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   6111:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6112:                       &mt('Retain standard text:').
                   6113:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   6114:                       &mt('Yes').'</label>'.'&nbsp;'.
                   6115:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   6116:                       &mt('No').'</label></span><br />'.
                   6117:                       '<span class="LC_fontsize_small">'.
                   6118:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   6119:                       &mt('Include custom text:');
                   6120:         if ($customurl) {
                   6121:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('Custom text file'),600,500,
                   6122:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   6123:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   6124:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   6125:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   6126:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   6127:         }
                   6128:         if ($switchserver) {
                   6129:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   6130:         } else {
                   6131:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   6132:                          '<input type="file" name="passwords_customfile" /></span>';
                   6133:         }
                   6134:         $datatable .= '</td></tr>';
                   6135:     } elsif ($position eq 'middle') {
                   6136:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   6137:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   6138:         my %defaults;
                   6139:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   6140:             %defaults = %{$domconf{'defaults'}};
                   6141:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   6142:                 $defaults{'intauth_cost'} = 10;
                   6143:             }
                   6144:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   6145:                 $defaults{'intauth_check'} = 0;
                   6146:             }
                   6147:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   6148:                 $defaults{'intauth_switch'} = 0;
                   6149:             }
                   6150:         } else {
                   6151:             %defaults = (
                   6152:                           'intauth_cost'   => 10,
                   6153:                           'intauth_check'  => 0,
                   6154:                           'intauth_switch' => 0,
                   6155:                         );
                   6156:         }
                   6157:         foreach my $item (@items) {
                   6158:             if ($itemcount%2) {
                   6159:                 $css_class = '';
                   6160:             } else {
                   6161:                 $css_class = ' class="LC_odd_row" ';
                   6162:             }
                   6163:             $datatable .= '<tr'.$css_class.'>'.
                   6164:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   6165:                           '</span></td><td class="LC_left_item" colspan="3">';
                   6166:             if ($item eq 'intauth_switch') {
                   6167:                 my @options = (0,1,2);
                   6168:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6169:                                    0 => 'No',
                   6170:                                    1 => 'Yes',
                   6171:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   6172:                                  );
                   6173:                 $datatable .= '<table width="100%">';
                   6174:                 foreach my $option (@options) {
                   6175:                     my $checked = ' ';
                   6176:                     if ($defaults{$item} eq $option) {
                   6177:                         $checked = ' checked="checked"';
                   6178:                     }
                   6179:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6180:                                   '<label><input type="radio" name="'.$item.
                   6181:                                   '" value="'.$option.'"'.$checked.' />'.
                   6182:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6183:                 }
                   6184:                 $datatable .= '</table>';
                   6185:             } elsif ($item eq 'intauth_check') {
                   6186:                 my @options = (0,1,2);
                   6187:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6188:                                    0 => 'No',
                   6189:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   6190:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   6191:                                  );
                   6192:                 $datatable .= '<table width="100%">';
                   6193:                 foreach my $option (@options) {
                   6194:                     my $checked = ' ';
                   6195:                     my $onclick;
                   6196:                     if ($defaults{$item} eq $option) {
                   6197:                         $checked = ' checked="checked"';
                   6198:                     }
                   6199:                     if ($option == 2) {
                   6200:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   6201:                     }
                   6202:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6203:                                   '<label><input type="radio" name="'.$item.
                   6204:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   6205:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6206:                 }
                   6207:                 $datatable .= '</table>';
                   6208:             } else {
                   6209:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6210:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   6211:             }
                   6212:             $datatable .= '</td></tr>';
                   6213:             $itemcount ++;
                   6214:         }
                   6215:     } elsif ($position eq 'lower') {
1.356     raeburn  6216:         my ($min,$max,%chars,$expire,$numsaved);
1.354     raeburn  6217:         if (ref($settings) eq 'HASH') {
                   6218:             if ($settings->{min}) {
                   6219:                 $min = $settings->{min};
                   6220:             }
                   6221:             if ($settings->{max}) {
                   6222:                 $max = $settings->{max};
                   6223:             }
                   6224:             if (ref($settings->{chars}) eq 'ARRAY') {
                   6225:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   6226:             }
                   6227:             if ($settings->{expire}) {
                   6228:                 $expire = $settings->{expire};
                   6229:             }
1.358   ! raeburn  6230:             if ($settings->{numsaved}) {
        !          6231:                 $numsaved = $settings->{numsaved};
1.356     raeburn  6232:             }
1.354     raeburn  6233:         } else {
                   6234:             $min = '7';
                   6235:         }
                   6236:         my %rulenames = &Apache::lonlocal::texthash(
                   6237:                                                      uc => 'At least one upper case letter',
                   6238:                                                      lc => 'At least one lower case letter',
                   6239:                                                      num => 'At least one number',
                   6240:                                                      spec => 'At least one non-alphanumeric',
                   6241:                                                    );
                   6242:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6243:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   6244:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6245:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" />'.
                   6246:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no minimum)').'</span>'.
                   6247:                       '</span></td></tr>';
                   6248:         $itemcount ++;
                   6249:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6250:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   6251:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6252:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" />'.
                   6253:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   6254:                       '</span></td></tr>';
                   6255:         $itemcount ++;
                   6256:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6257:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   6258:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   6259:                       '</span></td>';
                   6260:         my $numinrow = 2;
                   6261:         my @possrules = ('uc','lc','num','spec');
                   6262:         $datatable .= '<td class="LC_left_item"><table>';
                   6263:         for (my $i=0; $i<@possrules; $i++) {
                   6264:             my ($rem,$checked);
                   6265:             if ($chars{$possrules[$i]}) {
                   6266:                 $checked = ' checked="checked"';
                   6267:             }
                   6268:             $rem = $i%($numinrow);
                   6269:             if ($rem == 0) {
                   6270:                 if ($i > 0) {
                   6271:                     $datatable .= '</tr>';
                   6272:                 }
                   6273:                 $datatable .= '<tr>';
                   6274:             }
                   6275:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   6276:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   6277:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   6278:         }
                   6279:         my $rem = @possrules%($numinrow);
                   6280:         my $colsleft = $numinrow - $rem;
                   6281:         if ($colsleft > 1 ) {
                   6282:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6283:                           '&nbsp;</td>';
                   6284:         } elsif ($colsleft == 1) {
                   6285:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   6286:         }
                   6287:         $datatable .='</table></td></tr>';
                   6288:         $itemcount ++;
                   6289:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6290:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   6291:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6292:                       '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" />'.
                   6293:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   6294:                       '</span></td></tr>';
1.356     raeburn  6295:         $itemcount ++;
                   6296:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6297:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   6298:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6299:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" />'.
                   6300:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   6301:                       '</span></td></tr>';
1.354     raeburn  6302:     } else {
                   6303:         my $checkedon;
                   6304:         my $checkedoff = ' checked="checked"';
                   6305:         if (ref($settings) eq 'HASH') {
                   6306:             if ($settings->{crsownerchg}) {
                   6307:                 $checkedon = $checkedoff;
                   6308:                 $checkedoff = '';
                   6309:             }
                   6310:         }
                   6311:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6312:         $datatable .= '<tr '.$css_class.'>'.
                   6313:                       '<td>'.
                   6314:                       &mt('Requirements').'<ul>'.
                   6315:                       '<li>'.&mt("Course 'type' is not a Community").'</li>'.
                   6316:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   6317:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
                   6318:                       '</ul>'.
                   6319:                       '</td>'.
                   6320:                       '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
                   6321:                       '<label><input type="radio" name="passwords_crsowner" value="1"'.$checkedon.' />'.&mt('Yes').'</label></span> &nbsp;&nbsp;'.
                   6322:                       '<span class="LC_nobreak"><label><input type="radio" name="passwords_crsowner" value="0"'.$checkedoff.' />'.
                   6323:                       &mt('No').'</label></span>'.
                   6324:                       '</td></tr>';
                   6325: 
                   6326:     }
                   6327:     return $datatable;
                   6328: }
                   6329: 
1.137     raeburn  6330: sub print_usersessions {
                   6331:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  6332:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  6333:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   6334:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  6335: 
                   6336:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  6337:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  6338:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  6339:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  6340:     if ($position eq 'top') {
1.152     raeburn  6341:         if (keys(%serverhomes) > 1) {
1.145     raeburn  6342:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.261     raeburn  6343:             my $curroffloadnow;
                   6344:             if (ref($settings) eq 'HASH') {
                   6345:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   6346:                     $curroffloadnow = $settings->{'offloadnow'};
                   6347:                 }
                   6348:             }
                   6349:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  6350:         } else {
1.140     raeburn  6351:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  6352:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   6353:                           '</td></tr>';
1.140     raeburn  6354:         }
1.137     raeburn  6355:     } else {
1.279     raeburn  6356:         my %titles = &usersession_titles();
                   6357:         my ($prefix,@types);
                   6358:         if ($position eq 'bottom') {
                   6359:             $prefix = 'remote';
                   6360:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  6361:         } else {
1.279     raeburn  6362:             $prefix = 'hosted';
                   6363:             @types = ('excludedomain','includedomain');
                   6364:         }
                   6365:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   6366:     }
                   6367:     $$rowtotal += $itemcount;
                   6368:     return $datatable;
                   6369: }
                   6370: 
                   6371: sub rules_by_location {
                   6372:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   6373:     my ($datatable,$itemcount,$css_class);
                   6374:     if (keys(%{$by_location}) == 0) {
                   6375:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6376:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   6377:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   6378:                      '</td></tr>';
                   6379:         $itemcount = 1;
                   6380:     } else {
                   6381:         $itemcount = 0;
                   6382:         my $numinrow = 5;
                   6383:         my (%current,%checkedon,%checkedoff);
                   6384:         my @locations = sort(keys(%{$by_location}));
                   6385:         foreach my $type (@{$types}) {
                   6386:             $checkedon{$type} = '';
                   6387:             $checkedoff{$type} = ' checked="checked"';
                   6388:         }
                   6389:         if (ref($settings) eq 'HASH') {
                   6390:             if (ref($settings->{$prefix}) eq 'HASH') {
                   6391:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   6392:                     $current{$key} = $settings->{$prefix}{$key};
                   6393:                     if ($key eq 'version') {
                   6394:                         if ($current{$key} ne '') {
1.145     raeburn  6395:                             $checkedon{$key} = ' checked="checked"';
                   6396:                             $checkedoff{$key} = '';
                   6397:                         }
1.279     raeburn  6398:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   6399:                         $checkedon{$key} = ' checked="checked"';
                   6400:                         $checkedoff{$key} = '';
1.137     raeburn  6401:                     }
                   6402:                 }
                   6403:             }
1.279     raeburn  6404:         }
                   6405:         foreach my $type (@{$types}) {
                   6406:             next if ($type ne 'version' && !@locations);
                   6407:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6408:             $datatable .= '<tr'.$css_class.'>
                   6409:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   6410:                            <span class="LC_nobreak">&nbsp;
                   6411:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   6412:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   6413:             if ($type eq 'version') {
                   6414:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   6415:                 my $selector = '<select name="'.$prefix.'_version">';
                   6416:                 foreach my $version (@lcversions) {
                   6417:                     my $selected = '';
                   6418:                     if ($current{'version'} eq $version) {
                   6419:                         $selected = ' selected="selected"';
1.145     raeburn  6420:                     }
1.279     raeburn  6421:                     $selector .= ' <option value="'.$version.'"'.
                   6422:                                  $selected.'>'.$version.'</option>';
                   6423:                 }
                   6424:                 $selector .= '</select> ';
                   6425:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   6426:             } else {
                   6427:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   6428:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   6429:                              ' />'.('&nbsp;'x2).
                   6430:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   6431:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   6432:                              "\n".
                   6433:                              '</div><div><table>';
                   6434:                 my $rem;
                   6435:                 for (my $i=0; $i<@locations; $i++) {
                   6436:                     my ($showloc,$value,$checkedtype);
                   6437:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   6438:                         my $ip = $by_location->{$locations[$i]}->[0];
                   6439:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6440:                             $value = join(':',@{$by_ip->{$ip}});
                   6441:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   6442:                             if (ref($current{$type}) eq 'ARRAY') {
                   6443:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   6444:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   6445:                                         $checkedtype = ' checked="checked"';
                   6446:                                         last;
1.145     raeburn  6447:                                     }
1.138     raeburn  6448:                                 }
                   6449:                             }
                   6450:                         }
1.137     raeburn  6451:                     }
1.279     raeburn  6452:                     $rem = $i%($numinrow);
                   6453:                     if ($rem == 0) {
                   6454:                         if ($i > 0) {
                   6455:                             $datatable .= '</tr>';
                   6456:                         }
                   6457:                         $datatable .= '<tr>';
                   6458:                     }
                   6459:                     $datatable .= '<td class="LC_left_item">'.
                   6460:                                   '<span class="LC_nobreak"><label>'.
                   6461:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   6462:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   6463:                                   '</label></span></td>';
                   6464:                 }
                   6465:                 $rem = @locations%($numinrow);
                   6466:                 my $colsleft = $numinrow - $rem;
                   6467:                 if ($colsleft > 1 ) {
                   6468:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6469:                                   '&nbsp;</td>';
                   6470:                 } elsif ($colsleft == 1) {
                   6471:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  6472:                 }
1.279     raeburn  6473:                 $datatable .= '</tr></table>';
1.137     raeburn  6474:             }
1.279     raeburn  6475:             $datatable .= '</td></tr>';
                   6476:             $itemcount ++;
1.137     raeburn  6477:         }
                   6478:     }
1.279     raeburn  6479:     return ($datatable,$itemcount);
1.137     raeburn  6480: }
                   6481: 
1.275     raeburn  6482: sub print_ssl {
                   6483:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6484:     my ($css_class,$datatable);
                   6485:     my $itemcount = 1;
                   6486:     if ($position eq 'top') {
1.281     raeburn  6487:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   6488:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   6489:         my $same_institution;
                   6490:         if ($intdom ne '') {
                   6491:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   6492:             if (ref($internet_names) eq 'ARRAY') {
                   6493:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   6494:                     $same_institution = 1;
                   6495:                 }
                   6496:             }
                   6497:         }
1.275     raeburn  6498:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  6499:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   6500:         if ($same_institution) {
                   6501:             my %domservers = &Apache::lonnet::get_servers($dom);
                   6502:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   6503:         } else {
                   6504:             $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.");
                   6505:         }
                   6506:         $datatable .= '</td></tr>';
1.275     raeburn  6507:         $itemcount ++;
                   6508:     } else {
                   6509:         my %titles = &ssl_titles();
                   6510:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   6511:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   6512:         my @alldoms = &Apache::lonnet::all_domains();
                   6513:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   6514:         my @domservers = &Apache::lonnet::get_servers($dom);
                   6515:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   6516:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  6517:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   6518:             my $legacy;
                   6519:             unless (ref($settings) eq 'HASH') {
                   6520:                 my $name;
                   6521:                 if ($position eq 'connto') {
                   6522:                     $name = 'loncAllowInsecure';
                   6523:                 } else {
                   6524:                     $name = 'londAllowInsecure';
                   6525:                 }
                   6526:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   6527:                 my @ids=&Apache::lonnet::current_machine_ids();
                   6528:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   6529:                     my %what = (
                   6530:                                    $name => 1,
                   6531:                                );
                   6532:                     my ($result,$returnhash) =
                   6533:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   6534:                     if ($result eq 'ok') {
                   6535:                         if (ref($returnhash) eq 'HASH') {
                   6536:                             $legacy = $returnhash->{$name};
                   6537:                         }
                   6538:                     }
                   6539:                 } else {
                   6540:                     $legacy = $Apache::lonnet::perlvar{$name};
                   6541:                 }
                   6542:             }
1.275     raeburn  6543:             foreach my $type ('dom','intdom','other') {
                   6544:                 my %checked;
                   6545:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6546:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   6547:                               '<td class="LC_right_item">';
                   6548:                 my $skip; 
                   6549:                 if ($type eq 'dom') {
                   6550:                     unless (keys(%servers) > 1) {
                   6551:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   6552:                         $skip = 1;
                   6553:                     }
                   6554:                 }
                   6555:                 if ($type eq 'intdom') {
                   6556:                     unless (@instdoms > 1) {
                   6557:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   6558:                         $skip = 1;
                   6559:                     } 
                   6560:                 } elsif ($type eq 'other') {
                   6561:                     if (keys(%by_location) == 0) {
                   6562:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   6563:                         $skip = 1;
                   6564:                     }
                   6565:                 }
                   6566:                 unless ($skip) {
                   6567:                     $checked{'yes'} = ' checked="checked"'; 
                   6568:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  6569:                         if (ref($settings->{$position}) eq 'HASH') {
                   6570:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  6571:                                 $checked{$1} = $checked{'yes'};
                   6572:                                 delete($checked{'yes'}); 
                   6573:                             }
                   6574:                         }
1.293     raeburn  6575:                     } else {
                   6576:                         if ($legacy == 0) {
                   6577:                             $checked{'req'} = $checked{'yes'};
                   6578:                             delete($checked{'yes'});    
                   6579:                         }
1.275     raeburn  6580:                     }
                   6581:                     foreach my $option ('no','yes','req') {
                   6582:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  6583:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  6584:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   6585:                                       '</label></span>'.('&nbsp;'x2);
                   6586:                     }
                   6587:                 }
                   6588:                 $datatable .= '</td></tr>';
                   6589:                 $itemcount ++; 
                   6590:             }
                   6591:         } else {
                   6592:             my $prefix = 'replication';
                   6593:             my @types = ('certreq','nocertreq');
1.279     raeburn  6594:             if (keys(%by_location) == 0) {
                   6595:                 $datatable .= '<tr'.$css_class.'><td>'.
                   6596:                               &mt('Nothing to set here, as there are no other institutions').
                   6597:                               '</td></tr>';
                   6598:                 $itemcount ++;
1.275     raeburn  6599:             } else {
1.279     raeburn  6600:                 ($datatable,$itemcount) = 
                   6601:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  6602:             }
                   6603:         }
                   6604:     }
                   6605:     $$rowtotal += $itemcount;
                   6606:     return $datatable;
                   6607: }
                   6608: 
                   6609: sub ssl_titles {
                   6610:     return &Apache::lonlocal::texthash (
                   6611:                dom           => 'LON-CAPA servers/VMs from same domain',
                   6612:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   6613:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  6614:                connto        => 'Connections to other servers',
                   6615:                connfrom      => 'Connections from other servers',
1.275     raeburn  6616:                replication   => 'Replicating content to other institutions',
                   6617:                certreq       => 'Client certificate required, but specific domains exempt',
                   6618:                nocertreq     => 'No client certificate required, except for specific domains',
                   6619:                no            => 'SSL not used',
                   6620:                yes           => 'SSL Optional (used if available)',
                   6621:                req           => 'SSL Required',
                   6622:     );
1.279     raeburn  6623: }
                   6624: 
                   6625: sub print_trust {
                   6626:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   6627:     my ($css_class,$datatable,%checked,%choices);
                   6628:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   6629:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   6630:     my $itemcount = 1;
                   6631:     my %titles = &trust_titles();
                   6632:     my @types = ('exc','inc');
                   6633:     if ($prefix eq 'top') {
                   6634:         $prefix = 'content';
                   6635:     } elsif ($prefix eq 'bottom') {
                   6636:         $prefix = 'msg';
                   6637:     }
                   6638:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   6639:     $$rowtotal += $itemcount;
                   6640:     return $datatable;
                   6641: }
                   6642: 
                   6643: sub trust_titles {
                   6644:     return &Apache::lonlocal::texthash(
                   6645:                content  => "Access to this domain's content by others",
                   6646:                shared   => "Access to other domain's content by this domain",
                   6647:                enroll   => "Enrollment in this domain's courses by others", 
                   6648:                othcoau  => "Co-author roles in this domain for others",
                   6649:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   6650:                domroles => "Domain roles in this domain assignable to others",
                   6651:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   6652:                reqcrs   => "Requests for creation of courses in this domain by others",
                   6653:                msg      => "Users in other domains can send messages to this domain",
                   6654:                exc      => "Allow all, but exclude specific domains",
                   6655:                inc      => "Deny all, but include specific domains",
                   6656:            );
1.275     raeburn  6657: } 
                   6658: 
1.138     raeburn  6659: sub build_location_hashes {
1.275     raeburn  6660:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  6661:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  6662:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  6663:     my %iphost = &Apache::lonnet::get_iphost();
                   6664:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   6665:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   6666:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   6667:         foreach my $id (@{$iphost{$primary_ip}}) {
                   6668:             my $intdom = &Apache::lonnet::internet_dom($id);
                   6669:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   6670:                 push(@{$intdoms},$intdom);
                   6671:             }
                   6672:         }
                   6673:     }
                   6674:     foreach my $ip (keys(%iphost)) {
                   6675:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   6676:             foreach my $id (@{$iphost{$ip}}) {
                   6677:                 my $location = &Apache::lonnet::internet_dom($id);
                   6678:                 if ($location) {
1.275     raeburn  6679:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   6680:                         my $dom = &Apache::lonnet::host_domain($id);
                   6681:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   6682:                             push(@{$instdoms},$dom);
                   6683:                         }
                   6684:                         next;
                   6685:                     }
1.138     raeburn  6686:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6687:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   6688:                             push(@{$by_ip->{$ip}},$location);
                   6689:                         }
                   6690:                     } else {
                   6691:                         $by_ip->{$ip} = [$location];
                   6692:                     }
                   6693:                 }
                   6694:             }
                   6695:         }
                   6696:     }
                   6697:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   6698:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6699:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   6700:             my $first = $by_ip->{$ip}->[0];
                   6701:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   6702:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   6703:                     push(@{$by_location->{$first}},$ip);
                   6704:                 }
                   6705:             } else {
                   6706:                 $by_location->{$first} = [$ip];
                   6707:             }
                   6708:         }
                   6709:     }
                   6710:     return;
                   6711: }
                   6712: 
1.145     raeburn  6713: sub current_offloads_to {
                   6714:     my ($dom,$settings,$servers) = @_;
                   6715:     my (%spareid,%otherdomconfigs);
1.152     raeburn  6716:     if (ref($servers) eq 'HASH') {
1.145     raeburn  6717:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   6718:             my $gotspares;
1.152     raeburn  6719:             if (ref($settings) eq 'HASH') {
                   6720:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   6721:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   6722:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   6723:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   6724:                         $gotspares = 1;
                   6725:                     }
1.145     raeburn  6726:                 }
                   6727:             }
                   6728:             unless ($gotspares) {
                   6729:                 my $gotspares;
                   6730:                 my $serverhomeID =
                   6731:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   6732:                 my $serverhomedom =
                   6733:                     &Apache::lonnet::host_domain($serverhomeID);
                   6734:                 if ($serverhomedom ne $dom) {
                   6735:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   6736:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6737:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6738:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6739:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6740:                                 $gotspares = 1;
                   6741:                             }
                   6742:                         }
                   6743:                     } else {
                   6744:                         $otherdomconfigs{$serverhomedom} =
                   6745:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   6746:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   6747:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6748:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6749:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   6750:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6751:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6752:                                         $gotspares = 1;
                   6753:                                     }
                   6754:                                 }
                   6755:                             }
                   6756:                         }
                   6757:                     }
                   6758:                 }
                   6759:             }
                   6760:             unless ($gotspares) {
                   6761:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6762:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6763:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6764:                } else {
                   6765:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   6766:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   6767:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6768:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6769:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6770:                     } else {
1.150     raeburn  6771:                         my %what = (
                   6772:                              spareid => 1,
                   6773:                         );
                   6774:                         my ($result,$returnhash) = 
                   6775:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   6776:                         if ($result eq 'ok') { 
                   6777:                             if (ref($returnhash) eq 'HASH') {
                   6778:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   6779:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   6780:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   6781:                                 }
                   6782:                             }
1.145     raeburn  6783:                         }
                   6784:                     }
                   6785:                 }
                   6786:             }
                   6787:         }
                   6788:     }
                   6789:     return %spareid;
                   6790: }
                   6791: 
                   6792: sub spares_row {
1.261     raeburn  6793:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  6794:     my $css_class;
                   6795:     my $numinrow = 4;
                   6796:     my $itemcount = 1;
                   6797:     my $datatable;
1.152     raeburn  6798:     my %typetitles = &sparestype_titles();
                   6799:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  6800:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  6801:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   6802:             my ($othercontrol,$serverdom);
                   6803:             if ($serverhome ne $server) {
                   6804:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   6805:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6806:             } else {
                   6807:                 $serverdom = &Apache::lonnet::host_domain($server);
                   6808:                 if ($serverdom ne $dom) {
                   6809:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6810:                 }
                   6811:             }
                   6812:             next unless (ref($spareid->{$server}) eq 'HASH');
1.261     raeburn  6813:             my $checkednow;
                   6814:             if (ref($curroffloadnow) eq 'HASH') {
                   6815:                 if ($curroffloadnow->{$server}) {
                   6816:                     $checkednow = ' checked="checked"';
                   6817:                 }
                   6818:             }
1.145     raeburn  6819:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6820:             $datatable .= '<tr'.$css_class.'>
                   6821:                            <td rowspan="2">
1.183     bisitz   6822:                             <span class="LC_nobreak">'.
                   6823:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  6824:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  6825:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  6826:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   6827:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.183     bisitz   6828:                           "\n";
1.145     raeburn  6829:             my (%current,%canselect);
1.152     raeburn  6830:             my @choices = 
                   6831:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   6832:             foreach my $type ('primary','default') {
                   6833:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  6834:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   6835:                         my @spares = @{$spareid->{$server}{$type}};
                   6836:                         if (@spares > 0) {
1.152     raeburn  6837:                             if ($othercontrol) {
                   6838:                                 $current{$type} = join(', ',@spares);
                   6839:                             } else {
                   6840:                                 $current{$type} .= '<table>';
                   6841:                                 my $numspares = scalar(@spares);
                   6842:                                 for (my $i=0;  $i<@spares; $i++) {
                   6843:                                     my $rem = $i%($numinrow);
                   6844:                                     if ($rem == 0) {
                   6845:                                         if ($i > 0) {
                   6846:                                             $current{$type} .= '</tr>';
                   6847:                                         }
                   6848:                                         $current{$type} .= '<tr>';
1.145     raeburn  6849:                                     }
1.152     raeburn  6850:                                     $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;'.
                   6851:                                                        $spareid->{$server}{$type}[$i].
                   6852:                                                        '</label></td>'."\n";
                   6853:                                 }
                   6854:                                 my $rem = @spares%($numinrow);
                   6855:                                 my $colsleft = $numinrow - $rem;
                   6856:                                 if ($colsleft > 1 ) {
                   6857:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   6858:                                                        '" class="LC_left_item">'.
                   6859:                                                        '&nbsp;</td>';
                   6860:                                 } elsif ($colsleft == 1) {
                   6861:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  6862:                                 }
1.152     raeburn  6863:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  6864:                             }
1.145     raeburn  6865:                         }
                   6866:                     }
                   6867:                     if ($current{$type} eq '') {
                   6868:                         $current{$type} = &mt('None specified');
                   6869:                     }
1.152     raeburn  6870:                     if ($othercontrol) {
                   6871:                         if ($type eq 'primary') {
                   6872:                             $canselect{$type} = $othercontrol;
                   6873:                         }
                   6874:                     } else {
                   6875:                         $canselect{$type} = 
                   6876:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   6877:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   6878:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   6879:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   6880:                         if (@choices > 0) {
                   6881:                             foreach my $lonhost (@choices) {
                   6882:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   6883:                             }
                   6884:                         }
                   6885:                         $canselect{$type} .= '</select>'."\n";
                   6886:                     }
                   6887:                 } else {
                   6888:                     $current{$type} = &mt('Could not be determined');
                   6889:                     if ($type eq 'primary') {
                   6890:                         $canselect{$type} =  $othercontrol;
                   6891:                     }
1.145     raeburn  6892:                 }
1.152     raeburn  6893:                 if ($type eq 'default') {
                   6894:                     $datatable .= '<tr'.$css_class.'>';
                   6895:                 }
                   6896:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   6897:                               '<td>'.$current{$type}.'</td>'."\n".
                   6898:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  6899:             }
                   6900:             $itemcount ++;
                   6901:         }
                   6902:     }
                   6903:     $$rowtotal += $itemcount;
                   6904:     return $datatable;
                   6905: }
                   6906: 
1.152     raeburn  6907: sub possible_newspares {
                   6908:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   6909:     my $serverhostname = &Apache::lonnet::hostname($server);
                   6910:     my %excluded;
                   6911:     if ($serverhostname ne '') {
                   6912:         %excluded = (
                   6913:                        $serverhostname => 1,
                   6914:                     );
                   6915:     }
                   6916:     if (ref($currspares) eq 'HASH') {
                   6917:         foreach my $type (keys(%{$currspares})) {
                   6918:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   6919:                 if (@{$currspares->{$type}} > 0) {
                   6920:                     foreach my $curr (@{$currspares->{$type}}) {
                   6921:                         my $hostname = &Apache::lonnet::hostname($curr);
                   6922:                         $excluded{$hostname} = 1;
                   6923:                     }
                   6924:                 }
                   6925:             }
                   6926:         }
                   6927:     }
                   6928:     my @choices;
                   6929:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   6930:         if (keys(%{$serverhomes}) > 1) {
                   6931:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   6932:                 unless ($excluded{$name}) {
                   6933:                     if (exists($altids->{$serverhomes->{$name}})) {
                   6934:                         push(@choices,$altids->{$serverhomes->{$name}});
                   6935:                     } else {
                   6936:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  6937:                     }
                   6938:                 }
                   6939:             }
                   6940:         }
                   6941:     }
1.152     raeburn  6942:     return sort(@choices);
1.145     raeburn  6943: }
                   6944: 
1.150     raeburn  6945: sub print_loadbalancing {
                   6946:     my ($dom,$settings,$rowtotal) = @_;
                   6947:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   6948:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   6949:     my $numinrow = 1;
                   6950:     my $datatable;
                   6951:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  6952:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  6953:     if (ref($settings) eq 'HASH') {
                   6954:         %existing = %{$settings};
                   6955:     }
                   6956:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   6957:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  6958:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  6959:     } else {
                   6960:         return;
                   6961:     }
                   6962:     my ($othertitle,$usertypes,$types) =
                   6963:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  6964:     my $rownum = 8;
1.150     raeburn  6965:     if (ref($types) eq 'ARRAY') {
                   6966:         $rownum += scalar(@{$types});
                   6967:     }
1.171     raeburn  6968:     my @css_class = ('LC_odd_row','LC_even_row');
                   6969:     my $balnum = 0;
                   6970:     my $islast;
                   6971:     my (@toshow,$disabledtext);
                   6972:     if (keys(%currbalancer) > 0) {
                   6973:         @toshow = sort(keys(%currbalancer));
                   6974:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   6975:             push(@toshow,'');
                   6976:         }
                   6977:     } else {
                   6978:         @toshow = ('');
                   6979:         $disabledtext = &mt('No existing load balancer');
                   6980:     }
                   6981:     foreach my $lonhost (@toshow) {
                   6982:         if ($balnum == scalar(@toshow)-1) {
                   6983:             $islast = 1;
                   6984:         } else {
                   6985:             $islast = 0;
                   6986:         }
                   6987:         my $cssidx = $balnum%2;
                   6988:         my $targets_div_style = 'display: none';
                   6989:         my $disabled_div_style = 'display: block';
                   6990:         my $homedom_div_style = 'display: none';
                   6991:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  6992:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  6993:                       '<p>';
                   6994:         if ($lonhost eq '') {
1.210     raeburn  6995:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  6996:             if (keys(%currbalancer) > 0) {
                   6997:                 $datatable .= &mt('Add balancer:');
                   6998:             } else {
                   6999:                 $datatable .= &mt('Enable balancer:');
                   7000:             }
                   7001:             $datatable .= '&nbsp;'.
                   7002:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   7003:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   7004:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   7005:                           '<option value="" selected="selected">'.&mt('None').
                   7006:                           '</option>'."\n";
                   7007:             foreach my $server (sort(keys(%servers))) {
                   7008:                 next if ($currbalancer{$server});
                   7009:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   7010:             }
1.210     raeburn  7011:             $datatable .=
1.171     raeburn  7012:                 '</select>'."\n".
                   7013:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   7014:         } else {
                   7015:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   7016:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   7017:                            &mt('Stop balancing').'</label>'.
                   7018:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   7019:             $targets_div_style = 'display: block';
                   7020:             $disabled_div_style = 'display: none';
                   7021:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   7022:                 $homedom_div_style = 'display: block';
                   7023:             }
                   7024:         }
1.306     raeburn  7025:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  7026:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   7027:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   7028:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   7029:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   7030:         my @sparestypes = ('primary','default');
                   7031:         my %typetitles = &sparestype_titles();
1.284     raeburn  7032:         my %hostherechecked = (
                   7033:                                   no => ' checked="checked"',
                   7034:                               );
1.342     raeburn  7035:         my %balcookiechecked = (
                   7036:                                   no => ' checked="checked"', 
                   7037:                                );
1.171     raeburn  7038:         foreach my $sparetype (@sparestypes) {
                   7039:             my $targettable;
                   7040:             for (my $i=0; $i<$numspares; $i++) {
                   7041:                 my $checked;
                   7042:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7043:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7044:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7045:                             $checked = ' checked="checked"';
                   7046:                         }
                   7047:                     }
                   7048:                 }
                   7049:                 my ($chkboxval,$disabled);
                   7050:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   7051:                     $chkboxval = $spares[$i];
                   7052:                 }
                   7053:                 if (exists($currbalancer{$spares[$i]})) {
                   7054:                     $disabled = ' disabled="disabled"';
                   7055:                 }
1.210     raeburn  7056:                 $targettable .=
1.253     raeburn  7057:                     '<td><span class="LC_nobreak"><label>'.
                   7058:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  7059:                     $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  7060:                     '</span></label></span></td>';
1.171     raeburn  7061:                 my $rem = $i%($numinrow);
                   7062:                 if ($rem == 0) {
                   7063:                     if (($i > 0) && ($i < $numspares-1)) {
                   7064:                         $targettable .= '</tr>';
                   7065:                     }
                   7066:                     if ($i < $numspares-1) {
                   7067:                         $targettable .= '<tr>';
1.150     raeburn  7068:                     }
                   7069:                 }
                   7070:             }
1.171     raeburn  7071:             if ($targettable ne '') {
                   7072:                 my $rem = $numspares%($numinrow);
                   7073:                 my $colsleft = $numinrow - $rem;
                   7074:                 if ($colsleft > 1 ) {
                   7075:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7076:                                     '&nbsp;</td>';
                   7077:                 } elsif ($colsleft == 1) {
                   7078:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   7079:                 }
                   7080:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   7081:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   7082:             }
1.284     raeburn  7083:             $hostherechecked{$sparetype} = '';
                   7084:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7085:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7086:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7087:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   7088:                         $hostherechecked{'no'} = '';
                   7089:                     }
                   7090:                 }
                   7091:             }
                   7092:         }
1.342     raeburn  7093:         if ($currcookies{$lonhost}) {
                   7094:             %balcookiechecked = (
                   7095:                                     yes => ' checked="checked"',
                   7096:                                 );
                   7097:         }
1.284     raeburn  7098:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   7099:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   7100:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   7101:         foreach my $sparetype (@sparestypes) {
                   7102:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   7103:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   7104:                           '</i></label><br />';
1.171     raeburn  7105:         }
1.342     raeburn  7106:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   7107:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   7108:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   7109:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   7110:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   7111:                       '</div></td></tr>'.
1.171     raeburn  7112:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   7113:                                            $othertitle,$usertypes,$types,\%servers,
                   7114:                                            \%currbalancer,$lonhost,
                   7115:                                            $targets_div_style,$homedom_div_style,
                   7116:                                            $css_class[$cssidx],$balnum,$islast);
                   7117:         $$rowtotal += $rownum;
                   7118:         $balnum ++;
                   7119:     }
                   7120:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   7121:     return $datatable;
                   7122: }
                   7123: 
                   7124: sub get_loadbalancers_config {
1.342     raeburn  7125:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  7126:     return unless ((ref($servers) eq 'HASH') &&
                   7127:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  7128:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   7129:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  7130:     if (keys(%{$existing}) > 0) {
                   7131:         my $oldlonhost;
                   7132:         foreach my $key (sort(keys(%{$existing}))) {
                   7133:             if ($key eq 'lonhost') {
                   7134:                 $oldlonhost = $existing->{'lonhost'};
                   7135:                 $currbalancer->{$oldlonhost} = 1;
                   7136:             } elsif ($key eq 'targets') {
                   7137:                 if ($oldlonhost) {
                   7138:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   7139:                 }
                   7140:             } elsif ($key eq 'rules') {
                   7141:                 if ($oldlonhost) {
                   7142:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   7143:                 }
                   7144:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   7145:                 $currbalancer->{$key} = 1;
                   7146:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   7147:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  7148:                 if ($existing->{$key}{'cookie'}) {
                   7149:                     $currcookies->{$key} = 1;
                   7150:                 }
1.150     raeburn  7151:             }
                   7152:         }
1.171     raeburn  7153:     } else {
                   7154:         my ($balancerref,$targetsref) =
                   7155:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   7156:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   7157:             foreach my $server (sort(keys(%{$balancerref}))) {
                   7158:                 $currbalancer->{$server} = 1;
                   7159:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  7160:             }
                   7161:         }
                   7162:     }
1.171     raeburn  7163:     return;
1.150     raeburn  7164: }
                   7165: 
                   7166: sub loadbalancing_rules {
                   7167:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  7168:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   7169:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  7170:     my $output;
1.171     raeburn  7171:     my $num = 0;
1.210     raeburn  7172:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  7173:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7174:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   7175:         foreach my $type (@{$alltypes}) {
1.171     raeburn  7176:             $num ++;
1.150     raeburn  7177:             my $current;
                   7178:             if (ref($currrules) eq 'HASH') {
                   7179:                 $current = $currrules->{$type};
                   7180:             }
1.253     raeburn  7181:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  7182:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  7183:                     $current = '';
                   7184:                 }
                   7185:             }
                   7186:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  7187:                                              $servers,$currbalancer,$lonhost,$dom,
                   7188:                                              $targets_div_style,$homedom_div_style,
                   7189:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  7190:         }
                   7191:     }
                   7192:     return $output;
                   7193: }
                   7194: 
                   7195: sub loadbalancing_titles {
                   7196:     my ($dom,$intdom,$usertypes,$types) = @_;
                   7197:     my %othertypes = (
                   7198:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   7199:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   7200:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   7201:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  7202:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   7203:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  7204:                      );
1.209     raeburn  7205:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  7206:     my @available;
1.150     raeburn  7207:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  7208:         @available = @{$types};
1.150     raeburn  7209:     }
1.302     raeburn  7210:     unless (grep(/^default$/,@available)) {
                   7211:         push(@available,'default');
                   7212:     }
                   7213:     unshift(@alltypes,@available);
1.150     raeburn  7214:     my %titles;
                   7215:     foreach my $type (@alltypes) {
                   7216:         if ($type =~ /^_LC_/) {
                   7217:             $titles{$type} = $othertypes{$type};
                   7218:         } elsif ($type eq 'default') {
                   7219:             $titles{$type} = &mt('All users from [_1]',$dom);
                   7220:             if (ref($types) eq 'ARRAY') {
                   7221:                 if (@{$types} > 0) {
                   7222:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   7223:                 }
                   7224:             }
                   7225:         } elsif (ref($usertypes) eq 'HASH') {
                   7226:             $titles{$type} = $usertypes->{$type};
                   7227:         }
                   7228:     }
                   7229:     return (\@alltypes,\%othertypes,\%titles);
                   7230: }
                   7231: 
                   7232: sub loadbalance_rule_row {
1.171     raeburn  7233:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   7234:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  7235:     my @rulenames;
1.150     raeburn  7236:     my %ruletitles = &offloadtype_text();
1.209     raeburn  7237:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  7238:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  7239:     } else {
1.209     raeburn  7240:         @rulenames = ('default','homeserver');
                   7241:         if ($type eq '_LC_external') {
                   7242:             push(@rulenames,'externalbalancer');
                   7243:         } else {
                   7244:             push(@rulenames,'specific');
                   7245:         }
                   7246:         push(@rulenames,'none');
1.150     raeburn  7247:     }
                   7248:     my $style = $targets_div_style;
1.253     raeburn  7249:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  7250:         $style = $homedom_div_style;
                   7251:     }
1.171     raeburn  7252:     my $space;
                   7253:     if ($islast && $num == 1) {
1.317     raeburn  7254:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  7255:     }
1.210     raeburn  7256:     my $output =
1.306     raeburn  7257:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  7258:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   7259:         '<td valaign="top">'.$space.
                   7260:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  7261:     for (my $i=0; $i<@rulenames; $i++) {
                   7262:         my $rule = $rulenames[$i];
                   7263:         my ($checked,$extra);
                   7264:         if ($rulenames[$i] eq 'default') {
                   7265:             $rule = '';
                   7266:         }
                   7267:         if ($rulenames[$i] eq 'specific') {
                   7268:             if (ref($servers) eq 'HASH') {
                   7269:                 my $default;
                   7270:                 if (($current ne '') && (exists($servers->{$current}))) {
                   7271:                     $checked = ' checked="checked"';
                   7272:                 }
                   7273:                 unless ($checked) {
                   7274:                     $default = ' selected="selected"';
                   7275:                 }
1.210     raeburn  7276:                 $extra =
1.171     raeburn  7277:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7278:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7279:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   7280:                     '<option value=""'.$default.'></option>'."\n";
                   7281:                 foreach my $server (sort(keys(%{$servers}))) {
                   7282:                     if (ref($currbalancer) eq 'HASH') {
                   7283:                         next if (exists($currbalancer->{$server}));
                   7284:                     }
1.150     raeburn  7285:                     my $selected;
1.171     raeburn  7286:                     if ($server eq $current) {
1.150     raeburn  7287:                         $selected = ' selected="selected"';
                   7288:                     }
1.171     raeburn  7289:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  7290:                 }
                   7291:                 $extra .= '</select>';
                   7292:             }
                   7293:         } elsif ($rule eq $current) {
                   7294:             $checked = ' checked="checked"';
                   7295:         }
                   7296:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  7297:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   7298:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   7299:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  7300:                    ')"'.$checked.' />&nbsp;';
                   7301:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   7302:             $output .= $ruletitles{'particular'};
                   7303:         } else {
                   7304:             $output .= $ruletitles{$rulenames[$i]};
                   7305:         }
                   7306:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  7307:     }
                   7308:     $output .= '</div></td></tr>'."\n";
                   7309:     return $output;
                   7310: }
                   7311: 
                   7312: sub offloadtype_text {
                   7313:     my %ruletitles = &Apache::lonlocal::texthash (
                   7314:            'default'          => 'Offloads to default destinations',
                   7315:            'homeserver'       => "Offloads to user's home server",
                   7316:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   7317:            'specific'         => 'Offloads to specific server',
1.161     raeburn  7318:            'none'             => 'No offload',
1.209     raeburn  7319:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   7320:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  7321:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  7322:     );
                   7323:     return %ruletitles;
                   7324: }
                   7325: 
                   7326: sub sparestype_titles {
                   7327:     my %typestitles = &Apache::lonlocal::texthash (
                   7328:                           'primary' => 'primary',
                   7329:                           'default' => 'default',
                   7330:                       );
                   7331:     return %typestitles;
                   7332: }
                   7333: 
1.28      raeburn  7334: sub contact_titles {
                   7335:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  7336:                    'supportemail'    => 'Support E-mail address',
                   7337:                    'adminemail'      => 'Default Server Admin E-mail address',
                   7338:                    'errormail'       => 'Error reports to be e-mailed to',
                   7339:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  7340:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   7341:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  7342:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   7343:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   7344:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  7345:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  7346:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.340     raeburn  7347:                    'errorthreshold'  => 'Error/warning threshold for status e-mail',
                   7348:                    'errorsysmail'    => 'Error threshold for e-mail to core group',
                   7349:                    'errorweights'    => 'Weights used to compute error count',
                   7350:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  7351:                  );
                   7352:     my %short_titles = &Apache::lonlocal::texthash (
                   7353:                            adminemail   => 'Admin E-mail address',
                   7354:                            supportemail => 'Support E-mail',
                   7355:                        );   
                   7356:     return (\%titles,\%short_titles);
                   7357: }
                   7358: 
1.286     raeburn  7359: sub helpform_fields {
                   7360:     my %titles =  &Apache::lonlocal::texthash (
                   7361:                        'username'   => 'Name',
                   7362:                        'user'       => 'Username/domain',
                   7363:                        'phone'      => 'Phone',
                   7364:                        'cc'         => 'Cc e-mail',
                   7365:                        'course'     => 'Course Details',
                   7366:                        'section'    => 'Sections',
1.289     raeburn  7367:                        'screenshot' => 'File upload',
1.286     raeburn  7368:     );
                   7369:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   7370:     my %possoptions = (
                   7371:                         username     => ['yes','no','req'],
1.289     raeburn  7372:                         phone        => ['yes','no','req'],
1.286     raeburn  7373:                         user         => ['yes','no'],
1.289     raeburn  7374:                         cc           => ['yes','no'],
1.286     raeburn  7375:                         course       => ['yes','no'],
                   7376:                         section      => ['yes','no'],
                   7377:                         screenshot   => ['yes','no'],
                   7378:                       );
                   7379:     my %fieldoptions = &Apache::lonlocal::texthash (
                   7380:                          'yes'  => 'Optional',
                   7381:                          'req'  => 'Required',
                   7382:                          'no'   => "Not shown",
                   7383:     );
                   7384:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   7385: }
                   7386: 
1.72      raeburn  7387: sub tool_titles {
                   7388:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  7389:                      aboutme    => 'Personal web page',
1.86      raeburn  7390:                      blog       => 'Blog',
1.162     raeburn  7391:                      webdav     => 'WebDAV',
1.86      raeburn  7392:                      portfolio  => 'Portfolio',
1.88      bisitz   7393:                      official   => 'Official courses (with institutional codes)',
                   7394:                      unofficial => 'Unofficial courses',
1.98      raeburn  7395:                      community  => 'Communities',
1.216     raeburn  7396:                      textbook   => 'Textbook courses',
1.271     raeburn  7397:                      placement  => 'Placement tests',
1.86      raeburn  7398:                  );
1.72      raeburn  7399:     return %titles;
                   7400: }
                   7401: 
1.101     raeburn  7402: sub courserequest_titles {
                   7403:     my %titles = &Apache::lonlocal::texthash (
                   7404:                                    official   => 'Official',
                   7405:                                    unofficial => 'Unofficial',
                   7406:                                    community  => 'Communities',
1.216     raeburn  7407:                                    textbook   => 'Textbook',
1.271     raeburn  7408:                                    placement  => 'Placement tests',
1.325     raeburn  7409:                                    lti        => 'LTI Provider',
1.101     raeburn  7410:                                    norequest  => 'Not allowed',
1.325     raeburn  7411:                                    approval   => 'Approval by DC',
1.101     raeburn  7412:                                    validate   => 'With validation',
                   7413:                                    autolimit  => 'Numerical limit',
1.103     raeburn  7414:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  7415:                  );
                   7416:     return %titles;
                   7417: }
                   7418: 
1.163     raeburn  7419: sub authorrequest_titles {
                   7420:     my %titles = &Apache::lonlocal::texthash (
                   7421:                                    norequest  => 'Not allowed',
                   7422:                                    approval   => 'Approval by Dom. Coord.',
                   7423:                                    automatic  => 'Automatic approval',
                   7424:                  );
                   7425:     return %titles;
1.210     raeburn  7426: }
1.163     raeburn  7427: 
1.101     raeburn  7428: sub courserequest_conditions {
                   7429:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  7430:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   7431:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  7432:                  );
                   7433:     return %conditions;
                   7434: }
                   7435: 
                   7436: 
1.27      raeburn  7437: sub print_usercreation {
1.30      raeburn  7438:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  7439:     my $numinrow = 4;
1.28      raeburn  7440:     my $datatable;
                   7441:     if ($position eq 'top') {
1.30      raeburn  7442:         $$rowtotal ++;
1.34      raeburn  7443:         my $rowcount = 0;
1.32      raeburn  7444:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  7445:         if (ref($rules) eq 'HASH') {
                   7446:             if (keys(%{$rules}) > 0) {
1.32      raeburn  7447:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   7448:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  7449:                 $$rowtotal ++;
1.32      raeburn  7450:                 $rowcount ++;
                   7451:             }
                   7452:         }
                   7453:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   7454:         if (ref($idrules) eq 'HASH') {
                   7455:             if (keys(%{$idrules}) > 0) {
                   7456:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   7457:                                                 $idruleorder,$numinrow,$rowcount);
                   7458:                 $$rowtotal ++;
                   7459:                 $rowcount ++;
1.28      raeburn  7460:             }
                   7461:         }
1.39      raeburn  7462:         if ($rowcount == 0) {
                   7463:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   7464:             $$rowtotal ++;
                   7465:             $rowcount ++;
                   7466:         }
1.34      raeburn  7467:     } elsif ($position eq 'middle') {
1.224     raeburn  7468:         my @creators = ('author','course','requestcrs');
1.37      raeburn  7469:         my ($rules,$ruleorder) =
                   7470:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  7471:         my %lt = &usercreation_types();
                   7472:         my %checked;
                   7473:         if (ref($settings) eq 'HASH') {
                   7474:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7475:                 foreach my $item (@creators) {
                   7476:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   7477:                 }
                   7478:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   7479:                 foreach my $item (@creators) {
                   7480:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   7481:                         $checked{$item} = 'none';
                   7482:                     }
                   7483:                 }
                   7484:             }
                   7485:         }
                   7486:         my $rownum = 0;
                   7487:         foreach my $item (@creators) {
                   7488:             $rownum ++;
1.224     raeburn  7489:             if ($checked{$item} eq '') {
                   7490:                 $checked{$item} = 'any';
1.34      raeburn  7491:             }
                   7492:             my $css_class;
                   7493:             if ($rownum%2) {
                   7494:                 $css_class = '';
                   7495:             } else {
                   7496:                 $css_class = ' class="LC_odd_row" ';
                   7497:             }
                   7498:             $datatable .= '<tr'.$css_class.'>'.
                   7499:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  7500:                          '</span></td><td style="text-align: right">';
1.224     raeburn  7501:             my @options = ('any');
                   7502:             if (ref($rules) eq 'HASH') {
                   7503:                 if (keys(%{$rules}) > 0) {
                   7504:                     push(@options,('official','unofficial'));
1.37      raeburn  7505:                 }
                   7506:             }
1.224     raeburn  7507:             push(@options,'none');
1.37      raeburn  7508:             foreach my $option (@options) {
1.50      raeburn  7509:                 my $type = 'radio';
1.34      raeburn  7510:                 my $check = ' ';
1.224     raeburn  7511:                 if ($checked{$item} eq $option) {
                   7512:                     $check = ' checked="checked" ';
1.34      raeburn  7513:                 } 
                   7514:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  7515:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  7516:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   7517:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   7518:             }
                   7519:             $datatable .= '</td></tr>';
                   7520:         }
1.28      raeburn  7521:     } else {
                   7522:         my @contexts = ('author','course','domain');
1.325     raeburn  7523:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  7524:         my %checked;
                   7525:         if (ref($settings) eq 'HASH') {
                   7526:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   7527:                 foreach my $item (@contexts) {
                   7528:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   7529:                         foreach my $auth (@authtypes) {
                   7530:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   7531:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   7532:                             }
                   7533:                         }
                   7534:                     }
                   7535:                 }
1.27      raeburn  7536:             }
1.35      raeburn  7537:         } else {
                   7538:             foreach my $item (@contexts) {
1.36      raeburn  7539:                 foreach my $auth (@authtypes) {
1.35      raeburn  7540:                     $checked{$item}{$auth} = ' checked="checked" ';
                   7541:                 }
                   7542:             }
1.27      raeburn  7543:         }
1.28      raeburn  7544:         my %title = &context_names();
                   7545:         my %authname = &authtype_names();
                   7546:         my $rownum = 0;
                   7547:         my $css_class; 
                   7548:         foreach my $item (@contexts) {
                   7549:             if ($rownum%2) {
                   7550:                 $css_class = '';
                   7551:             } else {
                   7552:                 $css_class = ' class="LC_odd_row" ';
                   7553:             }
1.30      raeburn  7554:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  7555:                             '<td>'.$title{$item}.
                   7556:                             '</td><td class="LC_left_item">'.
                   7557:                             '<span class="LC_nobreak">';
                   7558:             foreach my $auth (@authtypes) {
                   7559:                 $datatable .= '<label>'. 
                   7560:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   7561:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   7562:                               $authname{$auth}.'</label>&nbsp;';
                   7563:             }
                   7564:             $datatable .= '</span></td></tr>';
                   7565:             $rownum ++;
1.27      raeburn  7566:         }
1.30      raeburn  7567:         $$rowtotal += $rownum;
1.27      raeburn  7568:     }
                   7569:     return $datatable;
                   7570: }
                   7571: 
1.224     raeburn  7572: sub print_selfcreation {
                   7573:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  7574:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   7575:         $emaildomain,$datatable);
1.224     raeburn  7576:     if (ref($settings) eq 'HASH') {
                   7577:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7578:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  7579:             if (ref($createsettings) eq 'HASH') {
                   7580:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   7581:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   7582:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   7583:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   7584:                         @selfcreate = ('email','login','sso');
                   7585:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   7586:                         @selfcreate = ($createsettings->{'selfcreate'});
                   7587:                     }
                   7588:                 }
                   7589:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   7590:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  7591:                 }
1.305     raeburn  7592:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   7593:                     $emailoptions = $createsettings->{'emailoptions'};
                   7594:                 }
1.303     raeburn  7595:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   7596:                     $emailverified = $createsettings->{'emailverified'};
                   7597:                 }
                   7598:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   7599:                     $emaildomain = $createsettings->{'emaildomain'};
                   7600:                 }
1.224     raeburn  7601:             }
                   7602:         }
                   7603:     }
                   7604:     my %radiohash;
                   7605:     my $numinrow = 4;
                   7606:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  7607:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  7608:     if ($position eq 'top') {
                   7609:         my %choices = &Apache::lonlocal::texthash (
                   7610:                                                       cancreate_login      => 'Institutional Login',
                   7611:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   7612:                                                   );
                   7613:         my @toggles = sort(keys(%choices));
                   7614:         my %defaultchecked = (
                   7615:                                'cancreate_login' => 'off',
                   7616:                                'cancreate_sso'   => 'off',
                   7617:                              );
1.228     raeburn  7618:         my ($onclick,$itemcount);
1.224     raeburn  7619:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7620:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  7621:         $$rowtotal += $itemcount;
                   7622:         
1.224     raeburn  7623:         if (ref($usertypes) eq 'HASH') {
                   7624:             if (keys(%{$usertypes}) > 0) {
                   7625:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   7626:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  7627:                                              'statustocreate',$rowtotal);
1.224     raeburn  7628:                 $$rowtotal ++;
                   7629:             }
                   7630:         }
1.240     raeburn  7631:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   7632:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7633:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   7634:         my $rem;
                   7635:         my $numperrow = 2;
                   7636:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   7637:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  7638:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  7639:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  7640:                      '<table>'."\n";
1.240     raeburn  7641:         for (my $i=0; $i<@fields; $i++) {
                   7642:             $rem = $i%($numperrow);
                   7643:             if ($rem == 0) {
                   7644:                 if ($i > 0) {
                   7645:                     $datatable .= '</tr>';
                   7646:                 }
                   7647:                 $datatable .= '<tr>';
                   7648:             }
                   7649:             my $currval;
1.248     raeburn  7650:             if (ref($createsettings) eq 'HASH') {
                   7651:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   7652:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   7653:                 }
1.240     raeburn  7654:             }
                   7655:             $datatable .= '<td class="LC_left_item">'.
                   7656:                           '<span class="LC_nobreak">'.
                   7657:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   7658:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   7659:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   7660:         }
                   7661:         my $colsleft = $numperrow - $rem;
                   7662:         if ($colsleft > 1 ) {
                   7663:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7664:                          '&nbsp;</td>';
                   7665:         } elsif ($colsleft == 1) {
                   7666:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7667:         }
                   7668:         $datatable .= '</tr></table></td></tr>';
                   7669:         $$rowtotal ++;
1.224     raeburn  7670:     } elsif ($position eq 'middle') {
                   7671:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  7672:         my @posstypes;
1.224     raeburn  7673:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  7674:             @posstypes = @{$types};
                   7675:         }
                   7676:         unless (grep(/^default$/,@posstypes)) {
                   7677:             push(@posstypes,'default');
                   7678:         }
                   7679:         my %usertypeshash;
                   7680:         if (ref($usertypes) eq 'HASH') {
                   7681:             %usertypeshash = %{$usertypes};
                   7682:         }
                   7683:         $usertypeshash{'default'} = $othertitle;
                   7684:         foreach my $status (@posstypes) {
                   7685:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   7686:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   7687:             $$rowtotal ++;
1.224     raeburn  7688:         }
                   7689:     } else {
1.236     raeburn  7690:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  7691:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  7692:                                                   );
                   7693:         my @toggles = sort(keys(%choices));
                   7694:         my %defaultchecked = (
                   7695:                                'cancreate_email' => 'off',
                   7696:                              );
1.305     raeburn  7697:         my $customclass = 'LC_selfcreate_email';
                   7698:         my $classprefix = 'LC_canmodify_emailusername_';
                   7699:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  7700:         my $display = 'none';
1.305     raeburn  7701:         my $rowstyle = 'display:none';
1.236     raeburn  7702:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   7703:             $display = 'block';
1.305     raeburn  7704:             $rowstyle = 'display:table-row';
1.236     raeburn  7705:         }
1.305     raeburn  7706:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   7707:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7708:                                                      \%choices,$$rowtotal,$onclick);
                   7709:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   7710:                                          $rowstyle);
                   7711:         $$rowtotal ++;
                   7712:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   7713:                                       $rowstyle);
                   7714:         $$rowtotal ++;
                   7715:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  7716:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  7717:         my ($emailrules,$emailruleorder) =
                   7718:             &Apache::lonnet::inst_userrules($dom,'email');
                   7719:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7720:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7721:         if (ref($types) eq 'ARRAY') {
                   7722:             @posstypes = @{$types};
                   7723:         }
                   7724:         if (@posstypes) {
                   7725:             unless (grep(/^default$/,@posstypes)) {
                   7726:                 push(@posstypes,'default');
1.302     raeburn  7727:             }
                   7728:             if (ref($usertypes) eq 'HASH') {
                   7729:                 %usertypeshash = %{$usertypes};
                   7730:             }
1.305     raeburn  7731:             my $currassign;
                   7732:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   7733:                 $currassign = {
                   7734:                                   selfassign => $domdefaults{'inststatusguest'},
                   7735:                               };
                   7736:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   7737:             } else {
                   7738:                 $currassign = { selfassign => [] };
                   7739:             }
                   7740:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   7741:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   7742:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   7743:                                          $numinrow,$othertitle,'selfassign',
                   7744:                                          $rowtotal,$onclicktypes,$customclass,
                   7745:                                          $rowstyle);
                   7746:             $$rowtotal ++;
1.302     raeburn  7747:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  7748:             foreach my $status (@posstypes) {
                   7749:                 my $css_class;
                   7750:                 if ($$rowtotal%2) {
                   7751:                     $css_class = 'LC_odd_row ';
                   7752:                 }
                   7753:                 $css_class .= $customclass;
                   7754:                 my $rowid = $optionsprefix.$status;
                   7755:                 my $hidden = 1;
                   7756:                 my $currstyle = 'display:none';
                   7757:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   7758:                     $currstyle = $rowstyle;
                   7759:                     $hidden = 0; 
                   7760:                 }
                   7761:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7762:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   7763:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   7764:                 unless ($hidden) {
                   7765:                     $$rowtotal ++;
                   7766:                 }
1.224     raeburn  7767:             }
1.302     raeburn  7768:         } else {
1.305     raeburn  7769:             my $css_class;
                   7770:             if ($$rowtotal%2) {
                   7771:                 $css_class = 'LC_odd_row ';
                   7772:             }
                   7773:             $css_class .= $customclass;
1.302     raeburn  7774:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  7775:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7776:                                          $emailrules,$emailruleorder,$settings,'default','',
                   7777:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   7778:             $$rowtotal ++;
1.224     raeburn  7779:         }
                   7780:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  7781:         $numinrow = 1;
1.305     raeburn  7782:         if (@posstypes) {
                   7783:             foreach my $status (@posstypes) {
                   7784:                 my $rowid = $classprefix.$status;
                   7785:                 my $datarowstyle = 'display:none';
                   7786:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   7787:                     $datarowstyle = $rowstyle; 
                   7788:                 }
                   7789:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   7790:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7791:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   7792:                 unless ($datarowstyle eq 'display:none') {
                   7793:                     $$rowtotal ++;
                   7794:                 }
1.224     raeburn  7795:             }
1.305     raeburn  7796:         } else {
                   7797:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   7798:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7799:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  7800:         }
                   7801:     }
                   7802:     return $datatable;
                   7803: }
                   7804: 
1.305     raeburn  7805: sub selfcreate_javascript {
                   7806:     return <<"ENDSCRIPT";
                   7807: 
                   7808: <script type="text/javascript">
                   7809: // <![CDATA[
                   7810: 
                   7811: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   7812:     var x = document.getElementsByClassName(target);
                   7813:     var insttypes = 0;
                   7814:     var insttypeRegExp = new RegExp(prefix);
                   7815:     if ((x.length != undefined) && (x.length > 0)) {
                   7816:         if (form.elements[radio].length != undefined) {
                   7817:             for (var i=0; i<form.elements[radio].length; i++) {
                   7818:                 if (form.elements[radio][i].checked) {
                   7819:                     if (form.elements[radio][i].value == 1) {
                   7820:                         for (var j=0; j<x.length; j++) {
                   7821:                             if (x[j].id == 'undefined') {
                   7822:                                 x[j].style.display = 'table-row';
                   7823:                             } else if (insttypeRegExp.test(x[j].id)) {
                   7824:                                 insttypes ++;
                   7825:                             } else {
                   7826:                                 x[j].style.display = 'table-row';
                   7827:                             }
                   7828:                         }
                   7829:                     } else {
                   7830:                         for (var j=0; j<x.length; j++) {
                   7831:                             x[j].style.display = 'none';
                   7832:                         }
1.236     raeburn  7833:                     }
1.305     raeburn  7834:                     break;
                   7835:                 }
                   7836:             }
                   7837:             if (insttypes > 0) {
                   7838:                 toggleDataRow(form,checkbox,target,altprefix);
                   7839:                 toggleDataRow(form,checkbox,target,prefix,1);
                   7840:             }
                   7841:         }
                   7842:     }
                   7843:     return;
                   7844: }
                   7845: 
                   7846: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   7847:     if (form.elements[checkbox].length != undefined) {
                   7848:         var count = 0;
                   7849:         if (docount) {
                   7850:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   7851:                 if (form.elements[checkbox][i].checked) {
                   7852:                     count ++;
1.236     raeburn  7853:                 }
1.305     raeburn  7854:             }
                   7855:         }
                   7856:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   7857:             var type = form.elements[checkbox][i].value;
                   7858:             if (document.getElementById(prefix+type)) {
                   7859:                 if (form.elements[checkbox][i].checked) {
                   7860:                     document.getElementById(prefix+type).style.display = 'table-row';
                   7861:                     if (count % 2 == 1) {
                   7862:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   7863:                     } else {
                   7864:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  7865:                     }
1.305     raeburn  7866:                     count ++;
1.236     raeburn  7867:                 } else {
1.305     raeburn  7868:                     document.getElementById(prefix+type).style.display = 'none';
                   7869:                 }
                   7870:             }
                   7871:         }
                   7872:     }
                   7873:     return;
                   7874: }
                   7875: 
                   7876: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   7877:     var caller = radio+'_'+status;
                   7878:     if (form.elements[caller].length != undefined) {
                   7879:         for (var i=0; i<form.elements[caller].length; i++) {
                   7880:             if (form.elements[caller][i].checked) {
                   7881:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   7882:                     var curr = form.elements[caller][i].value;
                   7883:                     if (prefix) {
                   7884:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   7885:                     }
                   7886:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   7887:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   7888:                     if (curr == 'custom') {
                   7889:                         if (prefix) { 
                   7890:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   7891:                         }
                   7892:                     } else if (curr == 'inst') {
                   7893:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   7894:                     } else if (curr == 'noninst') {
                   7895:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  7896:                     }
1.305     raeburn  7897:                     break;
1.236     raeburn  7898:                 }
                   7899:             }
                   7900:         }
                   7901:     }
                   7902: }
                   7903: 
1.305     raeburn  7904: // ]]>
                   7905: </script>
                   7906: 
                   7907: ENDSCRIPT
                   7908: }
                   7909: 
                   7910: sub noninst_users {
                   7911:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   7912:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   7913:     my $class = 'LC_left_item';
                   7914:     if ($css_class) {
                   7915:         $css_class = ' class="'.$css_class.'"'; 
                   7916:     }
                   7917:     if ($rowid) {
                   7918:         $rowid = ' id="'.$rowid.'"';
                   7919:     }
                   7920:     if ($rowstyle) {
                   7921:         $rowstyle = ' style="'.$rowstyle.'"';
                   7922:     }
                   7923:     my ($output,$description);
                   7924:     if ($type eq 'default') {
                   7925:         $description = &mt('Requests for: [_1]',$typetitle);
                   7926:     } else {
                   7927:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   7928:     }
                   7929:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   7930:               "<td>$description</td>\n".           
                   7931:               '<td class="'.$class.'" colspan="2">'.
                   7932:               '<table><tr>';
                   7933:     my %headers = &Apache::lonlocal::texthash( 
                   7934:               approve  => 'Processing',
                   7935:               email    => 'E-mail',
                   7936:               username => 'Username',
                   7937:     );
                   7938:     foreach my $item ('approve','email','username') {
                   7939:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  7940:     }
1.305     raeburn  7941:     $output .= '</tr><tr>';
                   7942:     foreach my $item ('approve','email','username') {
1.306     raeburn  7943:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  7944:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   7945:         if ($item eq 'approve') {
                   7946:             %choices = &Apache::lonlocal::texthash (
                   7947:                                                      automatic => 'Automatically approved',
                   7948:                                                      approval  => 'Queued for approval',
                   7949:                                                    );
                   7950:             @options = ('automatic','approval');
                   7951:             $hashref = $processing;
                   7952:             $defoption = 'automatic';
                   7953:             $name = 'cancreate_emailprocess_'.$type;
                   7954:         } elsif ($item eq 'email') {
                   7955:             %choices = &Apache::lonlocal::texthash (
                   7956:                                                      any     => 'Any e-mail',
                   7957:                                                      inst    => 'Institutional only',
                   7958:                                                      noninst => 'Non-institutional only',
                   7959:                                                      custom  => 'Custom restrictions',
                   7960:                                                    );
                   7961:             @options = ('any','inst','noninst');
                   7962:             my $showcustom;
                   7963:             if (ref($emailrules) eq 'HASH') {
                   7964:                 if (keys(%{$emailrules}) > 0) {
                   7965:                     push(@options,'custom');
                   7966:                     $showcustom = 'cancreate_emailrule';
                   7967:                     if (ref($settings) eq 'HASH') {
                   7968:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   7969:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   7970:                                 if (exists($emailrules->{$rule})) {
                   7971:                                     $hascustom ++;
                   7972:                                 }
                   7973:                             }
                   7974:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   7975:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   7976:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   7977:                                     if (exists($emailrules->{$rule})) {
                   7978:                                         $hascustom ++;
                   7979:                                     }
                   7980:                                 }
                   7981:                             }
                   7982:                         }
                   7983:                     }
                   7984:                 }
                   7985:             }
                   7986:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   7987:                                                      "'cancreate_emaildomain','$type'".');"';
                   7988:             $hashref = $emailoptions;
                   7989:             $defoption = 'any';
                   7990:             $name = 'cancreate_emailoptions_'.$type;
                   7991:         } elsif ($item eq 'username') {
                   7992:             %choices = &Apache::lonlocal::texthash (
                   7993:                                                      all    => 'Same as e-mail',
                   7994:                                                      first  => 'Omit @domain',
                   7995:                                                      free   => 'Free to choose',
                   7996:                                                    );
                   7997:             @options = ('all','first','free');
                   7998:             $hashref = $emailverified;
                   7999:             $defoption = 'all';
                   8000:             $name = 'cancreate_usernameoptions_'.$type;
                   8001:         }
                   8002:         foreach my $option (@options) {
                   8003:             my $checked;
                   8004:             if (ref($hashref) eq 'HASH') {
                   8005:                 if ($type eq '') {
                   8006:                     if (!exists($hashref->{'default'})) {
                   8007:                         if ($option eq $defoption) {
                   8008:                             $checked = ' checked="checked"';
                   8009:                         }
                   8010:                     } else {
                   8011:                         if ($hashref->{'default'} eq $option) {
                   8012:                             $checked = ' checked="checked"';
                   8013:                         }
1.303     raeburn  8014:                     }
                   8015:                 } else {
1.305     raeburn  8016:                     if (!exists($hashref->{$type})) {
                   8017:                         if ($option eq $defoption) {
                   8018:                             $checked = ' checked="checked"';
                   8019:                         }
                   8020:                     } else {
                   8021:                         if ($hashref->{$type} eq $option) {
                   8022:                             $checked = ' checked="checked"';
                   8023:                         }
1.303     raeburn  8024:                     }
                   8025:                 }
1.305     raeburn  8026:             } elsif (($item eq 'email') && ($hascustom)) {
                   8027:                 if ($option eq 'custom') {
                   8028:                     $checked = ' checked="checked"';
                   8029:                 }
                   8030:             } elsif ($option eq $defoption) {
                   8031:                 $checked = ' checked="checked"';
                   8032:             }
                   8033:             $output .= '<span class="LC_nobreak"><label>'.
                   8034:                        '<input type="radio" name="'.$name.'"'.
                   8035:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   8036:                        $choices{$option}.'</label></span><br />';
                   8037:             if ($item eq 'email') {
                   8038:                 if ($option eq 'custom') {
                   8039:                     my $id = 'cancreate_emailrule_'.$type;
                   8040:                     my $display = 'none';
                   8041:                     if ($checked) {
                   8042:                         $display = 'inline';
1.303     raeburn  8043:                     }
1.305     raeburn  8044:                     my $numinrow = 2;
                   8045:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   8046:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   8047:                                &user_formats_row('email',$settings,$emailrules,
                   8048:                                                  $emailruleorder,$numinrow,'',$type);
                   8049:                               '</table></fieldset>';
                   8050:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   8051:                     my %text = &Apache::lonlocal::texthash (
                   8052:                                                              inst    => 'must end:',
                   8053:                                                              noninst => 'cannot end:',
                   8054:                                                            );
                   8055:                     my $value;
                   8056:                     if (ref($emaildomain) eq 'HASH') {
                   8057:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   8058:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  8059:                         }
                   8060:                     }
1.305     raeburn  8061:                     if ($value eq '') {
                   8062:                         $value = '@'.$intdom;
                   8063:                     }
                   8064:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   8065:                     my $display = 'none';
                   8066:                     if ($checked) {
                   8067:                         $display = 'inline';
                   8068:                     }
                   8069:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   8070:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   8071:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   8072:                                '</div>';
1.303     raeburn  8073:                 }
                   8074:             }
                   8075:         }
1.305     raeburn  8076:         $output .= '</td>'."\n";
1.303     raeburn  8077:     }
1.305     raeburn  8078:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  8079:     return $output;
                   8080: }
                   8081: 
1.165     raeburn  8082: sub captcha_choice {
1.305     raeburn  8083:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  8084:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   8085:         $vertext,$currver);
1.165     raeburn  8086:     my %lt = &captcha_phrases();
                   8087:     $keyentry = 'hidden';
1.354     raeburn  8088:     my $colspan=2;
1.165     raeburn  8089:     if ($context eq 'cancreate') {
1.224     raeburn  8090:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  8091:     } elsif ($context eq 'login') {
                   8092:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  8093:     } elsif ($context eq 'passwords') {
                   8094:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   8095:         $colspan=1;
1.165     raeburn  8096:     }
                   8097:     if (ref($settings) eq 'HASH') {
                   8098:         if ($settings->{'captcha'}) {
                   8099:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   8100:         } else {
                   8101:             $checked{'original'} = ' checked="checked"';
                   8102:         }
                   8103:         if ($settings->{'captcha'} eq 'recaptcha') {
                   8104:             $pubtext = $lt{'pub'};
                   8105:             $privtext = $lt{'priv'};
                   8106:             $keyentry = 'text';
1.269     raeburn  8107:             $vertext = $lt{'ver'};
                   8108:             $currver = $settings->{'recaptchaversion'};
                   8109:             if ($currver ne '2') {
                   8110:                 $currver = 1;
                   8111:             }
1.165     raeburn  8112:         }
                   8113:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   8114:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   8115:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   8116:         }
                   8117:     } else {
                   8118:         $checked{'original'} = ' checked="checked"';
                   8119:     }
1.305     raeburn  8120:     my $css_class;
                   8121:     if ($itemcount%2) {
                   8122:         $css_class = 'LC_odd_row';
                   8123:     }
                   8124:     if ($customcss) {
                   8125:         $css_class .= " $customcss";
                   8126:     }
                   8127:     $css_class =~ s/^\s+//;
                   8128:     if ($css_class) {
                   8129:         $css_class = ' class="'.$css_class.'"';
                   8130:     }
                   8131:     if ($rowstyle) {
                   8132:         $css_class .= ' style="'.$rowstyle.'"';
                   8133:     }
1.169     raeburn  8134:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  8135:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  8136:                  '<table><tr><td>'."\n";
                   8137:     foreach my $option ('original','recaptcha','notused') {
                   8138:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   8139:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   8140:                    $lt{$option}.'</label></span>';
                   8141:         unless ($option eq 'notused') {
                   8142:             $output .= ('&nbsp;'x2)."\n";
                   8143:         }
                   8144:     }
                   8145: #
                   8146: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   8147: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  8148: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  8149: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  8150: #
1.165     raeburn  8151:     $output .= '</td></tr>'."\n".
1.305     raeburn  8152:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  8153:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   8154:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   8155:                $currpub.'" size="40" /></span><br />'."\n".
                   8156:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   8157:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  8158:                $currpriv.'" size="40" /></span><br />'.
                   8159:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   8160:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   8161:                $currver.'" size="3" /></span><br />'.
                   8162:                '</td></tr></table>'."\n".
1.165     raeburn  8163:                '</td></tr>';
                   8164:     return $output;
                   8165: }
                   8166: 
1.32      raeburn  8167: sub user_formats_row {
1.305     raeburn  8168:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  8169:     my $output;
                   8170:     my %text = (
                   8171:                    'username' => 'new usernames',
                   8172:                    'id'       => 'IDs',
                   8173:                );
1.305     raeburn  8174:     unless ($type eq 'email') {
                   8175:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   8176:         $output = '<tr '.$css_class.'>'.
                   8177:                   '<td><span class="LC_nobreak">'.
                   8178:                   &mt("Format rules to check for $text{$type}: ").
                   8179:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  8180:     }
1.27      raeburn  8181:     my $rem;
                   8182:     if (ref($ruleorder) eq 'ARRAY') {
                   8183:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   8184:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   8185:                 my $rem = $i%($numinrow);
                   8186:                 if ($rem == 0) {
                   8187:                     if ($i > 0) {
                   8188:                         $output .= '</tr>';
                   8189:                     }
                   8190:                     $output .= '<tr>';
                   8191:                 }
                   8192:                 my $check = ' ';
1.39      raeburn  8193:                 if (ref($settings) eq 'HASH') {
                   8194:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   8195:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   8196:                             $check = ' checked="checked" ';
                   8197:                         }
1.305     raeburn  8198:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   8199:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   8200:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   8201:                                 $check = ' checked="checked" ';
                   8202:                             }
                   8203:                         }
1.27      raeburn  8204:                     }
                   8205:                 }
1.305     raeburn  8206:                 my $name = $type.'_rule';
                   8207:                 if ($type eq 'email') {
                   8208:                     $name .= '_'.$status;
                   8209:                 }
1.27      raeburn  8210:                 $output .= '<td class="LC_left_item">'.
                   8211:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  8212:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  8213:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   8214:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   8215:             }
                   8216:         }
                   8217:         $rem = @{$ruleorder}%($numinrow);
                   8218:     }
1.305     raeburn  8219:     my $colsleft;
                   8220:     if ($rem) {
                   8221:         $colsleft = $numinrow - $rem;
                   8222:     }
1.27      raeburn  8223:     if ($colsleft > 1 ) {
                   8224:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8225:                    '&nbsp;</td>';
                   8226:     } elsif ($colsleft == 1) {
                   8227:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   8228:     }
1.305     raeburn  8229:     $output .= '</tr></table>';
                   8230:     unless ($type eq 'email') {
                   8231:         $output .= '</td></tr>';
                   8232:     }
1.27      raeburn  8233:     return $output;
                   8234: }
                   8235: 
1.34      raeburn  8236: sub usercreation_types {
                   8237:     my %lt = &Apache::lonlocal::texthash (
                   8238:                     author     => 'When adding a co-author',
                   8239:                     course     => 'When adding a user to a course',
1.100     raeburn  8240:                     requestcrs => 'When requesting a course',
1.34      raeburn  8241:                     any        => 'Any',
                   8242:                     official   => 'Institutional only ',
                   8243:                     unofficial => 'Non-institutional only',
                   8244:                     none       => 'None',
                   8245:     );
                   8246:     return %lt;
1.48      raeburn  8247: }
1.34      raeburn  8248: 
1.224     raeburn  8249: sub selfcreation_types {
                   8250:     my %lt = &Apache::lonlocal::texthash (
                   8251:                     selfcreate => 'User creates own account',
                   8252:                     any        => 'Any',
                   8253:                     official   => 'Institutional only ',
                   8254:                     unofficial => 'Non-institutional only',
                   8255:                     email      => 'E-mail address',
                   8256:                     login      => 'Institutional Login',
                   8257:                     sso        => 'SSO',
                   8258:              );
                   8259: }
                   8260: 
1.28      raeburn  8261: sub authtype_names {
                   8262:     my %lt = &Apache::lonlocal::texthash(
                   8263:                       int    => 'Internal',
                   8264:                       krb4   => 'Kerberos 4',
                   8265:                       krb5   => 'Kerberos 5',
                   8266:                       loc    => 'Local',
1.325     raeburn  8267:                       lti    => 'LTI',
1.28      raeburn  8268:                   );
                   8269:     return %lt;
                   8270: }
                   8271: 
                   8272: sub context_names {
                   8273:     my %context_title = &Apache::lonlocal::texthash(
                   8274:        author => 'Creating users when an Author',
                   8275:        course => 'Creating users when in a course',
                   8276:        domain => 'Creating users when a Domain Coordinator',
                   8277:     );
                   8278:     return %context_title;
                   8279: }
                   8280: 
1.33      raeburn  8281: sub print_usermodification {
                   8282:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8283:     my $numinrow = 4;
                   8284:     my ($context,$datatable,$rowcount);
                   8285:     if ($position eq 'top') {
                   8286:         $rowcount = 0;
                   8287:         $context = 'author'; 
                   8288:         foreach my $role ('ca','aa') {
                   8289:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8290:                                                    $numinrow,$rowcount);
                   8291:             $$rowtotal ++;
                   8292:             $rowcount ++;
                   8293:         }
1.230     raeburn  8294:     } elsif ($position eq 'bottom') {
1.33      raeburn  8295:         $context = 'course';
                   8296:         $rowcount = 0;
                   8297:         foreach my $role ('st','ep','ta','in','cr') {
                   8298:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8299:                                                    $numinrow,$rowcount);
                   8300:             $$rowtotal ++;
                   8301:             $rowcount ++;
                   8302:         }
                   8303:     }
                   8304:     return $datatable;
                   8305: }
                   8306: 
1.43      raeburn  8307: sub print_defaults {
1.236     raeburn  8308:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  8309:     my $rownum = 0;
1.294     raeburn  8310:     my ($datatable,$css_class,$titles);
                   8311:     unless ($position eq 'bottom') {
                   8312:         $titles = &defaults_titles($dom);
                   8313:     }
1.236     raeburn  8314:     if ($position eq 'top') {
                   8315:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   8316:                      'datelocale_def','portal_def');
                   8317:         my %defaults;
                   8318:         if (ref($settings) eq 'HASH') {
                   8319:             %defaults = %{$settings};
1.43      raeburn  8320:         } else {
1.236     raeburn  8321:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8322:             foreach my $item (@items) {
                   8323:                 $defaults{$item} = $domdefaults{$item};
                   8324:             }
1.43      raeburn  8325:         }
1.236     raeburn  8326:         foreach my $item (@items) {
                   8327:             if ($rownum%2) {
                   8328:                 $css_class = '';
                   8329:             } else {
                   8330:                 $css_class = ' class="LC_odd_row" ';
                   8331:             }
                   8332:             $datatable .= '<tr'.$css_class.'>'.
                   8333:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   8334:                           '</span></td><td class="LC_right_item" colspan="3">';
                   8335:             if ($item eq 'auth_def') {
1.325     raeburn  8336:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  8337:                 my %shortauth = (
                   8338:                                  internal => 'int',
                   8339:                                  krb4 => 'krb4',
                   8340:                                  krb5 => 'krb5',
1.325     raeburn  8341:                                  localauth  => 'loc',
                   8342:                                  lti => 'lti',
1.236     raeburn  8343:                                 );
                   8344:                 my %authnames = &authtype_names();
                   8345:                 foreach my $auth (@authtypes) {
                   8346:                     my $checked = ' ';
                   8347:                     if ($defaults{$item} eq $auth) {
                   8348:                         $checked = ' checked="checked" ';
                   8349:                     }
                   8350:                     $datatable .= '<label><input type="radio" name="'.$item.
                   8351:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   8352:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   8353:                 }
                   8354:             } elsif ($item eq 'timezone_def') {
                   8355:                 my $includeempty = 1;
                   8356:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   8357:             } elsif ($item eq 'datelocale_def') {
                   8358:                 my $includeempty = 1;
                   8359:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   8360:             } elsif ($item eq 'lang_def') {
1.263     raeburn  8361:                 my $includeempty = 1;
                   8362:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  8363:             } else {
                   8364:                 my $size;
                   8365:                 if ($item eq 'portal_def') {
                   8366:                     $size = ' size="25"';
                   8367:                 }
                   8368:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   8369:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  8370:             }
1.236     raeburn  8371:             $datatable .= '</td></tr>';
                   8372:             $rownum ++;
                   8373:         }
1.354     raeburn  8374:     } else {
1.294     raeburn  8375:         my %defaults;
                   8376:         if (ref($settings) eq 'HASH') {
1.354     raeburn  8377:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   8378:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   8379:                 for (my $i=0; $i<$maxnum; $i++) {
                   8380:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8381:                     my $item = $settings->{'inststatusorder'}->[$i];
                   8382:                     my $title = $settings->{'inststatustypes'}->{$item};
                   8383:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   8384:                     $datatable .= '<tr'.$css_class.'>'.
                   8385:                                   '<td><span class="LC_nobreak">'.
                   8386:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   8387:                     for (my $k=0; $k<=$maxnum; $k++) {
                   8388:                         my $vpos = $k+1;
                   8389:                         my $selstr;
                   8390:                         if ($k == $i) {
                   8391:                             $selstr = ' selected="selected" ';
                   8392:                         }
                   8393:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8394:                     }
                   8395:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   8396:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   8397:                                   &mt('delete').'</span></td>'.
                   8398:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
                   8399:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   8400:                                   '</span></td></tr>';
                   8401:                 }
                   8402:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8403:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   8404:                 $datatable .= '<tr '.$css_class.'>'.
                   8405:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   8406:                 for (my $k=0; $k<=$maxnum; $k++) {
                   8407:                     my $vpos = $k+1;
                   8408:                     my $selstr;
                   8409:                     if ($k == $maxnum) {
                   8410:                         $selstr = ' selected="selected" ';
                   8411:                     }
                   8412:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8413:                 }
                   8414:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   8415:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   8416:                               '&nbsp;'.&mt('(new)').
                   8417:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
                   8418:                               &mt('Name displayed:').
                   8419:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   8420:                               '</tr>'."\n";
                   8421:                 $rownum ++;
1.294     raeburn  8422:             }
1.354     raeburn  8423:         }
                   8424:     }
                   8425:     $$rowtotal += $rownum;
1.43      raeburn  8426:     return $datatable;
                   8427: }
                   8428: 
1.168     raeburn  8429: sub get_languages_hash {
                   8430:     my %langchoices;
                   8431:     foreach my $id (&Apache::loncommon::languageids()) {
                   8432:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   8433:         if ($code ne '') {
                   8434:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   8435:         }
                   8436:     }
                   8437:     return %langchoices;
                   8438: }
                   8439: 
1.43      raeburn  8440: sub defaults_titles {
1.141     raeburn  8441:     my ($dom) = @_;
1.43      raeburn  8442:     my %titles = &Apache::lonlocal::texthash (
                   8443:                    'auth_def'      => 'Default authentication type',
                   8444:                    'auth_arg_def'  => 'Default authentication argument',
                   8445:                    'lang_def'      => 'Default language',
1.54      raeburn  8446:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  8447:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  8448:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  8449:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   8450:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   8451:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  8452:                  );
1.141     raeburn  8453:     if ($dom) {
                   8454:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   8455:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   8456:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   8457:         $protocol = 'http' if ($protocol ne 'https');
                   8458:         if ($uint_dom) {
                   8459:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   8460:                                          $uint_dom);
                   8461:         }
                   8462:     }
1.43      raeburn  8463:     return (\%titles);
                   8464: }
                   8465: 
1.346     raeburn  8466: sub print_scantron {
                   8467:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   8468:     if ($position eq 'top') {
                   8469:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   8470:     } else {
                   8471:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   8472:     }
                   8473: }
                   8474: 
                   8475: sub scantron_javascript {
                   8476:     return <<"ENDSCRIPT";
                   8477: 
                   8478: <script type="text/javascript">
                   8479: // <![CDATA[
                   8480: 
                   8481: function toggleScantron(form) {
1.347     raeburn  8482:     var csvfieldset = new Array();
1.346     raeburn  8483:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  8484:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   8485:     }
                   8486:     if (document.getElementById('scantroncsv_options')) {
                   8487:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   8488:     }
                   8489:     if (csvfieldset.length) {
1.346     raeburn  8490:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  8491:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  8492:             if (scantroncsv.checked) {
1.347     raeburn  8493:                 for (var i=0; i<csvfieldset.length; i++) {
                   8494:                     csvfieldset[i].style.display = 'block';
                   8495:                 }
1.346     raeburn  8496:             } else {
1.347     raeburn  8497:                 for (var i=0; i<csvfieldset.length; i++) {
                   8498:                     csvfieldset[i].style.display = 'none';
                   8499:                 }
1.346     raeburn  8500:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   8501:                 if (csvselects.length) {
                   8502:                     for (var j=0; j<csvselects.length; j++) {
                   8503:                         csvselects[j].selectedIndex = 0;
                   8504:                     }
                   8505:                 }
                   8506:             }
                   8507:         }
                   8508:     }
                   8509:     return;
                   8510: }
                   8511: // ]]>
                   8512: </script>
                   8513: 
                   8514: ENDSCRIPT
                   8515: 
                   8516: }
                   8517: 
1.46      raeburn  8518: sub print_scantronformat {
                   8519:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   8520:     my $itemcount = 1;
1.60      raeburn  8521:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   8522:         %confhash);
1.46      raeburn  8523:     my $switchserver = &check_switchserver($dom,$confname);
                   8524:     my %lt = &Apache::lonlocal::texthash (
1.95      www      8525:                 default => 'Default bubblesheet format file error',
                   8526:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  8527:              );
                   8528:     my %scantronfiles = (
                   8529:         default => 'default.tab',
                   8530:         custom => 'custom.tab',
                   8531:     );
                   8532:     foreach my $key (keys(%scantronfiles)) {
                   8533:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   8534:                               .$scantronfiles{$key};
                   8535:     }
                   8536:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   8537:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   8538:         if (!$switchserver) {
                   8539:             my $servadm = $r->dir_config('lonAdmEMail');
                   8540:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   8541:             if ($configuserok eq 'ok') {
                   8542:                 if ($author_ok eq 'ok') {
                   8543:                     my %legacyfile = (
1.346     raeburn  8544:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   8545:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  8546:                     );
                   8547:                     my %md5chk;
                   8548:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  8549:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   8550:                         chomp($md5chk{$type});
1.46      raeburn  8551:                     }
                   8552:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   8553:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  8554:                             ($scantronurls{$type},my $error) =
1.46      raeburn  8555:                                 &legacy_scantronformat($r,$dom,$confname,
                   8556:                                                  $type,$legacyfile{$type},
                   8557:                                                  $scantronurls{$type},
                   8558:                                                  $scantronfiles{$type});
1.60      raeburn  8559:                             if ($error ne '') {
                   8560:                                 $error{$type} = $error;
                   8561:                             }
                   8562:                         }
                   8563:                         if (keys(%error) == 0) {
                   8564:                             $is_custom = 1;
1.346     raeburn  8565:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  8566:                                 $scantronurls{'custom'};
1.346     raeburn  8567:                             my $putresult =
1.60      raeburn  8568:                                 &Apache::lonnet::put_dom('configuration',
                   8569:                                                          \%confhash,$dom);
                   8570:                             if ($putresult ne 'ok') {
1.346     raeburn  8571:                                 $error{'custom'} =
1.60      raeburn  8572:                                     '<span class="LC_error">'.
                   8573:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8574:                             }
1.46      raeburn  8575:                         }
                   8576:                     } else {
1.60      raeburn  8577:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  8578:                             &legacy_scantronformat($r,$dom,$confname,
                   8579:                                           'default',$legacyfile{'default'},
                   8580:                                           $scantronurls{'default'},
                   8581:                                           $scantronfiles{'default'});
1.60      raeburn  8582:                         if ($error eq '') {
                   8583:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   8584:                             my $putresult =
                   8585:                                 &Apache::lonnet::put_dom('configuration',
                   8586:                                                          \%confhash,$dom);
                   8587:                             if ($putresult ne 'ok') {
                   8588:                                 $error{'default'} =
                   8589:                                     '<span class="LC_error">'.
                   8590:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8591:                             }
                   8592:                         } else {
                   8593:                             $error{'default'} = $error;
                   8594:                         }
1.46      raeburn  8595:                     }
                   8596:                 }
                   8597:             }
                   8598:         } else {
1.95      www      8599:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  8600:         }
                   8601:     }
                   8602:     if (ref($settings) eq 'HASH') {
                   8603:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   8604:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   8605:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   8606:                 $scantronurl = '';
                   8607:             } else {
                   8608:                 $scantronurl = $settings->{'scantronformat'};
                   8609:             }
                   8610:             $is_custom = 1;
                   8611:         } else {
                   8612:             $scantronurl = $scantronurls{'default'};
                   8613:         }
                   8614:     } else {
1.60      raeburn  8615:         if ($is_custom) {
                   8616:             $scantronurl = $scantronurls{'custom'};
                   8617:         } else {
                   8618:             $scantronurl = $scantronurls{'default'};
                   8619:         }
1.46      raeburn  8620:     }
                   8621:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8622:     $datatable .= '<tr'.$css_class.'>';
                   8623:     if (!$is_custom) {
1.65      raeburn  8624:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   8625:                       '<span class="LC_nobreak">';
1.46      raeburn  8626:         if ($scantronurl) {
1.199     raeburn  8627:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   8628:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  8629:         } else {
                   8630:             $datatable = &mt('File unavailable for display');
                   8631:         }
1.65      raeburn  8632:         $datatable .= '</span></td>';
1.60      raeburn  8633:         if (keys(%error) == 0) { 
1.306     raeburn  8634:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  8635:             if (!$switchserver) {
                   8636:                 $datatable .= &mt('Upload:').'<br />';
                   8637:             }
                   8638:         } else {
                   8639:             my $errorstr;
                   8640:             foreach my $key (sort(keys(%error))) {
                   8641:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8642:             }
                   8643:             $datatable .= '<td>'.$errorstr;
                   8644:         }
1.46      raeburn  8645:     } else {
                   8646:         if (keys(%error) > 0) {
                   8647:             my $errorstr;
                   8648:             foreach my $key (sort(keys(%error))) {
                   8649:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8650:             } 
1.60      raeburn  8651:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  8652:         } elsif ($scantronurl) {
1.199     raeburn  8653:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   8654:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  8655:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  8656:                           $link.
                   8657:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   8658:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  8659:                           '<td><span class="LC_nobreak">&nbsp;'.
                   8660:                           &mt('Replace:').'</span><br />';
1.46      raeburn  8661:         }
                   8662:     }
                   8663:     if (keys(%error) == 0) {
                   8664:         if ($switchserver) {
                   8665:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   8666:         } else {
1.65      raeburn  8667:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   8668:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  8669:         }
                   8670:     }
                   8671:     $datatable .= '</td></tr>';
                   8672:     $$rowtotal ++;
                   8673:     return $datatable;
                   8674: }
                   8675: 
                   8676: sub legacy_scantronformat {
                   8677:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   8678:     my ($url,$error);
                   8679:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   8680:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   8681:         (my $result,$url) =
                   8682:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   8683:                          '','',$newfile);
                   8684:         if ($result ne 'ok') {
1.130     raeburn  8685:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  8686:         }
                   8687:     }
                   8688:     return ($url,$error);
                   8689: }
1.43      raeburn  8690: 
1.346     raeburn  8691: sub print_scantronconfig {
                   8692:     my ($dom,$settings,$rowtotal) = @_;
                   8693:     my $itemcount = 2;
                   8694:     my $is_checked = ' checked="checked"';
1.347     raeburn  8695:     my %optionson = (
                   8696:                      hdr => ' checked="checked"',
                   8697:                      pad => ' checked="checked"',
                   8698:                      rem => ' checked="checked"',
                   8699:                     );
                   8700:     my %optionsoff = (
                   8701:                       hdr => '',
                   8702:                       pad => '',
                   8703:                       rem => '',
                   8704:                      );
1.346     raeburn  8705:     my $currcsvsty = 'none';
1.347     raeburn  8706:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  8707:     my @fields = &scantroncsv_fields();
                   8708:     my %titles = &scantronconfig_titles();
                   8709:     if (ref($settings) eq 'HASH') {
                   8710:         if (ref($settings->{config}) eq 'HASH') {
                   8711:             if ($settings->{config}->{dat}) {
                   8712:                 $checked{'dat'} = $is_checked;
                   8713:             }
                   8714:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  8715:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   8716:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   8717:                     if (keys(%csvfields) > 0) {
                   8718:                         $checked{'csv'} = $is_checked;
                   8719:                         $currcsvsty = 'block';
                   8720:                     }
                   8721:                 }
                   8722:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   8723:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   8724:                     foreach my $option (keys(%optionson)) {
                   8725:                         unless ($csvoptions{$option}) {
                   8726:                             $optionsoff{$option} = $optionson{$option};
                   8727:                             $optionson{$option} = '';
                   8728:                         }
                   8729:                     }
1.346     raeburn  8730:                 }
                   8731:             }
                   8732:         } else {
                   8733:             $checked{'dat'} = $is_checked;
                   8734:         }
                   8735:     } else {
                   8736:         $checked{'dat'} = $is_checked;
                   8737:     }
                   8738:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   8739:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   8740:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   8741:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   8742:     foreach my $item ('dat','csv') {
                   8743:         my $id;
                   8744:         if ($item eq 'csv') {
                   8745:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  8746:         }
1.346     raeburn  8747:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   8748:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   8749:         if ($item eq 'csv') {
                   8750:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   8751:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   8752:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   8753:             foreach my $col (@fields) {
                   8754:                 my $selnone;
                   8755:                 if ($csvfields{$col} eq '') {
                   8756:                     $selnone = ' selected="selected"';
                   8757:                 }
                   8758:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   8759:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   8760:                               '<option value=""'.$selnone.'></option>';
                   8761:                 for (my $i=0; $i<20; $i++) {
                   8762:                     my $shown = $i+1;
                   8763:                     my $sel;
                   8764:                     unless ($selnone) {
                   8765:                         if (exists($csvfields{$col})) {
                   8766:                             if ($csvfields{$col} == $i) {
                   8767:                                 $sel = ' selected="selected"';
                   8768:                             }
                   8769:                         }
                   8770:                     }
                   8771:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   8772:                 }
                   8773:                 $datatable .= '</select></td></tr>';
                   8774:            }
1.347     raeburn  8775:            $datatable .= '</table></fieldset>'.
                   8776:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   8777:                          '<legend>'.&mt('CSV Options').'</legend>';
                   8778:            foreach my $option ('hdr','pad','rem') {
                   8779:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   8780:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   8781:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   8782:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   8783:            }
                   8784:            $datatable .= '</fieldset>';
1.346     raeburn  8785:            $itemcount ++;
                   8786:         }
                   8787:     }
                   8788:     $datatable .= '</td></tr>';
                   8789:     $$rowtotal ++;
                   8790:     return $datatable;
                   8791: }
                   8792: 
                   8793: sub scantronconfig_titles {
                   8794:     return &Apache::lonlocal::texthash(
                   8795:                                           dat => 'Standard format (.dat)',
                   8796:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  8797:                                           hdr => 'Remove first line in file (contains column titles)',
                   8798:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  8799:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  8800:                                           CODE => 'CODE',
                   8801:                                           ID   => 'Student ID',
                   8802:                                           PaperID => 'Paper ID',
                   8803:                                           FirstName => 'First Name',
                   8804:                                           LastName => 'Last Name',
                   8805:                                           FirstQuestion => 'First Question Response',
                   8806:                                           Section => 'Section',
                   8807:     );
                   8808: }
                   8809: 
                   8810: sub scantroncsv_fields {
                   8811:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   8812: }
                   8813: 
1.49      raeburn  8814: sub print_coursecategories {
1.57      raeburn  8815:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   8816:     my $datatable;
                   8817:     if ($position eq 'top') {
1.238     raeburn  8818:         my (%checked);
                   8819:         my @catitems = ('unauth','auth');
                   8820:         my @cattypes = ('std','domonly','codesrch','none');
                   8821:         $checked{'unauth'} = 'std';
                   8822:         $checked{'auth'} = 'std';
                   8823:         if (ref($settings) eq 'HASH') {
                   8824:             foreach my $type (@cattypes) {
                   8825:                 if ($type eq $settings->{'unauth'}) {
                   8826:                     $checked{'unauth'} = $type;
                   8827:                 }
                   8828:                 if ($type eq $settings->{'auth'}) {
                   8829:                     $checked{'auth'} = $type;
                   8830:                 }
                   8831:             }
                   8832:         }
                   8833:         my %lt = &Apache::lonlocal::texthash (
                   8834:                                                unauth   => 'Catalog type for unauthenticated users',
                   8835:                                                auth     => 'Catalog type for authenticated users',
                   8836:                                                none     => 'No catalog',
                   8837:                                                std      => 'Standard catalog',
                   8838:                                                domonly  => 'Domain-only catalog',
                   8839:                                                codesrch => "Code search form",
                   8840:                                              );
                   8841:        my $itemcount = 0;
                   8842:        foreach my $item (@catitems) {
                   8843:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   8844:            $datatable .= '<tr '.$css_class.'>'.
                   8845:                          '<td>'.$lt{$item}.'</td>'.
                   8846:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   8847:            foreach my $type (@cattypes) {
                   8848:                my $ischecked;
                   8849:                if ($checked{$item} eq $type) {
                   8850:                    $ischecked=' checked="checked"';
                   8851:                }
                   8852:                $datatable .= '<label>'.
                   8853:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   8854:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   8855:            }
1.327     raeburn  8856:            $datatable .= '</span></td></tr>';
1.238     raeburn  8857:            $itemcount ++;
                   8858:         }
                   8859:         $$rowtotal += $itemcount;
                   8860:     } elsif ($position eq 'middle') {
1.57      raeburn  8861:         my $toggle_cats_crs = ' ';
                   8862:         my $toggle_cats_dom = ' checked="checked" ';
                   8863:         my $can_cat_crs = ' ';
                   8864:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  8865:         my $toggle_catscomm_comm = ' ';
                   8866:         my $toggle_catscomm_dom = ' checked="checked" ';
                   8867:         my $can_catcomm_comm = ' ';
                   8868:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  8869:         my $toggle_catsplace_place = ' ';
                   8870:         my $toggle_catsplace_dom = ' checked="checked" ';
                   8871:         my $can_catplace_place = ' ';
                   8872:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  8873: 
1.57      raeburn  8874:         if (ref($settings) eq 'HASH') {
                   8875:             if ($settings->{'togglecats'} eq 'crs') {
                   8876:                 $toggle_cats_crs = $toggle_cats_dom;
                   8877:                 $toggle_cats_dom = ' ';
                   8878:             }
                   8879:             if ($settings->{'categorize'} eq 'crs') {
                   8880:                 $can_cat_crs = $can_cat_dom;
                   8881:                 $can_cat_dom = ' ';
                   8882:             }
1.120     raeburn  8883:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   8884:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   8885:                 $toggle_catscomm_dom = ' ';
                   8886:             }
                   8887:             if ($settings->{'categorizecomm'} eq 'comm') {
                   8888:                 $can_catcomm_comm = $can_catcomm_dom;
                   8889:                 $can_catcomm_dom = ' ';
                   8890:             }
1.272     raeburn  8891:             if ($settings->{'togglecatsplace'} eq 'place') {
                   8892:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   8893:                 $toggle_catsplace_dom = ' ';
                   8894:             }
                   8895:             if ($settings->{'categorizeplace'} eq 'place') {
                   8896:                 $can_catplace_place = $can_catplace_dom;
                   8897:                 $can_catplace_dom = ' ';
                   8898:             }
1.57      raeburn  8899:         }
                   8900:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  8901:                      togglecats      => 'Show/Hide a course in catalog',
                   8902:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   8903:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   8904:                      categorize      => 'Assign a category to a course',
                   8905:                      categorizecomm  => 'Assign a category to a community',
                   8906:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  8907:                     );
                   8908:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  8909:                      dom   => 'Set in Domain',
                   8910:                      crs   => 'Set in Course',
                   8911:                      comm  => 'Set in Community',
                   8912:                      place => 'Set in Placement Test',
1.57      raeburn  8913:                     );
                   8914:         $datatable = '<tr class="LC_odd_row">'.
                   8915:                   '<td>'.$title{'togglecats'}.'</td>'.
                   8916:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   8917:                   '<input type="radio" name="togglecats"'.
                   8918:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8919:                   '<label><input type="radio" name="togglecats"'.
                   8920:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   8921:                   '</tr><tr>'.
                   8922:                   '<td>'.$title{'categorize'}.'</td>'.
                   8923:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   8924:                   '<label><input type="radio" name="categorize"'.
                   8925:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8926:                   '<label><input type="radio" name="categorize"'.
                   8927:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  8928:                   '</tr><tr class="LC_odd_row">'.
                   8929:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   8930:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   8931:                   '<input type="radio" name="togglecatscomm"'.
                   8932:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8933:                   '<label><input type="radio" name="togglecatscomm"'.
                   8934:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   8935:                   '</tr><tr>'.
                   8936:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   8937:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   8938:                   '<label><input type="radio" name="categorizecomm"'.
                   8939:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8940:                   '<label><input type="radio" name="categorizecomm"'.
                   8941:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  8942:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  8943:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   8944:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   8945:                   '<input type="radio" name="togglecatsplace"'.
                   8946:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8947:                   '<label><input type="radio" name="togglecatscomm"'.
                   8948:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   8949:                   '</tr><tr>'.
                   8950:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   8951:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   8952:                   '<label><input type="radio" name="categorizeplace"'.
                   8953:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   8954:                   '<label><input type="radio" name="categorizeplace"'.
                   8955:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  8956:                   '</tr>';
1.272     raeburn  8957:         $$rowtotal += 6;
1.57      raeburn  8958:     } else {
                   8959:         my $css_class;
                   8960:         my $itemcount = 1;
                   8961:         my $cathash; 
                   8962:         if (ref($settings) eq 'HASH') {
                   8963:             $cathash = $settings->{'cats'};
                   8964:         }
                   8965:         if (ref($cathash) eq 'HASH') {
                   8966:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   8967:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   8968:                                                    \%allitems,\%idx,\@jsarray);
                   8969:             my $maxdepth = scalar(@cats);
                   8970:             my $colattrib = '';
                   8971:             if ($maxdepth > 2) {
                   8972:                 $colattrib = ' colspan="2" ';
                   8973:             }
                   8974:             my @path;
                   8975:             if (@cats > 0) {
                   8976:                 if (ref($cats[0]) eq 'ARRAY') {
                   8977:                     my $numtop = @{$cats[0]};
                   8978:                     my $maxnum = $numtop;
1.120     raeburn  8979:                     my %default_names = (
                   8980:                           instcode    => &mt('Official courses'),
                   8981:                           communities => &mt('Communities'),
1.272     raeburn  8982:                           placement   => &mt('Placement Tests'),
1.120     raeburn  8983:                     );
                   8984: 
                   8985:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   8986:                         ($cathash->{'instcode::0'} eq '') ||
                   8987:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  8988:                         ($cathash->{'communities::0'} eq '') ||
                   8989:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   8990:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  8991:                         $maxnum ++;
                   8992:                     }
                   8993:                     my $lastidx;
                   8994:                     for (my $i=0; $i<$numtop; $i++) {
                   8995:                         my $parent = $cats[0][$i];
                   8996:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8997:                         my $item = &escape($parent).'::0';
                   8998:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   8999:                         $lastidx = $idx{$item};
                   9000:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   9001:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   9002:                         for (my $k=0; $k<=$maxnum; $k++) {
                   9003:                             my $vpos = $k+1;
                   9004:                             my $selstr;
                   9005:                             if ($k == $i) {
                   9006:                                 $selstr = ' selected="selected" ';
                   9007:                             }
                   9008:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9009:                         }
1.214     raeburn  9010:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  9011:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  9012:                             $datatable .=  '<span class="LC_nobreak">'
                   9013:                                            .$default_names{$parent}.'</span>';
                   9014:                             if ($parent eq 'instcode') {
                   9015:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   9016:                                               .&mt('with institutional codes')
                   9017:                                               .')</span></td><td'.$colattrib.'>';
                   9018:                             } else {
                   9019:                                 $datatable .= '<table><tr><td>';
                   9020:                             }
                   9021:                             $datatable .= '<span class="LC_nobreak">'
                   9022:                                           .'<label><input type="radio" name="'
                   9023:                                           .$parent.'" value="1" checked="checked" />'
                   9024:                                           .&mt('Display').'</label>';
                   9025:                             if ($parent eq 'instcode') {
                   9026:                                 $datatable .= '&nbsp;';
                   9027:                             } else {
                   9028:                                 $datatable .= '</span></td></tr><tr><td>'
                   9029:                                               .'<span class="LC_nobreak">';
                   9030:                             }
                   9031:                             $datatable .= '<label><input type="radio" name="'
                   9032:                                           .$parent.'" value="0" />'
                   9033:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  9034:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  9035:                                 $datatable .= '</td></tr></table>';
                   9036:                             }
                   9037:                             $datatable .= '</td>';
1.57      raeburn  9038:                         } else {
                   9039:                             $datatable .= $parent
1.214     raeburn  9040:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   9041:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  9042:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   9043:                         }
                   9044:                         my $depth = 1;
                   9045:                         push(@path,$parent);
                   9046:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   9047:                         pop(@path);
                   9048:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9049:                         $itemcount ++;
                   9050:                     }
1.48      raeburn  9051:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  9052:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   9053:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  9054:                     for (my $k=0; $k<=$maxnum; $k++) {
                   9055:                         my $vpos = $k+1;
                   9056:                         my $selstr;
1.57      raeburn  9057:                         if ($k == $numtop) {
1.48      raeburn  9058:                             $selstr = ' selected="selected" ';
                   9059:                         }
                   9060:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9061:                     }
1.59      bisitz   9062:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  9063:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   9064:                                   .'</tr>'."\n";
1.48      raeburn  9065:                     $itemcount ++;
1.272     raeburn  9066:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  9067:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   9068:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9069:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   9070:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   9071:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   9072:                             for (my $k=0; $k<=$maxnum; $k++) {
                   9073:                                 my $vpos = $k+1;
                   9074:                                 my $selstr;
                   9075:                                 if ($k == $maxnum) {
                   9076:                                     $selstr = ' selected="selected" ';
                   9077:                                 }
                   9078:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  9079:                             }
1.120     raeburn  9080:                             $datatable .= '</select></span></td>'.
                   9081:                                           '<td><span class="LC_nobreak">'.
                   9082:                                           $default_names{$default}.'</span>';
                   9083:                             if ($default eq 'instcode') {
                   9084:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   9085:                                               .&mt('with institutional codes').')</span>';
                   9086:                             }
                   9087:                             $datatable .= '</td>'
                   9088:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   9089:                                           .&mt('Display').'</label>&nbsp;'
                   9090:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   9091:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  9092:                         }
                   9093:                     }
                   9094:                 }
1.57      raeburn  9095:             } else {
                   9096:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  9097:             }
                   9098:         } else {
1.327     raeburn  9099:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  9100:                           .&initialize_categories($itemcount);
1.48      raeburn  9101:         }
1.57      raeburn  9102:         $$rowtotal += $itemcount;
1.48      raeburn  9103:     }
                   9104:     return $datatable;
                   9105: }
                   9106: 
1.69      raeburn  9107: sub print_serverstatuses {
                   9108:     my ($dom,$settings,$rowtotal) = @_;
                   9109:     my $datatable;
                   9110:     my @pages = &serverstatus_pages();
                   9111:     my (%namedaccess,%machineaccess);
                   9112:     foreach my $type (@pages) {
                   9113:         $namedaccess{$type} = '';
                   9114:         $machineaccess{$type}= '';
                   9115:     }
                   9116:     if (ref($settings) eq 'HASH') {
                   9117:         foreach my $type (@pages) {
                   9118:             if (exists($settings->{$type})) {
                   9119:                 if (ref($settings->{$type}) eq 'HASH') {
                   9120:                     foreach my $key (keys(%{$settings->{$type}})) {
                   9121:                         if ($key eq 'namedusers') {
                   9122:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   9123:                         } elsif ($key eq 'machines') {
                   9124:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   9125:                         }
                   9126:                     }
                   9127:                 }
                   9128:             }
                   9129:         }
                   9130:     }
1.81      raeburn  9131:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  9132:     my $rownum = 0;
                   9133:     my $css_class;
                   9134:     foreach my $type (@pages) {
                   9135:         $rownum ++;
                   9136:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   9137:         $datatable .= '<tr'.$css_class.'>'.
                   9138:                       '<td><span class="LC_nobreak">'.
                   9139:                       $titles->{$type}.'</span></td>'.
                   9140:                       '<td class="LC_left_item">'.
                   9141:                       '<input type="text" name="'.$type.'_namedusers" '.
                   9142:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   9143:                       '<td class="LC_right_item">'.
                   9144:                       '<span class="LC_nobreak">'.
                   9145:                       '<input type="text" name="'.$type.'_machines" '.
                   9146:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  9147:                       '</span></td></tr>'."\n";
1.69      raeburn  9148:     }
                   9149:     $$rowtotal += $rownum;
                   9150:     return $datatable;
                   9151: }
                   9152: 
                   9153: sub serverstatus_pages {
                   9154:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  9155:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   9156:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   9157:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  9158: }
                   9159: 
1.236     raeburn  9160: sub defaults_javascript {
                   9161:     my ($settings) = @_;
1.354     raeburn  9162:     return unless (ref($settings) eq 'HASH');
1.236     raeburn  9163:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   9164:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   9165:         if ($maxnum eq '') {
                   9166:             $maxnum = 0;
                   9167:         }
                   9168:         $maxnum ++;
1.249     raeburn  9169:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  9170:         return <<"ENDSCRIPT";
                   9171: <script type="text/javascript">
                   9172: // <![CDATA[
                   9173: function reorderTypes(form,caller) {
                   9174:     var changedVal;
                   9175: $jstext 
                   9176:     var newpos = 'addinststatus_pos';
                   9177:     var current = new Array;
                   9178:     var maxh = $maxnum;
                   9179:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9180:     var oldVal;
                   9181:     if (caller == newpos) {
                   9182:         changedVal = newitemVal;
                   9183:     } else {
                   9184:         var curritem = 'inststatus_pos_'+caller;
                   9185:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   9186:         current[newitemVal] = newpos;
                   9187:     }
                   9188:     for (var i=0; i<inststatuses.length; i++) {
                   9189:         if (inststatuses[i] != caller) {
                   9190:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   9191:             if (form.elements[elementName]) {
                   9192:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9193:                 current[currVal] = elementName;
                   9194:             }
                   9195:         }
                   9196:     }
                   9197:     for (var j=0; j<maxh; j++) {
                   9198:         if (current[j] == undefined) {
                   9199:             oldVal = j;
                   9200:         }
                   9201:     }
                   9202:     if (oldVal < changedVal) {
                   9203:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9204:            var elementName = current[k];
                   9205:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9206:         }
                   9207:     } else {
                   9208:         for (var k=changedVal; k<oldVal; k++) {
                   9209:             var elementName = current[k];
                   9210:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9211:         }
                   9212:     }
                   9213:     return;
                   9214: }
                   9215: 
                   9216: // ]]>
                   9217: </script>
                   9218: 
                   9219: ENDSCRIPT
                   9220:     }
1.354     raeburn  9221:     return;
                   9222: }
                   9223: 
                   9224: sub passwords_javascript {
                   9225:     my $intauthcheck = &mt('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.');
                   9226:     my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
                   9227:     &js_escape(\$intauthcheck);
                   9228:     &js_escape(\$intauthcost);
                   9229:     my $intauthjs = <<"ENDSCRIPT";
                   9230: 
                   9231: function warnIntAuth(field) {
                   9232:     if (field.name == 'intauth_check') {
                   9233:         if (field.value == '2') {
                   9234:             alert('$intauthcheck');
                   9235:         }
                   9236:     }
                   9237:     if (field.name == 'intauth_cost') {
                   9238:         field.value.replace(/\s/g,'');
                   9239:         if (field.value != '') {
                   9240:             var regexdigit=/^\\d+\$/;
                   9241:             if (!regexdigit.test(field.value)) {
                   9242:                 alert('$intauthcost');
                   9243:             }
                   9244:         }
                   9245:     }
                   9246:     return;
                   9247: }
                   9248: 
                   9249: ENDSCRIPT
                   9250:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  9251: }
                   9252: 
1.49      raeburn  9253: sub coursecategories_javascript {
                   9254:     my ($settings) = @_;
1.57      raeburn  9255:     my ($output,$jstext,$cathash);
1.49      raeburn  9256:     if (ref($settings) eq 'HASH') {
1.57      raeburn  9257:         $cathash = $settings->{'cats'};
                   9258:     }
                   9259:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  9260:         my (@cats,@jsarray,%idx);
1.57      raeburn  9261:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  9262:         if (@jsarray > 0) {
                   9263:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   9264:             for (my $i=0; $i<@jsarray; $i++) {
                   9265:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   9266:                     my $catstr = join('","',@{$jsarray[$i]});
                   9267:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   9268:                 }
                   9269:             }
                   9270:         }
                   9271:     } else {
                   9272:         $jstext  = '    var categories = Array(1);'."\n".
                   9273:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   9274:     }
1.237     bisitz   9275:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   9276:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  9277:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  9278:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   9279:     &js_escape(\$instcode_reserved);
                   9280:     &js_escape(\$communities_reserved);
1.272     raeburn  9281:     &js_escape(\$placement_reserved);
1.265     damieng  9282:     &js_escape(\$choose_again);
1.49      raeburn  9283:     $output = <<"ENDSCRIPT";
                   9284: <script type="text/javascript">
1.109     raeburn  9285: // <![CDATA[
1.49      raeburn  9286: function reorderCats(form,parent,item,idx) {
                   9287:     var changedVal;
                   9288: $jstext
                   9289:     var newpos = 'addcategory_pos';
                   9290:     if (parent == '') {
                   9291:         var has_instcode = 0;
                   9292:         var maxtop = categories[idx].length;
                   9293:         for (var j=0; j<maxtop; j++) {
                   9294:             if (categories[idx][j] == 'instcode::0') {
                   9295:                 has_instcode == 1;
                   9296:             }
                   9297:         }
                   9298:         if (has_instcode == 0) {
                   9299:             categories[idx][maxtop] = 'instcode_pos';
                   9300:         }
                   9301:     } else {
                   9302:         newpos += '_'+parent;
                   9303:     }
                   9304:     var maxh = 1 + categories[idx].length;
                   9305:     var current = new Array;
                   9306:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9307:     if (item == newpos) {
                   9308:         changedVal = newitemVal;
                   9309:     } else {
                   9310:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   9311:         current[newitemVal] = newpos;
                   9312:     }
                   9313:     for (var i=0; i<categories[idx].length; i++) {
                   9314:         var elementName = categories[idx][i];
                   9315:         if (elementName != item) {
                   9316:             if (form.elements[elementName]) {
                   9317:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9318:                 current[currVal] = elementName;
                   9319:             }
                   9320:         }
                   9321:     }
                   9322:     var oldVal;
                   9323:     for (var j=0; j<maxh; j++) {
                   9324:         if (current[j] == undefined) {
                   9325:             oldVal = j;
                   9326:         }
                   9327:     }
                   9328:     if (oldVal < changedVal) {
                   9329:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9330:            var elementName = current[k];
                   9331:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9332:         }
                   9333:     } else {
                   9334:         for (var k=changedVal; k<oldVal; k++) {
                   9335:             var elementName = current[k];
                   9336:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9337:         }
                   9338:     }
                   9339:     return;
                   9340: }
1.120     raeburn  9341: 
                   9342: function categoryCheck(form) {
                   9343:     if (form.elements['addcategory_name'].value == 'instcode') {
                   9344:         alert('$instcode_reserved\\n$choose_again');
                   9345:         return false;
                   9346:     }
                   9347:     if (form.elements['addcategory_name'].value == 'communities') {
                   9348:         alert('$communities_reserved\\n$choose_again');
                   9349:         return false;
                   9350:     }
1.272     raeburn  9351:     if (form.elements['addcategory_name'].value == 'placement') {
                   9352:         alert('$placement_reserved\\n$choose_again');
                   9353:         return false;
                   9354:     }
1.120     raeburn  9355:     return true;
                   9356: }
                   9357: 
1.109     raeburn  9358: // ]]>
1.49      raeburn  9359: </script>
                   9360: 
                   9361: ENDSCRIPT
                   9362:     return $output;
                   9363: }
                   9364: 
1.48      raeburn  9365: sub initialize_categories {
                   9366:     my ($itemcount) = @_;
1.120     raeburn  9367:     my ($datatable,$css_class,$chgstr);
                   9368:     my %default_names = (
                   9369:                       instcode    => 'Official courses (with institutional codes)',
                   9370:                       communities => 'Communities',
1.272     raeburn  9371:                       placement   => 'Placement Tests',
1.120     raeburn  9372:                         );
1.328     raeburn  9373:     my %selnum = (
                   9374:                    instcode    => '0',
                   9375:                    communities => '1',
                   9376:                    placement   => '2',
                   9377:                  );
                   9378:     my %selected;
1.272     raeburn  9379:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  9380:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  9381:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  9382:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   9383:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  9384:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  9385:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   9386:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   9387:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   9388:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   9389:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  9390:                      .$default_names{$default}
                   9391:                      .'</span></td><td><span class="LC_nobreak">'
                   9392:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   9393:                      .&mt('Display').'</label>&nbsp;<label>'
                   9394:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  9395:                  .'</label></span></td></tr>';
1.120     raeburn  9396:         $itemcount ++;
                   9397:     }
1.48      raeburn  9398:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  9399:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  9400:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  9401:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   9402:                   .'<option value="0">1</option>'
                   9403:                   .'<option value="1">2</option>'
1.328     raeburn  9404:                   .'<option value="2">3</option>'
                   9405:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  9406:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   9407:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   9408:                   .'</td></tr>';
1.48      raeburn  9409:     return $datatable;
                   9410: }
                   9411: 
                   9412: sub build_category_rows {
1.49      raeburn  9413:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   9414:     my ($text,$name,$item,$chgstr);
1.48      raeburn  9415:     if (ref($cats) eq 'ARRAY') {
                   9416:         my $maxdepth = scalar(@{$cats});
                   9417:         if (ref($cats->[$depth]) eq 'HASH') {
                   9418:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9419:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9420:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  9421:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  9422:                 my ($idxnum,$parent_name,$parent_item);
                   9423:                 my $higher = $depth - 1;
                   9424:                 if ($higher == 0) {
                   9425:                     $parent_name = &escape($parent).'::'.$higher;
                   9426:                 } else {
                   9427:                     if (ref($path) eq 'ARRAY') {
                   9428:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9429:                     }
                   9430:                 }
                   9431:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  9432:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  9433:                     if ($j < $numchildren) {
1.48      raeburn  9434:                         $name = $cats->[$depth]{$parent}[$j];
                   9435:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  9436:                         $idxnum = $idx->{$item};
                   9437:                     } else {
                   9438:                         $name = $parent_name;
                   9439:                         $item = $parent_item;
1.48      raeburn  9440:                     }
1.49      raeburn  9441:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   9442:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  9443:                     for (my $i=0; $i<=$numchildren; $i++) {
                   9444:                         my $vpos = $i+1;
                   9445:                         my $selstr;
                   9446:                         if ($j == $i) {
                   9447:                             $selstr = ' selected="selected" ';
                   9448:                         }
                   9449:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   9450:                     }
                   9451:                     $text .= '</select>&nbsp;';
                   9452:                     if ($j < $numchildren) {
                   9453:                         my $deeper = $depth+1;
                   9454:                         $text .= $name.'&nbsp;'
                   9455:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   9456:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   9457:                         if(ref($path) eq 'ARRAY') {
                   9458:                             push(@{$path},$name);
1.49      raeburn  9459:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  9460:                             pop(@{$path});
                   9461:                         }
                   9462:                     } else {
1.330     raeburn  9463:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  9464:                         if ($j == $numchildren) {
                   9465:                             $text .= $name;
                   9466:                         } else {
                   9467:                             $text .= $item;
                   9468:                         }
                   9469:                         $text .= '" value="" />';
                   9470:                     }
                   9471:                     $text .= '</td></tr>';
                   9472:                 }
                   9473:                 $text .= '</table></td>';
                   9474:             } else {
                   9475:                 my $higher = $depth-1;
                   9476:                 if ($higher == 0) {
                   9477:                     $name = &escape($parent).'::'.$higher;
                   9478:                 } else {
                   9479:                     if (ref($path) eq 'ARRAY') {
                   9480:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9481:                     }
                   9482:                 }
                   9483:                 my $colspan;
                   9484:                 if ($parent ne 'instcode') {
                   9485:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  9486:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  9487:                 }
                   9488:             }
                   9489:         }
                   9490:     }
                   9491:     return $text;
                   9492: }
                   9493: 
1.33      raeburn  9494: sub modifiable_userdata_row {
1.305     raeburn  9495:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  9496:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  9497:     my ($role,$rolename,$statustype);
                   9498:     $role = $item;
1.224     raeburn  9499:     if ($context eq 'cancreate') {
1.305     raeburn  9500:         if ($item =~ /^(emailusername)_(.+)$/) {
                   9501:             $role = $1;
                   9502:             $statustype = $2;
1.228     raeburn  9503:             if (ref($usertypes) eq 'HASH') {
                   9504:                 if ($usertypes->{$statustype}) {
                   9505:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   9506:                 } else {
                   9507:                     $rolename = &mt('Data provided by user');
                   9508:                 }
                   9509:             }
1.224     raeburn  9510:         }
                   9511:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  9512:         if (ref($usertypes) eq 'HASH') {
                   9513:             $rolename = $usertypes->{$role};
                   9514:         } else {
                   9515:             $rolename = $role;
                   9516:         }
1.325     raeburn  9517:     } elsif ($context eq 'lti') {
                   9518:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  9519:     } elsif ($context eq 'privacy') {
                   9520:         $rolename = $itemdesc;
1.33      raeburn  9521:     } else {
1.63      raeburn  9522:         if ($role eq 'cr') {
                   9523:             $rolename = &mt('Custom role');
                   9524:         } else {
                   9525:             $rolename = &Apache::lonnet::plaintext($role);
                   9526:         }
1.33      raeburn  9527:     }
1.224     raeburn  9528:     my (@fields,%fieldtitles);
                   9529:     if (ref($fieldsref) eq 'ARRAY') {
                   9530:         @fields = @{$fieldsref};
                   9531:     } else {
                   9532:         @fields = ('lastname','firstname','middlename','generation',
                   9533:                    'permanentemail','id');
                   9534:     }
                   9535:     if ((ref($titlesref) eq 'HASH')) {
                   9536:         %fieldtitles = %{$titlesref};
                   9537:     } else {
                   9538:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9539:     }
1.33      raeburn  9540:     my $output;
1.305     raeburn  9541:     my $css_class;
                   9542:     if ($rowcount%2) {
                   9543:         $css_class = 'LC_odd_row';
                   9544:     }
                   9545:     if ($customcss) {
                   9546:         $css_class .= " $customcss";
                   9547:     }
                   9548:     $css_class =~ s/^\s+//;
                   9549:     if ($css_class) {
                   9550:         $css_class = ' class="'.$css_class.'"';
                   9551:     }
                   9552:     if ($rowstyle) {
                   9553:         $css_class .= ' style="'.$rowstyle.'"';
                   9554:     }
                   9555:     if ($rowid) {
                   9556:         $rowid = ' id="'.$rowid.'"';
                   9557:     }
                   9558:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  9559:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   9560:               '<td class="LC_left_item" colspan="2"><table>';
                   9561:     my $rem;
                   9562:     my %checks;
1.325     raeburn  9563:     my %current;
1.33      raeburn  9564:     if (ref($settings) eq 'HASH') {
1.325     raeburn  9565:         my $hashref;
                   9566:         if ($context eq 'lti') {
                   9567:             if (ref($settings) eq 'HASH') {
                   9568:                 $hashref = $settings->{'instdata'};
                   9569:             }
1.357     raeburn  9570:         } elsif ($context eq 'privacy') {
                   9571:             my ($key,$inner) = split(/_/,$role);
                   9572:             if (ref($settings) eq 'HASH') {
                   9573:                 if (ref($settings->{$key}) eq 'HASH') {
                   9574:                     $hashref = $settings->{$key}->{$inner};
                   9575:                 }
                   9576:             }
1.325     raeburn  9577:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  9578:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  9579:                 $hashref = $settings->{'lti_instdata'};
                   9580:             }
                   9581:             if ($role eq 'emailusername') {
                   9582:                 if ($statustype) {
                   9583:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   9584:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  9585:                     }
1.325     raeburn  9586:                 }
                   9587:             }
                   9588:         }
                   9589:         if (ref($hashref) eq 'HASH') { 
                   9590:             foreach my $field (@fields) {
                   9591:                 if ($hashref->{$field}) {
                   9592:                     if ($role eq 'emailusername') {
                   9593:                         $checks{$field} = $hashref->{$field};
                   9594:                     } else {
                   9595:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  9596:                     }
                   9597:                 }
                   9598:             }
                   9599:         }
                   9600:     }
1.305     raeburn  9601:  
                   9602:     my $total = scalar(@fields);
                   9603:     for (my $i=0; $i<$total; $i++) {
                   9604:         $rem = $i%($numinrow);
1.33      raeburn  9605:         if ($rem == 0) {
                   9606:             if ($i > 0) {
                   9607:                 $output .= '</tr>';
                   9608:             }
                   9609:             $output .= '<tr>';
                   9610:         }
                   9611:         my $check = ' ';
1.228     raeburn  9612:         unless ($role eq 'emailusername') {
                   9613:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  9614:                 $check = $checks{$fields[$i]};
1.357     raeburn  9615:             } elsif ($context eq 'privacy') {
                   9616:                 if ($role =~ /^priv_(domain|course)$/) {
                   9617:                     if (ref($settings) ne 'HASH') {
                   9618:                         $check = ' checked="checked" ';
                   9619:                     }
                   9620:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   9621:                     if (ref($settings) ne 'HASH') {
                   9622:                         unless ($fields[$i] eq 'id') {
                   9623:                             $check = ' checked="checked" ';
                   9624:                         }
                   9625:                     }
                   9626:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   9627:                     if (ref($settings) ne 'HASH') {
                   9628:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   9629:                             $check = ' checked="checked" ';
                   9630:                         }
                   9631:                     }
                   9632:                 }
1.325     raeburn  9633:             } elsif ($context ne 'lti') {
1.228     raeburn  9634:                 if ($role eq 'st') {
                   9635:                     if (ref($settings) ne 'HASH') {
                   9636:                         $check = ' checked="checked" '; 
                   9637:                     }
1.33      raeburn  9638:                 }
                   9639:             }
                   9640:         }
                   9641:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  9642:                    '<span class="LC_nobreak">';
1.325     raeburn  9643:         my $prefix = 'canmodify';
1.228     raeburn  9644:         if ($role eq 'emailusername') {
                   9645:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   9646:                 $checks{$fields[$i]} = 'omit';
                   9647:             }
                   9648:             foreach my $option ('required','optional','omit') {
                   9649:                 my $checked='';
                   9650:                 if ($checks{$fields[$i]} eq $option) {
                   9651:                     $checked='checked="checked" ';
                   9652:                 }
                   9653:                 $output .= '<label>'.
1.325     raeburn  9654:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  9655:                            &mt($option).'</label>'.('&nbsp;' x2);
                   9656:             }
                   9657:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   9658:         } else {
1.325     raeburn  9659:             if ($context eq 'lti') {
                   9660:                 $prefix = 'lti';
1.357     raeburn  9661:             } elsif ($context eq 'privacy') {
                   9662:                 $prefix = 'privacy';
1.325     raeburn  9663:             }
1.228     raeburn  9664:             $output .= '<label>'.
1.325     raeburn  9665:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  9666:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   9667:                        '</label>';
                   9668:         }
                   9669:         $output .= '</span></td>';
1.33      raeburn  9670:     }
1.305     raeburn  9671:     $rem = $total%$numinrow;
                   9672:     my $colsleft;
                   9673:     if ($rem) {
                   9674:         $colsleft = $numinrow - $rem;
                   9675:     }
                   9676:     if ($colsleft > 1) {
1.33      raeburn  9677:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9678:                    '&nbsp;</td>';
                   9679:     } elsif ($colsleft == 1) {
                   9680:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   9681:     }
                   9682:     $output .= '</tr></table></td></tr>';
                   9683:     return $output;
                   9684: }
1.28      raeburn  9685: 
1.93      raeburn  9686: sub insttypes_row {
1.305     raeburn  9687:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   9688:         $customcss,$rowstyle) = @_;
1.93      raeburn  9689:     my %lt = &Apache::lonlocal::texthash (
                   9690:                       cansearch => 'Users allowed to search',
                   9691:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  9692:                       lockablenames => 'User preference to lock name',
1.305     raeburn  9693:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  9694:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  9695:              );
                   9696:     my $showdom;
                   9697:     if ($context eq 'cansearch') {
                   9698:         $showdom = ' ('.$dom.')';
                   9699:     }
1.165     raeburn  9700:     my $class = 'LC_left_item';
                   9701:     if ($context eq 'statustocreate') {
                   9702:         $class = 'LC_right_item';
                   9703:     }
1.305     raeburn  9704:     my $css_class;
                   9705:     if ($$rowtotal%2) {
                   9706:         $css_class = 'LC_odd_row';
                   9707:     }
                   9708:     if ($customcss) {
                   9709:         $css_class .= ' '.$customcss;
                   9710:     }
                   9711:     $css_class =~ s/^\s+//;
                   9712:     if ($css_class) {
                   9713:         $css_class = ' class="'.$css_class.'"';
                   9714:     }
                   9715:     if ($rowstyle) {
                   9716:         $css_class .= ' style="'.$rowstyle.'"';
                   9717:     }
                   9718:     if ($onclick) {
                   9719:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  9720:     }
                   9721:     my $output = '<tr'.$css_class.'>'.
                   9722:                  '<td>'.$lt{$context}.$showdom.
                   9723:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  9724:     my $rem;
                   9725:     if (ref($types) eq 'ARRAY') {
                   9726:         for (my $i=0; $i<@{$types}; $i++) {
                   9727:             if (defined($usertypes->{$types->[$i]})) {
                   9728:                 my $rem = $i%($numinrow);
                   9729:                 if ($rem == 0) {
                   9730:                     if ($i > 0) {
                   9731:                         $output .= '</tr>';
                   9732:                     }
                   9733:                     $output .= '<tr>';
1.23      raeburn  9734:                 }
1.26      raeburn  9735:                 my $check = ' ';
1.99      raeburn  9736:                 if (ref($settings) eq 'HASH') {
                   9737:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   9738:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   9739:                             $check = ' checked="checked" ';
                   9740:                         }
1.315     raeburn  9741:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   9742:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   9743:                             $check = ' checked="checked" ';
                   9744:                         }
1.99      raeburn  9745:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  9746:                         $check = ' checked="checked" ';
                   9747:                     }
1.23      raeburn  9748:                 }
1.26      raeburn  9749:                 $output .= '<td class="LC_left_item">'.
                   9750:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  9751:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  9752:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  9753:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  9754:             }
                   9755:         }
1.26      raeburn  9756:         $rem = @{$types}%($numinrow);
1.23      raeburn  9757:     }
                   9758:     my $colsleft = $numinrow - $rem;
1.315     raeburn  9759:     if ($context eq 'overrides') {
                   9760:         if ($colsleft > 1) {
                   9761:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9762:         } else {
                   9763:             $output .= '<td class="LC_left_item">';
                   9764:         }
                   9765:         $output .= '&nbsp;';  
1.23      raeburn  9766:     } else {
1.334     raeburn  9767:         if ($rem == 0) {
1.315     raeburn  9768:             $output .= '<tr>';
                   9769:         }
                   9770:         if ($colsleft > 1) {
                   9771:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9772:         } else {
                   9773:             $output .= '<td class="LC_left_item">';
                   9774:         }
                   9775:         my $defcheck = ' ';
                   9776:         if (ref($settings) eq 'HASH') {  
                   9777:             if (ref($settings->{$context}) eq 'ARRAY') {
                   9778:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   9779:                     $defcheck = ' checked="checked" ';
                   9780:                 }
                   9781:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  9782:                 $defcheck = ' checked="checked" ';
                   9783:             }
1.26      raeburn  9784:         }
1.315     raeburn  9785:         $output .= '<span class="LC_nobreak"><label>'.
                   9786:                    '<input type="checkbox" name="'.$context.'" '.
                   9787:                    'value="default"'.$defcheck.$onclick.' />'.
                   9788:                    $othertitle.'</label></span>';
1.23      raeburn  9789:     }
1.315     raeburn  9790:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  9791:     return $output;
1.23      raeburn  9792: }
                   9793: 
                   9794: sub sorted_searchtitles {
                   9795:     my %searchtitles = &Apache::lonlocal::texthash(
                   9796:                          'uname' => 'username',
                   9797:                          'lastname' => 'last name',
                   9798:                          'lastfirst' => 'last name, first name',
                   9799:                      );
                   9800:     my @titleorder = ('uname','lastname','lastfirst');
                   9801:     return (\%searchtitles,\@titleorder);
                   9802: }
                   9803: 
1.25      raeburn  9804: sub sorted_searchtypes {
                   9805:     my %srchtypes_desc = (
                   9806:                            exact    => 'is exact match',
                   9807:                            contains => 'contains ..',
                   9808:                            begins   => 'begins with ..',
                   9809:                          );
                   9810:     my @srchtypeorder = ('exact','begins','contains');
                   9811:     return (\%srchtypes_desc,\@srchtypeorder);
                   9812: }
                   9813: 
1.3       raeburn  9814: sub usertype_update_row {
                   9815:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   9816:     my $datatable;
                   9817:     my $numinrow = 4;
                   9818:     foreach my $type (@{$types}) {
                   9819:         if (defined($usertypes->{$type})) {
                   9820:             $$rownums ++;
                   9821:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   9822:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   9823:                           '</td><td class="LC_left_item"><table>';
                   9824:             for (my $i=0; $i<@{$fields}; $i++) {
                   9825:                 my $rem = $i%($numinrow);
                   9826:                 if ($rem == 0) {
                   9827:                     if ($i > 0) {
                   9828:                         $datatable .= '</tr>';
                   9829:                     }
                   9830:                     $datatable .= '<tr>';
                   9831:                 }
                   9832:                 my $check = ' ';
1.39      raeburn  9833:                 if (ref($settings) eq 'HASH') {
                   9834:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   9835:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   9836:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   9837:                                 $check = ' checked="checked" ';
                   9838:                             }
1.3       raeburn  9839:                         }
                   9840:                     }
                   9841:                 }
                   9842: 
                   9843:                 if ($i == @{$fields}-1) {
                   9844:                     my $colsleft = $numinrow - $rem;
                   9845:                     if ($colsleft > 1) {
                   9846:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   9847:                     } else {
                   9848:                         $datatable .= '<td>';
                   9849:                     }
                   9850:                 } else {
                   9851:                     $datatable .= '<td>';
                   9852:                 }
1.8       raeburn  9853:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   9854:                               '<input type="checkbox" name="updateable_'.$type.
                   9855:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   9856:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  9857:             }
                   9858:             $datatable .= '</tr></table></td></tr>';
                   9859:         }
                   9860:     }
                   9861:     return $datatable;
1.1       raeburn  9862: }
                   9863: 
                   9864: sub modify_login {
1.205     raeburn  9865:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  9866:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   9867:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   9868:     %title = ( coursecatalog => 'Display course catalog',
                   9869:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  9870:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  9871:                newuser => 'Link for visitors to create a user account',
                   9872:                loginheader => 'Log-in box header');
                   9873:     @offon = ('off','on');
1.112     raeburn  9874:     if (ref($domconfig{login}) eq 'HASH') {
                   9875:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   9876:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   9877:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   9878:             }
                   9879:         }
                   9880:     }
1.9       raeburn  9881:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   9882:                                            \%domconfig,\%loginhash);
1.188     raeburn  9883:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  9884:     foreach my $item (@toggles) {
                   9885:         $loginhash{login}{$item} = $env{'form.'.$item};
                   9886:     }
1.41      raeburn  9887:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  9888:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   9889:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   9890:                                          \%loginhash);
                   9891:     }
1.110     raeburn  9892: 
1.149     raeburn  9893:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  9894:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  9895:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  9896:     if (keys(%servers) > 1) {
                   9897:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  9898:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   9899:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   9900:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   9901:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   9902:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   9903:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   9904:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   9905:                         $changes{'loginvia'}{$lonhost} = 1;
                   9906:                     } else {
                   9907:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   9908:                         $changes{'loginvia'}{$lonhost} = 1;
                   9909:                     }
                   9910:                 } else {
                   9911:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   9912:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   9913:                         $changes{'loginvia'}{$lonhost} = 1;
                   9914:                     }
                   9915:                 }
                   9916:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   9917:                     foreach my $item (@loginvia_attribs) {
                   9918:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   9919:                     }
                   9920:                 } else {
                   9921:                     foreach my $item (@loginvia_attribs) {
                   9922:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   9923:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   9924:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   9925:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   9926:                                 $new = '/';
                   9927:                             }
                   9928:                         }
                   9929:                         if (($item eq 'custompath') && 
                   9930:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   9931:                             $new = '';
                   9932:                         }
                   9933:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   9934:                             $changes{'loginvia'}{$lonhost} = 1;
                   9935:                         }
                   9936:                         if ($item eq 'exempt') {
1.256     raeburn  9937:                             $new = &check_exempt_addresses($new);
1.128     raeburn  9938:                         }
                   9939:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   9940:                     }
                   9941:                 }
1.112     raeburn  9942:             } else {
1.128     raeburn  9943:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   9944:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  9945:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  9946:                     foreach my $item (@loginvia_attribs) {
                   9947:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   9948:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   9949:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   9950:                                 $new = '/';
                   9951:                             }
                   9952:                         }
                   9953:                         if (($item eq 'custompath') && 
                   9954:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   9955:                             $new = '';
                   9956:                         }
                   9957:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   9958:                     }
1.110     raeburn  9959:                 }
                   9960:             }
                   9961:         }
                   9962:     }
1.119     raeburn  9963: 
1.168     raeburn  9964:     my $servadm = $r->dir_config('lonAdmEMail');
                   9965:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   9966:     if (ref($domconfig{'login'}) eq 'HASH') {
                   9967:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   9968:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   9969:                 if ($lang eq 'nolang') {
                   9970:                     push(@currlangs,$lang);
                   9971:                 } elsif (defined($langchoices{$lang})) {
                   9972:                     push(@currlangs,$lang);
                   9973:                 } else {
                   9974:                     next;
                   9975:                 }
                   9976:             }
                   9977:         }
                   9978:     }
                   9979:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   9980:     if (@currlangs > 0) {
                   9981:         foreach my $lang (@currlangs) {
                   9982:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   9983:                 $changes{'helpurl'}{$lang} = 1;
                   9984:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   9985:                 $changes{'helpurl'}{$lang} = 1;
                   9986:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   9987:                 push(@newlangs,$lang);
                   9988:             } else {
                   9989:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   9990:             }
                   9991:         }
                   9992:     }
                   9993:     unless (grep(/^nolang$/,@currlangs)) {
                   9994:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   9995:             $changes{'helpurl'}{'nolang'} = 1;
                   9996:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   9997:             push(@newlangs,'nolang');
                   9998:         }
                   9999:     }
                   10000:     if ($env{'form.loginhelpurl_add_lang'}) {
                   10001:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   10002:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   10003:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   10004:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   10005:         }
                   10006:     }
                   10007:     if ((@newlangs > 0) || ($addedfile)) {
                   10008:         my $error;
                   10009:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10010:         if ($configuserok eq 'ok') {
                   10011:             if ($switchserver) {
                   10012:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   10013:             } elsif ($author_ok eq 'ok') {
                   10014:                 my @allnew = @newlangs;
                   10015:                 if ($addedfile ne '') {
                   10016:                     push(@allnew,$addedfile);
                   10017:                 }
                   10018:                 foreach my $lang (@allnew) {
                   10019:                     my $formelem = 'loginhelpurl_'.$lang;
                   10020:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   10021:                         $formelem = 'loginhelpurl_add_file';
                   10022:                     }
                   10023:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10024:                                                                "help/$lang",'','',$newfile{$lang});
                   10025:                     if ($result eq 'ok') {
                   10026:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   10027:                         $changes{'helpurl'}{$lang} = 1;
                   10028:                     } else {
                   10029:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   10030:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  10031:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  10032:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   10033:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   10034:                         }
                   10035:                     }
                   10036:                 }
                   10037:             } else {
                   10038:                 $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);
                   10039:             }
                   10040:         } else {
                   10041:             $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);
                   10042:         }
                   10043:         if ($error) {
                   10044:             &Apache::lonnet::logthis($error);
                   10045:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10046:         }
                   10047:     }
1.256     raeburn  10048: 
                   10049:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   10050:     if (ref($domconfig{'login'}) eq 'HASH') {
                   10051:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   10052:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   10053:                 if ($domservers{$lonhost}) {
                   10054:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10055:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  10056:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  10057:                     }
                   10058:                 }
                   10059:             }
                   10060:         }
                   10061:     }
                   10062:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   10063:     foreach my $lonhost (sort(keys(%domservers))) {
                   10064:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10065:             $changes{'headtag'}{$lonhost} = 1;
                   10066:         } else {
                   10067:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   10068:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   10069:             }
                   10070:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   10071:                 push(@newhosts,$lonhost);
                   10072:             } elsif ($currheadtagurls{$lonhost}) {
                   10073:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   10074:                 if ($currexempt{$lonhost}) {
1.289     raeburn  10075:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  10076:                         $changes{'headtag'}{$lonhost} = 1;
                   10077:                     }
                   10078:                 } elsif ($possexempt{$lonhost}) {
                   10079:                     $changes{'headtag'}{$lonhost} = 1;
                   10080:                 }
                   10081:                 if ($possexempt{$lonhost}) {
                   10082:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10083:                 }
                   10084:             }
                   10085:         }
                   10086:     }
                   10087:     if (@newhosts) {
                   10088:         my $error;
                   10089:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10090:         if ($configuserok eq 'ok') {
                   10091:             if ($switchserver) {
                   10092:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   10093:             } elsif ($author_ok eq 'ok') {
                   10094:                 foreach my $lonhost (@newhosts) {
                   10095:                     my $formelem = 'loginheadtag_'.$lonhost;
                   10096:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10097:                                                                           "login/headtag/$lonhost",'','',
                   10098:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   10099:                     if ($result eq 'ok') {
                   10100:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   10101:                         $changes{'headtag'}{$lonhost} = 1;
                   10102:                         if ($possexempt{$lonhost}) {
                   10103:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10104:                         }
                   10105:                     } else {
                   10106:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   10107:                                            $newheadtagurls{$lonhost},$result);
                   10108:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   10109:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   10110:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   10111:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   10112:                         }
                   10113:                     }
                   10114:                 }
                   10115:             } else {
                   10116:                 $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);
                   10117:             }
                   10118:         } else {
                   10119:             $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);
                   10120:         }
                   10121:         if ($error) {
                   10122:             &Apache::lonnet::logthis($error);
                   10123:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10124:         }
                   10125:     }
1.169     raeburn  10126:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  10127: 
                   10128:     my $defaulthelpfile = '/adm/loginproblems.html';
                   10129:     my $defaulttext = &mt('Default in use');
                   10130: 
1.1       raeburn  10131:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   10132:                                              $dom);
                   10133:     if ($putresult eq 'ok') {
1.188     raeburn  10134:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  10135:         my %defaultchecked = (
                   10136:                     'coursecatalog' => 'on',
1.188     raeburn  10137:                     'helpdesk'      => 'on',
1.42      raeburn  10138:                     'adminmail'     => 'off',
1.43      raeburn  10139:                     'newuser'       => 'off',
1.42      raeburn  10140:         );
1.55      raeburn  10141:         if (ref($domconfig{'login'}) eq 'HASH') {
                   10142:             foreach my $item (@toggles) {
                   10143:                 if ($defaultchecked{$item} eq 'on') { 
                   10144:                     if (($domconfig{'login'}{$item} eq '0') &&
                   10145:                         ($env{'form.'.$item} eq '1')) {
                   10146:                         $changes{$item} = 1;
                   10147:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10148:                               $domconfig{'login'}{$item} eq '1') &&
                   10149:                              ($env{'form.'.$item} eq '0')) {
                   10150:                         $changes{$item} = 1;
                   10151:                     }
                   10152:                 } elsif ($defaultchecked{$item} eq 'off') {
                   10153:                     if (($domconfig{'login'}{$item} eq '1') &&
                   10154:                         ($env{'form.'.$item} eq '0')) {
                   10155:                         $changes{$item} = 1;
                   10156:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10157:                               $domconfig{'login'}{$item} eq '0') &&
                   10158:                              ($env{'form.'.$item} eq '1')) {
                   10159:                         $changes{$item} = 1;
                   10160:                     }
1.42      raeburn  10161:                 }
                   10162:             }
1.41      raeburn  10163:         }
1.6       raeburn  10164:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  10165:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10166:             if (ref($lastactref) eq 'HASH') {
                   10167:                 $lastactref->{'domainconfig'} = 1;
                   10168:             }
1.1       raeburn  10169:             $resulttext = &mt('Changes made:').'<ul>';
                   10170:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   10171:                 if ($item eq 'loginvia') {
1.112     raeburn  10172:                     if (ref($changes{$item}) eq 'HASH') {
                   10173:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   10174:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  10175:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   10176:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   10177:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   10178:                                     $protocol = 'http' if ($protocol ne 'https');
                   10179:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   10180: 
                   10181:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   10182:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   10183:                                     } else {
                   10184:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   10185:                                     }
                   10186:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   10187:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   10188:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   10189:                                     }
                   10190:                                     $resulttext .= '</li>';
                   10191:                                 } else {
                   10192:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   10193:                                 }
1.112     raeburn  10194:                             } else {
1.128     raeburn  10195:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  10196:                             }
                   10197:                         }
1.128     raeburn  10198:                         $resulttext .= '</ul></li>';
1.112     raeburn  10199:                     }
1.168     raeburn  10200:                 } elsif ($item eq 'helpurl') {
                   10201:                     if (ref($changes{$item}) eq 'HASH') {
                   10202:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   10203:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   10204:                                 my ($chg,$link);
                   10205:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   10206:                                 if ($lang eq 'nolang') {
                   10207:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   10208:                                 } else {
                   10209:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   10210:                                 }
                   10211:                                 $resulttext .= '<li>'.$chg.'</li>';
                   10212:                             } else {
                   10213:                                 my $chg;
                   10214:                                 if ($lang eq 'nolang') {
                   10215:                                     $chg = &mt('custom log-in help file for no preferred language');
                   10216:                                 } else {
                   10217:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   10218:                                 }
                   10219:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   10220:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   10221:                                                       '?inhibitmenu=yes',$chg,600,500).
                   10222:                                                '</li>';
                   10223:                             }
                   10224:                         }
                   10225:                     }
1.256     raeburn  10226:                 } elsif ($item eq 'headtag') {
                   10227:                     if (ref($changes{$item}) eq 'HASH') {
                   10228:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   10229:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10230:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   10231:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10232:                                 $resulttext .= '<li><a href="'.
                   10233:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   10234:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   10235:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   10236:                                 if ($possexempt{$lonhost}) {
                   10237:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   10238:                                 } else {
                   10239:                                     $resulttext .= &mt('included for any client IP');
                   10240:                                 }
                   10241:                                 $resulttext .= '</li>';
                   10242:                             }
                   10243:                         }
                   10244:                     }
1.169     raeburn  10245:                 } elsif ($item eq 'captcha') {
                   10246:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  10247:                         my $chgtxt;
1.169     raeburn  10248:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   10249:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   10250:                         } else {
                   10251:                             my %captchas = &captcha_phrases();
                   10252:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   10253:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   10254:                             } else {
                   10255:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   10256:                             }
                   10257:                         }
                   10258:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10259:                     }
                   10260:                 } elsif ($item eq 'recaptchakeys') {
                   10261:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10262:                         my ($privkey,$pubkey);
                   10263:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   10264:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   10265:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   10266:                         }
                   10267:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10268:                         if (!$pubkey) {
                   10269:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   10270:                         } else {
                   10271:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10272:                         }
                   10273:                         if (!$privkey) {
                   10274:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   10275:                         } else {
1.251     raeburn  10276:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  10277:                         }
                   10278:                         $chgtxt .= '</ul>';
                   10279:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10280:                     }
1.269     raeburn  10281:                 } elsif ($item eq 'recaptchaversion') {
                   10282:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10283:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  10284:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  10285:                                            '</li>';
                   10286:                         }
                   10287:                     }
1.41      raeburn  10288:                 } else {
                   10289:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   10290:                 }
1.1       raeburn  10291:             }
1.6       raeburn  10292:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  10293:         } else {
                   10294:             $resulttext = &mt('No changes made to log-in page settings');
                   10295:         }
                   10296:     } else {
1.11      albertel 10297:         $resulttext = '<span class="LC_error">'.
                   10298: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10299:     }
1.6       raeburn  10300:     if ($errors) {
1.9       raeburn  10301:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  10302:                        $errors.'</ul>';
                   10303:     }
                   10304:     return $resulttext;
                   10305: }
                   10306: 
1.256     raeburn  10307: sub check_exempt_addresses {
                   10308:     my ($iplist) = @_;
                   10309:     $iplist =~ s/^\s+//;
                   10310:     $iplist =~ s/\s+$//;
                   10311:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   10312:     my (@okips,$new);
                   10313:     foreach my $ip (@poss_ips) {
                   10314:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   10315:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   10316:                 push(@okips,$ip);
                   10317:             }
                   10318:         }
                   10319:     }
                   10320:     if (@okips > 0) {
                   10321:         $new = join(',',@okips);
                   10322:     } else {
                   10323:         $new = '';
                   10324:     }
                   10325:     return $new;
                   10326: }
                   10327: 
1.6       raeburn  10328: sub color_font_choices {
                   10329:     my %choices =
                   10330:         &Apache::lonlocal::texthash (
                   10331:             img => "Header",
                   10332:             bgs => "Background colors",
                   10333:             links => "Link colors",
1.55      raeburn  10334:             images => "Images",
1.6       raeburn  10335:             font => "Font color",
1.201     raeburn  10336:             fontmenu => "Font menu",
1.76      raeburn  10337:             pgbg => "Page",
1.6       raeburn  10338:             tabbg => "Header",
                   10339:             sidebg => "Border",
                   10340:             link => "Link",
                   10341:             alink => "Active link",
                   10342:             vlink => "Visited link",
                   10343:         );
                   10344:     return %choices;
                   10345: }
                   10346: 
                   10347: sub modify_rolecolors {
1.205     raeburn  10348:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  10349:     my ($resulttext,%rolehash);
                   10350:     $rolehash{'rolecolors'} = {};
1.55      raeburn  10351:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   10352:         if ($domconfig{'rolecolors'} eq '') {
                   10353:             $domconfig{'rolecolors'} = {};
                   10354:         }
                   10355:     }
1.9       raeburn  10356:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  10357:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   10358:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   10359:                                              $dom);
                   10360:     if ($putresult eq 'ok') {
                   10361:         if (keys(%changes) > 0) {
1.41      raeburn  10362:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10363:             if (ref($lastactref) eq 'HASH') {
                   10364:                 $lastactref->{'domainconfig'} = 1;
                   10365:             }
1.6       raeburn  10366:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   10367:                                              $rolehash{'rolecolors'});
                   10368:         } else {
                   10369:             $resulttext = &mt('No changes made to default color schemes');
                   10370:         }
                   10371:     } else {
1.11      albertel 10372:         $resulttext = '<span class="LC_error">'.
                   10373: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  10374:     }
                   10375:     if ($errors) {
                   10376:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10377:                        $errors.'</ul>';
                   10378:     }
                   10379:     return $resulttext;
                   10380: }
                   10381: 
                   10382: sub modify_colors {
1.9       raeburn  10383:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  10384:     my (%changes,%choices);
1.51      raeburn  10385:     my @bgs;
1.6       raeburn  10386:     my @links = ('link','alink','vlink');
1.41      raeburn  10387:     my @logintext;
1.6       raeburn  10388:     my @images;
                   10389:     my $servadm = $r->dir_config('lonAdmEMail');
                   10390:     my $errors;
1.200     raeburn  10391:     my %defaults;
1.6       raeburn  10392:     foreach my $role (@{$roles}) {
                   10393:         if ($role eq 'login') {
1.12      raeburn  10394:             %choices = &login_choices();
1.41      raeburn  10395:             @logintext = ('textcol','bgcol');
1.12      raeburn  10396:         } else {
                   10397:             %choices = &color_font_choices();
                   10398:         }
                   10399:         if ($role eq 'login') {
1.41      raeburn  10400:             @images = ('img','logo','domlogo','login');
1.51      raeburn  10401:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  10402:         } else {
                   10403:             @images = ('img');
1.200     raeburn  10404:             @bgs = ('pgbg','tabbg','sidebg');
                   10405:         }
                   10406:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   10407:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   10408:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   10409:         }
                   10410:         if ($role eq 'login') {
                   10411:             foreach my $item (@logintext) {
1.234     raeburn  10412:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10413:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10414:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10415:                 }
                   10416:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  10417:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10418:                 }
                   10419:             }
                   10420:         } else {
1.234     raeburn  10421:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   10422:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   10423:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   10424:             }
                   10425:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  10426:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   10427:             }
1.6       raeburn  10428:         }
1.200     raeburn  10429:         foreach my $item (@bgs) {
1.234     raeburn  10430:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10431:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10432:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10433:             }
                   10434:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  10435:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10436:             }
                   10437:         }
                   10438:         foreach my $item (@links) {
1.234     raeburn  10439:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10440:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10441:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10442:             }
                   10443:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  10444:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10445:             }
1.6       raeburn  10446:         }
1.46      raeburn  10447:         my ($configuserok,$author_ok,$switchserver) = 
                   10448:             &config_check($dom,$confname,$servadm);
1.9       raeburn  10449:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  10450:         if (ref($domconfig->{$role}) ne 'HASH') {
                   10451:             $domconfig->{$role} = {};
                   10452:         }
1.8       raeburn  10453:         foreach my $img (@images) {
1.70      raeburn  10454:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   10455:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   10456:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   10457:                 } else { 
                   10458:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   10459:                 }
                   10460:             } 
1.18      albertel 10461: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   10462: 		 && !defined($domconfig->{$role}{$img})
                   10463: 		 && !$env{'form.'.$role.'_del_'.$img}
                   10464: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   10465: 		# import the old configured image from the .tab setting
                   10466: 		# if they haven't provided a new one 
                   10467: 		$domconfig->{$role}{$img} = 
                   10468: 		    $env{'form.'.$role.'_import_'.$img};
                   10469: 	    }
1.6       raeburn  10470:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  10471:                 my $error;
1.6       raeburn  10472:                 if ($configuserok eq 'ok') {
1.9       raeburn  10473:                     if ($switchserver) {
1.12      raeburn  10474:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  10475:                     } else {
                   10476:                         if ($author_ok eq 'ok') {
                   10477:                             my ($result,$logourl) = 
                   10478:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   10479:                                            $dom,$confname,$img,$width,$height);
                   10480:                             if ($result eq 'ok') {
                   10481:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  10482:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  10483:                             } else {
1.12      raeburn  10484:                                 $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  10485:                             }
                   10486:                         } else {
1.46      raeburn  10487:                             $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  10488:                         }
                   10489:                     }
                   10490:                 } else {
1.46      raeburn  10491:                     $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  10492:                 }
                   10493:                 if ($error) {
1.8       raeburn  10494:                     &Apache::lonnet::logthis($error);
1.11      albertel 10495:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  10496:                 }
                   10497:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  10498:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   10499:                     my $error;
                   10500:                     if ($configuserok eq 'ok') {
                   10501: # is confname an author?
                   10502:                         if ($switchserver eq '') {
                   10503:                             if ($author_ok eq 'ok') {
                   10504:                                 my ($result,$logourl) = 
                   10505:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   10506:                                             $dom,$confname,$img,$width,$height);
                   10507:                                 if ($result eq 'ok') {
                   10508:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 10509: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  10510:                                 }
                   10511:                             }
                   10512:                         }
                   10513:                     }
1.6       raeburn  10514:                 }
                   10515:             }
                   10516:         }
                   10517:         if (ref($domconfig) eq 'HASH') {
                   10518:             if (ref($domconfig->{$role}) eq 'HASH') {
                   10519:                 foreach my $img (@images) {
                   10520:                     if ($domconfig->{$role}{$img} ne '') {
                   10521:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   10522:                             $confhash->{$role}{$img} = '';
1.12      raeburn  10523:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  10524:                         } else {
1.9       raeburn  10525:                             if ($confhash->{$role}{$img} eq '') {
                   10526:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   10527:                             }
1.6       raeburn  10528:                         }
                   10529:                     } else {
                   10530:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   10531:                             $confhash->{$role}{$img} = '';
1.12      raeburn  10532:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  10533:                         } 
                   10534:                     }
1.70      raeburn  10535:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   10536:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   10537:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   10538:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   10539:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   10540:                             }
                   10541:                         } else {
                   10542:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   10543:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   10544:                             }
                   10545:                         }
                   10546:                     }
                   10547:                 }
1.6       raeburn  10548:                 if ($domconfig->{$role}{'font'} ne '') {
                   10549:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   10550:                         $changes{$role}{'font'} = 1;
                   10551:                     }
                   10552:                 } else {
                   10553:                     if ($confhash->{$role}{'font'}) {
                   10554:                         $changes{$role}{'font'} = 1;
                   10555:                     }
                   10556:                 }
1.107     raeburn  10557:                 if ($role ne 'login') {
                   10558:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   10559:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   10560:                             $changes{$role}{'fontmenu'} = 1;
                   10561:                         }
                   10562:                     } else {
                   10563:                         if ($confhash->{$role}{'fontmenu'}) {
                   10564:                             $changes{$role}{'fontmenu'} = 1;
                   10565:                         }
1.97      tempelho 10566:                     }
                   10567:                 }
1.6       raeburn  10568:                 foreach my $item (@bgs) {
                   10569:                     if ($domconfig->{$role}{$item} ne '') {
                   10570:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10571:                             $changes{$role}{'bgs'}{$item} = 1;
                   10572:                         } 
                   10573:                     } else {
                   10574:                         if ($confhash->{$role}{$item}) {
                   10575:                             $changes{$role}{'bgs'}{$item} = 1;
                   10576:                         }
                   10577:                     }
                   10578:                 }
                   10579:                 foreach my $item (@links) {
                   10580:                     if ($domconfig->{$role}{$item} ne '') {
                   10581:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10582:                             $changes{$role}{'links'}{$item} = 1;
                   10583:                         }
                   10584:                     } else {
                   10585:                         if ($confhash->{$role}{$item}) {
                   10586:                             $changes{$role}{'links'}{$item} = 1;
                   10587:                         }
                   10588:                     }
                   10589:                 }
1.41      raeburn  10590:                 foreach my $item (@logintext) {
                   10591:                     if ($domconfig->{$role}{$item} ne '') {
                   10592:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10593:                             $changes{$role}{'logintext'}{$item} = 1;
                   10594:                         }
                   10595:                     } else {
                   10596:                         if ($confhash->{$role}{$item}) {
                   10597:                             $changes{$role}{'logintext'}{$item} = 1;
                   10598:                         }
                   10599:                     }
                   10600:                 }
1.6       raeburn  10601:             } else {
                   10602:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  10603:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  10604:             }
                   10605:         } else {
                   10606:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  10607:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  10608:         }
                   10609:     }
                   10610:     return ($errors,%changes);
                   10611: }
                   10612: 
1.46      raeburn  10613: sub config_check {
                   10614:     my ($dom,$confname,$servadm) = @_;
                   10615:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   10616:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   10617:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   10618:                                                    $confname,$servadm);
                   10619:     if ($configuserok eq 'ok') {
                   10620:         $switchserver = &check_switchserver($dom,$confname);
                   10621:         if ($switchserver eq '') {
                   10622:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   10623:         }
                   10624:     }
                   10625:     return ($configuserok,$author_ok,$switchserver);
                   10626: }
                   10627: 
1.6       raeburn  10628: sub default_change_checker {
1.41      raeburn  10629:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  10630:     foreach my $item (@{$links}) {
                   10631:         if ($confhash->{$role}{$item}) {
                   10632:             $changes->{$role}{'links'}{$item} = 1;
                   10633:         }
                   10634:     }
                   10635:     foreach my $item (@{$bgs}) {
                   10636:         if ($confhash->{$role}{$item}) {
                   10637:             $changes->{$role}{'bgs'}{$item} = 1;
                   10638:         }
                   10639:     }
1.41      raeburn  10640:     foreach my $item (@{$logintext}) {
                   10641:         if ($confhash->{$role}{$item}) {
                   10642:             $changes->{$role}{'logintext'}{$item} = 1;
                   10643:         }
                   10644:     }
1.6       raeburn  10645:     foreach my $img (@{$images}) {
                   10646:         if ($env{'form.'.$role.'_del_'.$img}) {
                   10647:             $confhash->{$role}{$img} = '';
1.12      raeburn  10648:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  10649:         }
1.70      raeburn  10650:         if ($role eq 'login') {
                   10651:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   10652:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   10653:             }
                   10654:         }
1.6       raeburn  10655:     }
                   10656:     if ($confhash->{$role}{'font'}) {
                   10657:         $changes->{$role}{'font'} = 1;
                   10658:     }
1.48      raeburn  10659: }
1.6       raeburn  10660: 
                   10661: sub display_colorchgs {
                   10662:     my ($dom,$changes,$roles,$confhash) = @_;
                   10663:     my (%choices,$resulttext);
                   10664:     if (!grep(/^login$/,@{$roles})) {
                   10665:         $resulttext = &mt('Changes made:').'<br />';
                   10666:     }
                   10667:     foreach my $role (@{$roles}) {
                   10668:         if ($role eq 'login') {
                   10669:             %choices = &login_choices();
                   10670:         } else {
                   10671:             %choices = &color_font_choices();
                   10672:         }
                   10673:         if (ref($changes->{$role}) eq 'HASH') {
                   10674:             if ($role ne 'login') {
                   10675:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   10676:             }
                   10677:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   10678:                 if ($role ne 'login') {
                   10679:                     $resulttext .= '<ul>';
                   10680:                 }
                   10681:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   10682:                     if ($role ne 'login') {
                   10683:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   10684:                     }
                   10685:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  10686:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   10687:                             if ($confhash->{$role}{$key}{$item}) {
                   10688:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   10689:                             } else {
                   10690:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   10691:                             }
                   10692:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  10693:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   10694:                         } else {
1.12      raeburn  10695:                             my $newitem = $confhash->{$role}{$item};
                   10696:                             if ($key eq 'images') {
1.306     raeburn  10697:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  10698:                             }
                   10699:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  10700:                         }
                   10701:                     }
                   10702:                     if ($role ne 'login') {
                   10703:                         $resulttext .= '</ul></li>';
                   10704:                     }
                   10705:                 } else {
                   10706:                     if ($confhash->{$role}{$key} eq '') {
                   10707:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   10708:                     } else {
                   10709:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   10710:                     }
                   10711:                 }
                   10712:                 if ($role ne 'login') {
                   10713:                     $resulttext .= '</ul>';
                   10714:                 }
                   10715:             }
                   10716:         }
                   10717:     }
1.3       raeburn  10718:     return $resulttext;
1.1       raeburn  10719: }
                   10720: 
1.9       raeburn  10721: sub thumb_dimensions {
                   10722:     return ('200','50');
                   10723: }
                   10724: 
1.16      raeburn  10725: sub check_dimensions {
                   10726:     my ($inputfile) = @_;
                   10727:     my ($fullwidth,$fullheight);
                   10728:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   10729:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   10730:             my $imageinfo = <PIPE>;
                   10731:             if (!close(PIPE)) {
                   10732:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   10733:             }
                   10734:             chomp($imageinfo);
                   10735:             my ($fullsize) = 
1.21      raeburn  10736:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  10737:             if ($fullsize) {
                   10738:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   10739:             }
                   10740:         }
                   10741:     }
                   10742:     return ($fullwidth,$fullheight);
                   10743: }
                   10744: 
1.9       raeburn  10745: sub check_configuser {
                   10746:     my ($uhome,$dom,$confname,$servadm) = @_;
                   10747:     my ($configuserok,%currroles);
                   10748:     if ($uhome eq 'no_host') {
                   10749:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   10750:         my $configpass = &LONCAPA::Enrollment::create_password();
                   10751:         $configuserok = 
                   10752:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   10753:                              $configpass,'','','','','',undef,$servadm);
                   10754:     } else {
                   10755:         $configuserok = 'ok';
                   10756:         %currroles = 
                   10757:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   10758:     }
                   10759:     return ($configuserok,%currroles);
                   10760: }
                   10761: 
                   10762: sub check_authorstatus {
                   10763:     my ($dom,$confname,%currroles) = @_;
                   10764:     my $author_ok;
1.40      raeburn  10765:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  10766:         my $start = time;
                   10767:         my $end = 0;
                   10768:         $author_ok = 
                   10769:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  10770:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  10771:     } else {
                   10772:         $author_ok = 'ok';
                   10773:     }
                   10774:     return $author_ok;
                   10775: }
                   10776: 
                   10777: sub publishlogo {
1.46      raeburn  10778:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  10779:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  10780:     if ($action eq 'upload') {
                   10781:         $fname=$env{'form.'.$formname.'.filename'};
                   10782:         chop($env{'form.'.$formname});
                   10783:     } else {
                   10784:         ($fname) = ($formname =~ /([^\/]+)$/);
                   10785:     }
1.46      raeburn  10786:     if ($savefileas ne '') {
                   10787:         $fname = $savefileas;
                   10788:     }
1.9       raeburn  10789:     $fname=&Apache::lonnet::clean_filename($fname);
                   10790: # See if there is anything left
                   10791:     unless ($fname) { return ('error: no uploaded file'); }
                   10792:     $fname="$subdir/$fname";
1.210     raeburn  10793:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  10794:     my $filepath="$docroot/priv";
                   10795:     my $relpath = "$dom/$confname";
1.9       raeburn  10796:     my ($fnamepath,$file,$fetchthumb);
                   10797:     $file=$fname;
                   10798:     if ($fname=~m|/|) {
                   10799:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   10800:     }
1.164     raeburn  10801:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  10802:     my $count;
1.164     raeburn  10803:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  10804:         $filepath.="/$parts[$count]";
                   10805:         if ((-e $filepath)!=1) {
                   10806:             mkdir($filepath,02770);
                   10807:         }
                   10808:     }
                   10809:     # Check for bad extension and disallow upload
                   10810:     if ($file=~/\.(\w+)$/ &&
                   10811:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   10812:         $output = 
1.207     bisitz   10813:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  10814:     } elsif ($file=~/\.(\w+)$/ &&
                   10815:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   10816:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   10817:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   10818:         $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  10819:     } elsif (-d "$filepath/$file") {
1.195     bisitz   10820:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  10821:     } else {
                   10822:         my $source = $filepath.'/'.$file;
                   10823:         my $logfile;
1.316     raeburn  10824:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  10825:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  10826:         }
                   10827:         print $logfile
                   10828: "\n================= Publish ".localtime()." ================\n".
                   10829: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   10830: # Save the file
1.316     raeburn  10831:         if (!open(FH,">",$source)) {
1.9       raeburn  10832:             &Apache::lonnet::logthis('Failed to create '.$source);
                   10833:             return (&mt('Failed to create file'));
                   10834:         }
                   10835:         if ($action eq 'upload') {
                   10836:             if (!print FH ($env{'form.'.$formname})) {
                   10837:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   10838:                 return (&mt('Failed to write file'));
                   10839:             }
                   10840:         } else {
                   10841:             my $original = &Apache::lonnet::filelocation('',$formname);
                   10842:             if(!copy($original,$source)) {
                   10843:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   10844:                 return (&mt('Failed to write file'));
                   10845:             }
                   10846:         }
                   10847:         close(FH);
                   10848:         chmod(0660, $source); # Permissions to rw-rw---.
                   10849: 
                   10850:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   10851:         my $copyfile=$targetdir.'/'.$file;
                   10852: 
                   10853:         my @parts=split(/\//,$targetdir);
                   10854:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   10855:         for (my $count=5;$count<=$#parts;$count++) {
                   10856:             $path.="/$parts[$count]";
                   10857:             if (!-e $path) {
                   10858:                 print $logfile "\nCreating directory ".$path;
                   10859:                 mkdir($path,02770);
                   10860:             }
                   10861:         }
                   10862:         my $versionresult;
                   10863:         if (-e $copyfile) {
                   10864:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   10865:         } else {
                   10866:             $versionresult = 'ok';
                   10867:         }
                   10868:         if ($versionresult eq 'ok') {
                   10869:             if (copy($source,$copyfile)) {
                   10870:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   10871:                 $output = 'ok';
                   10872:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  10873:                 push(@{$modified_urls},[$copyfile,$source]);
                   10874:                 my $metaoutput = 
                   10875:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   10876:                 unless ($registered_cleanup) {
                   10877:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   10878:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   10879:                     $registered_cleanup=1;
                   10880:                 }
1.9       raeburn  10881:             } else {
                   10882:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   10883:                 $output = &mt('Failed to copy file to RES space').", $!";
                   10884:             }
                   10885:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   10886:                 my $inputfile = $filepath.'/'.$file;
                   10887:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  10888:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   10889:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   10890:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   10891:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  10892:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   10893:                         system({$args[0]} @args);
1.16      raeburn  10894:                         chmod(0660, $filepath.'/tn-'.$file);
                   10895:                         if (-e $outfile) {
                   10896:                             my $copyfile=$targetdir.'/tn-'.$file;
                   10897:                             if (copy($outfile,$copyfile)) {
                   10898:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  10899:                                 my $thumb_metaoutput = 
                   10900:                                     &write_metadata($dom,$confname,$formname,
                   10901:                                                     $targetdir,'tn-'.$file,$logfile);
                   10902:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   10903:                                 unless ($registered_cleanup) {
                   10904:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   10905:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   10906:                                     $registered_cleanup=1;
                   10907:                                 }
1.267     raeburn  10908:                                 $madethumb = 1;
1.16      raeburn  10909:                             } else {
                   10910:                                 print $logfile "\nUnable to write ".$copyfile.
                   10911:                                                ':'.$!."\n";
                   10912:                             }
                   10913:                         }
1.9       raeburn  10914:                     }
                   10915:                 }
                   10916:             }
                   10917:         } else {
                   10918:             $output = $versionresult;
                   10919:         }
                   10920:     }
1.267     raeburn  10921:     return ($output,$logourl,$madethumb);
1.9       raeburn  10922: }
                   10923: 
                   10924: sub logo_versioning {
                   10925:     my ($targetdir,$file,$logfile) = @_;
                   10926:     my $target = $targetdir.'/'.$file;
                   10927:     my ($maxversion,$fn,$extn,$output);
                   10928:     $maxversion = 0;
                   10929:     if ($file =~ /^(.+)\.(\w+)$/) {
                   10930:         $fn=$1;
                   10931:         $extn=$2;
                   10932:     }
                   10933:     opendir(DIR,$targetdir);
                   10934:     while (my $filename=readdir(DIR)) {
                   10935:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   10936:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   10937:         }
                   10938:     }
                   10939:     $maxversion++;
                   10940:     print $logfile "\nCreating old version ".$maxversion."\n";
                   10941:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   10942:     if (copy($target,$copyfile)) {
                   10943:         print $logfile "Copied old target to ".$copyfile."\n";
                   10944:         $copyfile=$copyfile.'.meta';
                   10945:         if (copy($target.'.meta',$copyfile)) {
                   10946:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   10947:             $output = 'ok';
                   10948:         } else {
                   10949:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   10950:             $output = &mt('Failed to copy old meta').", $!, ";
                   10951:         }
                   10952:     } else {
                   10953:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   10954:         $output = &mt('Failed to copy old target').", $!, ";
                   10955:     }
                   10956:     return $output;
                   10957: }
                   10958: 
                   10959: sub write_metadata {
                   10960:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   10961:     my (%metadatafields,%metadatakeys,$output);
                   10962:     $metadatafields{'title'}=$formname;
                   10963:     $metadatafields{'creationdate'}=time;
                   10964:     $metadatafields{'lastrevisiondate'}=time;
                   10965:     $metadatafields{'copyright'}='public';
                   10966:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   10967:                                          $env{'user.domain'};
                   10968:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   10969:     $metadatafields{'domain'}=$dom;
                   10970:     {
                   10971:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   10972:         my $mfh;
1.316     raeburn  10973:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  10974:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  10975:                 unless ($_=~/\./) {
                   10976:                     my $unikey=$_;
                   10977:                     $unikey=~/^([A-Za-z]+)/;
                   10978:                     my $tag=$1;
                   10979:                     $tag=~tr/A-Z/a-z/;
                   10980:                     print $mfh "\n\<$tag";
                   10981:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   10982:                         my $value=$metadatafields{$unikey.'.'.$_};
                   10983:                         $value=~s/\"/\'\'/g;
                   10984:                         print $mfh ' '.$_.'="'.$value.'"';
                   10985:                     }
                   10986:                     print $mfh '>'.
                   10987:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   10988:                             .'</'.$tag.'>';
                   10989:                 }
                   10990:             }
                   10991:             $output = 'ok';
                   10992:             print $logfile "\nWrote metadata";
                   10993:             close($mfh);
                   10994:         } else {
                   10995:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  10996:             $output = &mt('Could not write metadata');
                   10997:         }
                   10998:     }
1.155     raeburn  10999:     return $output;
                   11000: }
                   11001: 
                   11002: sub notifysubscribed {
                   11003:     foreach my $targetsource (@{$modified_urls}){
                   11004:         next unless (ref($targetsource) eq 'ARRAY');
                   11005:         my ($target,$source)=@{$targetsource};
                   11006:         if ($source ne '') {
1.316     raeburn  11007:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  11008:                 print $logfh "\nCleanup phase: Notifications\n";
                   11009:                 my @subscribed=&subscribed_hosts($target);
                   11010:                 foreach my $subhost (@subscribed) {
                   11011:                     print $logfh "\nNotifying host ".$subhost.':';
                   11012:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   11013:                     print $logfh $reply;
                   11014:                 }
                   11015:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   11016:                 foreach my $subhost (@subscribedmeta) {
                   11017:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   11018:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   11019:                                                         $subhost);
                   11020:                     print $logfh $reply;
                   11021:                 }
                   11022:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  11023:                 close($logfh);
1.155     raeburn  11024:             }
                   11025:         }
                   11026:     }
                   11027:     return OK;
                   11028: }
                   11029: 
                   11030: sub subscribed_hosts {
                   11031:     my ($target) = @_;
                   11032:     my @subscribed;
1.316     raeburn  11033:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  11034:         while (my $subline=<$fh>) {
                   11035:             if ($subline =~ /^($match_lonid):/) {
                   11036:                 my $host = $1;
                   11037:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   11038:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   11039:                         push(@subscribed,$host);
                   11040:                     }
                   11041:                 }
                   11042:             }
                   11043:         }
                   11044:     }
                   11045:     return @subscribed;
1.9       raeburn  11046: }
                   11047: 
                   11048: sub check_switchserver {
                   11049:     my ($dom,$confname) = @_;
                   11050:     my ($allowed,$switchserver);
                   11051:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   11052:     if ($home eq 'no_host') {
                   11053:         $home = &Apache::lonnet::domain($dom,'primary');
                   11054:     }
                   11055:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 11056:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   11057:     if (!$allowed) {
1.180     raeburn  11058: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  11059:     }
                   11060:     return $switchserver;
                   11061: }
                   11062: 
1.1       raeburn  11063: sub modify_quotas {
1.216     raeburn  11064:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  11065:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  11066:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  11067:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   11068:         $validationfieldsref);
1.86      raeburn  11069:     if ($action eq 'quotas') {
                   11070:         $context = 'tools'; 
1.163     raeburn  11071:     } else {
1.86      raeburn  11072:         $context = $action;
                   11073:     }
                   11074:     if ($context eq 'requestcourses') {
1.325     raeburn  11075:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  11076:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  11077:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   11078:         %titles = &courserequest_titles();
                   11079:         $toolregexp = join('|',@usertools);
                   11080:         %conditions = &courserequest_conditions();
1.216     raeburn  11081:         $confname = $dom.'-domainconfig';
                   11082:         my $servadm = $r->dir_config('lonAdmEMail');
                   11083:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  11084:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   11085:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  11086:     } elsif ($context eq 'requestauthor') {
                   11087:         @usertools = ('author');
                   11088:         %titles = &authorrequest_titles();
1.86      raeburn  11089:     } else {
1.162     raeburn  11090:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  11091:         %titles = &tool_titles();
1.86      raeburn  11092:     }
1.212     raeburn  11093:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  11094:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  11095:     foreach my $key (keys(%env)) {
1.101     raeburn  11096:         if ($context eq 'requestcourses') {
                   11097:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   11098:                 my $item = $1;
                   11099:                 my $type = $2;
                   11100:                 if ($type =~ /^limit_(.+)/) {
                   11101:                     $limithash{$item}{$1} = $env{$key};
                   11102:                 } else {
                   11103:                     $confhash{$item}{$type} = $env{$key};
                   11104:                 }
                   11105:             }
1.163     raeburn  11106:         } elsif ($context eq 'requestauthor') {
                   11107:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   11108:                 $confhash{$1} = $env{$key};
                   11109:             }
1.101     raeburn  11110:         } else {
1.86      raeburn  11111:             if ($key =~ /^form\.quota_(.+)$/) {
                   11112:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  11113:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   11114:                 $confhash{'authorquota'}{$1} = $env{$key};
                   11115:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  11116:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   11117:             }
1.72      raeburn  11118:         }
                   11119:     }
1.163     raeburn  11120:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  11121:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  11122:         @approvalnotify = sort(@approvalnotify);
                   11123:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  11124:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  11125:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   11126:         foreach my $type (@hasuniquecode) {
                   11127:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   11128:                 $confhash{'uniquecode'}{$type} = 1;
                   11129:             }
1.216     raeburn  11130:         }
1.242     raeburn  11131:         my (%newbook,%allpos);
1.216     raeburn  11132:         if ($context eq 'requestcourses') {
1.242     raeburn  11133:             foreach my $type ('textbooks','templates') {
                   11134:                 @{$allpos{$type}} = (); 
                   11135:                 my $invalid;
                   11136:                 if ($type eq 'textbooks') {
                   11137:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   11138:                 } else {
                   11139:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   11140:                 }
                   11141:                 if ($env{'form.'.$type.'_addbook'}) {
                   11142:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   11143:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   11144:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   11145:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   11146:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   11147:                         } else {
                   11148:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   11149:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   11150:                             $position =~ s/\D+//g;
                   11151:                             if ($position ne '') {
                   11152:                                 $allpos{$type}[$position] = $newbook{$type};
                   11153:                             }
1.216     raeburn  11154:                         }
1.242     raeburn  11155:                     } else {
                   11156:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  11157:                     }
                   11158:                 }
1.242     raeburn  11159:             } 
1.216     raeburn  11160:         }
1.102     raeburn  11161:         if (ref($domconfig{$action}) eq 'HASH') {
                   11162:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   11163:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   11164:                     $changes{'notify'}{'approval'} = 1;
                   11165:                 }
                   11166:             } else {
1.144     raeburn  11167:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11168:                     $changes{'notify'}{'approval'} = 1;
                   11169:                 }
                   11170:             }
1.218     raeburn  11171:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   11172:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11173:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   11174:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   11175:                             $changes{'uniquecode'} = 1;
                   11176:                         }
                   11177:                     }
                   11178:                     unless ($changes{'uniquecode'}) {
                   11179:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   11180:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   11181:                                 $changes{'uniquecode'} = 1;
                   11182:                             }
                   11183:                         }
                   11184:                     }
                   11185:                } else {
                   11186:                    $changes{'uniquecode'} = 1;
                   11187:                }
                   11188:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11189:                 $changes{'uniquecode'} = 1;
1.216     raeburn  11190:             }
                   11191:             if ($context eq 'requestcourses') {
1.242     raeburn  11192:                 foreach my $type ('textbooks','templates') {
                   11193:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11194:                         my %deletions;
                   11195:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   11196:                         if (@todelete) {
                   11197:                             map { $deletions{$_} = 1; } @todelete;
                   11198:                         }
                   11199:                         my %imgdeletions;
                   11200:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   11201:                         if (@todeleteimages) {
                   11202:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   11203:                         }
                   11204:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   11205:                         for (my $i=0; $i<=$maxnum; $i++) {
                   11206:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   11207:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   11208:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   11209:                                 if ($deletions{$key}) {
                   11210:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   11211:                                         #FIXME need to obsolete item in RES space
                   11212:                                     }
                   11213:                                     next;
                   11214:                                 } else {
                   11215:                                     my $newpos = $env{'form.'.$itemid};
                   11216:                                     $newpos =~ s/\D+//g;
1.243     raeburn  11217:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  11218:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  11219:                                                  ($type eq 'templates'));
1.242     raeburn  11220:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   11221:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   11222:                                             $changes{$type}{$key} = 1;
                   11223:                                         }
                   11224:                                     }
                   11225:                                     $allpos{$type}[$newpos] = $key;
                   11226:                                 }
                   11227:                                 if ($imgdeletions{$key}) {
                   11228:                                     $changes{$type}{$key} = 1;
1.216     raeburn  11229:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  11230:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   11231:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  11232:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11233:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11234:                                     } else {
                   11235:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   11236:                                                                                       $cdom,$cnum,$type,$configuserok,
                   11237:                                                                                       $switchserver,$author_ok);
                   11238:                                         if ($imgurl) {
                   11239:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   11240:                                             $changes{$type}{$key} = 1; 
                   11241:                                         }
                   11242:                                         if ($error) {
                   11243:                                             &Apache::lonnet::logthis($error);
                   11244:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11245:                                         }
                   11246:                                     }
1.242     raeburn  11247:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   11248:                                     $confhash{$type}{$key}{'image'} = 
                   11249:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  11250:                                 }
                   11251:                             }
                   11252:                         }
                   11253:                     }
                   11254:                 }
                   11255:             }
1.102     raeburn  11256:         } else {
1.144     raeburn  11257:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11258:                 $changes{'notify'}{'approval'} = 1;
                   11259:             }
1.218     raeburn  11260:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  11261:                 $changes{'uniquecode'} = 1;
                   11262:             }
                   11263:         }
                   11264:         if ($context eq 'requestcourses') {
1.242     raeburn  11265:             foreach my $type ('textbooks','templates') {
                   11266:                 if ($newbook{$type}) {
                   11267:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  11268:                     foreach my $item ('subject','title','publisher','author') {
                   11269:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11270:                                  ($type eq 'template'));
1.242     raeburn  11271:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   11272:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   11273:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   11274:                         }
                   11275:                     }
                   11276:                     if ($type eq 'textbooks') {
                   11277:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   11278:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  11279:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11280:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11281:                             } else {
                   11282:                                 my ($imageurl,$error) =
                   11283:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   11284:                                                             $configuserok,$switchserver,$author_ok);
                   11285:                                 if ($imageurl) {
                   11286:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   11287:                                 }
                   11288:                                 if ($error) {
                   11289:                                     &Apache::lonnet::logthis($error);
                   11290:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11291:                                 }
1.242     raeburn  11292:                             }
                   11293:                         }
1.216     raeburn  11294:                     }
                   11295:                 }
1.242     raeburn  11296:                 if (@{$allpos{$type}} > 0) {
                   11297:                     my $idx = 0;
                   11298:                     foreach my $item (@{$allpos{$type}}) {
                   11299:                         if ($item ne '') {
                   11300:                             $confhash{$type}{$item}{'order'} = $idx;
                   11301:                             if (ref($domconfig{$action}) eq 'HASH') {
                   11302:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11303:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   11304:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   11305:                                             $changes{$type}{$item} = 1;
                   11306:                                         }
1.216     raeburn  11307:                                     }
                   11308:                                 }
                   11309:                             }
1.242     raeburn  11310:                             $idx ++;
1.216     raeburn  11311:                         }
                   11312:                     }
                   11313:                 }
                   11314:             }
1.235     raeburn  11315:             if (ref($validationitemsref) eq 'ARRAY') {
                   11316:                 foreach my $item (@{$validationitemsref}) {
                   11317:                     if ($item eq 'fields') {
                   11318:                         my @changed;
                   11319:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   11320:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   11321:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   11322:                         }
1.266     raeburn  11323:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11324:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11325:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   11326:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   11327:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   11328:                                 } else {
                   11329:                                     @changed = @{$confhash{'validation'}{$item}};
                   11330:                                 }
1.235     raeburn  11331:                             } else {
                   11332:                                 @changed = @{$confhash{'validation'}{$item}};
                   11333:                             }
                   11334:                         } else {
                   11335:                             @changed = @{$confhash{'validation'}{$item}};
                   11336:                         }
                   11337:                         if (@changed) {
                   11338:                             if ($confhash{'validation'}{$item}) {
                   11339:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   11340:                             } else {
                   11341:                                 $changes{'validation'}{$item} = &mt('None');
                   11342:                             }
                   11343:                         }
                   11344:                     } else {
                   11345:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   11346:                         if ($item eq 'markup') {
                   11347:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   11348:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   11349:                             }
                   11350:                         }
1.266     raeburn  11351:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11352:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11353:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   11354:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11355:                                 }
                   11356:                             } else {
                   11357:                                 if ($confhash{'validation'}{$item} ne '') {
                   11358:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11359:                                 }
1.235     raeburn  11360:                             }
                   11361:                         } else {
                   11362:                             if ($confhash{'validation'}{$item} ne '') {
                   11363:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11364:                             }
                   11365:                         }
                   11366:                     }
                   11367:                 }
                   11368:             }
                   11369:             if ($env{'form.validationdc'}) {
                   11370:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  11371:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  11372:                 if (exists($domcoords{$newval})) {
                   11373:                     $confhash{'validation'}{'dc'} = $newval;
                   11374:                 }
                   11375:             }
                   11376:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  11377:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11378:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11379:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11380:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11381:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   11382:                                     $changes{'validation'}{'dc'} = &mt('None');
                   11383:                                 } else {
                   11384:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   11385:                                 }
1.235     raeburn  11386:                             }
1.266     raeburn  11387:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11388:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  11389:                         }
                   11390:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11391:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   11392:                     }
                   11393:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11394:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  11395:                 }
1.266     raeburn  11396:             } else {
                   11397:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11398:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11399:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11400:                             $changes{'validation'}{'dc'} = &mt('None');
                   11401:                         }
                   11402:                     }
1.235     raeburn  11403:                 }
                   11404:             }
1.102     raeburn  11405:         }
                   11406:     } else {
1.86      raeburn  11407:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  11408:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  11409:     }
1.72      raeburn  11410:     foreach my $item (@usertools) {
                   11411:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  11412:             my $unset; 
1.101     raeburn  11413:             if ($context eq 'requestcourses') {
1.104     raeburn  11414:                 $unset = '0';
                   11415:                 if ($type eq '_LC_adv') {
                   11416:                     $unset = '';
                   11417:                 }
1.101     raeburn  11418:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   11419:                     $confhash{$item}{$type} .= '=';
                   11420:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   11421:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   11422:                     }
                   11423:                 }
1.163     raeburn  11424:             } elsif ($context eq 'requestauthor') {
                   11425:                 $unset = '0';
                   11426:                 if ($type eq '_LC_adv') {
                   11427:                     $unset = '';
                   11428:                 }
1.72      raeburn  11429:             } else {
1.101     raeburn  11430:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   11431:                     $confhash{$item}{$type} = 1;
                   11432:                 } else {
                   11433:                     $confhash{$item}{$type} = 0;
                   11434:                 }
1.72      raeburn  11435:             }
1.86      raeburn  11436:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  11437:                 if ($action eq 'requestauthor') {
                   11438:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   11439:                         $changes{$type} = 1;
                   11440:                     }
                   11441:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  11442:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   11443:                         $changes{$item}{$type} = 1;
                   11444:                     }
                   11445:                 } else {
                   11446:                     if ($context eq 'requestcourses') {
1.104     raeburn  11447:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  11448:                             $changes{$item}{$type} = 1;
                   11449:                         }
                   11450:                     } else {
                   11451:                         if (!$confhash{$item}{$type}) {
                   11452:                             $changes{$item}{$type} = 1;
                   11453:                         }
                   11454:                     }
                   11455:                 }
                   11456:             } else {
                   11457:                 if ($context eq 'requestcourses') {
1.104     raeburn  11458:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  11459:                         $changes{$item}{$type} = 1;
                   11460:                     }
1.163     raeburn  11461:                 } elsif ($context eq 'requestauthor') {
                   11462:                     if ($confhash{$type} ne $unset) {
                   11463:                         $changes{$type} = 1;
                   11464:                     }
1.72      raeburn  11465:                 } else {
                   11466:                     if (!$confhash{$item}{$type}) {
                   11467:                         $changes{$item}{$type} = 1;
                   11468:                     }
                   11469:                 }
                   11470:             }
1.1       raeburn  11471:         }
                   11472:     }
1.163     raeburn  11473:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  11474:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11475:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   11476:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   11477:                     if (exists($confhash{'defaultquota'}{$key})) {
                   11478:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   11479:                             $changes{'defaultquota'}{$key} = 1;
                   11480:                         }
                   11481:                     } else {
                   11482:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  11483:                     }
                   11484:                 }
1.86      raeburn  11485:             } else {
                   11486:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   11487:                     if (exists($confhash{'defaultquota'}{$key})) {
                   11488:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   11489:                             $changes{'defaultquota'}{$key} = 1;
                   11490:                         }
                   11491:                     } else {
                   11492:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  11493:                     }
1.1       raeburn  11494:                 }
                   11495:             }
1.197     raeburn  11496:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   11497:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   11498:                     if (exists($confhash{'authorquota'}{$key})) {
                   11499:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   11500:                             $changes{'authorquota'}{$key} = 1;
                   11501:                         }
                   11502:                     } else {
                   11503:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   11504:                     }
                   11505:                 }
                   11506:             }
1.1       raeburn  11507:         }
1.86      raeburn  11508:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   11509:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   11510:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11511:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   11512:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   11513:                             $changes{'defaultquota'}{$key} = 1;
                   11514:                         }
                   11515:                     } else {
                   11516:                         if (!exists($domconfig{'quotas'}{$key})) {
                   11517:                             $changes{'defaultquota'}{$key} = 1;
                   11518:                         }
1.72      raeburn  11519:                     }
                   11520:                 } else {
1.86      raeburn  11521:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  11522:                 }
1.1       raeburn  11523:             }
                   11524:         }
1.197     raeburn  11525:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   11526:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   11527:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11528:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   11529:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   11530:                             $changes{'authorquota'}{$key} = 1;
                   11531:                         }
                   11532:                     } else {
                   11533:                         $changes{'authorquota'}{$key} = 1;
                   11534:                     }
                   11535:                 } else {
                   11536:                     $changes{'authorquota'}{$key} = 1;
                   11537:                 }
                   11538:             }
                   11539:         }
1.1       raeburn  11540:     }
1.72      raeburn  11541: 
1.163     raeburn  11542:     if ($context eq 'requestauthor') {
                   11543:         $domdefaults{'requestauthor'} = \%confhash;
                   11544:     } else {
                   11545:         foreach my $key (keys(%confhash)) {
1.242     raeburn  11546:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  11547:                 $domdefaults{$key} = $confhash{$key};
                   11548:             }
1.163     raeburn  11549:         }
1.72      raeburn  11550:     }
1.163     raeburn  11551: 
1.1       raeburn  11552:     my %quotahash = (
1.86      raeburn  11553:                       $action => { %confhash }
1.1       raeburn  11554:                     );
                   11555:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   11556:                                              $dom);
                   11557:     if ($putresult eq 'ok') {
                   11558:         if (keys(%changes) > 0) {
1.72      raeburn  11559:             my $cachetime = 24*60*60;
                   11560:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  11561:             if (ref($lastactref) eq 'HASH') {
                   11562:                 $lastactref->{'domdefaults'} = 1;
                   11563:             }
1.1       raeburn  11564:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  11565:             unless (($context eq 'requestcourses') ||
1.163     raeburn  11566:                     ($context eq 'requestauthor')) {
1.86      raeburn  11567:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   11568:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   11569:                     foreach my $type (@{$types},'default') {
                   11570:                         if (defined($changes{'defaultquota'}{$type})) {
                   11571:                             my $typetitle = $usertypes->{$type};
                   11572:                             if ($type eq 'default') {
                   11573:                                 $typetitle = $othertitle;
                   11574:                             }
1.213     raeburn  11575:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  11576:                         }
                   11577:                     }
1.86      raeburn  11578:                     $resulttext .= '</ul></li>';
1.72      raeburn  11579:                 }
1.197     raeburn  11580:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   11581:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  11582:                     foreach my $type (@{$types},'default') {
                   11583:                         if (defined($changes{'authorquota'}{$type})) {
                   11584:                             my $typetitle = $usertypes->{$type};
                   11585:                             if ($type eq 'default') {
                   11586:                                 $typetitle = $othertitle;
                   11587:                             }
1.213     raeburn  11588:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  11589:                         }
                   11590:                     }
                   11591:                     $resulttext .= '</ul></li>';
                   11592:                 }
1.72      raeburn  11593:             }
1.80      raeburn  11594:             my %newenv;
1.72      raeburn  11595:             foreach my $item (@usertools) {
1.163     raeburn  11596:                 my (%haschgs,%inconf);
                   11597:                 if ($context eq 'requestauthor') {
                   11598:                     %haschgs = %changes;
1.210     raeburn  11599:                     %inconf = %confhash;
1.163     raeburn  11600:                 } else {
                   11601:                     if (ref($changes{$item}) eq 'HASH') {
                   11602:                         %haschgs = %{$changes{$item}};
                   11603:                     }
                   11604:                     if (ref($confhash{$item}) eq 'HASH') {
                   11605:                         %inconf = %{$confhash{$item}};
                   11606:                     }
                   11607:                 }
                   11608:                 if (keys(%haschgs) > 0) {
1.80      raeburn  11609:                     my $newacc = 
                   11610:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   11611:                                                           $env{'user.domain'},
1.86      raeburn  11612:                                                           $item,'reload',$context);
1.210     raeburn  11613:                     if (($context eq 'requestcourses') ||
1.163     raeburn  11614:                         ($context eq 'requestauthor')) {
1.108     raeburn  11615:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   11616:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  11617:                         }
                   11618:                     } else {
                   11619:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   11620:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   11621:                         }
1.80      raeburn  11622:                     }
1.163     raeburn  11623:                     unless ($context eq 'requestauthor') {
                   11624:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   11625:                     }
1.72      raeburn  11626:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  11627:                         if ($haschgs{$type}) {
1.72      raeburn  11628:                             my $typetitle = $usertypes->{$type};
                   11629:                             if ($type eq 'default') {
                   11630:                                 $typetitle = $othertitle;
                   11631:                             } elsif ($type eq '_LC_adv') {
                   11632:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   11633:                             }
1.163     raeburn  11634:                             if ($inconf{$type}) {
1.101     raeburn  11635:                                 if ($context eq 'requestcourses') {
                   11636:                                     my $cond;
1.163     raeburn  11637:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  11638:                                         if ($1 eq '') {
                   11639:                                             $cond = &mt('(Automatic processing of any request).');
                   11640:                                         } else {
                   11641:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   11642:                                         }
                   11643:                                     } else { 
1.163     raeburn  11644:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  11645:                                     }
                   11646:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  11647:                                 } elsif ($context eq 'requestauthor') {
                   11648:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   11649:                                                              $titles{$inconf{$type}},$typetitle);
                   11650: 
1.101     raeburn  11651:                                 } else {
                   11652:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   11653:                                 }
1.72      raeburn  11654:                             } else {
1.104     raeburn  11655:                                 if ($type eq '_LC_adv') {
1.163     raeburn  11656:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  11657:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   11658:                                     } else { 
                   11659:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   11660:                                     }
                   11661:                                 } else {
                   11662:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   11663:                                 }
1.72      raeburn  11664:                             }
                   11665:                         }
1.26      raeburn  11666:                     }
1.163     raeburn  11667:                     unless ($context eq 'requestauthor') {
                   11668:                         $resulttext .= '</ul></li>';
                   11669:                     }
1.26      raeburn  11670:                 }
1.1       raeburn  11671:             }
1.163     raeburn  11672:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  11673:                 if (ref($changes{'notify'}) eq 'HASH') {
                   11674:                     if ($changes{'notify'}{'approval'}) {
                   11675:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   11676:                             if ($confhash{'notify'}{'approval'}) {
                   11677:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   11678:                             } else {
1.163     raeburn  11679:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  11680:                             }
                   11681:                         }
                   11682:                     }
                   11683:                 }
                   11684:             }
1.216     raeburn  11685:             if ($action eq 'requestcourses') {
                   11686:                 my @offon = ('off','on');
                   11687:                 if ($changes{'uniquecode'}) {
1.218     raeburn  11688:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11689:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   11690:                         $resulttext .= '<li>'.
                   11691:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   11692:                                        '</li>';
                   11693:                     } else {
                   11694:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   11695:                                        '</li>';
                   11696:                     }
1.216     raeburn  11697:                 }
1.242     raeburn  11698:                 foreach my $type ('textbooks','templates') {
                   11699:                     if (ref($changes{$type}) eq 'HASH') {
                   11700:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   11701:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   11702:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   11703:                             my $coursetitle = $coursehash{'description'};
                   11704:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   11705:                             $resulttext .= '<li>';
1.243     raeburn  11706:                             foreach my $item ('subject','title','publisher','author') {
                   11707:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11708:                                          ($type eq 'templates'));
1.242     raeburn  11709:                                 my $name = $item.':';
                   11710:                                 $name =~ s/^(\w)/\U$1/;
                   11711:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   11712:                             }
                   11713:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   11714:                             if ($type eq 'textbooks') {
                   11715:                                 if ($confhash{$type}{$key}{'image'}) {
                   11716:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   11717:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   11718:                                                    ' alt="Textbook cover" />').'<br />';
                   11719:                                 }
                   11720:                             }
                   11721:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  11722:                         }
1.242     raeburn  11723:                         $resulttext .= '</ul></li>';
1.216     raeburn  11724:                     }
                   11725:                 }
1.235     raeburn  11726:                 if (ref($changes{'validation'}) eq 'HASH') {
                   11727:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   11728:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   11729:                         foreach my $item (@{$validationitemsref}) {
                   11730:                             if (exists($changes{'validation'}{$item})) {
                   11731:                                 if ($item eq 'markup') {
                   11732:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   11733:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   11734:                                 } else {
                   11735:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   11736:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   11737:                                 }
                   11738:                             }
                   11739:                         }
                   11740:                         if (exists($changes{'validation'}{'dc'})) {
                   11741:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   11742:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   11743:                         }
                   11744:                     }
                   11745:                 }
1.216     raeburn  11746:             }
1.1       raeburn  11747:             $resulttext .= '</ul>';
1.80      raeburn  11748:             if (keys(%newenv)) {
                   11749:                 &Apache::lonnet::appenv(\%newenv);
                   11750:             }
1.1       raeburn  11751:         } else {
1.86      raeburn  11752:             if ($context eq 'requestcourses') {
                   11753:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  11754:             } elsif ($context eq 'requestauthor') {
                   11755:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  11756:             } else {
1.90      weissno  11757:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  11758:             }
1.1       raeburn  11759:         }
                   11760:     } else {
1.11      albertel 11761:         $resulttext = '<span class="LC_error">'.
                   11762: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  11763:     }
1.216     raeburn  11764:     if ($errors) {
                   11765:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   11766:                        '<ul>'.$errors.'</ul></p>';
                   11767:     }
1.3       raeburn  11768:     return $resulttext;
1.1       raeburn  11769: }
                   11770: 
1.216     raeburn  11771: sub process_textbook_image {
1.242     raeburn  11772:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  11773:     my $filename = $env{'form.'.$caller.'.filename'};
                   11774:     my ($error,$url);
                   11775:     my ($width,$height) = (50,50);
                   11776:     if ($configuserok eq 'ok') {
                   11777:         if ($switchserver) {
                   11778:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   11779:                          $switchserver);
                   11780:         } elsif ($author_ok eq 'ok') {
                   11781:             my ($result,$imageurl) =
                   11782:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  11783:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  11784:             if ($result eq 'ok') {
                   11785:                 $url = $imageurl;
                   11786:             } else {
                   11787:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   11788:             }
                   11789:         } else {
                   11790:             $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);
                   11791:         }
                   11792:     } else {
                   11793:         $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);
                   11794:     }
                   11795:     return ($url,$error);
                   11796: }
                   11797: 
1.267     raeburn  11798: sub modify_ltitools {
                   11799:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   11800:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  11801:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  11802:     my $confname = $dom.'-domainconfig';
                   11803:     my $servadm = $r->dir_config('lonAdmEMail');
                   11804:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   11805:     my (%posslti,%possfield);
                   11806:     my @courseroles = ('cc','in','ta','ep','st');
                   11807:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   11808:     map { $posslti{$_} = 1; } @ltiroles;
                   11809:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   11810:     map { $possfield{$_} = 1; } @allfields;
                   11811:     my %lt = &ltitools_names(); 
                   11812:     if ($env{'form.ltitools_add'}) {
                   11813:         my $title = $env{'form.ltitools_add_title'};
                   11814:         $title =~ s/(`)/'/g;
                   11815:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   11816:         if ($newid) {
                   11817:             my $position = $env{'form.ltitools_add_pos'};
                   11818:             $position =~ s/\D+//g;
                   11819:             if ($position ne '') {
                   11820:                 $allpos[$position] = $newid;
                   11821:             }
                   11822:             $changes{$newid} = 1;
1.322     raeburn  11823:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  11824:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  11825:                 if ($item eq 'lifetime') {
                   11826:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   11827:                 }
1.267     raeburn  11828:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  11829:                     if (($item eq 'key') || ($item eq 'secret')) {
                   11830:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   11831:                     } else {
                   11832:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   11833:                     }
1.267     raeburn  11834:                 }
                   11835:             }
                   11836:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   11837:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   11838:             }
                   11839:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   11840:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   11841:             }
1.323     raeburn  11842:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   11843:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   11844:             } else {
                   11845:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   11846:             }
1.296     raeburn  11847:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  11848:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   11849:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  11850:                 if (($item eq 'width') || ($item eq 'height')) {
                   11851:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   11852:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   11853:                     }
                   11854:                 } else {
                   11855:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   11856:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   11857:                     }
1.267     raeburn  11858:                 }
                   11859:             }
                   11860:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   11861:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  11862:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   11863:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  11864:             } else {
                   11865:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   11866:             }
                   11867:             foreach my $item ('passback','roster') {
1.319     raeburn  11868:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  11869:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  11870:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   11871:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   11872:                         $lifetime =~ s/^\s+|\s+$//g;
                   11873:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   11874:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   11875:                         }
                   11876:                     }
1.267     raeburn  11877:                 }
                   11878:             }
                   11879:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   11880:                 my ($imageurl,$error) =
1.307     raeburn  11881:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  11882:                                             $configuserok,$switchserver,$author_ok);
                   11883:                 if ($imageurl) {
                   11884:                     $confhash{$newid}{'image'} = $imageurl;
                   11885:                 }
                   11886:                 if ($error) {
                   11887:                     &Apache::lonnet::logthis($error);
                   11888:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11889:                 }
                   11890:             }
                   11891:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   11892:             foreach my $field (@fields) {
                   11893:                 if ($possfield{$field}) {
                   11894:                     if ($field eq 'roles') {
                   11895:                         foreach my $role (@courseroles) {
                   11896:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   11897:                             if (($choice ne '') && ($posslti{$choice})) {
                   11898:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   11899:                                 if ($role eq 'cc') {
                   11900:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   11901:                                 }
                   11902:                             }
                   11903:                         }
                   11904:                     } else {
                   11905:                         $confhash{$newid}{'fields'}{$field} = 1;
                   11906:                     }
                   11907:                 }
                   11908:             }
1.324     raeburn  11909:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   11910:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   11911:                     if ($env{'form.ltitools_userincdom_add'}) {
                   11912:                         $confhash{$newid}{'incdom'} = 1;
                   11913:                     }
                   11914:                 }
                   11915:             }
1.273     raeburn  11916:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   11917:             foreach my $item (@courseconfig) {
                   11918:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   11919:             }
1.267     raeburn  11920:             if ($env{'form.ltitools_add_custom'}) {
                   11921:                 my $name = $env{'form.ltitools_add_custom_name'};
                   11922:                 my $value = $env{'form.ltitools_add_custom_value'};
                   11923:                 $value =~ s/(`)/'/g;
                   11924:                 $name =~ s/(`)/'/g;
                   11925:                 $confhash{$newid}{'custom'}{$name} = $value;
                   11926:             }
                   11927:         } else {
                   11928:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   11929:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11930:         }
                   11931:     }
                   11932:     if (ref($domconfig{$action}) eq 'HASH') {
                   11933:         my %deletions;
                   11934:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   11935:         if (@todelete) {
                   11936:             map { $deletions{$_} = 1; } @todelete;
                   11937:         }
                   11938:         my %customadds;
                   11939:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   11940:         if (@newcustom) {
                   11941:             map { $customadds{$_} = 1; } @newcustom;
                   11942:         } 
                   11943:         my %imgdeletions;
                   11944:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   11945:         if (@todeleteimages) {
                   11946:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   11947:         }
                   11948:         my $maxnum = $env{'form.ltitools_maxnum'};
                   11949:         for (my $i=0; $i<=$maxnum; $i++) {
                   11950:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  11951:             $itemid =~ s/\D+//g;
1.267     raeburn  11952:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   11953:                 if ($deletions{$itemid}) {
                   11954:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   11955:                         #FIXME need to obsolete item in RES space
                   11956:                     }
                   11957:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   11958:                     next;
                   11959:                 } else {
                   11960:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   11961:                     $newpos =~ s/\D+//g;
1.322     raeburn  11962:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  11963:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   11964:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   11965:                             $changes{$itemid} = 1;
                   11966:                         }
                   11967:                     }
1.297     raeburn  11968:                     foreach my $item ('key','secret') {
                   11969:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   11970:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   11971:                             $changes{$itemid} = 1;
                   11972:                         }
                   11973:                     }
1.267     raeburn  11974:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   11975:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   11976:                     }
                   11977:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   11978:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   11979:                     }
1.323     raeburn  11980:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   11981:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   11982:                     } else {
                   11983:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   11984:                     }
                   11985:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   11986:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   11987:                             $changes{$itemid} = 1;
                   11988:                         }
                   11989:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   11990:                         $changes{$itemid} = 1;
                   11991:                     }
1.267     raeburn  11992:                     foreach my $size ('width','height') {
                   11993:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   11994:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   11995:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   11996:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   11997:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   11998:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   11999:                                     $changes{$itemid} = 1;
                   12000:                                 }
                   12001:                             } else {
                   12002:                                 $changes{$itemid} = 1;
                   12003:                             }
1.296     raeburn  12004:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12005:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   12006:                                 $changes{$itemid} = 1;
                   12007:                             }
                   12008:                         }
                   12009:                     }
                   12010:                     foreach my $item ('linktext','explanation') {
                   12011:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   12012:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   12013:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   12014:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12015:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12016:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   12017:                                     $changes{$itemid} = 1;
                   12018:                                 }
                   12019:                             } else {
                   12020:                                 $changes{$itemid} = 1;
                   12021:                             }
                   12022:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12023:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   12024:                                 $changes{$itemid} = 1;
                   12025:                             }
1.267     raeburn  12026:                         }
                   12027:                     }
                   12028:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   12029:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  12030:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   12031:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  12032:                     } else {
                   12033:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   12034:                     }
                   12035:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12036:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   12037:                             $changes{$itemid} = 1;
                   12038:                         }
                   12039:                     } else {
                   12040:                         $changes{$itemid} = 1;
                   12041:                     }
                   12042:                     foreach my $extra ('passback','roster') {
                   12043:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   12044:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  12045:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  12046:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  12047:                                 $lifetime =~ s/^\s+|\s+$//g;
                   12048:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   12049:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   12050:                                 }
                   12051:                             }
1.267     raeburn  12052:                         }
                   12053:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   12054:                             $changes{$itemid} = 1;
                   12055:                         }
1.319     raeburn  12056:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   12057:                             $changes{$itemid} = 1;
                   12058:                         }
1.267     raeburn  12059:                     }
1.273     raeburn  12060:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  12061:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  12062:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   12063:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   12064:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   12065:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   12066:                                     $changes{$itemid} = 1;
                   12067:                                 }
                   12068:                             } else {
                   12069:                                 $changes{$itemid} = 1;
                   12070:                             }
                   12071:                         }
                   12072:                     }
1.267     raeburn  12073:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   12074:                     foreach my $field (@fields) {
                   12075:                         if ($possfield{$field}) {
                   12076:                             if ($field eq 'roles') {
                   12077:                                 foreach my $role (@courseroles) {
                   12078:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   12079:                                     if (($choice ne '') && ($posslti{$choice})) {
                   12080:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   12081:                                         if ($role eq 'cc') {
                   12082:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   12083:                                         }
                   12084:                                     }
                   12085:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   12086:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   12087:                                             $changes{$itemid} = 1;
                   12088:                                         }
                   12089:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   12090:                                         $changes{$itemid} = 1;
                   12091:                                     }
                   12092:                                 }
                   12093:                             } else {
                   12094:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   12095:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   12096:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   12097:                                         $changes{$itemid} = 1;
                   12098:                                     }
                   12099:                                 } else {
                   12100:                                     $changes{$itemid} = 1;
                   12101:                                 }
                   12102:                             }
                   12103:                         }
                   12104:                     }
1.324     raeburn  12105:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12106:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   12107:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   12108:                                 $confhash{$itemid}{'incdom'} = 1;
                   12109:                             }
                   12110:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   12111:                                 $changes{$itemid} = 1;
                   12112:                             }
                   12113:                         }
                   12114:                     }
1.267     raeburn  12115:                     $allpos[$newpos] = $itemid;
                   12116:                 }
                   12117:                 if ($imgdeletions{$itemid}) {
                   12118:                     $changes{$itemid} = 1;
                   12119:                     #FIXME need to obsolete item in RES space
                   12120:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   12121:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   12122:                                                                  $itemid,$configuserok,$switchserver,
                   12123:                                                                  $author_ok);
                   12124:                     if ($imgurl) {
                   12125:                         $confhash{$itemid}{'image'} = $imgurl;
                   12126:                         $changes{$itemid} = 1;
                   12127:                     }
                   12128:                     if ($error) {
                   12129:                         &Apache::lonnet::logthis($error);
                   12130:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12131:                     }
                   12132:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   12133:                     $confhash{$itemid}{'image'} =
                   12134:                        $domconfig{$action}{$itemid}{'image'};
                   12135:                 }
                   12136:                 if ($customadds{$i}) {
                   12137:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   12138:                     $name =~ s/(`)/'/g;
                   12139:                     $name =~ s/^\s+//;
                   12140:                     $name =~ s/\s+$//;
                   12141:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   12142:                     $value =~ s/(`)/'/g;
                   12143:                     $value =~ s/^\s+//;
                   12144:                     $value =~ s/\s+$//;
                   12145:                     if ($name ne '') {
                   12146:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   12147:                         $changes{$itemid} = 1;
                   12148:                     }
                   12149:                 }
                   12150:                 my %customdels;
                   12151:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   12152:                 if (@customdeletions) {
                   12153:                     $changes{$itemid} = 1;
                   12154:                 }
                   12155:                 map { $customdels{$_} = 1; } @customdeletions;
                   12156:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   12157:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   12158:                         unless ($customdels{$key}) {
                   12159:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   12160:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   12161:                             }
                   12162:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   12163:                                 $changes{$itemid} = 1;
                   12164:                             }
                   12165:                         }
                   12166:                     }
                   12167:                 }
                   12168:                 unless ($changes{$itemid}) {
                   12169:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   12170:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   12171:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   12172:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   12173:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   12174:                                         $changes{$itemid} = 1;
                   12175:                                         last;
                   12176:                                     }
                   12177:                                 }
                   12178:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   12179:                                 $changes{$itemid} = 1;
                   12180:                             }
                   12181:                         }
                   12182:                         last if ($changes{$itemid});
                   12183:                     }
                   12184:                 }
                   12185:             }
                   12186:         }
                   12187:     }
                   12188:     if (@allpos > 0) {
                   12189:         my $idx = 0;
                   12190:         foreach my $itemid (@allpos) {
                   12191:             if ($itemid ne '') {
                   12192:                 $confhash{$itemid}{'order'} = $idx;
                   12193:                 if (ref($domconfig{$action}) eq 'HASH') {
                   12194:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12195:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   12196:                             $changes{$itemid} = 1;
                   12197:                         }
                   12198:                     }
                   12199:                 }
                   12200:                 $idx ++;
                   12201:             }
                   12202:         }
                   12203:     }
                   12204:     my %ltitoolshash = (
                   12205:                           $action => { %confhash }
                   12206:                        );
                   12207:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   12208:                                              $dom);
                   12209:     if ($putresult eq 'ok') {
1.297     raeburn  12210:         my %ltienchash = (
                   12211:                              $action => { %encconfig }
                   12212:                          );
                   12213:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267     raeburn  12214:         if (keys(%changes) > 0) {
                   12215:             my $cachetime = 24*60*60;
1.297     raeburn  12216:             my %ltiall = %confhash;
                   12217:             foreach my $id (keys(%ltiall)) {
                   12218:                 if (ref($encconfig{$id}) eq 'HASH') {
                   12219:                     foreach my $item ('key','secret') {
                   12220:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   12221:                     }
                   12222:                 }
                   12223:             }
                   12224:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  12225:             if (ref($lastactref) eq 'HASH') {
                   12226:                 $lastactref->{'ltitools'} = 1;
                   12227:             }
                   12228:             $resulttext = &mt('Changes made:').'<ul>';
                   12229:             my %bynum;
                   12230:             foreach my $itemid (sort(keys(%changes))) {
                   12231:                 my $position = $confhash{$itemid}{'order'};
                   12232:                 $bynum{$position} = $itemid;
                   12233:             }
                   12234:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12235:                 my $itemid = $bynum{$pos}; 
                   12236:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   12237:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12238:                 } else {
                   12239:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   12240:                     if ($confhash{$itemid}{'image'}) {
                   12241:                         $resulttext .= '&nbsp;'.
                   12242:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   12243:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   12244:                     }
                   12245:                     $resulttext .= '</li><ul>';
                   12246:                     my $position = $pos + 1;
                   12247:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  12248:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  12249:                         if ($confhash{$itemid}{$item} ne '') {
                   12250:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   12251:                         }
                   12252:                     }
1.297     raeburn  12253:                     if ($encconfig{$itemid}{'key'} ne '') {
                   12254:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   12255:                     }
                   12256:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  12257:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  12258:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  12259:                         $resulttext .= ('*'x$num).'</li>';
                   12260:                     }
1.273     raeburn  12261:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  12262:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  12263:                     my $numconfig = 0; 
                   12264:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   12265:                         foreach my $item (@possconfig) {
                   12266:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   12267:                                 $numconfig ++;
1.296     raeburn  12268:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  12269:                             }
                   12270:                         }
                   12271:                     }
                   12272:                     if (!$numconfig) {
                   12273:                         $resulttext .= &mt('None');
                   12274:                     }
                   12275:                     $resulttext .= '</li>';
1.267     raeburn  12276:                     foreach my $item ('passback','roster') {
                   12277:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   12278:                         if ($confhash{$itemid}{$item}) {
                   12279:                             $resulttext .= &mt('Yes');
1.319     raeburn  12280:                             if ($confhash{$itemid}{$item.'valid'}) {
                   12281:                                 if ($item eq 'passback') {
                   12282:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   12283:                                                            $confhash{$itemid}{$item.'valid'});
                   12284:                                 } else {
                   12285:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   12286:                                                            $confhash{$itemid}{$item.'valid'});
                   12287:                                 }
                   12288:                             }
1.267     raeburn  12289:                         } else {
                   12290:                             $resulttext .= &mt('No');
                   12291:                         }
                   12292:                         $resulttext .= '</li>';
                   12293:                     }
                   12294:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   12295:                         my $displaylist;
                   12296:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   12297:                             $displaylist = &mt('Display target').':&nbsp;'.
                   12298:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   12299:                         }
                   12300:                         foreach my $size ('width','height') { 
                   12301:                             if ($confhash{$itemid}{'display'}{$size}) {
                   12302:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   12303:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   12304:                             }
                   12305:                         }
                   12306:                         if ($displaylist) {
                   12307:                             $displaylist =~ s/,$//;
                   12308:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   12309:                         }
1.296     raeburn  12310:                         foreach my $item ('linktext','explanation') {
                   12311:                             if ($confhash{$itemid}{'display'}{$item}) {
                   12312:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   12313:                             }
                   12314:                         }
                   12315:                     }
1.267     raeburn  12316:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12317:                         my $fieldlist;
                   12318:                         foreach my $field (@allfields) {
                   12319:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   12320:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   12321:                             }
                   12322:                         }
                   12323:                         if ($fieldlist) {
                   12324:                             $fieldlist =~ s/,$//;
1.324     raeburn  12325:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   12326:                                 if ($confhash{$itemid}{'incdom'}) {
                   12327:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   12328:                                 } else {
                   12329:                                     $fieldlist .= ' ('.&mt('username').')';
                   12330:                                 }
                   12331:                             }
1.267     raeburn  12332:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   12333:                         }
                   12334:                     }
                   12335:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   12336:                         my $rolemaps;
                   12337:                         foreach my $role (@courseroles) {
                   12338:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   12339:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   12340:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   12341:                             }
                   12342:                         }
                   12343:                         if ($rolemaps) {
                   12344:                             $rolemaps =~ s/,$//; 
                   12345:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   12346:                         }
                   12347:                     }
                   12348:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   12349:                         my $customlist;
                   12350:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   12351:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   12352:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   12353:                             } 
                   12354:                         }
                   12355:                         if ($customlist) {
1.317     raeburn  12356:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  12357:                         }
                   12358:                     } 
                   12359:                     $resulttext .= '</ul></li>';
                   12360:                 }
                   12361:             }
                   12362:             $resulttext .= '</ul>';
                   12363:         } else {
                   12364:             $resulttext = &mt('No changes made.');
                   12365:         }
                   12366:     } else {
                   12367:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12368:     }
                   12369:     if ($errors) {
                   12370:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12371:                        $errors.'</ul>';
                   12372:     }
                   12373:     return $resulttext;
                   12374: }
                   12375: 
                   12376: sub process_ltitools_image {
                   12377:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   12378:     my $filename = $env{'form.'.$caller.'.filename'};
                   12379:     my ($error,$url);
                   12380:     my ($width,$height) = (21,21);
                   12381:     if ($configuserok eq 'ok') {
                   12382:         if ($switchserver) {
                   12383:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   12384:                          $switchserver);
                   12385:         } elsif ($author_ok eq 'ok') {
                   12386:             my ($result,$imageurl,$madethumb) =
                   12387:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   12388:                              "ltitools/$itemid/icon",$width,$height);
                   12389:             if ($result eq 'ok') {
                   12390:                 if ($madethumb) {
                   12391:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   12392:                     my $imagethumb = "$path/tn-".$imagefile;
                   12393:                     $url = $imagethumb;
                   12394:                 } else {
                   12395:                     $url = $imageurl;
                   12396:                 }
                   12397:             } else {
                   12398:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   12399:             }
                   12400:         } else {
                   12401:             $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);
                   12402:         }
                   12403:     } else {
                   12404:         $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);
                   12405:     }
                   12406:     return ($url,$error);
                   12407: }
                   12408: 
                   12409: sub get_ltitools_id {
                   12410:     my ($cdom,$title) = @_;
                   12411:     # get lock on ltitools db
                   12412:     my $lockhash = {
                   12413:                       lock => $env{'user.name'}.
                   12414:                               ':'.$env{'user.domain'},
                   12415:                    };
                   12416:     my $tries = 0;
                   12417:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   12418:     my ($id,$error);
                   12419:  
                   12420:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12421:         $tries ++;
                   12422:         sleep (0.1);
                   12423:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   12424:     }
                   12425:     if ($gotlock eq 'ok') {
                   12426:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   12427:         if ($currids{'lock'}) {
                   12428:             delete($currids{'lock'});
                   12429:             if (keys(%currids)) {
                   12430:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12431:                 if ($curr[-1] =~ /^\d+$/) {
                   12432:                     $id = 1 + $curr[-1];
                   12433:                 }
                   12434:             } else {
                   12435:                 $id = 1;
                   12436:             }
                   12437:             if ($id) {
                   12438:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   12439:                     $error = 'nostore';
                   12440:                 }
                   12441:             } else {
                   12442:                 $error = 'nonumber';
                   12443:             }
                   12444:         }
                   12445:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   12446:     } else {
                   12447:         $error = 'nolock';
                   12448:     }
                   12449:     return ($id,$error);
                   12450: }
                   12451: 
1.320     raeburn  12452: sub modify_lti {
                   12453:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   12454:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12455:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   12456:     my (%posslti,%posslticrs,%posscrstype);
                   12457:     my @courseroles = ('cc','in','ta','ep','st');
                   12458:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   12459:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
                   12460:     my @coursetypes = ('official','unofficial','community','textbook','placement');
                   12461:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   12462:                                official   => 'Official',
                   12463:                                unofficial => 'Unofficial',
                   12464:                                community  => 'Community',
                   12465:                                textbook   => 'Textbook',
                   12466:                                placement  => 'Placement Test',
                   12467:     );
1.325     raeburn  12468:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  12469:     my %lt = &lti_names();
                   12470:     map { $posslti{$_} = 1; } @ltiroles;
                   12471:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   12472:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  12473: 
1.326     raeburn  12474:     my %menutitles = &ltimenu_titles();
                   12475: 
1.320     raeburn  12476:     my (@items,%deletions,%itemids);
                   12477:     if ($env{'form.lti_add'}) {
                   12478:         my $consumer = $env{'form.lti_consumer_add'};
                   12479:         $consumer =~ s/(`)/'/g;
                   12480:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   12481:         if ($newid) {
                   12482:             $itemids{'add'} = $newid;
                   12483:             push(@items,'add');
                   12484:             $changes{$newid} = 1;
                   12485:         } else {
                   12486:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   12487:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12488:         }
                   12489:     }
                   12490:     if (ref($domconfig{$action}) eq 'HASH') {
                   12491:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   12492:         if (@todelete) {
                   12493:             map { $deletions{$_} = 1; } @todelete;
                   12494:         }
                   12495:         my $maxnum = $env{'form.lti_maxnum'};
                   12496:         for (my $i=0; $i<=$maxnum; $i++) {
                   12497:             my $itemid = $env{'form.lti_id_'.$i};
                   12498:             $itemid =~ s/\D+//g;
                   12499:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12500:                 if ($deletions{$itemid}) {
                   12501:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   12502:                 } else {
                   12503:                    push(@items,$i);
                   12504:                    $itemids{$i} = $itemid;
                   12505:                 }
                   12506:             }
                   12507:         }
                   12508:     }
                   12509:     foreach my $idx (@items) {
                   12510:         my $itemid = $itemids{$idx};
                   12511:         next unless ($itemid);
                   12512:         my $position = $env{'form.lti_pos_'.$idx};
                   12513:         $position =~ s/\D+//g;
                   12514:         if ($position ne '') {
                   12515:             $allpos[$position] = $itemid;
                   12516:         }
1.345     raeburn  12517:         foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320     raeburn  12518:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   12519:             $env{$formitem} =~ s/(`)/'/g;
                   12520:             if ($item eq 'lifetime') {
                   12521:                 $env{$formitem} =~ s/[^\d.]//g;
                   12522:             }
                   12523:             if ($env{$formitem} ne '') {
                   12524:                 if (($item eq 'key') || ($item eq 'secret')) {
                   12525:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   12526:                 } else {
                   12527:                     $confhash{$itemid}{$item} = $env{$formitem};
                   12528:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   12529:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   12530:                             $changes{$itemid} = 1;
                   12531:                         }
                   12532:                     }
                   12533:                 }
                   12534:             }
                   12535:         }
                   12536:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   12537:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   12538:         }
1.345     raeburn  12539:         if ($confhash{$itemid}{'requser'}) {
                   12540:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
                   12541:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
                   12542:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   12543:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   12544:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   12545:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   12546:                 $mapuser =~ s/(`)/'/g;
                   12547:                 $mapuser =~ s/^\s+|\s+$//g; 
                   12548:                 $confhash{$itemid}{'mapuser'} = $mapuser; 
                   12549:             }
                   12550:             foreach my $ltirole (@lticourseroles) {
                   12551:                 my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   12552:                 if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   12553:                     $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   12554:                 }
                   12555:             }
                   12556:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   12557:             my @makeuser;
                   12558:             foreach my $ltirole (sort(@possmakeuser)) {
                   12559:                 if ($posslti{$ltirole}) {
                   12560:                     push(@makeuser,$ltirole);
                   12561:                 }
                   12562:             }
                   12563:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   12564:             if (@makeuser) {
                   12565:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   12566:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   12567:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   12568:                     if ($lcauth ne 'internal') {
                   12569:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   12570:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   12571:                         $lcauthparm =~ s/`//g;
                   12572:                         if ($lcauthparm ne '') {
                   12573:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   12574:                         }
                   12575:                     }
                   12576:                 } else {
                   12577:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   12578:                 }
1.320     raeburn  12579:             }
1.345     raeburn  12580:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   12581:             if (@possinstdata) {
                   12582:                 foreach my $field (@possinstdata) {
                   12583:                     if (exists($fieldtitles{$field})) {
                   12584:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  12585:                     }
                   12586:                 }
                   12587:             }
1.345     raeburn  12588:             if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   12589:                 ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   12590:                 $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   12591:             } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   12592:                 my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   12593:                 $mapcrs =~ s/(`)/'/g;
                   12594:                 $mapcrs =~ s/^\s+|\s+$//g;
                   12595:                 $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   12596:             }
                   12597:             my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   12598:             my @crstypes;
                   12599:             foreach my $type (sort(@posstypes)) {
                   12600:                 if ($posscrstype{$type}) {
                   12601:                     push(@crstypes,$type);
1.325     raeburn  12602:                 }
                   12603:             }
1.345     raeburn  12604:             $confhash{$itemid}{'mapcrstype'} = \@crstypes;
                   12605:             if ($env{'form.lti_makecrs_'.$idx}) {
                   12606:                 $confhash{$itemid}{'makecrs'} = 1;
1.320     raeburn  12607:             }
1.345     raeburn  12608:             my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   12609:             my @selfenroll;
                   12610:             foreach my $type (sort(@possenroll)) {
                   12611:                 if ($posslticrs{$type}) {
                   12612:                     push(@selfenroll,$type);
                   12613:                 }
1.320     raeburn  12614:             }
1.345     raeburn  12615:             $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   12616:             if ($env{'form.lti_crssec_'.$idx}) {
                   12617:                 if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   12618:                     $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   12619:                 } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   12620:                     my $section = $env{'form.lti_customsection_'.$idx};
                   12621:                     $section =~ s/(`)/'/g;
                   12622:                     $section =~ s/^\s+|\s+$//g;
                   12623:                     if ($section ne '') {
                   12624:                         $confhash{$itemid}{'section'} = $section;
                   12625:                     }
1.320     raeburn  12626:                 }
                   12627:             }
1.345     raeburn  12628:             foreach my $field ('passback','roster','topmenu','inlinemenu') {
                   12629:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   12630:                     $confhash{$itemid}{$field} = 1;
                   12631:                 }
1.320     raeburn  12632:             }
1.345     raeburn  12633:             if ($env{'form.lti_passback_'.$idx}) {
                   12634:                 if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   12635:                     $confhash{$itemid}{'passbackformat'} = '1.0';
                   12636:                 } else {
                   12637:                     $confhash{$itemid}{'passbackformat'} = '1.1';
                   12638:                 }
1.337     raeburn  12639:             }
1.345     raeburn  12640:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   12641:                 $confhash{$itemid}{lcmenu} = [];
                   12642:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   12643:                 foreach my $field (@possmenu) {
                   12644:                     if (exists($menutitles{$field})) {
                   12645:                         if ($field eq 'grades') {
                   12646:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   12647:                         }
                   12648:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  12649:                     }
                   12650:                 }
                   12651:             }
1.345     raeburn  12652:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   12653:                 foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu') {
                   12654:                     if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337     raeburn  12655:                         $changes{$itemid} = 1;
                   12656:                     }
                   12657:                 }
1.320     raeburn  12658:                 unless ($changes{$itemid}) {
1.345     raeburn  12659:                     if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   12660:                         if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  12661:                             $changes{$itemid} = 1;
                   12662:                         }
1.345     raeburn  12663:                     }
1.320     raeburn  12664:                 }
1.345     raeburn  12665:                 foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
                   12666:                     unless ($changes{$itemid}) {
                   12667:                         if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   12668:                             if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   12669:                                 my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   12670:                                                                                $confhash{$itemid}{$field});
                   12671:                                 if (@diffs) {
                   12672:                                     $changes{$itemid} = 1;
                   12673:                                 }
                   12674:                             } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   12675:                                 $changes{$itemid} = 1;
                   12676:                             }
                   12677:                         } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   12678:                             if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  12679:                                 $changes{$itemid} = 1;
                   12680:                             }
                   12681:                         }
1.345     raeburn  12682:                     }
                   12683:                 }
                   12684:                 unless ($changes{$itemid}) {
                   12685:                     if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   12686:                         if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12687:                             foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   12688:                                 if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   12689:                                     $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320     raeburn  12690:                                     $changes{$itemid} = 1;
                   12691:                                     last;
                   12692:                                 }
                   12693:                             }
1.345     raeburn  12694:                             unless ($changes{$itemid}) {
                   12695:                                 foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   12696:                                     if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   12697:                                         $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   12698:                                         $changes{$itemid} = 1;
                   12699:                                         last;
                   12700:                                     }
                   12701:                                 }
                   12702:                             }
                   12703:                         } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   12704:                             $changes{$itemid} = 1;
1.320     raeburn  12705:                         }
1.345     raeburn  12706:                     } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12707:                         unless ($changes{$itemid}) {
                   12708:                             if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   12709:                                 $changes{$itemid} = 1;
                   12710:                             }
1.320     raeburn  12711:                         }
                   12712:                     }
                   12713:                 }
                   12714:             }
                   12715:         }
                   12716:     }
                   12717:     if (@allpos > 0) {
                   12718:         my $idx = 0;
                   12719:         foreach my $itemid (@allpos) {
                   12720:             if ($itemid ne '') {
                   12721:                 $confhash{$itemid}{'order'} = $idx;
                   12722:                 if (ref($domconfig{$action}) eq 'HASH') {
                   12723:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12724:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   12725:                             $changes{$itemid} = 1;
                   12726:                         }
                   12727:                     }
                   12728:                 }
                   12729:                 $idx ++;
                   12730:             }
                   12731:         }
                   12732:     }
                   12733:     my %ltihash = (
                   12734:                           $action => { %confhash }
                   12735:                        );
                   12736:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
                   12737:                                              $dom);
                   12738:     if ($putresult eq 'ok') {
                   12739:         my %ltienchash = (
                   12740:                              $action => { %encconfig }
                   12741:                          );
                   12742:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
                   12743:         if (keys(%changes) > 0) {
                   12744:             my $cachetime = 24*60*60;
                   12745:             my %ltiall = %confhash;
                   12746:             foreach my $id (keys(%ltiall)) {
                   12747:                 if (ref($encconfig{$id}) eq 'HASH') {
                   12748:                     foreach my $item ('key','secret') {
                   12749:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   12750:                     }
                   12751:                 }
                   12752:             }
                   12753:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   12754:             if (ref($lastactref) eq 'HASH') {
                   12755:                 $lastactref->{'lti'} = 1;
                   12756:             }
                   12757:             $resulttext = &mt('Changes made:').'<ul>';
                   12758:             my %bynum;
                   12759:             foreach my $itemid (sort(keys(%changes))) {
                   12760:                 my $position = $confhash{$itemid}{'order'};
                   12761:                 $bynum{$position} = $itemid;
                   12762:             }
                   12763:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12764:                 my $itemid = $bynum{$pos};
                   12765:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   12766:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12767:                 } else {
                   12768:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
                   12769:                     my $position = $pos + 1;
                   12770:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12771:                     foreach my $item ('version','lifetime') {
                   12772:                         if ($confhash{$itemid}{$item} ne '') {
                   12773:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   12774:                         }
                   12775:                     }
                   12776:                     if ($encconfig{$itemid}{'key'} ne '') {
                   12777:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   12778:                     }
                   12779:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   12780:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   12781:                         my $num = length($encconfig{$itemid}{'secret'});
                   12782:                         $resulttext .= ('*'x$num).'</li>';
                   12783:                     }
1.345     raeburn  12784:                     if ($confhash{$itemid}{'requser'}) {
                   12785:                         if ($confhash{$itemid}{'mapuser'}) {
                   12786:                             my $shownmapuser;
                   12787:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   12788:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   12789:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   12790:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   12791:                             } else {
                   12792:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  12793:                             }
1.345     raeburn  12794:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  12795:                         }
1.345     raeburn  12796:                         if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12797:                             my $rolemaps;
                   12798:                             foreach my $role (@ltiroles) {
                   12799:                                 if ($confhash{$itemid}{'maproles'}{$role}) {
                   12800:                                     $rolemaps .= ('&nbsp;'x2).$role.'='.
                   12801:                                                  &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   12802:                                                                             'Course').',';
                   12803:                                 }
                   12804:                             }
                   12805:                             if ($rolemaps) {
                   12806:                                 $rolemaps =~ s/,$//;
                   12807:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   12808:                             }
                   12809:                         }
                   12810:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   12811:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   12812:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   12813:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   12814:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   12815:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   12816:                                 } else {
                   12817:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   12818:                                                        $confhash{$itemid}{'lcauth'});
                   12819:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   12820:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   12821:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   12822:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   12823:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   12824:                                         }
                   12825:                                     } else {
                   12826:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   12827:                                     }
                   12828:                                 }
                   12829:                                 $resulttext .= '</li>';
                   12830:                             } else {
                   12831:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   12832:                             }
1.320     raeburn  12833:                         }
1.345     raeburn  12834:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   12835:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   12836:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   12837:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  12838:                             } else {
1.345     raeburn  12839:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  12840:                             }
1.320     raeburn  12841:                         }
1.345     raeburn  12842:                         if ($confhash{$itemid}{'mapcrs'}) {
                   12843:                             $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   12844:                         }
                   12845:                         if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   12846:                             if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   12847:                                 $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   12848:                                                join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   12849:                                                '</li>';
                   12850:                             } else {
                   12851:                                 $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   12852:                             }
1.325     raeburn  12853:                         }
1.345     raeburn  12854:                         if ($confhash{$itemid}{'makecrs'}) {
                   12855:                             $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320     raeburn  12856:                         } else {
1.345     raeburn  12857:                             $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320     raeburn  12858:                         }
1.345     raeburn  12859:                         if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   12860:                             if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   12861:                                 $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   12862:                                                           join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   12863:                                                '</li>';
                   12864:                             } else {
                   12865:                                 $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   12866:                             }
1.320     raeburn  12867:                         }
1.345     raeburn  12868:                         if ($confhash{$itemid}{'section'}) {
                   12869:                             if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   12870:                                 $resulttext .= '<li>'.&mt('User section from standard field:').
                   12871:                                                      ' (course_section_sourcedid)'.'</li>';  
                   12872:                             } else {
                   12873:                                 $resulttext .= '<li>'.&mt('User section from:').' '.
                   12874:                                                       $confhash{$itemid}{'section'}.'</li>';
                   12875:                             }
1.320     raeburn  12876:                         } else {
1.345     raeburn  12877:                             $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320     raeburn  12878:                         }
1.345     raeburn  12879:                         foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   12880:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   12881:                             if ($confhash{$itemid}{$item}) {
                   12882:                                 $resulttext .= &mt('Yes');
                   12883:                                 if ($item eq 'passback') {
                   12884:                                     if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   12885:                                         $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   12886:                                     } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   12887:                                         $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   12888:                                     }
1.337     raeburn  12889:                                 }
1.345     raeburn  12890:                             } else {
                   12891:                                 $resulttext .= &mt('No');
1.337     raeburn  12892:                             }
1.345     raeburn  12893:                             $resulttext .= '</li>';
1.320     raeburn  12894:                         }
1.345     raeburn  12895:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   12896:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   12897:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
                   12898:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   12899:                             } else {
                   12900:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   12901:                             }
1.326     raeburn  12902:                         }
                   12903:                     }
1.320     raeburn  12904:                     $resulttext .= '</ul></li>';
                   12905:                 }
                   12906:             }
                   12907:             $resulttext .= '</ul>';
                   12908:         } else {
                   12909:             $resulttext = &mt('No changes made.');
                   12910:         }
                   12911:     } else {
                   12912:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12913:     }
                   12914:     if ($errors) {
                   12915:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12916:                        $errors.'</ul>';
                   12917:     }
                   12918:     return $resulttext;
                   12919: }
                   12920: 
                   12921: sub get_lti_id {
                   12922:     my ($domain,$consumer) = @_;
                   12923:     # get lock on lti db
                   12924:     my $lockhash = {
                   12925:                       lock => $env{'user.name'}.
                   12926:                               ':'.$env{'user.domain'},
                   12927:                    };
                   12928:     my $tries = 0;
                   12929:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   12930:     my ($id,$error);
                   12931: 
                   12932:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12933:         $tries ++;
                   12934:         sleep (0.1);
                   12935:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   12936:     }
                   12937:     if ($gotlock eq 'ok') {
                   12938:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   12939:         if ($currids{'lock'}) {
                   12940:             delete($currids{'lock'});
                   12941:             if (keys(%currids)) {
                   12942:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12943:                 if ($curr[-1] =~ /^\d+$/) {
                   12944:                     $id = 1 + $curr[-1];
                   12945:                 }
                   12946:             } else {
                   12947:                 $id = 1;
                   12948:             }
                   12949:             if ($id) {
                   12950:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   12951:                     $error = 'nostore';
                   12952:                 }
                   12953:             } else {
                   12954:                 $error = 'nonumber';
                   12955:             }
                   12956:         }
                   12957:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   12958:     } else {
                   12959:         $error = 'nolock';
                   12960:     }
                   12961:     return ($id,$error);
                   12962: }
                   12963: 
1.3       raeburn  12964: sub modify_autoenroll {
1.205     raeburn  12965:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  12966:     my ($resulttext,%changes);
                   12967:     my %currautoenroll;
                   12968:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   12969:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   12970:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   12971:         }
                   12972:     }
                   12973:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   12974:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  12975:                   sender => 'Sender for notification messages',
1.274     raeburn  12976:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   12977:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  12978:     my @offon = ('off','on');
1.17      raeburn  12979:     my $sender_uname = $env{'form.sender_uname'};
                   12980:     my $sender_domain = $env{'form.sender_domain'};
                   12981:     if ($sender_domain eq '') {
                   12982:         $sender_uname = '';
                   12983:     } elsif ($sender_uname eq '') {
                   12984:         $sender_domain = '';
                   12985:     }
1.129     raeburn  12986:     my $coowners = $env{'form.autoassign_coowners'};
1.274     raeburn  12987:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   12988:     $failsafe =~ s{^\s+|\s+$}{}g;
                   12989:     if ($failsafe =~ /\D/) {
                   12990:         undef($failsafe);
                   12991:     }
1.1       raeburn  12992:     my %autoenrollhash =  (
1.129     raeburn  12993:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   12994:                                        'sender_uname' => $sender_uname,
                   12995:                                        'sender_domain' => $sender_domain,
                   12996:                                        'co-owners' => $coowners,
1.274     raeburn  12997:                                        'autofailsafe' => $failsafe,
1.1       raeburn  12998:                                 }
                   12999:                      );
1.4       raeburn  13000:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   13001:                                              $dom);
1.1       raeburn  13002:     if ($putresult eq 'ok') {
                   13003:         if (exists($currautoenroll{'run'})) {
                   13004:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   13005:                  $changes{'run'} = 1;
                   13006:              }
                   13007:         } elsif ($autorun) {
                   13008:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  13009:                  $changes{'run'} = 1;
1.1       raeburn  13010:             }
                   13011:         }
1.17      raeburn  13012:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  13013:             $changes{'sender'} = 1;
                   13014:         }
1.17      raeburn  13015:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  13016:             $changes{'sender'} = 1;
                   13017:         }
1.129     raeburn  13018:         if ($currautoenroll{'co-owners'} ne '') {
                   13019:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   13020:                 $changes{'coowners'} = 1;
                   13021:             }
                   13022:         } elsif ($coowners) {
                   13023:             $changes{'coowners'} = 1;
1.274     raeburn  13024:         }
                   13025:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   13026:             $changes{'autofailsafe'} = 1;
                   13027:         }
1.1       raeburn  13028:         if (keys(%changes) > 0) {
                   13029:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  13030:             if ($changes{'run'}) {
1.1       raeburn  13031:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   13032:             }
                   13033:             if ($changes{'sender'}) {
1.17      raeburn  13034:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   13035:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   13036:                 } else {
                   13037:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   13038:                 }
1.1       raeburn  13039:             }
1.129     raeburn  13040:             if ($changes{'coowners'}) {
                   13041:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   13042:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13043:                 if (ref($lastactref) eq 'HASH') {
                   13044:                     $lastactref->{'domainconfig'} = 1;
                   13045:                 }
1.129     raeburn  13046:             }
1.274     raeburn  13047:             if ($changes{'autofailsafe'}) {
                   13048:                 if ($failsafe ne '') {
1.299     raeburn  13049:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274     raeburn  13050:                 } else {
1.299     raeburn  13051:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274     raeburn  13052:                 }
                   13053:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   13054:                 if (ref($lastactref) eq 'HASH') {
                   13055:                     $lastactref->{'domdefaults'} = 1;
                   13056:                 }
                   13057:             }
1.1       raeburn  13058:             $resulttext .= '</ul>';
                   13059:         } else {
                   13060:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   13061:         }
                   13062:     } else {
1.11      albertel 13063:         $resulttext = '<span class="LC_error">'.
                   13064: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13065:     }
1.3       raeburn  13066:     return $resulttext;
1.1       raeburn  13067: }
                   13068: 
                   13069: sub modify_autoupdate {
1.3       raeburn  13070:     my ($dom,%domconfig) = @_;
1.1       raeburn  13071:     my ($resulttext,%currautoupdate,%fields,%changes);
                   13072:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   13073:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   13074:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   13075:         }
                   13076:     }
                   13077:     my @offon = ('off','on');
                   13078:     my %title = &Apache::lonlocal::texthash (
                   13079:                    run => 'Auto-update:',
                   13080:                    classlists => 'Updates to user information in classlists?'
                   13081:                 );
1.44      raeburn  13082:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13083:     my %fieldtitles = &Apache::lonlocal::texthash (
                   13084:                         id => 'Student/Employee ID',
1.20      raeburn  13085:                         permanentemail => 'E-mail address',
1.1       raeburn  13086:                         lastname => 'Last Name',
                   13087:                         firstname => 'First Name',
                   13088:                         middlename => 'Middle Name',
1.132     raeburn  13089:                         generation => 'Generation',
1.1       raeburn  13090:                       );
1.142     raeburn  13091:     $othertitle = &mt('All users');
1.1       raeburn  13092:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  13093:         $othertitle = &mt('Other users');
1.1       raeburn  13094:     }
                   13095:     foreach my $key (keys(%env)) {
                   13096:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  13097:             my ($usertype,$item) = ($1,$2);
                   13098:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   13099:                 if ($usertype eq 'default') {   
                   13100:                     push(@{$fields{$1}},$2);
                   13101:                 } elsif (ref($types) eq 'ARRAY') {
                   13102:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   13103:                         push(@{$fields{$1}},$2);
                   13104:                     }
                   13105:                 }
                   13106:             }
1.1       raeburn  13107:         }
                   13108:     }
1.131     raeburn  13109:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   13110:     @lockablenames = sort(@lockablenames);
                   13111:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   13112:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13113:         if (@changed) {
                   13114:             $changes{'lockablenames'} = 1;
                   13115:         }
                   13116:     } else {
                   13117:         if (@lockablenames) {
                   13118:             $changes{'lockablenames'} = 1;
                   13119:         }
                   13120:     }
1.1       raeburn  13121:     my %updatehash = (
                   13122:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   13123:                                       classlists => $env{'form.classlists'},
                   13124:                                       fields => {%fields},
1.131     raeburn  13125:                                       lockablenames => \@lockablenames,
1.1       raeburn  13126:                                     }
                   13127:                      );
                   13128:     foreach my $key (keys(%currautoupdate)) {
                   13129:         if (($key eq 'run') || ($key eq 'classlists')) {
                   13130:             if (exists($updatehash{autoupdate}{$key})) {
                   13131:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   13132:                     $changes{$key} = 1;
                   13133:                 }
                   13134:             }
                   13135:         } elsif ($key eq 'fields') {
                   13136:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  13137:                 foreach my $item (@{$types},'default') {
1.1       raeburn  13138:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   13139:                         my $change = 0;
                   13140:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   13141:                             if (!exists($fields{$item})) {
                   13142:                                 $change = 1;
1.132     raeburn  13143:                                 last;
1.1       raeburn  13144:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  13145:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  13146:                                     $change = 1;
1.132     raeburn  13147:                                     last;
1.1       raeburn  13148:                                 }
                   13149:                             }
                   13150:                         }
                   13151:                         if ($change) {
                   13152:                             push(@{$changes{$key}},$item);
                   13153:                         }
1.26      raeburn  13154:                     } 
1.1       raeburn  13155:                 }
                   13156:             }
1.131     raeburn  13157:         } elsif ($key eq 'lockablenames') {
                   13158:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   13159:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13160:                 if (@changed) {
                   13161:                     $changes{'lockablenames'} = 1;
                   13162:                 }
                   13163:             } else {
                   13164:                 if (@lockablenames) {
                   13165:                     $changes{'lockablenames'} = 1;
                   13166:                 }
                   13167:             }
                   13168:         }
                   13169:     }
                   13170:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   13171:         if (@lockablenames) {
                   13172:             $changes{'lockablenames'} = 1;
1.1       raeburn  13173:         }
                   13174:     }
1.26      raeburn  13175:     foreach my $item (@{$types},'default') {
                   13176:         if (defined($fields{$item})) {
                   13177:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  13178:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   13179:                     my $change = 0;
                   13180:                     if (ref($fields{$item}) eq 'ARRAY') {
                   13181:                         foreach my $type (@{$fields{$item}}) {
                   13182:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   13183:                                 $change = 1;
                   13184:                                 last;
                   13185:                             }
                   13186:                         }
                   13187:                     }
                   13188:                     if ($change) {
                   13189:                         push(@{$changes{'fields'}},$item);
                   13190:                     }
                   13191:                 } else {
1.26      raeburn  13192:                     push(@{$changes{'fields'}},$item);
                   13193:                 }
                   13194:             } else {
                   13195:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  13196:             }
                   13197:         }
                   13198:     }
                   13199:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   13200:                                              $dom);
                   13201:     if ($putresult eq 'ok') {
                   13202:         if (keys(%changes) > 0) {
                   13203:             $resulttext = &mt('Changes made:').'<ul>';
                   13204:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  13205:                 if ($key eq 'lockablenames') {
                   13206:                     $resulttext .= '<li>';
                   13207:                     if (@lockablenames) {
                   13208:                         $usertypes->{'default'} = $othertitle;
                   13209:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   13210:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   13211:                     } else {
                   13212:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   13213:                     }
                   13214:                     $resulttext .= '</li>';
                   13215:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  13216:                     foreach my $item (@{$changes{$key}}) {
                   13217:                         my @newvalues;
                   13218:                         foreach my $type (@{$fields{$item}}) {
                   13219:                             push(@newvalues,$fieldtitles{$type});
                   13220:                         }
1.3       raeburn  13221:                         my $newvaluestr;
                   13222:                         if (@newvalues > 0) {
                   13223:                             $newvaluestr = join(', ',@newvalues);
                   13224:                         } else {
                   13225:                             $newvaluestr = &mt('none');
1.6       raeburn  13226:                         }
1.1       raeburn  13227:                         if ($item eq 'default') {
1.26      raeburn  13228:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  13229:                         } else {
1.26      raeburn  13230:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  13231:                         }
                   13232:                     }
                   13233:                 } else {
                   13234:                     my $newvalue;
                   13235:                     if ($key eq 'run') {
                   13236:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   13237:                     } else {
                   13238:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  13239:                     }
1.1       raeburn  13240:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   13241:                 }
                   13242:             }
                   13243:             $resulttext .= '</ul>';
                   13244:         } else {
1.3       raeburn  13245:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  13246:         }
                   13247:     } else {
1.11      albertel 13248:         $resulttext = '<span class="LC_error">'.
                   13249: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13250:     }
1.3       raeburn  13251:     return $resulttext;
1.1       raeburn  13252: }
                   13253: 
1.125     raeburn  13254: sub modify_autocreate {
                   13255:     my ($dom,%domconfig) = @_;
                   13256:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   13257:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   13258:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   13259:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   13260:         }
                   13261:     }
                   13262:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   13263:                  req => 'Auto-creation of validated requests for official courses',
                   13264:                  xmldc => 'Identity of course creator of courses from XML files',
                   13265:                );
                   13266:     my @types = ('xml','req');
                   13267:     foreach my $item (@types) {
                   13268:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   13269:         $newvals{$item} =~ s/\D//g;
                   13270:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   13271:     }
                   13272:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  13273:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  13274:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   13275:         $newvals{'xmldc'} = '';
                   13276:     } 
                   13277:     %autocreatehash =  (
                   13278:                         autocreate => { xml => $newvals{'xml'},
                   13279:                                         req => $newvals{'req'},
                   13280:                                       }
                   13281:                        );
                   13282:     if ($newvals{'xmldc'} ne '') {
                   13283:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   13284:     }
                   13285:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   13286:                                              $dom);
                   13287:     if ($putresult eq 'ok') {
                   13288:         my @items = @types;
                   13289:         if ($newvals{'xml'}) {
                   13290:             push(@items,'xmldc');
                   13291:         }
                   13292:         foreach my $item (@items) {
                   13293:             if (exists($currautocreate{$item})) {
                   13294:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   13295:                     $changes{$item} = 1;
                   13296:                 }
                   13297:             } elsif ($newvals{$item}) {
                   13298:                 $changes{$item} = 1;
                   13299:             }
                   13300:         }
                   13301:         if (keys(%changes) > 0) {
                   13302:             my @offon = ('off','on'); 
                   13303:             $resulttext = &mt('Changes made:').'<ul>';
                   13304:             foreach my $item (@types) {
                   13305:                 if ($changes{$item}) {
                   13306:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  13307:                     $resulttext .= '<li>'.
                   13308:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   13309:                                        '<b>','</b>').
                   13310:                                    '</li>';
1.125     raeburn  13311:                 }
                   13312:             }
                   13313:             if ($changes{'xmldc'}) {
                   13314:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   13315:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  13316:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  13317:             }
                   13318:             $resulttext .= '</ul>';
                   13319:         } else {
                   13320:             $resulttext = &mt('No changes made to auto-creation settings');
                   13321:         }
                   13322:     } else {
                   13323:         $resulttext = '<span class="LC_error">'.
                   13324:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13325:     }
                   13326:     return $resulttext;
                   13327: }
                   13328: 
1.23      raeburn  13329: sub modify_directorysrch {
1.295     raeburn  13330:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  13331:     my ($resulttext,%changes);
                   13332:     my %currdirsrch;
                   13333:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   13334:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   13335:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   13336:         }
                   13337:     }
1.277     raeburn  13338:     my %title = ( available => 'Institutional directory search available',
                   13339:                   localonly => 'Other domains can search institution',
                   13340:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  13341:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  13342:                   searchby => 'Search types',
                   13343:                   searchtypes => 'Search latitude');
                   13344:     my @offon = ('off','on');
1.24      raeburn  13345:     my @otherdoms = ('Yes','No');
1.23      raeburn  13346: 
1.25      raeburn  13347:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  13348:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   13349:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   13350: 
1.44      raeburn  13351:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  13352:     if (keys(%{$usertypes}) == 0) {
                   13353:         @cansearch = ('default');
                   13354:     } else {
                   13355:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   13356:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   13357:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   13358:                     push(@{$changes{'cansearch'}},$type);
                   13359:                 }
1.23      raeburn  13360:             }
1.26      raeburn  13361:             foreach my $type (@cansearch) {
                   13362:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   13363:                     push(@{$changes{'cansearch'}},$type);
                   13364:                 }
1.23      raeburn  13365:             }
1.26      raeburn  13366:         } else {
                   13367:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  13368:         }
                   13369:     }
                   13370: 
                   13371:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   13372:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   13373:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   13374:                 push(@{$changes{'searchby'}},$by);
                   13375:             }
                   13376:         }
                   13377:         foreach my $by (@searchby) {
                   13378:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   13379:                 push(@{$changes{'searchby'}},$by);
                   13380:             }
                   13381:         }
                   13382:     } else {
                   13383:         push(@{$changes{'searchby'}},@searchby);
                   13384:     }
1.25      raeburn  13385: 
                   13386:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   13387:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   13388:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   13389:                 push(@{$changes{'searchtypes'}},$type);
                   13390:             }
                   13391:         }
                   13392:         foreach my $type (@searchtypes) {
                   13393:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   13394:                 push(@{$changes{'searchtypes'}},$type);
                   13395:             }
                   13396:         }
                   13397:     } else {
                   13398:         if (exists($currdirsrch{'searchtypes'})) {
                   13399:             foreach my $type (@searchtypes) {  
                   13400:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   13401:                     push(@{$changes{'searchtypes'}},$type);
                   13402:                 }
                   13403:             }
                   13404:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   13405:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   13406:             }   
                   13407:         } else {
                   13408:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   13409:         }
                   13410:     }
                   13411: 
1.23      raeburn  13412:     my %dirsrch_hash =  (
                   13413:             directorysrch => { available => $env{'form.dirsrch_available'},
                   13414:                                cansearch => \@cansearch,
1.277     raeburn  13415:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   13416:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   13417:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  13418:                                searchby => \@searchby,
1.25      raeburn  13419:                                searchtypes => \@searchtypes,
1.23      raeburn  13420:                              }
                   13421:             );
                   13422:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   13423:                                              $dom);
                   13424:     if ($putresult eq 'ok') {
                   13425:         if (exists($currdirsrch{'available'})) {
                   13426:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   13427:                  $changes{'available'} = 1;
                   13428:              }
                   13429:         } else {
                   13430:             if ($env{'form.dirsrch_available'} eq '1') {
                   13431:                 $changes{'available'} = 1;
                   13432:             }
                   13433:         }
1.277     raeburn  13434:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  13435:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   13436:                 $changes{'lcavailable'} = 1;
                   13437:             }
1.277     raeburn  13438:         } else {
                   13439:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   13440:                 $changes{'lcavailable'} = 1;
                   13441:             }
                   13442:         }
1.24      raeburn  13443:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  13444:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   13445:                 $changes{'localonly'} = 1;
                   13446:             }
1.24      raeburn  13447:         } else {
1.277     raeburn  13448:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  13449:                 $changes{'localonly'} = 1;
                   13450:             }
                   13451:         }
1.277     raeburn  13452:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  13453:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   13454:                 $changes{'lclocalonly'} = 1;
                   13455:             }
1.277     raeburn  13456:         } else {
                   13457:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   13458:                 $changes{'lclocalonly'} = 1;
                   13459:             }
                   13460:         }
1.23      raeburn  13461:         if (keys(%changes) > 0) {
                   13462:             $resulttext = &mt('Changes made:').'<ul>';
                   13463:             if ($changes{'available'}) {
                   13464:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   13465:             }
1.277     raeburn  13466:             if ($changes{'lcavailable'}) {
                   13467:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   13468:             }
1.24      raeburn  13469:             if ($changes{'localonly'}) {
1.277     raeburn  13470:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  13471:             }
1.277     raeburn  13472:             if ($changes{'lclocalonly'}) {
                   13473:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  13474:             }
1.23      raeburn  13475:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   13476:                 my $chgtext;
1.26      raeburn  13477:                 if (ref($usertypes) eq 'HASH') {
                   13478:                     if (keys(%{$usertypes}) > 0) {
                   13479:                         foreach my $type (@{$types}) {
                   13480:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   13481:                                 $chgtext .= $usertypes->{$type}.'; ';
                   13482:                             }
                   13483:                         }
                   13484:                         if (grep(/^default$/,@cansearch)) {
                   13485:                             $chgtext .= $othertitle;
                   13486:                         } else {
                   13487:                             $chgtext =~ s/\; $//;
                   13488:                         }
1.210     raeburn  13489:                         $resulttext .=
1.178     raeburn  13490:                             '<li>'.
                   13491:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   13492:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   13493:                             '</li>';
1.23      raeburn  13494:                     }
                   13495:                 }
                   13496:             }
                   13497:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   13498:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   13499:                 my $chgtext;
                   13500:                 foreach my $type (@{$titleorder}) {
                   13501:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   13502:                         if (defined($searchtitles->{$type})) {
                   13503:                             $chgtext .= $searchtitles->{$type}.'; ';
                   13504:                         }
                   13505:                     }
                   13506:                 }
                   13507:                 $chgtext =~ s/\; $//;
                   13508:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   13509:             }
1.25      raeburn  13510:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   13511:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   13512:                 my $chgtext;
                   13513:                 foreach my $type (@{$srchtypeorder}) {
                   13514:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   13515:                         if (defined($srchtypes_desc->{$type})) {
                   13516:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   13517:                         }
                   13518:                     }
                   13519:                 }
                   13520:                 $chgtext =~ s/\; $//;
1.178     raeburn  13521:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  13522:             }
                   13523:             $resulttext .= '</ul>';
1.295     raeburn  13524:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   13525:             if (ref($lastactref) eq 'HASH') {
                   13526:                 $lastactref->{'directorysrch'} = 1;
                   13527:             }
1.23      raeburn  13528:         } else {
1.277     raeburn  13529:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  13530:         }
                   13531:     } else {
                   13532:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  13533:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   13534:     }
                   13535:     return $resulttext;
                   13536: }
                   13537: 
1.28      raeburn  13538: sub modify_contacts {
1.205     raeburn  13539:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  13540:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   13541:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   13542:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   13543:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   13544:         }
                   13545:     }
1.286     raeburn  13546:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  13547:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  13548:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  13549:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  13550:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   13551:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  13552:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  13553:     foreach my $type (@mailings) {
                   13554:         @{$newsetting{$type}} = 
                   13555:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   13556:         foreach my $item (@contacts) {
                   13557:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   13558:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   13559:             } else {
                   13560:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   13561:             }
1.289     raeburn  13562:         }
1.28      raeburn  13563:         $others{$type} = $env{'form.'.$type.'_others'};
                   13564:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  13565:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13566:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   13567:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  13568:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   13569:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   13570:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   13571:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   13572:             }
1.134     raeburn  13573:         }
1.28      raeburn  13574:     }
                   13575:     foreach my $item (@contacts) {
                   13576:         $to{$item} = $env{'form.'.$item};
                   13577:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   13578:     }
1.203     raeburn  13579:     foreach my $item (@toggles) {
                   13580:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   13581:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   13582:         }
                   13583:     }
1.340     raeburn  13584:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   13585:     foreach my $item (@lonstatus) {
                   13586:         if ($item eq 'excluded') {
                   13587:             my (%serverhomes,@excluded);
                   13588:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   13589:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   13590:             if (@possexcluded) {
                   13591:                 foreach my $id (sort(@possexcluded)) {
                   13592:                     if ($serverhomes{$id}) {
                   13593:                         push(@excluded,$id);
                   13594:                     }
                   13595:                 }
                   13596:             }
                   13597:             if (@excluded) {
                   13598:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   13599:             }
                   13600:         } elsif ($item eq 'weights') {
                   13601:             foreach my $type ('E','W','N') {
                   13602:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   13603:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   13604:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   13605:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   13606:                             $env{'form.error'.$item.'_'.$type};
                   13607:                     }
                   13608:                 }
                   13609:             }
                   13610:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   13611:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   13612:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   13613:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   13614:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   13615:                 }
                   13616:             }
                   13617:         }
                   13618:     }
1.286     raeburn  13619:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   13620:         foreach my $field (@{$fields}) {
                   13621:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   13622:                 my $value = $env{'form.helpform_'.$field};
                   13623:                 $value =~ s/^\s+|\s+$//g;
                   13624:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  13625:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  13626:                     if ($field eq 'screenshot') {
                   13627:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   13628:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  13629:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  13630:                         }
                   13631:                     }
                   13632:                 }
                   13633:             }
                   13634:         }
                   13635:     }
1.315     raeburn  13636:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   13637:     my (@statuses,%usertypeshash,@overrides);
                   13638:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   13639:         @statuses = @{$types};
                   13640:         if (ref($usertypes) eq 'HASH') {
                   13641:             %usertypeshash = %{$usertypes};
                   13642:         }
                   13643:     }
                   13644:     if (@statuses) {
                   13645:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   13646:         foreach my $type (@possoverrides) {
                   13647:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   13648:                 push(@overrides,$type);
                   13649:             }
                   13650:         }
                   13651:         if (@overrides) {
                   13652:             foreach my $type (@overrides) {
                   13653:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   13654:                 foreach my $item (@contacts) {
                   13655:                     if (grep(/^\Q$item\E$/,@standard)) {
                   13656:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   13657:                         $newsetting{'override_'.$type}{$item} = 1;
                   13658:                     } else {
                   13659:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   13660:                         $newsetting{'override_'.$type}{$item} = 0;
                   13661:                     }
                   13662:                 }
                   13663:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   13664:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   13665:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   13666:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   13667:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   13668:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   13669:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   13670:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   13671:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   13672:                 }
                   13673:             }     
                   13674:         }
                   13675:     }
1.28      raeburn  13676:     if (keys(%currsetting) > 0) {
                   13677:         foreach my $item (@contacts) {
                   13678:             if ($to{$item} ne $currsetting{$item}) {
                   13679:                 $changes{$item} = 1;
                   13680:             }
                   13681:         }
                   13682:         foreach my $type (@mailings) {
                   13683:             foreach my $item (@contacts) {
                   13684:                 if (ref($currsetting{$type}) eq 'HASH') {
                   13685:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   13686:                         push(@{$changes{$type}},$item);
                   13687:                     }
                   13688:                 } else {
                   13689:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   13690:                 }
                   13691:             }
                   13692:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   13693:                 push(@{$changes{$type}},'others');
                   13694:             }
1.289     raeburn  13695:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13696:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   13697:                     push(@{$changes{$type}},'bcc'); 
                   13698:                 }
1.286     raeburn  13699:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   13700:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   13701:                     push(@{$changes{$type}},'include');
                   13702:                 }
                   13703:             }
                   13704:         }
                   13705:         if (ref($fields) eq 'ARRAY') {
                   13706:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   13707:                 foreach my $field (@{$fields}) {
                   13708:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   13709:                         push(@{$changes{'helpform'}},$field);
                   13710:                     }
                   13711:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   13712:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   13713:                             push(@{$changes{'helpform'}},'maxsize');
                   13714:                         }
                   13715:                     }
                   13716:                 }
                   13717:             } else {
                   13718:                 foreach my $field (@{$fields}) {
                   13719:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   13720:                         push(@{$changes{'helpform'}},$field);
                   13721:                     }
                   13722:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   13723:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   13724:                             push(@{$changes{'helpform'}},'maxsize');
                   13725:                         }
                   13726:                     }
                   13727:                 }
1.134     raeburn  13728:             }
1.28      raeburn  13729:         }
1.315     raeburn  13730:         if (@statuses) {
                   13731:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   13732:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   13733:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   13734:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   13735:                             foreach my $item (@contacts,'bcc','others','include') {
                   13736:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   13737:                                     push(@{$changes{'overrides'}},$key);
                   13738:                                     last;
                   13739:                                 }
                   13740:                             }
                   13741:                         } else {
                   13742:                             push(@{$changes{'overrides'}},$key);
                   13743:                         }
                   13744:                     }
                   13745:                 }
                   13746:                 foreach my $key (@overrides) {
                   13747:                     unless (exists($currsetting{'overrides'}{$key})) {
                   13748:                         push(@{$changes{'overrides'}},$key);
                   13749:                     }
                   13750:                 }
                   13751:             } else {
                   13752:                 foreach my $key (@overrides) {
                   13753:                     push(@{$changes{'overrides'}},$key); 
                   13754:                 }
                   13755:             }
                   13756:         }
1.340     raeburn  13757:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   13758:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   13759:                 if ($key eq 'excluded') {
                   13760:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   13761:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   13762:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   13763:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   13764:                             my @diffs =
                   13765:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   13766:                                                                    $currsetting{'lonstatus'}{$key});
                   13767:                             if (@diffs) {
                   13768:                                 push(@{$changes{'lonstatus'}},$key);
                   13769:                             }
                   13770:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   13771:                             push(@{$changes{'lonstatus'}},$key);
                   13772:                         }
                   13773:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   13774:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   13775:                         push(@{$changes{'lonstatus'}},$key);
                   13776:                     }
                   13777:                 } elsif ($key eq 'weights') {
                   13778:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   13779:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   13780:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  13781:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  13782:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   13783:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   13784:                                     push(@{$changes{'lonstatus'}},$key);
                   13785:                                     last;
                   13786:                                 }
                   13787:                             }
                   13788:                         } else {
1.341     raeburn  13789:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  13790:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   13791:                                     push(@{$changes{'lonstatus'}},$key);
                   13792:                                     last;
                   13793:                                 }
                   13794:                             }
                   13795:                         }
                   13796:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  13797:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  13798:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   13799:                                 push(@{$changes{'lonstatus'}},$key);
                   13800:                                 last;
                   13801:                             }
                   13802:                         }
                   13803:                     }
                   13804:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   13805:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   13806:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   13807:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   13808:                                 push(@{$changes{'lonstatus'}},$key);
                   13809:                             }
                   13810:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   13811:                             push(@{$changes{'lonstatus'}},$key);
                   13812:                         }
                   13813:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   13814:                         push(@{$changes{'lonstatus'}},$key);
                   13815:                     }
                   13816:                 }
                   13817:             }
                   13818:         } else {
                   13819:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   13820:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   13821:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   13822:                         push(@{$changes{'lonstatus'}},$key);
                   13823:                     }
                   13824:                 }
                   13825:             }
                   13826:         }
1.28      raeburn  13827:     } else {
                   13828:         my %default;
                   13829:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   13830:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   13831:         $default{'errormail'} = 'adminemail';
                   13832:         $default{'packagesmail'} = 'adminemail';
                   13833:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  13834:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  13835:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  13836:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  13837:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  13838:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  13839:         foreach my $item (@contacts) {
                   13840:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  13841:                $changes{$item} = 1;
1.203     raeburn  13842:            }
1.28      raeburn  13843:         }
                   13844:         foreach my $type (@mailings) {
                   13845:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   13846:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   13847:             }
                   13848:             if ($others{$type} ne '') {
                   13849:                 push(@{$changes{$type}},'others');
1.134     raeburn  13850:             }
1.286     raeburn  13851:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13852:                 if ($bcc{$type} ne '') {
                   13853:                     push(@{$changes{$type}},'bcc');
                   13854:                 }
1.286     raeburn  13855:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   13856:                     push(@{$changes{$type}},'include');
                   13857:                 }
1.134     raeburn  13858:             }
1.28      raeburn  13859:         }
1.286     raeburn  13860:         if (ref($fields) eq 'ARRAY') {
                   13861:             foreach my $field (@{$fields}) {
                   13862:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   13863:                     push(@{$changes{'helpform'}},$field);
                   13864:                 }
                   13865:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   13866:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   13867:                         push(@{$changes{'helpform'}},'maxsize');
                   13868:                     }
                   13869:                 }
                   13870:             }
1.289     raeburn  13871:         }
1.340     raeburn  13872:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   13873:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   13874:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   13875:                     push(@{$changes{'lonstatus'}},$key);
                   13876:                 }
                   13877:             }
                   13878:         }
1.28      raeburn  13879:     }
1.203     raeburn  13880:     foreach my $item (@toggles) {
                   13881:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   13882:             $changes{$item} = 1;
                   13883:         } elsif ((!$env{'form.'.$item}) &&
                   13884:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   13885:             $changes{$item} = 1;
                   13886:         }
                   13887:     }
1.28      raeburn  13888:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   13889:                                              $dom);
                   13890:     if ($putresult eq 'ok') {
                   13891:         if (keys(%changes) > 0) {
1.205     raeburn  13892:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13893:             if (ref($lastactref) eq 'HASH') {
                   13894:                 $lastactref->{'domainconfig'} = 1;
                   13895:             }
1.28      raeburn  13896:             my ($titles,$short_titles)  = &contact_titles();
                   13897:             $resulttext = &mt('Changes made:').'<ul>';
                   13898:             foreach my $item (@contacts) {
                   13899:                 if ($changes{$item}) {
                   13900:                     $resulttext .= '<li>'.$titles->{$item}.
                   13901:                                     &mt(' set to: ').
                   13902:                                     '<span class="LC_cusr_emph">'.
                   13903:                                     $to{$item}.'</span></li>';
                   13904:                 }
                   13905:             }
                   13906:             foreach my $type (@mailings) {
                   13907:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  13908:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  13909:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  13910:                     } else {
                   13911:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   13912:                     }
1.28      raeburn  13913:                     my @text;
                   13914:                     foreach my $item (@{$newsetting{$type}}) {
                   13915:                         push(@text,$short_titles->{$item});
                   13916:                     }
                   13917:                     if ($others{$type} ne '') {
                   13918:                         push(@text,$others{$type});
                   13919:                     }
1.286     raeburn  13920:                     if (@text) {
                   13921:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   13922:                                        join(', ',@text).'</span>';
                   13923:                     }
                   13924:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13925:                         if ($bcc{$type} ne '') {
1.286     raeburn  13926:                             my $bcctext;
                   13927:                             if (@text) {
1.289     raeburn  13928:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  13929:                             } else {
                   13930:                                 $bcctext = '(Bcc)';
                   13931:                             }
                   13932:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   13933:                         } elsif (!@text) {
                   13934:                             $resulttext .= &mt('No one');
                   13935:                         }   
1.289     raeburn  13936:                         if ($includestr{$type} ne '') {
1.286     raeburn  13937:                             if ($includeloc{$type} eq 'b') {
                   13938:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   13939:                             } elsif ($includeloc{$type} eq 's') {
                   13940:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   13941:                             }
1.134     raeburn  13942:                         }
1.286     raeburn  13943:                     } elsif (!@text) {
                   13944:                         $resulttext .= &mt('No recipients');
1.134     raeburn  13945:                     }
                   13946:                     $resulttext .= '</li>';
1.28      raeburn  13947:                 }
                   13948:             }
1.315     raeburn  13949:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   13950:                 my @deletions;
                   13951:                 foreach my $type (@{$changes{'overrides'}}) {
                   13952:                     if ($usertypeshash{$type}) {
                   13953:                         if (grep(/^\Q$type\E/,@overrides)) {
                   13954:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   13955:                                                       $usertypeshash{$type}).'<ul><li>';
                   13956:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   13957:                                 my @text;
                   13958:                                 foreach my $item (@contacts) {
                   13959:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   13960:                                         push(@text,$short_titles->{$item});
                   13961:                                     }
                   13962:                                 }
                   13963:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   13964:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   13965:                                 }
                   13966:   
                   13967:                                 if (@text) {
                   13968:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   13969:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   13970:                                 }
                   13971:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   13972:                                     my $bcctext;
                   13973:                                     if (@text) {
                   13974:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   13975:                                     } else {
                   13976:                                         $bcctext = '(Bcc)';
                   13977:                                     }
                   13978:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   13979:                                 } elsif (!@text) {
                   13980:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   13981:                                 }
                   13982:                                 $resulttext .= '</li>';
                   13983:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   13984:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   13985:                                     if ($loc eq 'b') {
                   13986:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   13987:                                     } elsif ($loc eq 's') {
                   13988:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   13989:                                     }
                   13990:                                 }
                   13991:                             }
                   13992:                             $resulttext .= '</li></ul></li>';
                   13993:                         } else {
                   13994:                             push(@deletions,$usertypeshash{$type});
                   13995:                         }
                   13996:                     }
                   13997:                 }
                   13998:                 if (@deletions) {
                   13999:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   14000:                                               join(', ',@deletions)).'</li>';
                   14001:                 }
                   14002:             }
1.203     raeburn  14003:             my @offon = ('off','on');
1.340     raeburn  14004:             my $corelink = &core_link_msu();
1.203     raeburn  14005:             if ($changes{'reporterrors'}) {
                   14006:                 $resulttext .= '<li>'.
                   14007:                                &mt('E-mail error reports to [_1] set to "'.
                   14008:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  14009:                                    $corelink).
1.203     raeburn  14010:                                '</li>';
                   14011:             }
                   14012:             if ($changes{'reportupdates'}) {
                   14013:                 $resulttext .= '<li>'.
                   14014:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   14015:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  14016:                                     $corelink).
1.203     raeburn  14017:                                 '</li>';
                   14018:             }
1.340     raeburn  14019:             if ($changes{'reportstatus'}) {
                   14020:                 $resulttext .= '<li>'.
                   14021:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   14022:                                     $offon[$env{'form.reportstatus'}].'".',
                   14023:                                     $corelink).
                   14024:                                 '</li>';
                   14025:             }
                   14026:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   14027:                 $resulttext .= '<li>'.
                   14028:                                &mt('Nightly status check e-mail settings').':<ul>';
                   14029:                 my (%defval,%use_def,%shown);
                   14030:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   14031:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   14032:                 $defval{'weights'} =
1.341     raeburn  14033:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  14034:                 $defval{'excluded'} = &mt('None');
                   14035:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   14036:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   14037:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   14038:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   14039:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   14040:                             } elsif ($item eq 'weights') {
                   14041:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  14042:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  14043:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   14044:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   14045:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   14046:                                         } else {
                   14047:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   14048:                                         }
                   14049:                                         $shown{$item} .= ', ';
                   14050:                                     }
                   14051:                                     $shown{$item} =~ s/, $//;
                   14052:                                 } else {
                   14053:                                     $shown{$item} = $defval{$item};
                   14054:                                 }
                   14055:                             } elsif ($item eq 'excluded') {
                   14056:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   14057:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   14058:                                 } else {
                   14059:                                     $shown{$item} = $defval{$item};
                   14060:                                 }
                   14061:                             }
                   14062:                         } else {
                   14063:                             $shown{$item} = $defval{$item};
                   14064:                         }
                   14065:                     }
                   14066:                 } else {
                   14067:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   14068:                         $shown{$item} = $defval{$item};
                   14069:                     }
                   14070:                 }
                   14071:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   14072:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   14073:                                           $shown{$item}).'</li>';
                   14074:                 }
                   14075:                 $resulttext .= '</ul></li>';
                   14076:             }
1.286     raeburn  14077:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   14078:                 my (@optional,@required,@unused,$maxsizechg);
                   14079:                 foreach my $field (@{$changes{'helpform'}}) {
                   14080:                     if ($field eq 'maxsize') {
                   14081:                         $maxsizechg = 1;
                   14082:                         next;
                   14083:                     }
                   14084:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  14085:                         push(@optional,$field);
1.286     raeburn  14086:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   14087:                         push(@unused,$field);
                   14088:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  14089:                         push(@required,$field);
1.286     raeburn  14090:                     }
                   14091:                 }
                   14092:                 if (@optional) {
                   14093:                     $resulttext .= '<li>'.
                   14094:                                    &mt('Help form fields changed to "Optional": [_1].',
                   14095:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   14096:                                    '</li>';
                   14097:                 }
                   14098:                 if (@required) {
                   14099:                     $resulttext .= '<li>'.
                   14100:                                    &mt('Help form fields changed to "Required": [_1].',
                   14101:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   14102:                                    '</li>';
                   14103:                 }
                   14104:                 if (@unused) {
                   14105:                     $resulttext .= '<li>'.
                   14106:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   14107:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   14108:                                    '</li>';
                   14109:                 }
                   14110:                 if ($maxsizechg) {
                   14111:                     $resulttext .= '<li>'.
                   14112:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   14113:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   14114:                                    '</li>';
                   14115:                 }
                   14116:             }
1.28      raeburn  14117:             $resulttext .= '</ul>';
                   14118:         } else {
1.288     raeburn  14119:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  14120:         }
                   14121:     } else {
                   14122:         $resulttext = '<span class="LC_error">'.
                   14123:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   14124:     }
                   14125:     return $resulttext;
                   14126: }
                   14127: 
1.357     raeburn  14128: sub modify_privacy {
                   14129:     my ($dom,%domconfig) = @_;
                   14130:     my ($resulttext,%current,%changes);
                   14131:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   14132:         %current = %{$domconfig{'privacy'}};
                   14133:     }
                   14134:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   14135:     my @items = ('domain','author','course','community');
                   14136:     my %names = &Apache::lonlocal::texthash (
                   14137:                    domain => 'Assigned domain role(s)',
                   14138:                    author => 'Assigned co-author role(s)',
                   14139:                    course => 'Assigned course role(s)',
                   14140:                    community => 'Assigned community role',
                   14141:                 );
                   14142:     my %roles = &Apache::lonlocal::texthash (
                   14143:                    domain => 'Domain role',
                   14144:                    author => 'Co-author role',
                   14145:                    course => 'Course role',
                   14146:                    community => 'Community role',
                   14147:                 );
                   14148:     my %titles = &Apache::lonlocal::texthash (
                   14149:                   approval => 'Approval for role in different domain',
                   14150:                   othdom   => 'User information available in other domain',
                   14151:                   priv     => 'Information viewable by privileged user in same domain',
                   14152:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   14153:                   instdom  => 'Other domain shares institution/provider',
                   14154:                   extdom   => 'Other domain has different institution/provider',
                   14155:                   none     => 'Not allowed',
                   14156:                   user     => 'User authorizes',
                   14157:                   domain   => 'Domain Coordinator authorizes',
                   14158:                   auto     => 'Unrestricted',
                   14159:     );
                   14160:     my %fieldnames = &Apache::lonlocal::texthash (
                   14161:                         id => 'Student/Employee ID',
                   14162:                         permanentemail => 'E-mail address',
                   14163:                         lastname => 'Last Name',
                   14164:                         firstname => 'First Name',
                   14165:                         middlename => 'Middle Name',
                   14166:                         generation => 'Generation',
                   14167:     );
                   14168:     my ($othertitle,$usertypes,$types) =
                   14169:         &Apache::loncommon::sorted_inst_types($dom);
                   14170:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   14171:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   14172: 
                   14173:     my %privacyhash = (
                   14174:                        'approval' => {
                   14175:                                        instdom => {},
                   14176:                                        extdom  => {},
                   14177:                                      },
                   14178:                        'othdom'   => {},
                   14179:                        'priv'     => {},
                   14180:                        'unpriv'   => {},
                   14181:                       );
                   14182:     foreach my $item (@items) {
                   14183:         if (@instdoms > 1) {
                   14184:             if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   14185:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   14186:             }
                   14187:             if (ref($current{'approval'}) eq 'HASH') {
                   14188:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   14189:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   14190:                         $changes{'approval'} = 1;
                   14191:                     }
                   14192:                 }
                   14193:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   14194:                 $changes{'approval'} = 1;
                   14195:             }
                   14196:         }
                   14197:         if (keys(%by_location) > 0) {
                   14198:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   14199:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   14200:             }
                   14201:             if (ref($current{'approval'}) eq 'HASH') {
                   14202:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   14203:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   14204:                         $changes{'approval'} = 1;
                   14205:                     }
                   14206:                 }
                   14207:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   14208:                 $changes{'approval'} = 1;
                   14209:             }
                   14210:         }
                   14211:         foreach my $status ('priv','unpriv') {
                   14212:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   14213:             my @newvalues;
                   14214:             foreach my $field (@possibles) {
                   14215:                 if (grep(/^\Q$field\E$/,@fields)) {
                   14216:                     $privacyhash{$status}{$item}{$field} = 1;
                   14217:                     push(@newvalues,$field);
                   14218:                 }
                   14219:             }
                   14220:             @newvalues = sort(@newvalues);
                   14221:             if (ref($current{$status}) eq 'HASH') {
                   14222:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   14223:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   14224:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   14225:                     if (@diffs > 0) {
                   14226:                         $changes{$status} = 1;
                   14227:                     }
                   14228:                 }
                   14229:             } else {
                   14230:                 my @stdfields;
                   14231:                 foreach my $field (@fields) {
                   14232:                     if ($field eq 'id') {
                   14233:                         next if ($status eq 'unpriv');
                   14234:                         next if (($status eq 'priv') && ($item eq 'community'));
                   14235:                     }
                   14236:                     push(@stdfields,$field);
                   14237:                 }
                   14238:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   14239:                 if (@diffs > 0) {
                   14240:                     $changes{$status} = 1;
                   14241:                 }
                   14242:             }
                   14243:         }
                   14244:     }
                   14245:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   14246:         my @statuses;
                   14247:         if (ref($types) eq 'ARRAY') {
                   14248:             @statuses = @{$types};
                   14249:         }
                   14250:         foreach my $type (@statuses,'default') {
                   14251:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   14252:             my @newvalues;
                   14253:             foreach my $field (sort(@possfields)) {
                   14254:                 if (grep(/^\Q$field\E$/,@fields)) {
                   14255:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   14256:                     push(@newvalues,$field);
                   14257:                 }
                   14258:             }
                   14259:             @newvalues = sort(@newvalues);
                   14260:             if (ref($current{'othdom'}) eq 'HASH') {
                   14261:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   14262:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   14263:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   14264:                     if (@diffs > 0) {
                   14265:                         $changes{'othdom'} = 1;
                   14266:                     }
                   14267:                 }
                   14268:             } else {
                   14269:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   14270:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   14271:                 if (@diffs > 0) {
                   14272:                     $changes{'othdom'} = 1;
                   14273:                 }
                   14274:             }
                   14275:         }
                   14276:     }
                   14277:     my %confighash = (
                   14278:                         privacy => \%privacyhash,
                   14279:                      );
                   14280:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   14281:     if ($putresult eq 'ok') {
                   14282:         if (keys(%changes) > 0) {
                   14283:             $resulttext = &mt('Changes made: ').'<ul>';
                   14284:             foreach my $key ('approval','othdom','priv','unpriv') {
                   14285:                 if ($changes{$key}) {
                   14286:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   14287:                     if ($key eq 'approval') {
                   14288:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   14289:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   14290:                             foreach my $item (@items) {
                   14291:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   14292:                             }
                   14293:                             $resulttext .= '</ul></li>';
                   14294:                         }
                   14295:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   14296:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   14297:                             foreach my $item (@items) {
                   14298:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   14299:                             }
                   14300:                             $resulttext .= '</ul></li>';
                   14301:                         }
                   14302:                     } elsif ($key eq 'othdom') {
                   14303:                         my @statuses;
                   14304:                         if (ref($types) eq 'ARRAY') {
                   14305:                             @statuses = @{$types};
                   14306:                         }
                   14307:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   14308:                             foreach my $status (@statuses,'default') {
                   14309:                                 if ($status eq 'default') {
                   14310:                                     $resulttext .= '<li>'.$othertitle.': ';
                   14311:                                 } elsif (ref($usertypes) eq 'HASH') {
                   14312:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   14313:                                 } else {
                   14314:                                     next;
                   14315:                                 }
                   14316:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   14317:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   14318:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   14319:                                     } else {
                   14320:                                         $resulttext .= &mt('none');
                   14321:                                     }
                   14322:                                 }
                   14323:                                 $resulttext .= '</li>';
                   14324:                             }
                   14325:                         }
                   14326:                     } else {
                   14327:                         foreach my $item (@items) {
                   14328:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   14329:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   14330:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   14331:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   14332:                                 } else {
                   14333:                                     $resulttext .= &mt('none');
                   14334:                                 }
                   14335:                                 $resulttext .= '</li>';
                   14336:                             }
                   14337:                         }
                   14338:                     }
                   14339:                     $resulttext .= '</ul></li>';
                   14340:                 }
                   14341:             }
                   14342:         } else {
                   14343:             $resulttext = &mt('No changes made to user information settings');
                   14344:         }
                   14345:     } else {
                   14346:         $resulttext = '<span class="LC_error">'.
                   14347:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14348:     }
                   14349:     return $resulttext;
                   14350: }
                   14351: 
1.354     raeburn  14352: sub modify_passwords {
                   14353:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  14354:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   14355:         $updatedefaults,$updateconf);
1.354     raeburn  14356:     my $customfn = 'resetpw.html';
                   14357:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   14358:         %current = %{$domconfig{'passwords'}};
                   14359:     }
                   14360:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14361:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   14362:     if (ref($types) eq 'ARRAY') {
                   14363:         @oktypes = @{$types};
                   14364:     }
                   14365:     push(@oktypes,'default');
                   14366: 
                   14367:     my %titles = &Apache::lonlocal::texthash (
                   14368:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   14369:         intauth_check  => 'Check bcrypt cost if authenticated',
                   14370:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   14371:         permanent      => 'Permanent e-mail address',
                   14372:         critical       => 'Critical notification address',
                   14373:         notify         => 'Notification address',
                   14374:         min            => 'Minimum password length',
                   14375:         max            => 'Maximum password length',
                   14376:         chars          => 'Required characters',
                   14377:         expire         => 'Password expiration (days)',
1.356     raeburn  14378:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  14379:         reset          => 'Resetting Forgotten Password',
                   14380:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   14381:         rules          => 'Rules for LON-CAPA Passwords',
                   14382:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   14383:         username       => 'Username',
                   14384:         email          => 'E-mail address',
                   14385:     );
                   14386: 
                   14387: #
                   14388: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   14389: #
                   14390:     my (%curr_defaults,%save_defaults);
                   14391:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   14392:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   14393:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   14394:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   14395:             } else {
                   14396:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   14397:             }
                   14398:         }
                   14399:     }
                   14400:     my %staticdefaults = (
                   14401:         'resetlink'      => 2,
                   14402:         'resetcase'      => \@oktypes,
                   14403:         'resetprelink'   => 'both',
                   14404:         'resetemail'     => ['critical','notify','permanent'],
                   14405:         'intauth_cost'   => 10,
                   14406:         'intauth_check'  => 0,
                   14407:         'intauth_switch' => 0,
                   14408:         'min'            => 7,
                   14409:     );
                   14410:     foreach my $type (@oktypes) {
                   14411:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   14412:     }
                   14413:     my $linklife = $env{'form.passwords_link'};
                   14414:     $linklife =~ s/^\s+|\s+$//g;
                   14415:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   14416:         $newvalues{'resetlink'} = $linklife;
                   14417:         if ($current{'resetlink'}) {
                   14418:             if ($current{'resetlink'} ne $linklife) {
                   14419:                 $changes{'reset'} = 1;
                   14420:             }
                   14421:         } elsif (!exists($domconfig{passwords})) {
                   14422:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   14423:                 $changes{'reset'} = 1;
                   14424:             }
                   14425:         }
                   14426:     } elsif ($current{'resetlink'}) {
                   14427:         $changes{'reset'} = 1;
                   14428:     }
                   14429:     my @casesens;
                   14430:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   14431:     foreach my $case (sort(@posscase)) {
                   14432:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   14433:             push(@casesens,$case);
                   14434:         }
                   14435:     }
                   14436:     $newvalues{'resetcase'} = \@casesens;
                   14437:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   14438:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   14439:         if (@diffs > 0) {
                   14440:             $changes{'reset'} = 1;
                   14441:         }
                   14442:     } elsif (!exists($domconfig{passwords})) {
                   14443:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   14444:         if (@diffs > 0) {
                   14445:             $changes{'reset'} = 1;
                   14446:         }
                   14447:     }
                   14448:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   14449:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   14450:         if (exists($current{'resetprelink'})) {
                   14451:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14452:                 $changes{'reset'} = 1;
                   14453:             }
                   14454:         } elsif (!exists($domconfig{passwords})) {
                   14455:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14456:                 $changes{'reset'} = 1;
                   14457:             }
                   14458:         }
                   14459:     } elsif ($current{'resetprelink'}) {
                   14460:         $changes{'reset'} = 1;
                   14461:     }
                   14462:     foreach my $type (@oktypes) {
                   14463:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   14464:         my @postlink;
                   14465:         foreach my $item (sort(@possplink)) {
                   14466:             if ($item =~ /^(email|username)$/) {
                   14467:                 push(@postlink,$item);
                   14468:             }
                   14469:         }
                   14470:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   14471:         unless ($changes{'reset'}) {
                   14472:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   14473:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14474:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   14475:                     if (@diffs > 0) {
                   14476:                         $changes{'reset'} = 1;
                   14477:                     }
                   14478:                 } else {
                   14479:                     $changes{'reset'} = 1;
                   14480:                 }
                   14481:             } elsif (!exists($domconfig{passwords})) {
                   14482:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   14483:                 if (@diffs > 0) {
                   14484:                     $changes{'reset'} = 1;
                   14485:                 }
                   14486:             }
                   14487:         }
                   14488:     }
                   14489:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   14490:     my @resetemail;
                   14491:     foreach my $item (sort(@possemailsrc)) {
                   14492:         if ($item =~ /^(permanent|critical|notify)$/) {
                   14493:             push(@resetemail,$item);
                   14494:         }
                   14495:     }
                   14496:     $newvalues{'resetemail'} = \@resetemail;
                   14497:     unless ($changes{'reset'}) {
                   14498:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   14499:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   14500:             if (@diffs > 0) {
                   14501:                 $changes{'reset'} = 1;
                   14502:             }
                   14503:         } elsif (!exists($domconfig{passwords})) {
                   14504:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   14505:             if (@diffs > 0) {
                   14506:                 $changes{'reset'} = 1;
                   14507:             }
                   14508:         }
                   14509:     }
                   14510:     if ($env{'form.passwords_stdtext'} == 0) {
                   14511:         $newvalues{'resetremove'} = 1;
                   14512:         unless ($current{'resetremove'}) {
                   14513:             $changes{'reset'} = 1;
                   14514:         }
                   14515:     } elsif ($current{'resetremove'}) {
                   14516:         $changes{'reset'} = 1;
                   14517:     }
                   14518:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   14519:         my $servadm = $r->dir_config('lonAdmEMail');
                   14520:         my ($configuserok,$author_ok,$switchserver) =
                   14521:             &config_check($dom,$confname,$servadm);
                   14522:         my $error;
                   14523:         if ($configuserok eq 'ok') {
                   14524:             if ($switchserver) {
                   14525:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   14526:             } else {
                   14527:                 if ($author_ok eq 'ok') {
                   14528:                     my ($result,$customurl) =
                   14529:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   14530:                                      $confname,'customtext/resetpw','','',$customfn);
                   14531:                     if ($result eq 'ok') {
                   14532:                         $newvalues{'resetcustom'} = $customurl;
                   14533:                         $changes{'reset'} = 1;
                   14534:                     } else {
                   14535:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   14536:                     }
                   14537:                 } else {
                   14538:                     $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);
                   14539:                 }
                   14540:             }
                   14541:         } else {
                   14542:             $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);
                   14543:         }
                   14544:         if ($error) {
                   14545:             &Apache::lonnet::logthis($error);
                   14546:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14547:         }
                   14548:     } elsif ($current{'resetcustom'}) {
                   14549:         if ($env{'form.passwords_custom_del'}) {
                   14550:             $changes{'reset'} = 1;
                   14551:         } else {
                   14552:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   14553:         }
                   14554:     }
                   14555:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   14556:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   14557:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   14558:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   14559:             $changes{'intauth'} = 1;
                   14560:         }
                   14561:     } else {
                   14562:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   14563:     }
                   14564:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   14565:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   14566:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   14567:             $changes{'intauth'} = 1;
                   14568:         }
                   14569:     } else {
                   14570:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14571:     }
                   14572:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   14573:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   14574:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   14575:             $changes{'intauth'} = 1;
                   14576:         }
                   14577:     } else {
                   14578:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14579:     }
                   14580:     foreach my $item ('cost','check','switch') {
                   14581:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   14582:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   14583:             $updatedefaults = 1;
                   14584:         }
                   14585:     }
1.356     raeburn  14586:     foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  14587:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356     raeburn  14588:         my $ruleok;
                   14589:         if ($rule eq 'expire') {
                   14590:             if ($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) {
                   14591:                 $ruleok = 1; 
                   14592:             }
                   14593:         } elsif ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   14594:             $ruleok = 1;
                   14595:         }
                   14596:         if ($ruleok) {
1.354     raeburn  14597:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   14598:             if (exists($current{$rule})) {
                   14599:                 if ($newvalues{$rule} ne $current{$rule}) {
                   14600:                     $changes{'rules'} = 1;
                   14601:                 }
                   14602:             } elsif ($rule eq 'min') {
                   14603:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   14604:                     $changes{'rules'} = 1;
                   14605:                 }
                   14606:             }
                   14607:         } elsif (exists($current{$rule})) {
                   14608:             $changes{'rules'} = 1;
                   14609:         }
                   14610:     }
                   14611:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   14612:     my @chars;
                   14613:     foreach my $item (sort(@posschars)) {
                   14614:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   14615:             push(@chars,$item);
                   14616:         }
                   14617:     }
                   14618:     $newvalues{'chars'} = \@chars;
                   14619:     unless ($changes{'rules'}) {
                   14620:         if (ref($current{'chars'}) eq 'ARRAY') {
                   14621:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   14622:             if (@diffs > 0) {
                   14623:                 $changes{'rules'} = 1;
                   14624:             }
                   14625:         } else {
                   14626:             if (@chars > 0) {
                   14627:                 $changes{'rules'} = 1;
                   14628:             }
                   14629:         }
                   14630:     }
                   14631:     if ($env{'form.passwords_crsowner'}) {
                   14632:         $newvalues{'crsownerchg'} = 1;
                   14633:         unless ($current{'crsownerchg'}) {
                   14634:             $changes{'crsownerchg'} = 1;
                   14635:         }
                   14636:     } elsif ($current{'crsownerchg'}) {
                   14637:         $changes{'crsownerchg'} = 1;
                   14638:     }
                   14639: 
                   14640:     my %confighash = (
                   14641:                         defaults  => \%save_defaults,
                   14642:                         passwords => \%newvalues,
                   14643:                      );
                   14644:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   14645: 
                   14646:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   14647:     if ($putresult eq 'ok') {
                   14648:         if (keys(%changes) > 0) {
                   14649:             $resulttext = &mt('Changes made: ').'<ul>';
                   14650:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   14651:                 if ($changes{$key}) {
1.355     raeburn  14652:                     unless ($key eq 'intauth') {
                   14653:                         $updateconf = 1;
                   14654:                     }
1.354     raeburn  14655:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   14656:                     if ($key eq 'reset') {
                   14657:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   14658:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   14659:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   14660:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
                   14661:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />'.
                   14662:                                            &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchapub'}).'</br>'.
                   14663:                                            &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchapriv'}).'</li>';
                   14664:                         } else {
                   14665:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   14666:                         }
                   14667:                         if ($confighash{'passwords'}{'resetlink'}) {
                   14668:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   14669:                         } else {
                   14670:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   14671:                                                   &mt('Will default to 2 hours').'</li>';
                   14672:                         }
                   14673:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   14674:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   14675:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   14676:                             } else {
                   14677:                                 my $casesens;
                   14678:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   14679:                                     if ($type eq 'default') {
                   14680:                                         $casesens .= $othertitle.', ';
                   14681:                                     } elsif ($usertypes->{$type} ne '') {
                   14682:                                         $casesens .= $usertypes->{$type}.', ';
                   14683:                                     }
                   14684:                                 }
                   14685:                                 $casesens =~ s/\Q, \E$//;
                   14686:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   14687:                             }
                   14688:                         } else {
                   14689:                             $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>';
                   14690:                         }
                   14691:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   14692:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   14693:                         } else {
                   14694:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   14695:                         }
                   14696:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   14697:                             my $output;
                   14698:                             if (ref($types) eq 'ARRAY') {
                   14699:                                 foreach my $type (@{$types}) {
                   14700:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14701:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   14702:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   14703:                                         } else {
                   14704:                                             $output .= $usertypes->{$type}.' -- '.
                   14705:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   14706:                                         }
                   14707:                                     }
                   14708:                                 }
                   14709:                             }
                   14710:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   14711:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   14712:                                     $output .= $othertitle.' -- '.&mt('none');
                   14713:                                 } else {
                   14714:                                     $output .= $othertitle.' -- '.
                   14715:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   14716:                                 }
                   14717:                             }
                   14718:                             if ($output) {
                   14719:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   14720:                             } else {
                   14721:                                 $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>';
                   14722:                             }
                   14723:                         } else {
                   14724:                             $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>';
                   14725:                         }
                   14726:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   14727:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   14728:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   14729:                             } else {
                   14730:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   14731:                             }
                   14732:                         } else {
                   14733:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   14734:                         }
                   14735:                         if ($confighash{'passwords'}{'resetremove'}) {
                   14736:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   14737:                         } else {
                   14738:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   14739:                         }
                   14740:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   14741:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
                   14742:                                                                             $titles{custom},600,500);
                   14743:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes [_1]',$customlink).'</li>';
                   14744:                         } else {
                   14745:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   14746:                         }
                   14747:                     } elsif ($key eq 'intauth') {
                   14748:                         foreach my $item ('cost','switch','check') {
                   14749:                             my $value = $save_defaults{$key.'_'.$item};
                   14750:                             if ($item eq 'switch') {
                   14751:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14752:                                                      0 => 'No',
                   14753:                                                      1 => 'Yes',
                   14754:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   14755:                                                  );
                   14756:                                 if ($value =~ /^(0|1|2)$/) {
                   14757:                                     $value = $optiondesc{$value};
                   14758:                                 } else {
                   14759:                                     $value = &mt('none -- defaults to No');
                   14760:                                 }
                   14761:                             } elsif ($item eq 'check') {
                   14762:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14763:                                                      0 => 'No',
                   14764:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   14765:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   14766:                                                  );
                   14767:                                 if ($value =~ /^(0|1|2)$/) {
                   14768:                                     $value = $optiondesc{$value};
                   14769:                                 } else {
                   14770:                                     $value = &mt('none -- defaults to No');
                   14771:                                 }
                   14772:                             }
                   14773:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   14774:                         }
                   14775:                     } elsif ($key eq 'rules') {
1.356     raeburn  14776:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  14777:                             if ($confighash{'passwords'}{$rule} eq '') {
                   14778:                                 if ($rule eq 'min') {
1.356     raeburn  14779:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
                   14780:                                                    ' '.&mt('Default of 7 will be used').'</li>';
                   14781:                                 } else {
                   14782:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  14783:                                 }
                   14784:                             } else {
                   14785:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   14786:                             }
                   14787:                         }
                   14788:                     } elsif ($key eq 'crsownerchg') {
                   14789:                         if ($confighash{'passwords'}{'crsownerchg'}) {
                   14790:                             $resulttext .= '<li>'.&mt('Course owner may change student passwords.').'</li>';
                   14791:                         } else {
                   14792:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.');
                   14793:                         }
                   14794:                     }
                   14795:                     $resulttext .= '</ul></li>';
                   14796:                 }
                   14797:             }
                   14798:             $resulttext .= '</ul>';
                   14799:         } else {
                   14800:             $resulttext = &mt('No changes made to password settings');
                   14801:         }
1.355     raeburn  14802:         my $cachetime = 24*60*60;
1.354     raeburn  14803:         if ($updatedefaults) {
                   14804:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14805:             if (ref($lastactref) eq 'HASH') {
                   14806:                 $lastactref->{'domdefaults'} = 1;
                   14807:             }
                   14808:         }
1.355     raeburn  14809:         if ($updateconf) {
                   14810:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   14811:             if (ref($lastactref) eq 'HASH') {
                   14812:                 $lastactref->{'passwdconf'} = 1;
                   14813:             }
                   14814:         }
1.354     raeburn  14815:     } else {
                   14816:         $resulttext = '<span class="LC_error">'.
                   14817:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14818:     }
                   14819:     if ($errors) {
                   14820:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   14821:                        $errors.'</ul></p>';
                   14822:     }
                   14823:     return $resulttext;
                   14824: }
                   14825: 
1.28      raeburn  14826: sub modify_usercreation {
1.27      raeburn  14827:     my ($dom,%domconfig) = @_;
1.224     raeburn  14828:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  14829:     my $warningmsg;
1.27      raeburn  14830:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   14831:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  14832:             if ($key eq 'cancreate') {
                   14833:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   14834:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  14835:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   14836:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   14837:                         } else {
1.224     raeburn  14838:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   14839:                         }
                   14840:                     }
                   14841:                 }
                   14842:             } elsif ($key eq 'email_rule') {
                   14843:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   14844:             } else {
                   14845:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   14846:             }
1.27      raeburn  14847:         }
                   14848:     }
                   14849:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  14850:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  14851:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  14852:     foreach my $item(@contexts) {
1.224     raeburn  14853:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  14854:     }
1.34      raeburn  14855:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   14856:         foreach my $item (@contexts) {
1.224     raeburn  14857:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   14858:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  14859:             }
1.27      raeburn  14860:         }
1.34      raeburn  14861:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   14862:         foreach my $item (@contexts) {
1.43      raeburn  14863:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  14864:                 if ($cancreate{$item} ne 'any') {
                   14865:                     push(@{$changes{'cancreate'}},$item);
                   14866:                 }
                   14867:             } else {
                   14868:                 if ($cancreate{$item} ne 'none') {
                   14869:                     push(@{$changes{'cancreate'}},$item);
                   14870:                 }
1.27      raeburn  14871:             }
                   14872:         }
                   14873:     } else {
1.43      raeburn  14874:         foreach my $item (@contexts)  {
1.34      raeburn  14875:             push(@{$changes{'cancreate'}},$item);
                   14876:         }
1.27      raeburn  14877:     }
1.34      raeburn  14878: 
1.27      raeburn  14879:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   14880:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   14881:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   14882:                 push(@{$changes{'username_rule'}},$type);
                   14883:             }
                   14884:         }
                   14885:         foreach my $type (@username_rule) {
                   14886:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   14887:                 push(@{$changes{'username_rule'}},$type);
                   14888:             }
                   14889:         }
                   14890:     } else {
                   14891:         push(@{$changes{'username_rule'}},@username_rule);
                   14892:     }
                   14893: 
1.32      raeburn  14894:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   14895:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   14896:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   14897:                 push(@{$changes{'id_rule'}},$type);
                   14898:             }
                   14899:         }
                   14900:         foreach my $type (@id_rule) {
                   14901:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   14902:                 push(@{$changes{'id_rule'}},$type);
                   14903:             }
                   14904:         }
                   14905:     } else {
                   14906:         push(@{$changes{'id_rule'}},@id_rule);
                   14907:     }
                   14908: 
1.43      raeburn  14909:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  14910:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  14911:     my %authhash;
1.43      raeburn  14912:     foreach my $item (@authen_contexts) {
1.28      raeburn  14913:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   14914:         foreach my $auth (@authtypes) {
                   14915:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   14916:                 $authhash{$item}{$auth} = 1;
                   14917:             } else {
                   14918:                 $authhash{$item}{$auth} = 0;
                   14919:             }
                   14920:         }
                   14921:     }
                   14922:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  14923:         foreach my $item (@authen_contexts) {
1.28      raeburn  14924:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   14925:                 foreach my $auth (@authtypes) {
                   14926:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   14927:                         push(@{$changes{'authtypes'}},$item);
                   14928:                         last;
                   14929:                     }
                   14930:                 }
                   14931:             }
                   14932:         }
                   14933:     } else {
1.43      raeburn  14934:         foreach my $item (@authen_contexts) {
1.28      raeburn  14935:             push(@{$changes{'authtypes'}},$item);
                   14936:         }
                   14937:     }
                   14938: 
1.224     raeburn  14939:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   14940:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   14941:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   14942:     $save_usercreate{'id_rule'} = \@id_rule;
                   14943:     $save_usercreate{'username_rule'} = \@username_rule,
                   14944:     $save_usercreate{'authtypes'} = \%authhash;
                   14945: 
1.27      raeburn  14946:     my %usercreation_hash =  (
1.224     raeburn  14947:         usercreation     => \%save_usercreate,
                   14948:     );
1.27      raeburn  14949: 
                   14950:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   14951:                                              $dom);
1.50      raeburn  14952: 
1.224     raeburn  14953:     if ($putresult eq 'ok') {
                   14954:         if (keys(%changes) > 0) {
                   14955:             $resulttext = &mt('Changes made:').'<ul>';
                   14956:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   14957:                 my %lt = &usercreation_types();
                   14958:                 foreach my $type (@{$changes{'cancreate'}}) {
                   14959:                     my $chgtext = $lt{$type}.', ';
                   14960:                     if ($cancreate{$type} eq 'none') {
                   14961:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   14962:                     } elsif ($cancreate{$type} eq 'any') {
                   14963:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   14964:                     } elsif ($cancreate{$type} eq 'official') {
                   14965:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   14966:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   14967:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   14968:                     }
                   14969:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   14970:                 }
                   14971:             }
                   14972:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   14973:                 my ($rules,$ruleorder) = 
                   14974:                     &Apache::lonnet::inst_userrules($dom,'username');
                   14975:                 my $chgtext = '<ul>';
                   14976:                 foreach my $type (@username_rule) {
                   14977:                     if (ref($rules->{$type}) eq 'HASH') {
                   14978:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   14979:                     }
                   14980:                 }
                   14981:                 $chgtext .= '</ul>';
                   14982:                 if (@username_rule > 0) {
                   14983:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   14984:                 } else {
                   14985:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   14986:                 }
                   14987:             }
                   14988:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   14989:                 my ($idrules,$idruleorder) = 
                   14990:                     &Apache::lonnet::inst_userrules($dom,'id');
                   14991:                 my $chgtext = '<ul>';
                   14992:                 foreach my $type (@id_rule) {
                   14993:                     if (ref($idrules->{$type}) eq 'HASH') {
                   14994:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   14995:                     }
                   14996:                 }
                   14997:                 $chgtext .= '</ul>';
                   14998:                 if (@id_rule > 0) {
                   14999:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   15000:                 } else {
                   15001:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   15002:                 }
                   15003:             }
                   15004:             my %authname = &authtype_names();
                   15005:             my %context_title = &context_names();
                   15006:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   15007:                 my $chgtext = '<ul>';
                   15008:                 foreach my $type (@{$changes{'authtypes'}}) {
                   15009:                     my @allowed;
                   15010:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   15011:                     foreach my $auth (@authtypes) {
                   15012:                         if ($authhash{$type}{$auth}) {
                   15013:                             push(@allowed,$authname{$auth});
                   15014:                         }
                   15015:                     }
                   15016:                     if (@allowed > 0) {
                   15017:                         $chgtext .= join(', ',@allowed).'</li>';
                   15018:                     } else {
                   15019:                         $chgtext .= &mt('none').'</li>';
                   15020:                     }
                   15021:                 }
                   15022:                 $chgtext .= '</ul>';
                   15023:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   15024:                 $resulttext .= '</li>';
                   15025:             }
                   15026:             $resulttext .= '</ul>';
                   15027:         } else {
                   15028:             $resulttext = &mt('No changes made to user creation settings');
                   15029:         }
                   15030:     } else {
                   15031:         $resulttext = '<span class="LC_error">'.
                   15032:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15033:     }
                   15034:     if ($warningmsg ne '') {
                   15035:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   15036:     }
                   15037:     return $resulttext;
                   15038: }
                   15039: 
                   15040: sub modify_selfcreation {
1.305     raeburn  15041:     my ($dom,$lastactref,%domconfig) = @_;
                   15042:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   15043:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   15044:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  15045:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   15046:     if (ref($typesref) eq 'ARRAY') {
                   15047:         @types = @{$typesref};
                   15048:     }
                   15049:     if (ref($usertypesref) eq 'HASH') {
                   15050:         %usertypes = %{$usertypesref};
1.228     raeburn  15051:     }
1.303     raeburn  15052:     $usertypes{'default'} = $othertitle;
1.224     raeburn  15053: #
                   15054: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   15055: #
                   15056:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   15057:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   15058:             if ($key eq 'cancreate') {
                   15059:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   15060:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   15061:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  15062:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   15063:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   15064:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   15065:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  15066:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  15067:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15068:                         } else {
                   15069:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15070:                         }
                   15071:                     }
                   15072:                 }
                   15073:             } elsif ($key eq 'email_rule') {
                   15074:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   15075:             } else {
                   15076:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   15077:             }
                   15078:         }
                   15079:     }
                   15080: #
                   15081: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   15082: #
                   15083:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   15084:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   15085:             if ($key eq 'selfcreate') {
                   15086:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15087:             } else {
                   15088:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15089:             }
                   15090:         }
                   15091:     }
1.305     raeburn  15092: #
                   15093: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   15094: #
                   15095:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   15096:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   15097:             if ($key eq 'inststatusguest') {
                   15098:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15099:             } else {
                   15100:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15101:             }
                   15102:         }
                   15103:     }
1.224     raeburn  15104: 
                   15105:     my @contexts = ('selfcreate');
                   15106:     @{$cancreate{'selfcreate'}} = ();
                   15107:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  15108:     if (@types) {
                   15109:         @{$cancreate{'statustocreate'}} = ();
                   15110:     }
1.236     raeburn  15111:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  15112:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  15113:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  15114:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  15115:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  15116:     my %selfcreatetypes = (
                   15117:                              sso   => 'users authenticated by institutional single sign on',
                   15118:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  15119:                              email => 'users verified by e-mail',
1.50      raeburn  15120:                           );
1.224     raeburn  15121: #
                   15122: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   15123: # is permitted.
                   15124: #
1.305     raeburn  15125:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  15126: 
1.305     raeburn  15127:     my (@statuses,%email_rule);
1.228     raeburn  15128:     foreach my $item ('login','sso','email') {
1.224     raeburn  15129:         if ($item eq 'email') {
1.236     raeburn  15130:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  15131:                 if (@types) {
                   15132:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   15133:                     foreach my $status (@poss_statuses) {
                   15134:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   15135:                             push(@statuses,$status);
                   15136:                         }
                   15137:                     }
                   15138:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   15139:                 } else {
                   15140:                     push(@statuses,'default');
                   15141:                 }
                   15142:                 if (@statuses) {
                   15143:                     my %curr_rule;
                   15144:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   15145:                         foreach my $type (@statuses) {
                   15146:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  15147:                         }
1.305     raeburn  15148:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   15149:                         foreach my $type (@statuses) {
                   15150:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   15151:                         }
                   15152:                     }
                   15153:                     push(@{$cancreate{'selfcreate'}},'email');
                   15154:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   15155:                     my %curremaildom;
                   15156:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   15157:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   15158:                     }
                   15159:                     foreach my $type (@statuses) {
                   15160:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   15161:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   15162:                         }
                   15163:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   15164:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   15165:                         }
                   15166:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   15167: #
                   15168: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   15169: #
                   15170:                             my $chosen = $1;
                   15171:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   15172:                                 my $emaildom;
                   15173:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   15174:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   15175:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   15176:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   15177:                                         if (exists($curremaildom{$type}{$chosen})) {
                   15178:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   15179:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   15180:                                             }
                   15181:                                         } elsif ($emaildom ne '') {
                   15182:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   15183:                                         }
                   15184:                                     } elsif ($emaildom ne '') {
                   15185:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   15186:                                     } 
                   15187:                                 }
                   15188:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15189:                             } elsif ($chosen eq 'custom') {
                   15190:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   15191:                                 $email_rule{$type} = [];
                   15192:                                 if (ref($emailrules) eq 'HASH') {
                   15193:                                     foreach my $rule (@possemail_rules) {
                   15194:                                         if (exists($emailrules->{$rule})) {
                   15195:                                             push(@{$email_rule{$type}},$rule);
                   15196:                                         }
                   15197:                                     }
                   15198:                                 }
                   15199:                                 if (@{$email_rule{$type}}) {
                   15200:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   15201:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   15202:                                         if (@{$curr_rule{$type}} > 0) {
                   15203:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   15204:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   15205:                                                     push(@{$changes{'email_rule'}},$type);
                   15206:                                                 }
                   15207:                                             }
                   15208:                                         }
                   15209:                                         foreach my $type (@{$email_rule{$type}}) {
                   15210:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   15211:                                                 push(@{$changes{'email_rule'}},$type);
                   15212:                                             }
                   15213:                                         }
                   15214:                                     } else {
                   15215:                                         push(@{$changes{'email_rule'}},$type);
                   15216:                                     }
                   15217:                                 }
                   15218:                             } else {
                   15219:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15220:                             }
                   15221:                         }
                   15222:                     }
                   15223:                     if (@types) {
                   15224:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15225:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   15226:                             if (@changed) {
                   15227:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   15228:                             }
                   15229:                         } else {
                   15230:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15231:                         }
                   15232:                     }
                   15233:                 } else {
                   15234:                     delete($env{'form.cancreate_email'});
                   15235:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15236:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15237:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15238:                         }
                   15239:                     }
                   15240:                 }
                   15241:             } else {
                   15242:                 $save_inststatus{'inststatusguest'} = [];
                   15243:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15244:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15245:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  15246:                     }
                   15247:                 }
1.224     raeburn  15248:             }
                   15249:         } else {
                   15250:             if ($env{'form.cancreate_'.$item}) {
                   15251:                 push(@{$cancreate{'selfcreate'}},$item);
                   15252:             }
                   15253:         }
                   15254:     }
1.305     raeburn  15255:     my (%userinfo,%savecaptcha);
1.224     raeburn  15256:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   15257: #
1.228     raeburn  15258: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   15259: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  15260: #
1.236     raeburn  15261: 
1.244     raeburn  15262:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  15263:         push(@contexts,'emailusername');
1.305     raeburn  15264:         if (@statuses) {
                   15265:             foreach my $type (@statuses) {
1.228     raeburn  15266:                 if (ref($infofields) eq 'ARRAY') {
                   15267:                     foreach my $field (@{$infofields}) {
                   15268:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   15269:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   15270:                         }
                   15271:                     }
1.224     raeburn  15272:                 }
                   15273:             }
                   15274:         }
                   15275: #
                   15276: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  15277: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  15278: #
                   15279: 
                   15280:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   15281:         @approvalnotify = sort(@approvalnotify);
                   15282:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   15283:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15284:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   15285:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   15286:                     push(@{$changes{'cancreate'}},'notify');
                   15287:                 }
                   15288:             } else {
                   15289:                 if ($cancreate{'notify'}{'approval'}) {
                   15290:                     push(@{$changes{'cancreate'}},'notify');
                   15291:                 }
                   15292:             }
                   15293:         } elsif ($cancreate{'notify'}{'approval'}) {
                   15294:             push(@{$changes{'cancreate'}},'notify');
                   15295:         }
                   15296: 
                   15297:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   15298:     }
                   15299: #  
1.236     raeburn  15300: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  15301: # institutional log-in.
                   15302: #
                   15303:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   15304:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   15305:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   15306:             $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.').' '.
                   15307:                           &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.');
                   15308:         }
                   15309:     }
                   15310:     my @fields = ('lastname','firstname','middlename','generation',
                   15311:                   'permanentemail','id');
1.240     raeburn  15312:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  15313:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   15314: #
                   15315: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   15316: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   15317: # may self-create accounts 
                   15318: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   15319: # which the user may supply, if institutional data is unavailable.
                   15320: #
                   15321:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  15322:         if (@types) {
1.305     raeburn  15323:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   15324:             push(@contexts,'statustocreate');
1.303     raeburn  15325:             foreach my $type (@types) {
1.224     raeburn  15326:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   15327:                 foreach my $field (@fields) {
                   15328:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   15329:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   15330:                     } else {
                   15331:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   15332:                     }
                   15333:                 }
                   15334:             }
                   15335:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  15336:                 foreach my $type (@types) {
1.224     raeburn  15337:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   15338:                         foreach my $field (@fields) {
                   15339:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   15340:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   15341:                                 push(@{$changes{'selfcreate'}},$type);
                   15342:                                 last;
                   15343:                             }
                   15344:                         }
                   15345:                     }
                   15346:                 }
                   15347:             } else {
1.303     raeburn  15348:                 foreach my $type (@types) {
1.224     raeburn  15349:                     push(@{$changes{'selfcreate'}},$type);
                   15350:                 }
                   15351:             }
                   15352:         }
1.240     raeburn  15353:         foreach my $field (@shibfields) {
                   15354:             if ($env{'form.shibenv_'.$field} ne '') {
                   15355:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   15356:             }
                   15357:         }
                   15358:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15359:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   15360:                 foreach my $field (@shibfields) {
                   15361:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   15362:                         push(@{$changes{'cancreate'}},'shibenv');
                   15363:                     }
                   15364:                 }
                   15365:             } else {
                   15366:                 foreach my $field (@shibfields) {
                   15367:                     if ($env{'form.shibenv_'.$field}) {
                   15368:                         push(@{$changes{'cancreate'}},'shibenv');
                   15369:                         last;
                   15370:                     }
                   15371:                 }
                   15372:             }
                   15373:         }
1.224     raeburn  15374:     }
                   15375:     foreach my $item (@contexts) {
                   15376:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   15377:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   15378:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   15379:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   15380:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15381:                             push(@{$changes{'cancreate'}},$item);
                   15382:                         }
                   15383:                     }
                   15384:                 }
                   15385:             }
                   15386:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15387:                 foreach my $type (@{$cancreate{$item}}) {
                   15388:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   15389:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15390:                             push(@{$changes{'cancreate'}},$item);
                   15391:                         }
                   15392:                     }
                   15393:                 }
                   15394:             }
                   15395:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   15396:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  15397:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   15398:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15399:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   15400:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  15401:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15402:                                     push(@{$changes{'cancreate'}},$item);
                   15403:                                 }
                   15404:                             }
                   15405:                         }
1.305     raeburn  15406:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15407:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  15408:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15409:                                 push(@{$changes{'cancreate'}},$item);
                   15410:                             }
1.224     raeburn  15411:                         }
                   15412:                     }
                   15413:                 }
1.305     raeburn  15414:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15415:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15416:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15417:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15418:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  15419:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15420:                                         push(@{$changes{'cancreate'}},$item);
                   15421:                                     }
                   15422:                                 }
                   15423:                             } else {
                   15424:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15425:                                     push(@{$changes{'cancreate'}},$item);
                   15426:                                 }
                   15427:                             }
                   15428:                         }
1.305     raeburn  15429:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15430:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  15431:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15432:                                 push(@{$changes{'cancreate'}},$item);
                   15433:                             }
1.224     raeburn  15434:                         }
                   15435:                     }
                   15436:                 }
                   15437:             }
                   15438:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   15439:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15440:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   15441:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15442:                         push(@{$changes{'cancreate'}},$item);
                   15443:                     }
                   15444:                 }
1.305     raeburn  15445:             }
                   15446:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15447:             if (ref($cancreate{$item}) eq 'HASH') {
                   15448:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15449:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  15450:                 }
                   15451:             }
                   15452:         } elsif ($item eq 'emailusername') {
1.228     raeburn  15453:             if (ref($cancreate{$item}) eq 'HASH') {
                   15454:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15455:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15456:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15457:                             if ($cancreate{$item}{$type}{$field}) {
                   15458:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15459:                                     push(@{$changes{'cancreate'}},$item);
                   15460:                                 }
                   15461:                                 last;
                   15462:                             }
                   15463:                         }
                   15464:                     }
                   15465:                 }
1.224     raeburn  15466:             }
                   15467:         }
                   15468:     }
                   15469: #
                   15470: # Populate %save_usercreate hash with updates to self-creation configuration.
                   15471: #
                   15472:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   15473:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  15474:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  15475:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   15476:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   15477:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   15478:     }
1.236     raeburn  15479:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   15480:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   15481:     }
1.303     raeburn  15482:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   15483:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   15484:     }
1.305     raeburn  15485:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   15486:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   15487:     }
1.303     raeburn  15488:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   15489:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   15490:     }
1.224     raeburn  15491:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15492:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   15493:     }
1.240     raeburn  15494:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   15495:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   15496:     }
1.224     raeburn  15497:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  15498:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  15499: 
                   15500:     my %userconfig_hash = (
                   15501:             usercreation     => \%save_usercreate,
                   15502:             usermodification => \%save_usermodify,
1.305     raeburn  15503:             inststatus       => \%save_inststatus,
1.224     raeburn  15504:     );
1.305     raeburn  15505: 
1.224     raeburn  15506:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   15507:                                              $dom);
                   15508: #
1.305     raeburn  15509: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  15510: #
1.27      raeburn  15511:     if ($putresult eq 'ok') {
                   15512:         if (keys(%changes) > 0) {
                   15513:             $resulttext = &mt('Changes made:').'<ul>';
                   15514:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  15515:                 my %lt = &selfcreation_types();
1.34      raeburn  15516:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  15517:                     my $chgtext = '';
1.45      raeburn  15518:                     if ($type eq 'selfcreate') {
1.50      raeburn  15519:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  15520:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  15521:                         } else {
1.224     raeburn  15522:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   15523:                                         '<ul>';
1.50      raeburn  15524:                             foreach my $case (@{$cancreate{$type}}) {
                   15525:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   15526:                             }
                   15527:                             $chgtext .= '</ul>';
1.100     raeburn  15528:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   15529:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   15530:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15531:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  15532:                                             $chgtext .= '<span class="LC_warning">'.
                   15533:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   15534:                                                         '</span><br />';
                   15535:                                         }
                   15536:                                     }
                   15537:                                 }
                   15538:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  15539:                                     if (!@statuses) {
                   15540:                                         $chgtext .= '<span class="LC_warning">'.
                   15541:                                                     &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.").
                   15542:                                                     '</span><br />';
1.303     raeburn  15543: 
1.100     raeburn  15544:                                     }
                   15545:                                 }
                   15546:                             }
1.43      raeburn  15547:                         }
1.240     raeburn  15548:                     } elsif ($type eq 'shibenv') {
                   15549:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  15550:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  15551:                         } else {
                   15552:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   15553:                                         '<ul>';
                   15554:                             foreach my $field (@shibfields) {
                   15555:                                 next if ($cancreate{$type}{$field} eq '');
                   15556:                                 if ($field eq 'inststatus') {
                   15557:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   15558:                                 } else {
                   15559:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   15560:                                 }
                   15561:                             }
                   15562:                             $chgtext .= '</ul>';
1.303     raeburn  15563:                         }
1.93      raeburn  15564:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  15565:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   15566:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   15567:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   15568:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  15569:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  15570:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  15571:                                         $chgtext .= '<br />'.
                   15572:                                                     '<span class="LC_warning">'.
                   15573:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   15574:                                                     '</span>';
                   15575:                                     }
1.303     raeburn  15576:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  15577:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  15578:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   15579:                                     } else {
                   15580:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   15581:                                     }
                   15582:                                     $chgtext .= '<ul>';
                   15583:                                     foreach my $case (@{$cancreate{$type}}) {
                   15584:                                         if ($case eq 'default') {
                   15585:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   15586:                                         } else {
1.303     raeburn  15587:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  15588:                                         }
                   15589:                                     }
1.100     raeburn  15590:                                     $chgtext .= '</ul>';
                   15591:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  15592:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  15593:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   15594:                                                     '</span>';
1.100     raeburn  15595:                                     }
                   15596:                                 }
                   15597:                             } else {
                   15598:                                 if (@{$cancreate{$type}} == 0) {
                   15599:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   15600:                                 } else {
                   15601:                                     $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  15602:                                 }
                   15603:                             }
1.303     raeburn  15604:                             $chgtext .= '<br />';
1.93      raeburn  15605:                         }
1.236     raeburn  15606:                     } elsif ($type eq 'selfcreateprocessing') {
                   15607:                         my %choices = &Apache::lonlocal::texthash (
                   15608:                                                                     automatic => 'Automatic approval',
                   15609:                                                                     approval  => 'Queued for approval',
                   15610:                                                                   );
1.305     raeburn  15611:                         if (@types) {
                   15612:                             if (@statuses) {
1.303     raeburn  15613:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  15614:                                             '<ul>';
1.305     raeburn  15615:                                 foreach my $status (@statuses) {
                   15616:                                     if ($status eq 'default') {
                   15617:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  15618:                                     } else {
1.305     raeburn  15619:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  15620:                                     }
                   15621:                                 }
                   15622:                                 $chgtext .= '</ul>';
                   15623:                             }
                   15624:                         } else {
                   15625:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   15626:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   15627:                         }
                   15628:                     } elsif ($type eq 'emailverified') {
                   15629:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  15630:                                                                     all   => 'Same as e-mail',
                   15631:                                                                     first => 'Omit @domain',
                   15632:                                                                     free  => 'Free to choose',
1.303     raeburn  15633:                                                                   );
1.305     raeburn  15634:                         if (@types) {
                   15635:                             if (@statuses) {
1.303     raeburn  15636:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   15637:                                             '<ul>';
1.305     raeburn  15638:                                 foreach my $status (@statuses) {
1.303     raeburn  15639:                                     if ($type eq 'default') {
1.305     raeburn  15640:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  15641:                                     } else {
1.305     raeburn  15642:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  15643:                                     }
                   15644:                                 }
                   15645:                                 $chgtext .= '</ul>';
                   15646:                             }
                   15647:                         } else {
1.305     raeburn  15648:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  15649:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  15650:                         }
1.305     raeburn  15651:                     } elsif ($type eq 'emailoptions') {
                   15652:                         my %options = &Apache::lonlocal::texthash (
                   15653:                                                                     any     => 'Any e-mail',
                   15654:                                                                     inst    => 'Institutional only',
                   15655:                                                                     noninst => 'Non-institutional only',
                   15656:                                                                     custom  => 'Custom restrictions',
                   15657:                                                                   );
                   15658:                         if (@types) {
                   15659:                             if (@statuses) {
                   15660:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   15661:                                             '<ul>';
                   15662:                                 foreach my $status (@statuses) {
                   15663:                                     if ($type eq 'default') {
                   15664:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   15665:                                     } else {
                   15666:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  15667:                                     }
                   15668:                                 }
1.305     raeburn  15669:                                 $chgtext .= '</ul>';
                   15670:                             }
                   15671:                         } else {
                   15672:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   15673:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   15674:                             } else {
                   15675:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   15676:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  15677:                             }
1.305     raeburn  15678:                         }
                   15679:                     } elsif ($type eq 'emaildomain') {
                   15680:                         my $output;
                   15681:                         if (@statuses) {
                   15682:                             foreach my $type (@statuses) {
                   15683:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   15684:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   15685:                                         if ($type eq 'default') {
                   15686:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15687:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15688:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15689:                                             } else {
                   15690:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15691:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   15692:                                             }
1.303     raeburn  15693:                                         } else {
1.305     raeburn  15694:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15695:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15696:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15697:                                             } else {
                   15698:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15699:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   15700:                                             }
1.303     raeburn  15701:                                         }
1.305     raeburn  15702:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   15703:                                         if ($type eq 'default') {
                   15704:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15705:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15706:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15707:                                             } else {
                   15708:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15709:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   15710:                                             }
1.303     raeburn  15711:                                         } else {
1.305     raeburn  15712:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15713:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15714:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15715:                                             } else {
                   15716:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15717:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   15718:                                             }
1.303     raeburn  15719:                                         }
                   15720:                                     }
                   15721:                                 }
                   15722:                             }
1.305     raeburn  15723:                         }
                   15724:                         if ($output ne '') {
                   15725:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   15726:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  15727:                         }
1.165     raeburn  15728:                     } elsif ($type eq 'captcha') {
1.224     raeburn  15729:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  15730:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   15731:                         } else {
                   15732:                             my %captchas = &captcha_phrases();
1.224     raeburn  15733:                             if ($captchas{$savecaptcha{$type}}) {
                   15734:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  15735:                             } else {
1.210     raeburn  15736:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  15737:                             }
                   15738:                         }
                   15739:                     } elsif ($type eq 'recaptchakeys') {
                   15740:                         my ($privkey,$pubkey);
1.224     raeburn  15741:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   15742:                             $pubkey = $savecaptcha{$type}{'public'};
                   15743:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  15744:                         }
                   15745:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   15746:                         if (!$pubkey) {
                   15747:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   15748:                         } else {
                   15749:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   15750:                         }
                   15751:                         if (!$privkey) {
                   15752:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   15753:                         } else {
                   15754:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   15755:                         }
                   15756:                         $chgtext .= '</ul>';
1.269     raeburn  15757:                     } elsif ($type eq 'recaptchaversion') {
                   15758:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  15759:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  15760:                         }
1.224     raeburn  15761:                     } elsif ($type eq 'emailusername') {
                   15762:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  15763:                             if (@statuses) {
                   15764:                                 foreach my $type (@statuses) {
1.228     raeburn  15765:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   15766:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  15767:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  15768:                                                     '<ul>';
                   15769:                                             foreach my $field (@{$infofields}) {
                   15770:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   15771:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   15772:                                                 }
                   15773:                                             }
1.245     raeburn  15774:                                             $chgtext .= '</ul>';
                   15775:                                         } else {
1.303     raeburn  15776:                                             $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  15777:                                         }
                   15778:                                     } else {
1.303     raeburn  15779:                                         $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  15780:                                     }
                   15781:                                 }
                   15782:                             }
                   15783:                         }
                   15784:                     } elsif ($type eq 'notify') {
1.303     raeburn  15785:                         my $numapprove = 0;
1.224     raeburn  15786:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   15787:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   15788:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  15789:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   15790:                                     $numapprove ++;
1.224     raeburn  15791:                                 }
                   15792:                             }
1.43      raeburn  15793:                         }
1.303     raeburn  15794:                         unless ($numapprove) {
                   15795:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   15796:                         }
1.34      raeburn  15797:                     }
1.224     raeburn  15798:                     if ($chgtext) {
                   15799:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  15800:                     }
                   15801:                 }
                   15802:             }
1.305     raeburn  15803:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  15804:                 my ($emailrules,$emailruleorder) =
                   15805:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  15806:                 foreach my $type (@{$changes{'email_rule'}}) {
                   15807:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   15808:                         my $chgtext = '<ul>';
                   15809:                         foreach my $rule (@{$email_rule{$type}}) {
                   15810:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   15811:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   15812:                             }
                   15813:                         }
                   15814:                         $chgtext .= '</ul>';
1.310     raeburn  15815:                         my $typename;
1.305     raeburn  15816:                         if (@types) {
                   15817:                             if ($type eq 'default') {
                   15818:                                 $typename = $othertitle;
                   15819:                             } else {
                   15820:                                 $typename = $usertypes{$type};
                   15821:                             } 
                   15822:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   15823:                         }
                   15824:                         if (@{$email_rule{$type}} > 0) {
                   15825:                             $resulttext .= '<li>'.
                   15826:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   15827:                                                $usertypes{$type}).
                   15828:                                            $chgtext.
                   15829:                                            '</li>';
                   15830:                         } else {
                   15831:                             $resulttext .= '<li>'.
1.310     raeburn  15832:                                            &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  15833:                                            '</li>'.
1.310     raeburn  15834:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  15835:                         }
1.43      raeburn  15836:                     }
                   15837:                 }
1.305     raeburn  15838:             }
                   15839:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   15840:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15841:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   15842:                         my $chgtext = '<ul>';
                   15843:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   15844:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   15845:                         }
                   15846:                         $chgtext .= '</ul>';
                   15847:                         $resulttext .= '<li>'.
                   15848:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   15849:                                           $chgtext.
                   15850:                                        '</li>';
                   15851:                     } else {
                   15852:                         $resulttext .= '<li>'.
                   15853:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   15854:                                        '</li>';
                   15855:                     }
1.43      raeburn  15856:                 }
                   15857:             }
1.224     raeburn  15858:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   15859:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   15860:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   15861:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   15862:                     my $typename = $type;
1.303     raeburn  15863:                     if (keys(%usertypes) > 0) {
                   15864:                         if ($usertypes{$type} ne '') {
                   15865:                             $typename = $usertypes{$type};
1.224     raeburn  15866:                         }
                   15867:                     }
                   15868:                     my @modifiable;
                   15869:                     $resulttext .= '<li>'.
                   15870:                                     &mt('Self-creation of account by users with status: [_1]',
                   15871:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   15872:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   15873:                     foreach my $field (@fields) {
                   15874:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   15875:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  15876:                         }
                   15877:                     }
1.224     raeburn  15878:                     if (@modifiable > 0) {
                   15879:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  15880:                     } else {
1.224     raeburn  15881:                         $resulttext .= &mt('none');
1.43      raeburn  15882:                     }
1.224     raeburn  15883:                     $resulttext .= '</li>';
1.28      raeburn  15884:                 }
1.224     raeburn  15885:                 $resulttext .= '</ul></li>';
1.28      raeburn  15886:             }
1.27      raeburn  15887:             $resulttext .= '</ul>';
1.305     raeburn  15888:             my $cachetime = 24*60*60;
                   15889:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   15890:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15891:             if (ref($lastactref) eq 'HASH') {
                   15892:                 $lastactref->{'domdefaults'} = 1;
                   15893:             }
1.27      raeburn  15894:         } else {
1.224     raeburn  15895:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  15896:         }
                   15897:     } else {
                   15898:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  15899:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15900:     }
1.43      raeburn  15901:     if ($warningmsg ne '') {
                   15902:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   15903:     }
1.23      raeburn  15904:     return $resulttext;
                   15905: }
                   15906: 
1.165     raeburn  15907: sub process_captcha {
                   15908:     my ($container,$changes,$newsettings,$current) = @_;
                   15909:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   15910:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   15911:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   15912:         $newsettings->{'captcha'} = 'original';
                   15913:     }
                   15914:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  15915:         if ($container eq 'cancreate') {
1.169     raeburn  15916:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   15917:                 push(@{$changes->{'cancreate'}},'captcha');
                   15918:             } elsif (!defined($changes->{'cancreate'})) {
                   15919:                 $changes->{'cancreate'} = ['captcha'];
                   15920:             }
                   15921:         } else {
                   15922:             $changes->{'captcha'} = 1;
1.165     raeburn  15923:         }
                   15924:     }
1.269     raeburn  15925:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  15926:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   15927:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   15928:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  15929:         $newpub =~ s/[^\w\-]//g;
                   15930:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  15931:         $newsettings->{'recaptchakeys'} = {
                   15932:                                              public  => $newpub,
                   15933:                                              private => $newpriv,
                   15934:                                           };
1.269     raeburn  15935:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   15936:         $newversion =~ s/\D//g;
                   15937:         if ($newversion ne '2') {
                   15938:             $newversion = 1;
                   15939:         }
                   15940:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  15941:     }
                   15942:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   15943:         $currpub = $current->{'recaptchakeys'}{'public'};
                   15944:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  15945:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   15946:             $newsettings->{'recaptchakeys'} = {
                   15947:                                                  public  => '',
                   15948:                                                  private => '',
                   15949:                                               }
                   15950:         }
1.165     raeburn  15951:     }
1.269     raeburn  15952:     if ($current->{'captcha'} eq 'recaptcha') {
                   15953:         $currversion = $current->{'recaptchaversion'};
                   15954:         if ($currversion ne '2') {
                   15955:             $currversion = 1;
                   15956:         }
                   15957:     }
                   15958:     if ($currversion ne $newversion) {
                   15959:         if ($container eq 'cancreate') {
                   15960:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   15961:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   15962:             } elsif (!defined($changes->{'cancreate'})) {
                   15963:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   15964:             }
                   15965:         } else {
                   15966:             $changes->{'recaptchaversion'} = 1;
                   15967:         }
                   15968:     }
1.165     raeburn  15969:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  15970:         if ($container eq 'cancreate') {
                   15971:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   15972:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   15973:             } elsif (!defined($changes->{'cancreate'})) {
                   15974:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   15975:             }
                   15976:         } else {
1.210     raeburn  15977:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  15978:         }
                   15979:     }
                   15980:     return;
                   15981: }
                   15982: 
1.33      raeburn  15983: sub modify_usermodification {
                   15984:     my ($dom,%domconfig) = @_;
1.224     raeburn  15985:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  15986:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   15987:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  15988:             if ($key eq 'selfcreate') {
                   15989:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   15990:             } else {  
                   15991:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   15992:             }
1.33      raeburn  15993:         }
                   15994:     }
1.224     raeburn  15995:     my @contexts = ('author','course');
1.33      raeburn  15996:     my %context_title = (
                   15997:                            author => 'In author context',
                   15998:                            course => 'In course context',
                   15999:                         );
                   16000:     my @fields = ('lastname','firstname','middlename','generation',
                   16001:                   'permanentemail','id');
                   16002:     my %roles = (
                   16003:                   author => ['ca','aa'],
                   16004:                   course => ['st','ep','ta','in','cr'],
                   16005:                 );
                   16006:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   16007:     foreach my $context (@contexts) {
                   16008:         foreach my $role (@{$roles{$context}}) {
                   16009:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   16010:             foreach my $item (@fields) {
                   16011:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   16012:                     $modifyhash{$context}{$role}{$item} = 1;
                   16013:                 } else {
                   16014:                     $modifyhash{$context}{$role}{$item} = 0;
                   16015:                 }
                   16016:             }
                   16017:         }
                   16018:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   16019:             foreach my $role (@{$roles{$context}}) {
                   16020:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   16021:                     foreach my $field (@fields) {
                   16022:                         if ($modifyhash{$context}{$role}{$field} ne 
                   16023:                                 $curr_usermodification{$context}{$role}{$field}) {
                   16024:                             push(@{$changes{$context}},$role);
                   16025:                             last;
                   16026:                         }
                   16027:                     }
                   16028:                 }
                   16029:             }
                   16030:         } else {
                   16031:             foreach my $context (@contexts) {
                   16032:                 foreach my $role (@{$roles{$context}}) {
                   16033:                     push(@{$changes{$context}},$role);
                   16034:                 }
                   16035:             }
                   16036:         }
                   16037:     }
                   16038:     my %usermodification_hash =  (
                   16039:                                    usermodification => \%modifyhash,
                   16040:                                  );
                   16041:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   16042:                                              \%usermodification_hash,$dom);
                   16043:     if ($putresult eq 'ok') {
                   16044:         if (keys(%changes) > 0) {
                   16045:             $resulttext = &mt('Changes made: ').'<ul>';
                   16046:             foreach my $context (@contexts) {
                   16047:                 if (ref($changes{$context}) eq 'ARRAY') {
                   16048:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   16049:                     if (ref($changes{$context}) eq 'ARRAY') {
                   16050:                         foreach my $role (@{$changes{$context}}) {
                   16051:                             my $rolename;
1.224     raeburn  16052:                             if ($role eq 'cr') {
                   16053:                                 $rolename = &mt('Custom');
1.33      raeburn  16054:                             } else {
1.224     raeburn  16055:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  16056:                             }
                   16057:                             my @modifiable;
1.224     raeburn  16058:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  16059:                             foreach my $field (@fields) {
                   16060:                                 if ($modifyhash{$context}{$role}{$field}) {
                   16061:                                     push(@modifiable,$fieldtitles{$field});
                   16062:                                 }
                   16063:                             }
                   16064:                             if (@modifiable > 0) {
                   16065:                                 $resulttext .= join(', ',@modifiable);
                   16066:                             } else {
                   16067:                                 $resulttext .= &mt('none'); 
                   16068:                             }
                   16069:                             $resulttext .= '</li>';
                   16070:                         }
                   16071:                         $resulttext .= '</ul></li>';
                   16072:                     }
                   16073:                 }
                   16074:             }
                   16075:             $resulttext .= '</ul>';
                   16076:         } else {
                   16077:             $resulttext = &mt('No changes made to user modification settings');
                   16078:         }
                   16079:     } else {
                   16080:         $resulttext = '<span class="LC_error">'.
                   16081:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16082:     }
                   16083:     return $resulttext;
                   16084: }
                   16085: 
1.43      raeburn  16086: sub modify_defaults {
1.212     raeburn  16087:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  16088:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  16089:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  16090:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  16091:                  'portal_def');
1.325     raeburn  16092:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  16093:     foreach my $item (@items) {
                   16094:         $newvalues{$item} = $env{'form.'.$item};
                   16095:         if ($item eq 'auth_def') {
                   16096:             if ($newvalues{$item} ne '') {
                   16097:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   16098:                     push(@errors,$item);
                   16099:                 }
                   16100:             }
                   16101:         } elsif ($item eq 'lang_def') {
                   16102:             if ($newvalues{$item} ne '') {
                   16103:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   16104:                     my $langcode = $1;
1.103     raeburn  16105:                     if ($langcode ne 'x_chef') {
                   16106:                         if (code2language($langcode) eq '') {
                   16107:                             push(@errors,$item);
                   16108:                         }
1.43      raeburn  16109:                     }
                   16110:                 } else {
                   16111:                     push(@errors,$item);
                   16112:                 }
                   16113:             }
1.54      raeburn  16114:         } elsif ($item eq 'timezone_def') {
                   16115:             if ($newvalues{$item} ne '') {
1.62      raeburn  16116:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  16117:                     push(@errors,$item);   
                   16118:                 }
                   16119:             }
1.68      raeburn  16120:         } elsif ($item eq 'datelocale_def') {
                   16121:             if ($newvalues{$item} ne '') {
                   16122:                 my @datelocale_ids = DateTime::Locale->ids();
                   16123:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   16124:                     push(@errors,$item);
                   16125:                 }
                   16126:             }
1.141     raeburn  16127:         } elsif ($item eq 'portal_def') {
                   16128:             if ($newvalues{$item} ne '') {
                   16129:                 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])\/?$/) {
                   16130:                     push(@errors,$item);
                   16131:                 }
                   16132:             }
1.43      raeburn  16133:         }
                   16134:         if (grep(/^\Q$item\E$/,@errors)) {
                   16135:             $newvalues{$item} = $domdefaults{$item};
                   16136:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   16137:             $changes{$item} = 1;
                   16138:         }
1.72      raeburn  16139:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  16140:     }
1.354     raeburn  16141:     my %staticdefaults = (
                   16142:                            'intauth_cost'   => 10,
                   16143:                            'intauth_check'  => 0,
                   16144:                            'intauth_switch' => 0,
                   16145:                          );
                   16146:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   16147:         if (exists($domdefaults{$item})) {
                   16148:             $newvalues{$item} = $domdefaults{$item};
                   16149:         } else {
                   16150:             $newvalues{$item} = $staticdefaults{$item};
                   16151:         }
                   16152:     }
1.43      raeburn  16153:     my %defaults_hash = (
1.72      raeburn  16154:                          defaults => \%newvalues,
                   16155:                         );
1.43      raeburn  16156:     my $title = &defaults_titles();
1.236     raeburn  16157: 
                   16158:     my $currinststatus;
                   16159:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   16160:         $currinststatus = $domconfig{'inststatus'};
                   16161:     } else {
                   16162:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16163:         $currinststatus = {
                   16164:                              inststatustypes => $usertypes,
                   16165:                              inststatusorder => $types,
                   16166:                              inststatusguest => [],
                   16167:                           };
                   16168:     }
                   16169:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   16170:     my @allpos;
                   16171:     my %alltypes;
1.305     raeburn  16172:     my @inststatusguest;
                   16173:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   16174:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   16175:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   16176:                 push(@inststatusguest,$type);
                   16177:             }
                   16178:         }
                   16179:     }
                   16180:     my ($currtitles,$currorder);
1.236     raeburn  16181:     if (ref($currinststatus) eq 'HASH') {
                   16182:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   16183:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   16184:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   16185:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   16186:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   16187:                     }
                   16188:                 }
                   16189:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   16190:                     my $position = $env{'form.inststatus_pos_'.$type};
                   16191:                     $position =~ s/\D+//g;
                   16192:                     $allpos[$position] = $type;
                   16193:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   16194:                     $alltypes{$type} =~ s/`//g;
                   16195:                 }
                   16196:             }
                   16197:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   16198:             $currtitles =~ s/,$//;
                   16199:         }
                   16200:     }
                   16201:     if ($env{'form.addinststatus'}) {
                   16202:         my $newtype = $env{'form.addinststatus'};
                   16203:         $newtype =~ s/\W//g;
                   16204:         unless (exists($alltypes{$newtype})) {
                   16205:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   16206:             $alltypes{$newtype} =~ s/`//g; 
                   16207:             my $position = $env{'form.addinststatus_pos'};
                   16208:             $position =~ s/\D+//g;
                   16209:             if ($position ne '') {
                   16210:                 $allpos[$position] = $newtype;
                   16211:             }
                   16212:         }
                   16213:     }
1.305     raeburn  16214:     my @orderedstatus;
1.236     raeburn  16215:     foreach my $type (@allpos) {
                   16216:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   16217:             push(@orderedstatus,$type);
                   16218:         }
                   16219:     }
                   16220:     foreach my $type (keys(%alltypes)) {
                   16221:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   16222:             delete($alltypes{$type});
                   16223:         }
                   16224:     }
                   16225:     $defaults_hash{'inststatus'} = {
                   16226:                                      inststatustypes => \%alltypes,
                   16227:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  16228:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  16229:                                    };
                   16230:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   16231:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   16232:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   16233:         }
                   16234:     }
                   16235:     if ($currorder ne join(',',@orderedstatus)) {
                   16236:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   16237:     }
                   16238:     my $newtitles;
                   16239:     foreach my $item (@orderedstatus) {
                   16240:         $newtitles .= $alltypes{$item}.',';
                   16241:     }
                   16242:     $newtitles =~ s/,$//;
                   16243:     if ($currtitles ne $newtitles) {
                   16244:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   16245:     }
1.43      raeburn  16246:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   16247:                                              $dom);
                   16248:     if ($putresult eq 'ok') {
                   16249:         if (keys(%changes) > 0) {
                   16250:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  16251:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  16252:             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";
                   16253:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  16254:                 if ($item eq 'inststatus') {
                   16255:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  16256:                         if (@orderedstatus) {
1.236     raeburn  16257:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   16258:                             foreach my $type (@orderedstatus) { 
                   16259:                                 $resulttext .= $alltypes{$type}.', ';
                   16260:                             }
                   16261:                             $resulttext =~ s/, $//;
                   16262:                             $resulttext .= '</li>';
1.305     raeburn  16263:                         } else {
                   16264:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  16265:                         }
                   16266:                     }
                   16267:                 } else {
                   16268:                     my $value = $env{'form.'.$item};
                   16269:                     if ($value eq '') {
                   16270:                         $value = &mt('none');
                   16271:                     } elsif ($item eq 'auth_def') {
                   16272:                         my %authnames = &authtype_names();
                   16273:                         my %shortauth = (
                   16274:                                           internal   => 'int',
                   16275:                                           krb4       => 'krb4',
                   16276:                                           krb5       => 'krb5',
                   16277:                                           localauth  => 'loc',
1.325     raeburn  16278:                                           lti        => 'lti',
1.236     raeburn  16279:                         );
                   16280:                         $value = $authnames{$shortauth{$value}};
                   16281:                     }
                   16282:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   16283:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  16284:                 }
                   16285:             }
                   16286:             $resulttext .= '</ul>';
                   16287:             $mailmsgtext .= "\n";
                   16288:             my $cachetime = 24*60*60;
1.72      raeburn  16289:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  16290:             if (ref($lastactref) eq 'HASH') {
                   16291:                 $lastactref->{'domdefaults'} = 1;
                   16292:             }
1.68      raeburn  16293:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  16294:                 my $notify = 1;
                   16295:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16296:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   16297:                         $notify = 0;
                   16298:                     }
                   16299:                 }
                   16300:                 if ($notify) {
                   16301:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   16302:                                                "LON-CAPA Domain Settings Change - $dom",
                   16303:                                                $mailmsgtext);
                   16304:                 }
1.54      raeburn  16305:             }
1.43      raeburn  16306:         } else {
1.54      raeburn  16307:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  16308:         }
                   16309:     } else {
                   16310:         $resulttext = '<span class="LC_error">'.
                   16311:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16312:     }
                   16313:     if (@errors > 0) {
                   16314:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   16315:         foreach my $item (@errors) {
                   16316:             $resulttext .= ' "'.$title->{$item}.'",';
                   16317:         }
                   16318:         $resulttext =~ s/,$//;
                   16319:     }
                   16320:     return $resulttext;
                   16321: }
                   16322: 
1.46      raeburn  16323: sub modify_scantron {
1.205     raeburn  16324:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  16325:     my ($resulttext,%confhash,%changes,$errors);
                   16326:     my $custom = 'custom.tab';
                   16327:     my $default = 'default.tab';
                   16328:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  16329:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  16330:         &config_check($dom,$confname,$servadm);
                   16331:     if ($env{'form.scantronformat.filename'} ne '') {
                   16332:         my $error;
                   16333:         if ($configuserok eq 'ok') {
                   16334:             if ($switchserver) {
1.130     raeburn  16335:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  16336:             } else {
                   16337:                 if ($author_ok eq 'ok') {
                   16338:                     my ($result,$scantronurl) =
                   16339:                         &publishlogo($r,'upload','scantronformat',$dom,
                   16340:                                      $confname,'scantron','','',$custom);
                   16341:                     if ($result eq 'ok') {
                   16342:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  16343:                         $changes{'scantronformat'} = 1;
1.46      raeburn  16344:                     } else {
                   16345:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   16346:                     }
                   16347:                 } else {
                   16348:                     $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);
                   16349:                 }
                   16350:             }
                   16351:         } else {
                   16352:             $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);
                   16353:         }
                   16354:         if ($error) {
                   16355:             &Apache::lonnet::logthis($error);
                   16356:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   16357:         }
                   16358:     }
1.48      raeburn  16359:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16360:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   16361:             if ($env{'form.scantronformat_del'}) {
                   16362:                 $confhash{'scantron'}{'scantronformat'} = '';
                   16363:                 $changes{'scantronformat'} = 1;
1.347     raeburn  16364:             } else {
                   16365:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  16366:             }
                   16367:         }
                   16368:     }
1.347     raeburn  16369:     my @options = ('hdr','pad','rem');
1.346     raeburn  16370:     my @fields = &scantroncsv_fields();
                   16371:     my %titles = &scantronconfig_titles();
1.347     raeburn  16372:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  16373:     my ($newdat,$currdat,%newcol,%currcol);
                   16374:     if (grep(/^dat$/,@formats)) {
                   16375:         $confhash{'scantron'}{config}{dat} = 1;
                   16376:         $newdat = 1;
                   16377:     } else {
                   16378:         $newdat = 0;
                   16379:     }
                   16380:     if (grep(/^csv$/,@formats)) {
                   16381:         my %bynum;
                   16382:         foreach my $field (@fields) {
                   16383:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   16384:                 my $posscol = $1;
                   16385:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  16386:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  16387:                     $bynum{$posscol} = $field;
                   16388:                     $newcol{$field} = $posscol;
                   16389:                 }
                   16390:             }
                   16391:         }
1.347     raeburn  16392:         if (keys(%newcol)) {
                   16393:             foreach my $option (@options) {
                   16394:                 if ($env{'form.scantroncsv_'.$option}) {
                   16395:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   16396:                 }
                   16397:             }
                   16398:         }
1.346     raeburn  16399:     }
                   16400:     $currdat = 1;
                   16401:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16402:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  16403:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  16404:                 $currdat = 0;
                   16405:             }
                   16406:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  16407:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16408:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   16409:                 }
1.346     raeburn  16410:             }
                   16411:         }
                   16412:     }
                   16413:     if ($currdat != $newdat) {
                   16414:         $changes{'config'} = 1;
                   16415:     } else {
                   16416:         foreach my $field (@fields) {
                   16417:             if ($currcol{$field} ne '') {
                   16418:                 if ($currcol{$field} ne $newcol{$field}) {
                   16419:                     $changes{'config'} = 1;
                   16420:                     last;
1.347     raeburn  16421:                 }
1.346     raeburn  16422:             } elsif ($newcol{$field} ne '') {
                   16423:                 $changes{'config'} = 1;
                   16424:                 last;
                   16425:             }
                   16426:         }
                   16427:     }
1.46      raeburn  16428:     if (keys(%confhash) > 0) {
                   16429:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   16430:                                                  $dom);
                   16431:         if ($putresult eq 'ok') {
                   16432:             if (keys(%changes) > 0) {
1.48      raeburn  16433:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   16434:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  16435:                     if ($changes{'scantronformat'}) {
                   16436:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   16437:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   16438:                         } else {
                   16439:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   16440:                         }
                   16441:                     }
1.347     raeburn  16442:                     if ($changes{'config'}) {
1.346     raeburn  16443:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   16444:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   16445:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   16446:                             }
                   16447:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  16448:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16449:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   16450:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   16451:                                         foreach my $field (@fields) {
                   16452:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   16453:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   16454:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   16455:                                             }
                   16456:                                         }
                   16457:                                         $resulttext .= '</ul></li>';
                   16458:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   16459:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   16460:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   16461:                                                 foreach my $option (@options) {
                   16462:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   16463:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   16464:                                                     }
                   16465:                                                 }
                   16466:                                                 $resulttext .= '</ul></li>';
                   16467:                                             }
1.346     raeburn  16468:                                         }
                   16469:                                     }
                   16470:                                 }
                   16471:                             }
                   16472:                         } else {
                   16473:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   16474:                         }
1.46      raeburn  16475:                     }
1.48      raeburn  16476:                     $resulttext .= '</ul>';
                   16477:                 } else {
1.130     raeburn  16478:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  16479:                 }
                   16480:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16481:                 if (ref($lastactref) eq 'HASH') {
                   16482:                     $lastactref->{'domainconfig'} = 1;
                   16483:                 }
1.46      raeburn  16484:             } else {
1.346     raeburn  16485:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  16486:             }
                   16487:         } else {
                   16488:             $resulttext = '<span class="LC_error">'.
                   16489:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   16490:         }
                   16491:     } else {
1.130     raeburn  16492:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  16493:     }
                   16494:     if ($errors) {
1.353     raeburn  16495:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   16496:                        $errors.'</ul></p>';
1.46      raeburn  16497:     }
                   16498:     return $resulttext;
                   16499: }
                   16500: 
1.48      raeburn  16501: sub modify_coursecategories {
1.239     raeburn  16502:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  16503:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   16504:         $cathash);
1.48      raeburn  16505:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  16506:     my @catitems = ('unauth','auth');
                   16507:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  16508:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  16509:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   16510:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   16511:             $changes{'togglecats'} = 1;
                   16512:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   16513:         }
                   16514:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   16515:             $changes{'categorize'} = 1;
                   16516:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   16517:         }
1.120     raeburn  16518:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   16519:             $changes{'togglecatscomm'} = 1;
                   16520:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   16521:         }
                   16522:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   16523:             $changes{'categorizecomm'} = 1;
                   16524:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  16525: 
                   16526:         }
                   16527:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   16528:             $changes{'togglecatsplace'} = 1;
                   16529:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   16530:         }
                   16531:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   16532:             $changes{'categorizeplace'} = 1;
                   16533:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  16534:         }
1.238     raeburn  16535:         foreach my $item (@catitems) {
                   16536:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16537:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   16538:                     $changes{$item} = 1;
                   16539:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16540:                 }
                   16541:             }
                   16542:         }
1.57      raeburn  16543:     } else {
                   16544:         $changes{'togglecats'} = 1;
                   16545:         $changes{'categorize'} = 1;
1.124     raeburn  16546:         $changes{'togglecatscomm'} = 1;
                   16547:         $changes{'categorizecomm'} = 1;
1.272     raeburn  16548:         $changes{'togglecatsplace'} = 1;
                   16549:         $changes{'categorizeplace'} = 1;
1.87      raeburn  16550:         $domconfig{'coursecategories'} = {
                   16551:                                              togglecats => $env{'form.togglecats'},
                   16552:                                              categorize => $env{'form.categorize'},
1.124     raeburn  16553:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   16554:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  16555:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   16556:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  16557:                                          };
1.238     raeburn  16558:         foreach my $item (@catitems) {
                   16559:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   16560:                 $changes{$item} = 1;
                   16561:             }
                   16562:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16563:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16564:             }
                   16565:         }
1.57      raeburn  16566:     }
                   16567:     if (ref($cathash) eq 'HASH') {
                   16568:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  16569:             push (@deletecategory,'instcode::0');
                   16570:         }
1.120     raeburn  16571:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   16572:             push(@deletecategory,'communities::0');
                   16573:         }
1.272     raeburn  16574:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   16575:             push(@deletecategory,'placement::0');
                   16576:         }
1.48      raeburn  16577:     }
1.57      raeburn  16578:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   16579:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  16580:         if (@deletecategory > 0) {
                   16581:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  16582:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  16583:             foreach my $item (@deletecategory) {
1.57      raeburn  16584:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   16585:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  16586:                     $deletions{$item} = 1;
1.57      raeburn  16587:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  16588:                 }
                   16589:             }
                   16590:         }
1.57      raeburn  16591:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  16592:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  16593:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  16594:                 $reorderings{$item} = 1;
1.57      raeburn  16595:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  16596:             }
                   16597:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   16598:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   16599:                 my $newdepth = $depth+1;
                   16600:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16601:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  16602:                 $adds{$newitem} = 1; 
                   16603:             }
                   16604:             if ($env{'form.subcat_'.$item} ne '') {
                   16605:                 my $newcat = $env{'form.subcat_'.$item};
                   16606:                 my $newdepth = $depth+1;
                   16607:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16608:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  16609:                 $adds{$newitem} = 1;
                   16610:             }
                   16611:         }
                   16612:     }
                   16613:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  16614:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  16615:             my $newitem = 'instcode::0';
1.57      raeburn  16616:             if ($cathash->{$newitem} eq '') {  
                   16617:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16618:                 $adds{$newitem} = 1;
                   16619:             }
                   16620:         } else {
                   16621:             my $newitem = 'instcode::0';
1.57      raeburn  16622:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16623:             $adds{$newitem} = 1;
                   16624:         }
                   16625:     }
1.120     raeburn  16626:     if ($env{'form.communities'} eq '1') {
                   16627:         if (ref($cathash) eq 'HASH') {
                   16628:             my $newitem = 'communities::0';
                   16629:             if ($cathash->{$newitem} eq '') {
                   16630:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16631:                 $adds{$newitem} = 1;
                   16632:             }
                   16633:         } else {
                   16634:             my $newitem = 'communities::0';
                   16635:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16636:             $adds{$newitem} = 1;
                   16637:         }
                   16638:     }
1.272     raeburn  16639:     if ($env{'form.placement'} eq '1') {
                   16640:         if (ref($cathash) eq 'HASH') {
                   16641:             my $newitem = 'placement::0';
                   16642:             if ($cathash->{$newitem} eq '') {
                   16643:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   16644:                 $adds{$newitem} = 1;
                   16645:             }
                   16646:         } else {
                   16647:             my $newitem = 'placement::0';
                   16648:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   16649:             $adds{$newitem} = 1;
                   16650:         }
                   16651:     }
1.48      raeburn  16652:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  16653:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  16654:             ($env{'form.addcategory_name'} ne 'communities') &&
                   16655:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  16656:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   16657:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   16658:             $adds{$newitem} = 1;
                   16659:         }
1.48      raeburn  16660:     }
1.57      raeburn  16661:     my $putresult;
1.48      raeburn  16662:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16663:         if (keys(%deletions) > 0) {
                   16664:             foreach my $key (keys(%deletions)) {
                   16665:                 if ($predelallitems{$key} ne '') {
                   16666:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   16667:                 }
                   16668:             }
                   16669:         }
                   16670:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  16671:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  16672:         if (ref($chkcats[0]) eq 'ARRAY') {
                   16673:             my $depth = 0;
                   16674:             my $chg = 0;
                   16675:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   16676:                 my $name = $chkcats[0][$i];
                   16677:                 my $item;
                   16678:                 if ($name eq '') {
                   16679:                     $chg ++;
                   16680:                 } else {
                   16681:                     $item = &escape($name).'::0';
                   16682:                     if ($chg) {
1.57      raeburn  16683:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  16684:                     }
                   16685:                     $depth ++; 
1.57      raeburn  16686:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  16687:                     $depth --;
                   16688:                 }
                   16689:             }
                   16690:         }
1.57      raeburn  16691:     }
                   16692:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16693:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  16694:         if ($putresult eq 'ok') {
1.57      raeburn  16695:             my %title = (
1.120     raeburn  16696:                          togglecats     => 'Show/Hide a course in catalog',
                   16697:                          categorize     => 'Assign a category to a course',
                   16698:                          togglecatscomm => 'Show/Hide a community in catalog',
                   16699:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  16700:                         );
                   16701:             my %level = (
1.120     raeburn  16702:                          dom  => 'set in Domain ("Modify Course/Community")',
                   16703:                          crs  => 'set in Course ("Course Configuration")',
                   16704:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  16705:                          none     => 'No catalog',
                   16706:                          std      => 'Standard catalog',
                   16707:                          domonly  => 'Domain-only catalog',
                   16708:                          codesrch => 'Code search form',
1.57      raeburn  16709:                         );
1.48      raeburn  16710:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  16711:             if ($changes{'togglecats'}) {
                   16712:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   16713:             }
                   16714:             if ($changes{'categorize'}) {
                   16715:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  16716:             }
1.120     raeburn  16717:             if ($changes{'togglecatscomm'}) {
                   16718:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   16719:             }
                   16720:             if ($changes{'categorizecomm'}) {
                   16721:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   16722:             }
1.238     raeburn  16723:             if ($changes{'unauth'}) {
                   16724:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   16725:             }
                   16726:             if ($changes{'auth'}) {
                   16727:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   16728:             }
1.57      raeburn  16729:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16730:                 my $cathash;
                   16731:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   16732:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   16733:                 } else {
                   16734:                     $cathash = {};
                   16735:                 } 
                   16736:                 my (@cats,@trails,%allitems);
                   16737:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   16738:                 if (keys(%deletions) > 0) {
                   16739:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   16740:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   16741:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   16742:                     }
                   16743:                     $resulttext .= '</ul></li>';
                   16744:                 }
                   16745:                 if (keys(%reorderings) > 0) {
                   16746:                     my %sort_by_trail;
                   16747:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   16748:                     foreach my $key (keys(%reorderings)) {
                   16749:                         if ($allitems{$key} ne '') {
                   16750:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   16751:                         }
1.48      raeburn  16752:                     }
1.57      raeburn  16753:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   16754:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   16755:                     }
                   16756:                     $resulttext .= '</ul></li>';
1.48      raeburn  16757:                 }
1.57      raeburn  16758:                 if (keys(%adds) > 0) {
                   16759:                     my %sort_by_trail;
                   16760:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   16761:                     foreach my $key (keys(%adds)) {
                   16762:                         if ($allitems{$key} ne '') {
                   16763:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   16764:                         }
                   16765:                     }
                   16766:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   16767:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  16768:                     }
1.57      raeburn  16769:                     $resulttext .= '</ul></li>';
1.48      raeburn  16770:                 }
                   16771:             }
                   16772:             $resulttext .= '</ul>';
1.239     raeburn  16773:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  16774:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   16775:                 if ($changes{'auth'}) {
                   16776:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   16777:                 }
                   16778:                 if ($changes{'unauth'}) {
                   16779:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   16780:                 }
                   16781:                 my $cachetime = 24*60*60;
                   16782:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  16783:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  16784:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  16785:                 }
                   16786:             }
1.48      raeburn  16787:         } else {
                   16788:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  16789:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  16790:         }
                   16791:     } else {
1.120     raeburn  16792:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  16793:     }
                   16794:     return $resulttext;
                   16795: }
                   16796: 
1.69      raeburn  16797: sub modify_serverstatuses {
                   16798:     my ($dom,%domconfig) = @_;
                   16799:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   16800:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   16801:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   16802:     }
                   16803:     my @pages = &serverstatus_pages();
                   16804:     foreach my $type (@pages) {
                   16805:         $newserverstatus{$type}{'namedusers'} = '';
                   16806:         $newserverstatus{$type}{'machines'} = '';
                   16807:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   16808:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   16809:             my @okusers;
                   16810:             foreach my $user (@users) {
                   16811:                 my ($uname,$udom) = split(/:/,$user);
                   16812:                 if (($udom =~ /^$match_domain$/) &&   
                   16813:                     (&Apache::lonnet::domain($udom)) &&
                   16814:                     ($uname =~ /^$match_username$/)) {
                   16815:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   16816:                         push(@okusers,$user);
                   16817:                     }
                   16818:                 }
                   16819:             }
                   16820:             if (@okusers > 0) {
                   16821:                  @okusers = sort(@okusers);
                   16822:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   16823:             }
                   16824:         }
                   16825:         if (defined($env{'form.'.$type.'_machines'})) {
                   16826:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   16827:             my @okmachines;
                   16828:             foreach my $ip (@machines) {
                   16829:                 my @parts = split(/\./,$ip);
                   16830:                 next if (@parts < 4);
                   16831:                 my $badip = 0;
                   16832:                 for (my $i=0; $i<4; $i++) {
                   16833:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   16834:                         $badip = 1;
                   16835:                         last;
                   16836:                     }
                   16837:                 }
                   16838:                 if (!$badip) {
                   16839:                     push(@okmachines,$ip);     
                   16840:                 }
                   16841:             }
                   16842:             @okmachines = sort(@okmachines);
                   16843:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   16844:         }
                   16845:     }
                   16846:     my %serverstatushash =  (
                   16847:                                 serverstatuses => \%newserverstatus,
                   16848:                             );
                   16849:     foreach my $type (@pages) {
1.83      raeburn  16850:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  16851:             my (@current,@new);
1.83      raeburn  16852:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  16853:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   16854:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   16855:                 }
                   16856:             }
                   16857:             if ($newserverstatus{$type}{$setting} ne '') {
                   16858:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  16859:             }
                   16860:             if (@current > 0) {
                   16861:                 if (@new > 0) {
                   16862:                     foreach my $item (@current) {
                   16863:                         if (!grep(/^\Q$item\E$/,@new)) {
                   16864:                             $changes{$type}{$setting} = 1;
1.82      raeburn  16865:                             last;
                   16866:                         }
                   16867:                     }
1.84      raeburn  16868:                     foreach my $item (@new) {
                   16869:                         if (!grep(/^\Q$item\E$/,@current)) {
                   16870:                             $changes{$type}{$setting} = 1;
                   16871:                             last;
1.82      raeburn  16872:                         }
                   16873:                     }
                   16874:                 } else {
1.83      raeburn  16875:                     $changes{$type}{$setting} = 1;
1.69      raeburn  16876:                 }
1.83      raeburn  16877:             } elsif (@new > 0) {
                   16878:                 $changes{$type}{$setting} = 1;
1.69      raeburn  16879:             }
                   16880:         }
                   16881:     }
                   16882:     if (keys(%changes) > 0) {
1.81      raeburn  16883:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  16884:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   16885:                                                  \%serverstatushash,$dom);
                   16886:         if ($putresult eq 'ok') {
                   16887:             $resulttext .= &mt('Changes made:').'<ul>';
                   16888:             foreach my $type (@pages) {
1.84      raeburn  16889:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  16890:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  16891:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  16892:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   16893:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   16894:                         } else {
                   16895:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   16896:                         }
1.84      raeburn  16897:                     }
                   16898:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  16899:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   16900:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   16901:                         } else {
                   16902:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   16903:                         }
                   16904: 
                   16905:                     }
                   16906:                     $resulttext .= '</ul></li>';
                   16907:                 }
                   16908:             }
                   16909:             $resulttext .= '</ul>';
                   16910:         } else {
                   16911:             $resulttext = '<span class="LC_error">'.
                   16912:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   16913: 
                   16914:         }
                   16915:     } else {
                   16916:         $resulttext = &mt('No changes made to access to server status pages');
                   16917:     }
                   16918:     return $resulttext;
                   16919: }
                   16920: 
1.118     jms      16921: sub modify_helpsettings {
1.285     raeburn  16922:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  16923:     my ($resulttext,$errors,%changes,%helphash);
                   16924:     my %defaultchecked = ('submitbugs' => 'on');
                   16925:     my @offon = ('off','on');
1.118     jms      16926:     my @toggles = ('submitbugs');
1.285     raeburn  16927:     my %current = ('submitbugs' => '',
                   16928:                    'adhoc'      => {},
                   16929:                   );
1.118     jms      16930:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  16931:         %current = %{$domconfig{'helpsettings'}};
                   16932:     }
1.285     raeburn  16933:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  16934:     foreach my $item (@toggles) {
                   16935:         if ($defaultchecked{$item} eq 'on') { 
                   16936:             if ($current{$item} eq '') {
                   16937:                 if ($env{'form.'.$item} eq '0') {
                   16938:                     $changes{$item} = 1;
                   16939:                 }
                   16940:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   16941:                 $changes{$item} = 1;
                   16942:             }
                   16943:         } elsif ($defaultchecked{$item} eq 'off') {
                   16944:             if ($current{$item} eq '') {
                   16945:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  16946:                     $changes{$item} = 1;
                   16947:                 }
1.282     raeburn  16948:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   16949:                 $changes{$item} = 1;
                   16950:             }
                   16951:         }
                   16952:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   16953:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   16954:         }
                   16955:     }
1.285     raeburn  16956:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  16957:     my $confname = $dom.'-domainconfig';
                   16958:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  16959:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   16960:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  16961:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  16962:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  16963:     my %lt = &Apache::lonlocal::texthash(
                   16964:                     s      => 'system',
                   16965:                     d      => 'domain',
                   16966:                     order  => 'Display order',
                   16967:                     access => 'Role usage',
1.291     raeburn  16968:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  16969:                     dh     => 'All with domain helpdesk role',
                   16970:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  16971:                     none   => 'None',
                   16972:                     status => 'Determined based on institutional status',
                   16973:                     inc    => 'Include all, but exclude specific personnel',
                   16974:                     exc    => 'Exclude all, but include specific personnel',
                   16975:     );
                   16976:     for (my $num=0; $num<=$maxnum; $num++) {
                   16977:         my ($prefix,$identifier,$rolename,%curr);
                   16978:         if ($num == $maxnum) {
                   16979:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   16980:             $identifier = 'custhelp'.$num;
                   16981:             $prefix = 'helproles_'.$num;
                   16982:             $rolename = $env{'form.custhelpname'.$num};
                   16983:             $rolename=~s/[^A-Za-z0-9]//gs;
                   16984:             next if ($rolename eq '');
                   16985:             next if (exists($existing{'rolesdef_'.$rolename}));
                   16986:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   16987:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   16988:                                                      $newprivs{'c'},$confname,$dom);
                   16989:             if ($result ne 'ok') {
                   16990:                 $errors .= '<li><span class="LC_error">'.
                   16991:                            &mt('An error occurred storing the new custom role: [_1]',
                   16992:                            $result).'</span></li>';
                   16993:                 next;
                   16994:             } else {
                   16995:                 $changedprivs{$rolename} = \%newprivs;
                   16996:                 $newrole = $rolename;
                   16997:             }
                   16998:         } else {
                   16999:             $prefix = 'helproles_'.$num;
                   17000:             $rolename = $env{'form.'.$prefix};
                   17001:             next if ($rolename eq '');
                   17002:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   17003:             $identifier = 'custhelp'.$num;
                   17004:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   17005:             my %currprivs;
1.289     raeburn  17006:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  17007:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   17008:             foreach my $level ('c','d','s') {
                   17009:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   17010:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   17011:                                                              $newprivs{'c'},$confname,$dom);
                   17012:                     if ($result ne 'ok') {
                   17013:                         $errors .= '<li><span class="LC_error">'.
                   17014:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   17015:                                        $rolename,$result).'</span></li>';
                   17016:                     } else {
                   17017:                         $changedprivs{$rolename} = \%newprivs;
                   17018:                     }
                   17019:                     last;
                   17020:                 }
                   17021:             }
                   17022:             if (ref($current{'adhoc'}) eq 'HASH') {
                   17023:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17024:                     %curr = %{$current{'adhoc'}{$rolename}};
                   17025:                 }
                   17026:             }
                   17027:         }
                   17028:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   17029:         $newpos =~ s/\D+//g;
                   17030:         $allpos[$newpos] = $rolename;
                   17031:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   17032:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   17033:         if ($curr{'desc'}) {
                   17034:             if ($curr{'desc'} ne $newdesc) {
                   17035:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17036:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   17037:             }
                   17038:         } elsif ($newdesc ne '') {
                   17039:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17040:             $newsettings{$rolename}{'desc'} = $newdesc;
                   17041:         }
                   17042:         my $access = $env{'form.'.$prefix.'_access'};
                   17043:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   17044:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   17045:             if ($access eq 'status') {
                   17046:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   17047:                 if (scalar(@statuses) == 0) {
1.289     raeburn  17048:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  17049:                 } else {
                   17050:                     my (@shownstatus,$numtypes);
                   17051:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17052:                     if (ref($types) eq 'ARRAY') {
                   17053:                         $numtypes = scalar(@{$types});
                   17054:                         foreach my $type (sort(@statuses)) {
                   17055:                             if ($type eq 'default') {
                   17056:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17057:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   17058:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17059:                                 push(@shownstatus,$usertypes->{$type});
                   17060:                             }
                   17061:                         }
                   17062:                     }
                   17063:                     if (grep(/^default$/,@statuses)) {
                   17064:                         push(@shownstatus,$othertitle);
                   17065:                     }
                   17066:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   17067:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   17068:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   17069:                     } else {
                   17070:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   17071:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   17072:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17073:                             if (@diffs) {
                   17074:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   17075:                             }
                   17076:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17077:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  17078:                         }
1.166     raeburn  17079:                     }
                   17080:                 }
1.285     raeburn  17081:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   17082:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   17083:                 my @newspecstaff;
                   17084:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17085:                 foreach my $person (sort(@personnel)) {
                   17086:                     if ($domhelpdesk{$person}) {
                   17087:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   17088:                     }
                   17089:                 }
                   17090:                 if (ref($curr{$access}) eq 'ARRAY') {
                   17091:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17092:                     if (@diffs) {
                   17093:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   17094:                     }
                   17095:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17096:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   17097:                 }
                   17098:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17099:                     my ($uname,$udom) = split(/:/,$person);
                   17100:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   17101:                 }
                   17102:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  17103:             }
1.285     raeburn  17104:         } else {
                   17105:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   17106:         }
                   17107:         unless ($curr{'access'} eq $access) {
                   17108:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   17109:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  17110:         }
                   17111:     }
1.285     raeburn  17112:     if (@allpos > 0) {
                   17113:         my $idx = 0;
                   17114:         foreach my $rolename (@allpos) {
                   17115:             if ($rolename ne '') {
                   17116:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   17117:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   17118:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17119:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   17120:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  17121:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  17122:                         }
                   17123:                     }
1.282     raeburn  17124:                 }
1.285     raeburn  17125:                 $idx ++;
1.166     raeburn  17126:             }
                   17127:         }
1.118     jms      17128:     }
1.123     jms      17129:     my $putresult;
                   17130:     if (keys(%changes) > 0) {
1.166     raeburn  17131:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  17132:         if ($putresult eq 'ok') {
1.285     raeburn  17133:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   17134:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   17135:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   17136:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   17137:                 }
                   17138:             }
                   17139:             my $cachetime = 24*60*60;
                   17140:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17141:             if (ref($lastactref) eq 'HASH') {
                   17142:                 $lastactref->{'domdefaults'} = 1;
                   17143:             }
                   17144:         } else {
                   17145:             $errors .= '<li><span class="LC_error">'.
                   17146:                        &mt('An error occurred storing the settings: [_1]',
                   17147:                            $putresult).'</span></li>';
                   17148:         }
                   17149:     }
                   17150:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   17151:         $resulttext = &mt('Changes made:').'<ul>';
                   17152:         my (%shownprivs,@levelorder);
                   17153:         @levelorder = ('c','d','s');
                   17154:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  17155:             foreach my $item (sort(keys(%changes))) {
                   17156:                 if ($item eq 'submitbugs') {
                   17157:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   17158:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   17159:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  17160:                 } elsif ($item eq 'customrole') {
                   17161:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  17162:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   17163:                         my %keytext = &Apache::lonlocal::texthash(
                   17164:                                                                    order  => 'Order',
                   17165:                                                                    desc   => 'Role description',
                   17166:                                                                    access => 'Role usage',
1.300     droeschl 17167:                                                                    status => 'Allowed institutional types',
1.285     raeburn  17168:                                                                    exc    => 'Allowed personnel',
                   17169:                                                                    inc    => 'Disallowed personnel',
                   17170:                         );
1.282     raeburn  17171:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  17172:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   17173:                                 if ($role eq $newrole) {
                   17174:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   17175:                                                               $role).'<ul>';
                   17176:                                 } else {
                   17177:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17178:                                                               $role).'<ul>';
                   17179:                                 }
                   17180:                                 foreach my $key (@keyorder) {
                   17181:                                     if ($changes{'customrole'}{$role}{$key}) {
                   17182:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   17183:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   17184:                                                        '</li>';
                   17185:                                     }
                   17186:                                 }
                   17187:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   17188:                                     $shownprivs{$role} = 1;
                   17189:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   17190:                                     foreach my $level (@levelorder) {
                   17191:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17192:                                             next if ($item eq '');
                   17193:                                             my ($priv) = split(/\&/,$item,2);
                   17194:                                             if (&Apache::lonnet::plaintext($priv)) {
                   17195:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17196:                                                 unless ($level eq 'c') {
                   17197:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   17198:                                                 }
                   17199:                                                 $resulttext .= '</li>';
                   17200:                                             }
                   17201:                                         }
                   17202:                                     }
                   17203:                                     $resulttext .= '</ul>';
                   17204:                                 }
                   17205:                                 $resulttext .= '</ul></li>';
                   17206:                             }
                   17207:                         }
                   17208:                     }
                   17209:                 }
                   17210:             }
                   17211:         }
                   17212:         if (keys(%changedprivs)) {
                   17213:             foreach my $role (sort(keys(%changedprivs))) {
                   17214:                 unless ($shownprivs{$role}) {
                   17215:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17216:                                               $role).'<ul>'.
                   17217:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   17218:                     foreach my $level (@levelorder) {
                   17219:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17220:                             next if ($item eq '');
                   17221:                             my ($priv) = split(/\&/,$item,2);
                   17222:                             if (&Apache::lonnet::plaintext($priv)) {
                   17223:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17224:                                 unless ($level eq 'c') {
                   17225:                                     $resulttext .= ' ('.$lt{$level}.')';
                   17226:                                 }
                   17227:                                 $resulttext .= '</li>';
                   17228:                             }
1.282     raeburn  17229:                         }
                   17230:                     }
1.285     raeburn  17231:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  17232:                 }
                   17233:             }
                   17234:         }
1.285     raeburn  17235:         $resulttext .= '</ul>';
                   17236:     } else {
                   17237:         $resulttext = &mt('No changes made to help settings');
1.118     jms      17238:     }
                   17239:     if ($errors) {
1.168     raeburn  17240:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  17241:                                     $errors.'</ul>';
1.118     jms      17242:     }
                   17243:     return $resulttext;
                   17244: }
                   17245: 
1.121     raeburn  17246: sub modify_coursedefaults {
1.212     raeburn  17247:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  17248:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  17249:     my %defaultchecked = (
                   17250:                            'canuse_pdfforms' => 'off',
                   17251:                            'uselcmath'       => 'on',
                   17252:                            'usejsme'         => 'on'
                   17253:                          );
                   17254:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  17255:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  17256:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   17257:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   17258:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  17259:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  17260:     my %staticdefaults = (
                   17261:                            anonsurvey_threshold => 10,
                   17262:                            uploadquota          => 500,
1.257     raeburn  17263:                            postsubmit           => 60,
1.276     raeburn  17264:                            mysqltables          => 172800,
1.198     raeburn  17265:                          );
1.314     raeburn  17266:     my %texoptions = (
                   17267:                         MathJax  => 'MathJax',
                   17268:                         mimetex  => &mt('Convert to Images'),
                   17269:                         tth      => &mt('TeX to HTML'),
                   17270:                      );
1.121     raeburn  17271:     $defaultshash{'coursedefaults'} = {};
                   17272: 
                   17273:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   17274:         if ($domconfig{'coursedefaults'} eq '') {
                   17275:             $domconfig{'coursedefaults'} = {};
                   17276:         }
                   17277:     }
                   17278: 
                   17279:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   17280:         foreach my $item (@toggles) {
                   17281:             if ($defaultchecked{$item} eq 'on') {
                   17282:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17283:                     ($env{'form.'.$item} eq '0')) {
                   17284:                     $changes{$item} = 1;
1.192     raeburn  17285:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  17286:                     $changes{$item} = 1;
                   17287:                 }
                   17288:             } elsif ($defaultchecked{$item} eq 'off') {
                   17289:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17290:                     ($env{'form.'.$item} eq '1')) {
                   17291:                     $changes{$item} = 1;
                   17292:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   17293:                     $changes{$item} = 1;
                   17294:                 }
                   17295:             }
                   17296:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   17297:         }
1.198     raeburn  17298:         foreach my $item (@numbers) {
                   17299:             my ($currdef,$newdef);
1.208     raeburn  17300:             $newdef = $env{'form.'.$item};
1.198     raeburn  17301:             if ($item eq 'anonsurvey_threshold') {
                   17302:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   17303:                 $newdef =~ s/\D//g;
                   17304:                 if ($newdef eq '' || $newdef < 1) {
                   17305:                     $newdef = 1;
                   17306:                 }
                   17307:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   17308:             } else {
1.276     raeburn  17309:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   17310:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   17311:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  17312:                 }
                   17313:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  17314:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  17315:             }
                   17316:             if ($currdef ne $newdef) {
                   17317:                 if ($item eq 'anonsurvey_threshold') {
                   17318:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   17319:                         $changes{$item} = 1;
                   17320:                     }
1.276     raeburn  17321:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  17322:                     my $setting = $1;
1.276     raeburn  17323:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   17324:                         $changes{$setting} = 1;
1.198     raeburn  17325:                     }
                   17326:                 }
1.139     raeburn  17327:             }
                   17328:         }
1.314     raeburn  17329:         my $texengine;
                   17330:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   17331:             $texengine = $env{'form.texengine'};
1.349     raeburn  17332:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   17333:             if ($currdef eq '') {
                   17334:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  17335:                     $changes{'texengine'} = 1;
                   17336:                 }
1.349     raeburn  17337:             } elsif ($currdef ne $texengine) {
1.314     raeburn  17338:                 $changes{'texengine'} = 1;
                   17339:             }
                   17340:         }
                   17341:         if ($texengine ne '') {
                   17342:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   17343:         }
1.264     raeburn  17344:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   17345:         my @currclonecode;
                   17346:         if (ref($currclone) eq 'HASH') {
                   17347:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   17348:                 @currclonecode = @{$currclone->{'instcode'}};
                   17349:             }
                   17350:         }
                   17351:         my $newclone;
1.289     raeburn  17352:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  17353:             $newclone = $env{'form.canclone'};
                   17354:         }
                   17355:         if ($newclone eq 'instcode') {
                   17356:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   17357:             my (%codedefaults,@code_order,@clonecode);
                   17358:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   17359:                                                     \@code_order);
                   17360:             foreach my $item (@code_order) {
                   17361:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   17362:                     push(@clonecode,$item);
                   17363:                 }
                   17364:             }
                   17365:             if (@clonecode) {
                   17366:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   17367:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   17368:                 if (@diffs) {
                   17369:                     $changes{'canclone'} = 1;
                   17370:                 }
                   17371:             } else {
                   17372:                 $newclone eq '';
                   17373:             }
                   17374:         } elsif ($newclone ne '') {
1.289     raeburn  17375:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   17376:         }
1.264     raeburn  17377:         if ($newclone ne $currclone) {
                   17378:             $changes{'canclone'} = 1;
                   17379:         }
1.257     raeburn  17380:         my %credits;
                   17381:         foreach my $type (@types) {
                   17382:             unless ($type eq 'community') {
                   17383:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   17384:                 $credits{$type} =~ s/[^\d.]+//g;
                   17385:             }
                   17386:         }
                   17387:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   17388:             ($env{'form.coursecredits'} eq '1')) {
                   17389:             $changes{'coursecredits'} = 1;
                   17390:             foreach my $type (keys(%credits)) {
                   17391:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17392:             }
                   17393:         } else {
1.289     raeburn  17394:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  17395:                 foreach my $type (@types) {
                   17396:                     unless ($type eq 'community') {
1.289     raeburn  17397:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  17398:                             $changes{'coursecredits'} = 1;
                   17399:                         }
                   17400:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17401:                     }
                   17402:                 }
                   17403:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17404:                 foreach my $type (@types) {
                   17405:                     unless ($type eq 'community') {
                   17406:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   17407:                             $changes{'coursecredits'} = 1;
                   17408:                             last;
                   17409:                         }
                   17410:                     }
                   17411:                 }
                   17412:             }
                   17413:         }
                   17414:         if ($env{'form.postsubmit'} eq '1') {
                   17415:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   17416:             my %currtimeout;
                   17417:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17418:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   17419:                     $changes{'postsubmit'} = 1;
                   17420:                 }
                   17421:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17422:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   17423:                 }
                   17424:             } else {
                   17425:                 $changes{'postsubmit'} = 1;
                   17426:             }
                   17427:             foreach my $type (@types) {
                   17428:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   17429:                 $timeout =~ s/\D//g;
                   17430:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   17431:                     $timeout = '';
                   17432:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   17433:                     $timeout = '0';
                   17434:                 }
                   17435:                 unless ($timeout eq '') {
                   17436:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   17437:                 }
                   17438:                 if (exists($currtimeout{$type})) {
                   17439:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  17440:                         $changes{'postsubmit'} = 1;
1.257     raeburn  17441:                     }
                   17442:                 } elsif ($timeout ne '') {
                   17443:                     $changes{'postsubmit'} = 1;
                   17444:                 }
                   17445:             }
                   17446:         } else {
                   17447:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   17448:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17449:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   17450:                     $changes{'postsubmit'} = 1;
                   17451:                 }
                   17452:             } else {
                   17453:                 $changes{'postsubmit'} = 1;
                   17454:             }
1.192     raeburn  17455:         }
1.121     raeburn  17456:     }
                   17457:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   17458:                                              $dom);
                   17459:     if ($putresult eq 'ok') {
                   17460:         if (keys(%changes) > 0) {
1.213     raeburn  17461:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  17462:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  17463:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314     raeburn  17464:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   17465:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257     raeburn  17466:                     if ($changes{$item}) {
                   17467:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   17468:                     }
1.289     raeburn  17469:                 }
1.192     raeburn  17470:                 if ($changes{'coursecredits'}) {
                   17471:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  17472:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   17473:                             $domdefaults{$type.'credits'} =
                   17474:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   17475:                         }
                   17476:                     }
                   17477:                 }
                   17478:                 if ($changes{'postsubmit'}) {
                   17479:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17480:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   17481:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17482:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   17483:                                 $domdefaults{$type.'postsubtimeout'} =
                   17484:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17485:                             }
                   17486:                         }
1.192     raeburn  17487:                     }
                   17488:                 }
1.198     raeburn  17489:                 if ($changes{'uploadquota'}) {
                   17490:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17491:                         foreach my $type (@types) {
                   17492:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   17493:                         }
                   17494:                     }
                   17495:                 }
1.264     raeburn  17496:                 if ($changes{'canclone'}) {
                   17497:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17498:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17499:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   17500:                             if (@clonecodes) {
                   17501:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   17502:                             }
                   17503:                         }
                   17504:                     } else {
                   17505:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   17506:                     }
                   17507:                 }
1.121     raeburn  17508:                 my $cachetime = 24*60*60;
                   17509:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  17510:                 if (ref($lastactref) eq 'HASH') {
                   17511:                     $lastactref->{'domdefaults'} = 1;
                   17512:                 }
1.121     raeburn  17513:             }
                   17514:             $resulttext = &mt('Changes made:').'<ul>';
                   17515:             foreach my $item (sort(keys(%changes))) {
                   17516:                 if ($item eq 'canuse_pdfforms') {
                   17517:                     if ($env{'form.'.$item} eq '1') {
                   17518:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   17519:                     } else {
                   17520:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   17521:                     }
1.257     raeburn  17522:                 } elsif ($item eq 'uselcmath') {
                   17523:                     if ($env{'form.'.$item} eq '1') {
                   17524:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   17525:                     } else {
                   17526:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   17527:                     }
                   17528:                 } elsif ($item eq 'usejsme') {
                   17529:                     if ($env{'form.'.$item} eq '1') {
                   17530:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   17531:                     } else {
1.289     raeburn  17532:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  17533:                     }
1.314     raeburn  17534:                 } elsif ($item eq 'texengine') {
                   17535:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   17536:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   17537:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   17538:                     }
1.139     raeburn  17539:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  17540:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  17541:                 } elsif ($item eq 'uploadquota') {
                   17542:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17543:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   17544:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   17545:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  17546:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  17547:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  17548:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   17549:                                        '</ul>'.
                   17550:                                        '</li>';
                   17551:                     } else {
                   17552:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   17553:                     }
1.276     raeburn  17554:                 } elsif ($item eq 'mysqltables') {
                   17555:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   17556:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   17557:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   17558:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   17559:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   17560:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   17561:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   17562:                                        '</ul>'.
                   17563:                                        '</li>';
                   17564:                     } else {
                   17565:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   17566:                     }
1.257     raeburn  17567:                 } elsif ($item eq 'postsubmit') {
                   17568:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   17569:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   17570:                     } else {
                   17571:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  17572:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  17573:                             $resulttext .= &mt('durations:').'<ul>';
                   17574:                             foreach my $type (@types) {
                   17575:                                 $resulttext .= '<li>';
                   17576:                                 my $timeout;
                   17577:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17578:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17579:                                 }
                   17580:                                 my $display;
                   17581:                                 if ($timeout eq '0') {
                   17582:                                     $display = &mt('unlimited');
                   17583:                                 } elsif ($timeout eq '') {
                   17584:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   17585:                                 } else {
                   17586:                                     $display = &mt('[quant,_1,second]',$timeout);
                   17587:                                 }
                   17588:                                 if ($type eq 'community') {
                   17589:                                     $resulttext .= &mt('Communities');
                   17590:                                 } elsif ($type eq 'official') {
                   17591:                                     $resulttext .= &mt('Official courses');
                   17592:                                 } elsif ($type eq 'unofficial') {
                   17593:                                     $resulttext .= &mt('Unofficial courses');
                   17594:                                 } elsif ($type eq 'textbook') {
                   17595:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  17596:                                 } elsif ($type eq 'placement') {
                   17597:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  17598:                                 }
                   17599:                                 $resulttext .= ' -- '.$display.'</li>';
                   17600:                             }
                   17601:                             $resulttext .= '</ul>';
                   17602:                         }
1.289     raeburn  17603:                         $resulttext .= '</li>';
1.257     raeburn  17604:                     }
1.192     raeburn  17605:                 } elsif ($item eq 'coursecredits') {
                   17606:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17607:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  17608:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   17609:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  17610:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17611:                         } else {
                   17612:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   17613:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   17614:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  17615:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  17616:                                            '</ul>'.
                   17617:                                            '</li>';
                   17618:                         }
                   17619:                     } else {
                   17620:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17621:                     }
1.264     raeburn  17622:                 } elsif ($item eq 'canclone') {
                   17623:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17624:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17625:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   17626:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   17627:                         }
                   17628:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   17629:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   17630:                     } else {
1.289     raeburn  17631:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  17632:                     }
1.140     raeburn  17633:                 }
1.121     raeburn  17634:             }
                   17635:             $resulttext .= '</ul>';
                   17636:         } else {
                   17637:             $resulttext = &mt('No changes made to course defaults');
                   17638:         }
                   17639:     } else {
                   17640:         $resulttext = '<span class="LC_error">'.
                   17641:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17642:     }
                   17643:     return $resulttext;
                   17644: }
                   17645: 
1.231     raeburn  17646: sub modify_selfenrollment {
                   17647:     my ($dom,$lastactref,%domconfig) = @_;
                   17648:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  17649:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  17650:     my %titles = &tool_titles();
1.232     raeburn  17651:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   17652:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  17653:     $ordered{'default'} = ['types','registered','approval','limit'];
                   17654: 
                   17655:     my (%roles,%shown,%toplevel);
                   17656:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   17657: 
                   17658:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   17659:         if ($domconfig{'selfenrollment'} eq '') {
                   17660:             $domconfig{'selfenrollment'} = {};
                   17661:         }
                   17662:     }
                   17663:     %toplevel = (
                   17664:                   admin      => 'Configuration Rights',
                   17665:                   default    => 'Default settings',
                   17666:                   validation => 'Validation of self-enrollment requests',
                   17667:                 );
1.233     raeburn  17668:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  17669: 
                   17670:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   17671:         foreach my $item (@{$ordered{'admin'}}) {
                   17672:             foreach my $type (@types) {
                   17673:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   17674:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   17675:                 } else {
                   17676:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   17677:                 }
                   17678:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   17679:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   17680:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   17681:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   17682:                             push(@{$changes{'admin'}{$type}},$item);
                   17683:                         }
                   17684:                     } else {
                   17685:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17686:                             push(@{$changes{'admin'}{$type}},$item);
                   17687:                         }
                   17688:                     }
                   17689:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17690:                     push(@{$changes{'admin'}{$type}},$item);
                   17691:                 }
                   17692:             }
                   17693:         }
                   17694:     }
                   17695: 
                   17696:     foreach my $item (@{$ordered{'default'}}) {
                   17697:         foreach my $type (@types) {
                   17698:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   17699:             if ($item eq 'types') {
                   17700:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   17701:                     $value = '';
                   17702:                 }
                   17703:             } elsif ($item eq 'registered') {
                   17704:                 unless ($value eq '1') {
                   17705:                     $value = 0;
                   17706:                 }
                   17707:             } elsif ($item eq 'approval') {
                   17708:                 unless ($value =~ /^[012]$/) {
                   17709:                     $value = 0;
                   17710:                 }
                   17711:             } else {
                   17712:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   17713:                     $value = 'none';
                   17714:                 }
                   17715:             }
                   17716:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   17717:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   17718:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   17719:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   17720:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   17721:                          push(@{$changes{'default'}{$type}},$item);
                   17722:                     }
                   17723:                 } else {
                   17724:                     push(@{$changes{'default'}{$type}},$item);
                   17725:                 }
                   17726:             } else {
                   17727:                 push(@{$changes{'default'}{$type}},$item);
                   17728:             }
                   17729:             if ($item eq 'limit') {
                   17730:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   17731:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   17732:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   17733:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   17734:                     }
                   17735:                 } else {
                   17736:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   17737:                 }
                   17738:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   17739:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   17740:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   17741:                          push(@{$changes{'default'}{$type}},'cap');
                   17742:                     }
                   17743:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   17744:                     push(@{$changes{'default'}{$type}},'cap');
                   17745:                 }
                   17746:             }
                   17747:         }
                   17748:     }
                   17749: 
                   17750:     foreach my $item (@{$itemsref}) {
                   17751:         if ($item eq 'fields') {
                   17752:             my @changed;
                   17753:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   17754:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   17755:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   17756:             }
                   17757:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   17758:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   17759:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   17760:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   17761:                 } else {
                   17762:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   17763:                 }
                   17764:             } else {
                   17765:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   17766:             }
                   17767:             if (@changed) {
                   17768:                 if ($selfenrollhash{'validation'}{$item}) { 
                   17769:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   17770:                 } else {
                   17771:                     $changes{'validation'}{$item} = &mt('None');
                   17772:                 }
                   17773:             }
                   17774:         } else {
                   17775:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   17776:             if ($item eq 'markup') {
                   17777:                if ($env{'form.selfenroll_validation_'.$item}) {
                   17778:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   17779:                }
                   17780:             }
                   17781:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   17782:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   17783:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   17784:                 }
                   17785:             }
                   17786:         }
                   17787:     }
                   17788: 
                   17789:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   17790:                                              $dom);
                   17791:     if ($putresult eq 'ok') {
                   17792:         if (keys(%changes) > 0) {
                   17793:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   17794:             $resulttext = &mt('Changes made:').'<ul>';
                   17795:             foreach my $key ('admin','default','validation') {
                   17796:                 if (ref($changes{$key}) eq 'HASH') {
                   17797:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   17798:                     if ($key eq 'validation') {
                   17799:                         foreach my $item (@{$itemsref}) {
                   17800:                             if (exists($changes{$key}{$item})) {
                   17801:                                 if ($item eq 'markup') {
                   17802:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   17803:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   17804:                                 } else {  
                   17805:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   17806:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   17807:                                 }
                   17808:                             }
                   17809:                         }
                   17810:                     } else {
                   17811:                         foreach my $type (@types) {
                   17812:                             if ($type eq 'community') {
                   17813:                                 $roles{'1'} = &mt('Community personnel');
                   17814:                             } else {
                   17815:                                 $roles{'1'} = &mt('Course personnel');
                   17816:                             }
                   17817:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  17818:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   17819:                                     if ($key eq 'admin') {
                   17820:                                         my @mgrdc = ();
                   17821:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   17822:                                             foreach my $item (@{$ordered{'admin'}}) {
                   17823:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   17824:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   17825:                                                         push(@mgrdc,$item);
                   17826:                                                     }
                   17827:                                                 }
                   17828:                                             }
                   17829:                                             if (@mgrdc) {
                   17830:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   17831:                                             } else {
                   17832:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   17833:                                             }
                   17834:                                         }
                   17835:                                     } else {
                   17836:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   17837:                                             foreach my $item (@{$ordered{$key}}) {
                   17838:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   17839:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   17840:                                                         $selfenrollhash{$key}{$type}{$item};
                   17841:                                                 }
                   17842:                                             }
                   17843:                                         }
                   17844:                                     }
                   17845:                                 }
1.231     raeburn  17846:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   17847:                                 foreach my $item (@{$ordered{$key}}) {
                   17848:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   17849:                                         $resulttext .= '<li>';
                   17850:                                         if ($key eq 'admin') {
                   17851:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   17852:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   17853:                                         } else {
                   17854:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   17855:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   17856:                                         }
                   17857:                                         $resulttext .= '</li>';
                   17858:                                     }
                   17859:                                 }
                   17860:                                 $resulttext .= '</ul></li>';
                   17861:                             }
                   17862:                         }
                   17863:                         $resulttext .= '</ul></li>'; 
                   17864:                     }
                   17865:                 }
1.305     raeburn  17866:             }
                   17867:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   17868:                 my $cachetime = 24*60*60;
                   17869:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17870:                 if (ref($lastactref) eq 'HASH') {
                   17871:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  17872:                 }
1.231     raeburn  17873:             }
                   17874:             $resulttext .= '</ul>';
                   17875:         } else {
                   17876:             $resulttext = &mt('No changes made to self-enrollment settings');
                   17877:         }
                   17878:     } else {
                   17879:         $resulttext = '<span class="LC_error">'.
                   17880:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17881:     }
                   17882:     return $resulttext;
                   17883: }
                   17884: 
1.137     raeburn  17885: sub modify_usersessions {
1.212     raeburn  17886:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  17887:     my @hostingtypes = ('version','excludedomain','includedomain');
                   17888:     my @offloadtypes = ('primary','default');
                   17889:     my %types = (
                   17890:                   remote => \@hostingtypes,
                   17891:                   hosted => \@hostingtypes,
                   17892:                   spares => \@offloadtypes,
                   17893:                 );
                   17894:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  17895:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  17896:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   17897:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  17898:     my @locations = sort(keys(%by_location));
1.137     raeburn  17899:     my (%defaultshash,%changes);
                   17900:     foreach my $prefix (@prefixes) {
                   17901:         $defaultshash{'usersessions'}{$prefix} = {};
                   17902:     }
1.212     raeburn  17903:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  17904:     my $resulttext;
1.138     raeburn  17905:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  17906:     foreach my $prefix (@prefixes) {
1.145     raeburn  17907:         next if ($prefix eq 'spares');
                   17908:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  17909:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   17910:             if ($type eq 'version') {
                   17911:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   17912:                 my $okvalue;
                   17913:                 if ($value ne '') {
                   17914:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   17915:                         $okvalue = $value;
                   17916:                     }
                   17917:                 }
                   17918:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   17919:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   17920:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   17921:                             if ($inuse == 0) {
                   17922:                                 $changes{$prefix}{$type} = 1;
                   17923:                             } else {
                   17924:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   17925:                                     $changes{$prefix}{$type} = 1;
                   17926:                                 }
                   17927:                                 if ($okvalue ne '') {
                   17928:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   17929:                                 } 
                   17930:                             }
                   17931:                         } else {
                   17932:                             if (($inuse == 1) && ($okvalue ne '')) {
                   17933:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   17934:                                 $changes{$prefix}{$type} = 1;
                   17935:                             }
                   17936:                         }
                   17937:                     } else {
                   17938:                         if (($inuse == 1) && ($okvalue ne '')) {
                   17939:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   17940:                             $changes{$prefix}{$type} = 1;
                   17941:                         }
                   17942:                     }
                   17943:                 } else {
                   17944:                     if (($inuse == 1) && ($okvalue ne '')) {
                   17945:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   17946:                         $changes{$prefix}{$type} = 1;
                   17947:                     }
                   17948:                 }
                   17949:             } else {
                   17950:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   17951:                 my @okvals;
                   17952:                 foreach my $val (@vals) {
1.138     raeburn  17953:                     if ($val =~ /:/) {
                   17954:                         my @items = split(/:/,$val);
                   17955:                         foreach my $item (@items) {
                   17956:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   17957:                                 push(@okvals,$item);
                   17958:                             }
                   17959:                         }
                   17960:                     } else {
                   17961:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   17962:                             push(@okvals,$val);
                   17963:                         }
1.137     raeburn  17964:                     }
                   17965:                 }
                   17966:                 @okvals = sort(@okvals);
                   17967:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   17968:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   17969:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   17970:                             if ($inuse == 0) {
                   17971:                                 $changes{$prefix}{$type} = 1; 
                   17972:                             } else {
                   17973:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   17974:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   17975:                                 if (@changed > 0) {
                   17976:                                     $changes{$prefix}{$type} = 1;
                   17977:                                 }
                   17978:                             }
                   17979:                         } else {
                   17980:                             if ($inuse == 1) {
                   17981:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   17982:                                 $changes{$prefix}{$type} = 1;
                   17983:                             }
                   17984:                         } 
                   17985:                     } else {
                   17986:                         if ($inuse == 1) {
                   17987:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   17988:                             $changes{$prefix}{$type} = 1;
                   17989:                         }
                   17990:                     }
                   17991:                 } else {
                   17992:                     if ($inuse == 1) {
                   17993:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   17994:                         $changes{$prefix}{$type} = 1;
                   17995:                     }
                   17996:                 }
                   17997:             }
                   17998:         }
                   17999:     }
1.145     raeburn  18000: 
                   18001:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  18002:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  18003:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   18004:     my $savespares;
                   18005: 
                   18006:     foreach my $lonhost (sort(keys(%servers))) {
                   18007:         my $serverhomeID =
                   18008:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  18009:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  18010:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   18011:         my %spareschg;
                   18012:         foreach my $type (@{$types{'spares'}}) {
                   18013:             my @okspares;
                   18014:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   18015:             foreach my $server (@checked) {
1.152     raeburn  18016:                 if (&Apache::lonnet::hostname($server) ne '') {
                   18017:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   18018:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   18019:                             push(@okspares,$server);
                   18020:                         }
1.145     raeburn  18021:                     }
                   18022:                 }
                   18023:             }
                   18024:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   18025:             my $newspare;
1.152     raeburn  18026:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   18027:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  18028:                     $newspare = $new;
                   18029:                 }
                   18030:             }
1.152     raeburn  18031:             my @spares;
                   18032:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   18033:                 @spares = sort(@okspares,$newspare);
                   18034:             } else {
                   18035:                 @spares = sort(@okspares);
                   18036:             }
                   18037:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  18038:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   18039:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  18040:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  18041:                     if (@diffs > 0) {
                   18042:                         $spareschg{$type} = 1;
                   18043:                     }
                   18044:                 }
                   18045:             }
                   18046:         }
                   18047:         if (keys(%spareschg) > 0) {
                   18048:             $changes{'spares'}{$lonhost} = \%spareschg;
                   18049:         }
                   18050:     }
1.261     raeburn  18051:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   18052:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   18053:     my @okoffload;
                   18054:     if (@offloadnow) {
                   18055:         foreach my $server (@offloadnow) {
                   18056:             if (&Apache::lonnet::hostname($server) ne '') {
                   18057:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   18058:                     push(@okoffload,$server);
                   18059:                 }
                   18060:             }
                   18061:         }
                   18062:         if (@okoffload) {
                   18063:             foreach my $lonhost (@okoffload) {
                   18064:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   18065:             }
                   18066:         }
                   18067:     }
1.145     raeburn  18068:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18069:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   18070:             if (ref($changes{'spares'}) eq 'HASH') {
                   18071:                 if (keys(%{$changes{'spares'}}) > 0) {
                   18072:                     $savespares = 1;
                   18073:                 }
                   18074:             }
                   18075:         } else {
                   18076:             $savespares = 1;
                   18077:         }
1.261     raeburn  18078:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18079:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   18080:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   18081:                     $changes{'offloadnow'} = 1;
                   18082:                     last;
                   18083:                 }
                   18084:             }
                   18085:             unless ($changes{'offloadnow'}) {
1.289     raeburn  18086:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261     raeburn  18087:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   18088:                         $changes{'offloadnow'} = 1;
                   18089:                         last;
                   18090:                     }
                   18091:                 }
                   18092:             }
                   18093:         } elsif (@okoffload) {
                   18094:             $changes{'offloadnow'} = 1;
                   18095:         }
                   18096:     } elsif (@okoffload) {
                   18097:         $changes{'offloadnow'} = 1;
1.145     raeburn  18098:     }
1.147     raeburn  18099:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   18100:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  18101:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18102:                                                  $dom);
                   18103:         if ($putresult eq 'ok') {
                   18104:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18105:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   18106:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   18107:                 }
                   18108:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   18109:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   18110:                 }
1.261     raeburn  18111:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18112:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   18113:                 }
1.137     raeburn  18114:             }
                   18115:             my $cachetime = 24*60*60;
                   18116:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  18117:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  18118:             if (ref($lastactref) eq 'HASH') {
                   18119:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  18120:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  18121:             }
1.147     raeburn  18122:             if (keys(%changes) > 0) {
                   18123:                 my %lt = &usersession_titles();
                   18124:                 $resulttext = &mt('Changes made:').'<ul>';
                   18125:                 foreach my $prefix (@prefixes) {
                   18126:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18127:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   18128:                         if ($prefix eq 'spares') {
                   18129:                             if (ref($changes{$prefix}) eq 'HASH') {
                   18130:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   18131:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  18132:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  18133:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   18134:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  18135:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   18136:                                         foreach my $type (@{$types{$prefix}}) {
                   18137:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   18138:                                                 my $offloadto = &mt('None');
                   18139:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   18140:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   18141:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   18142:                                                     }
1.145     raeburn  18143:                                                 }
1.147     raeburn  18144:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  18145:                                             }
1.137     raeburn  18146:                                         }
                   18147:                                     }
1.147     raeburn  18148:                                     $resulttext .= '</li>';
1.137     raeburn  18149:                                 }
                   18150:                             }
1.147     raeburn  18151:                         } else {
                   18152:                             foreach my $type (@{$types{$prefix}}) {
                   18153:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18154:                                     my ($newvalue,$notinuse);
1.147     raeburn  18155:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18156:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   18157:                                             if ($type eq 'version') {
                   18158:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  18159:                                             } else {
                   18160:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   18161:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   18162:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   18163:                                                     }
                   18164:                                                 } else {
                   18165:                                                     $notinuse = 1;
1.147     raeburn  18166:                                                 }
1.145     raeburn  18167:                                             }
                   18168:                                         }
                   18169:                                     }
1.147     raeburn  18170:                                     if ($newvalue eq '') {
                   18171:                                         if ($type eq 'version') {
                   18172:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  18173:                                         } elsif ($notinuse) {
                   18174:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  18175:                                         } else {
                   18176:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   18177:                                         }
1.145     raeburn  18178:                                     } else {
1.147     raeburn  18179:                                         if ($type eq 'version') {
1.344     raeburn  18180:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  18181:                                         }
                   18182:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  18183:                                     }
1.137     raeburn  18184:                                 }
                   18185:                             }
                   18186:                         }
1.147     raeburn  18187:                         $resulttext .= '</ul>';
1.137     raeburn  18188:                     }
                   18189:                 }
1.261     raeburn  18190:                 if ($changes{'offloadnow'}) {
                   18191:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18192:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   18193:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   18194:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   18195:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   18196:                             }
                   18197:                             $resulttext .= '</ul>';
                   18198:                         } else {
                   18199:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   18200:                         }
                   18201:                     } else {
                   18202:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   18203:                     }
                   18204:                 }
1.147     raeburn  18205:                 $resulttext .= '</ul>';
                   18206:             } else {
                   18207:                 $resulttext = $nochgmsg;
1.137     raeburn  18208:             }
                   18209:         } else {
                   18210:             $resulttext = '<span class="LC_error">'.
                   18211:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18212:         }
                   18213:     } else {
1.147     raeburn  18214:         $resulttext = $nochgmsg;
1.137     raeburn  18215:     }
                   18216:     return $resulttext;
                   18217: }
                   18218: 
1.275     raeburn  18219: sub modify_ssl {
                   18220:     my ($dom,$lastactref,%domconfig) = @_;
                   18221:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18222:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   18223:     my @locations = sort(keys(%by_location));
                   18224:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   18225:     my (%defaultshash,%changes);
                   18226:     my $action = 'ssl';
1.293     raeburn  18227:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  18228:     foreach my $prefix (@prefixes) {
                   18229:         $defaultshash{$action}{$prefix} = {};
                   18230:     }
                   18231:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18232:     my $resulttext;
                   18233:     my %iphost = &Apache::lonnet::get_iphost();
                   18234:     my @reptypes = ('certreq','nocertreq');
                   18235:     my @connecttypes = ('dom','intdom','other');
                   18236:     my %types = (
1.293     raeburn  18237:                   connto      => \@connecttypes,
                   18238:                   connfrom    => \@connecttypes,
                   18239:                   replication => \@reptypes,
1.275     raeburn  18240:                 );
                   18241:     foreach my $prefix (sort(keys(%types))) {
                   18242:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  18243:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  18244:                 my $value = 'yes';
                   18245:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   18246:                     $value = $env{'form.'.$prefix.'_'.$type};
                   18247:                 }
1.335     raeburn  18248:                 if (ref($domconfig{$action}) eq 'HASH') {
                   18249:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   18250:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   18251:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   18252:                                 $changes{$prefix}{$type} = 1;
                   18253:                             }
                   18254:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   18255:                         } else {
                   18256:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  18257:                             $changes{$prefix}{$type} = 1;
                   18258:                         }
                   18259:                     } else {
                   18260:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   18261:                         $changes{$prefix}{$type} = 1;
                   18262:                     }
                   18263:                 } else {
                   18264:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   18265:                     $changes{$prefix}{$type} = 1;
                   18266:                 }
                   18267:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   18268:                     delete($changes{$prefix}{$type});
                   18269:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   18270:                     delete($changes{$prefix}{$type});
                   18271:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   18272:                     delete($changes{$prefix}{$type});
                   18273:                 }
                   18274:             } elsif ($prefix eq 'replication') {
                   18275:                 if (@locations > 0) {
                   18276:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18277:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18278:                     my @okvals;
                   18279:                     foreach my $val (@vals) {
                   18280:                         if ($val =~ /:/) {
                   18281:                             my @items = split(/:/,$val);
                   18282:                             foreach my $item (@items) {
                   18283:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   18284:                                     push(@okvals,$item);
                   18285:                                 }
                   18286:                             }
                   18287:                         } else {
                   18288:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   18289:                                 push(@okvals,$val);
                   18290:                             }
                   18291:                         }
                   18292:                     }
                   18293:                     @okvals = sort(@okvals);
                   18294:                     if (ref($domconfig{$action}) eq 'HASH') {
                   18295:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   18296:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   18297:                                 if ($inuse == 0) {
                   18298:                                     $changes{$prefix}{$type} = 1;
                   18299:                                 } else {
                   18300:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18301:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   18302:                                     if (@changed > 0) {
                   18303:                                         $changes{$prefix}{$type} = 1;
                   18304:                                     }
                   18305:                                 }
                   18306:                             } else {
                   18307:                                 if ($inuse == 1) {
                   18308:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18309:                                     $changes{$prefix}{$type} = 1;
                   18310:                                 }
                   18311:                             }
                   18312:                         } else {
                   18313:                             if ($inuse == 1) {
                   18314:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18315:                                 $changes{$prefix}{$type} = 1;
                   18316:                             }
                   18317:                         }
                   18318:                     } else {
                   18319:                         if ($inuse == 1) {
                   18320:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18321:                             $changes{$prefix}{$type} = 1;
                   18322:                         }
                   18323:                     }
                   18324:                 }
                   18325:             }
                   18326:         }
                   18327:     }
1.336     raeburn  18328:     if (keys(%changes)) {
                   18329:         foreach my $prefix (keys(%changes)) {
                   18330:             if (ref($changes{$prefix}) eq 'HASH') {
                   18331:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   18332:                     delete($changes{$prefix});
                   18333:                 }
                   18334:             } else {
                   18335:                 delete($changes{$prefix});
                   18336:             }
                   18337:         }
                   18338:     }
1.275     raeburn  18339:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   18340:     if (keys(%changes) > 0) {
                   18341:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18342:                                                  $dom);
                   18343:         if ($putresult eq 'ok') {
                   18344:             if (ref($defaultshash{$action}) eq 'HASH') {
                   18345:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   18346:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   18347:                 }
1.293     raeburn  18348:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  18349:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  18350:                 }
                   18351:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  18352:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  18353:                 }
                   18354:             }
                   18355:             my $cachetime = 24*60*60;
                   18356:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18357:             if (ref($lastactref) eq 'HASH') {
                   18358:                 $lastactref->{'domdefaults'} = 1;
                   18359:             }
                   18360:             if (keys(%changes) > 0) {
                   18361:                 my %titles = &ssl_titles();
                   18362:                 $resulttext = &mt('Changes made:').'<ul>';
                   18363:                 foreach my $prefix (@prefixes) {
                   18364:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18365:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   18366:                         foreach my $type (@{$types{$prefix}}) {
                   18367:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18368:                                 my ($newvalue,$notinuse);
1.275     raeburn  18369:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   18370:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  18371:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  18372:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  18373:                                         } else {
                   18374:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   18375:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   18376:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   18377:                                                 }
                   18378:                                             } else {
                   18379:                                                 $notinuse = 1;
1.275     raeburn  18380:                                             }
                   18381:                                         }
                   18382:                                     }
1.344     raeburn  18383:                                     if ($notinuse) {
                   18384:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   18385:                                     } elsif ($newvalue eq '') {
1.275     raeburn  18386:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   18387:                                     } else {
                   18388:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   18389:                                     }
                   18390:                                 }
                   18391:                             }
                   18392:                         }
                   18393:                         $resulttext .= '</ul>';
                   18394:                     }
                   18395:                 }
                   18396:             } else {
                   18397:                 $resulttext = $nochgmsg;
                   18398:             }
                   18399:         } else {
                   18400:             $resulttext = '<span class="LC_error">'.
                   18401:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18402:         }
                   18403:     } else {
                   18404:         $resulttext = $nochgmsg;
                   18405:     }
                   18406:     return $resulttext;
                   18407: }
                   18408: 
1.279     raeburn  18409: sub modify_trust {
                   18410:     my ($dom,$lastactref,%domconfig) = @_;
                   18411:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18412:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   18413:     my @locations = sort(keys(%by_location));
                   18414:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   18415:     my @types = ('exc','inc');
                   18416:     my (%defaultshash,%changes);
                   18417:     foreach my $prefix (@prefixes) {
                   18418:         $defaultshash{'trust'}{$prefix} = {};
                   18419:     }
                   18420:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18421:     my $resulttext;
                   18422:     foreach my $prefix (@prefixes) {
                   18423:         foreach my $type (@types) {
                   18424:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18425:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18426:             my @okvals;
                   18427:             foreach my $val (@vals) {
                   18428:                 if ($val =~ /:/) {
                   18429:                     my @items = split(/:/,$val);
                   18430:                     foreach my $item (@items) {
                   18431:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   18432:                             push(@okvals,$item);
                   18433:                         }
                   18434:                     }
                   18435:                 } else {
                   18436:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   18437:                         push(@okvals,$val);
                   18438:                     }
                   18439:                 }
                   18440:             }
                   18441:             @okvals = sort(@okvals);
                   18442:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   18443:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   18444:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   18445:                         if ($inuse == 0) {
                   18446:                             $changes{$prefix}{$type} = 1;
                   18447:                         } else {
                   18448:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18449:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   18450:                             if (@changed > 0) {
                   18451:                                 $changes{$prefix}{$type} = 1;
                   18452:                             }
                   18453:                         }
                   18454:                     } else {
                   18455:                         if ($inuse == 1) {
                   18456:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18457:                             $changes{$prefix}{$type} = 1;
                   18458:                         }
                   18459:                     }
                   18460:                 } else {
                   18461:                     if ($inuse == 1) {
                   18462:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18463:                         $changes{$prefix}{$type} = 1;
                   18464:                     }
                   18465:                 }
                   18466:             } else {
                   18467:                 if ($inuse == 1) {
                   18468:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18469:                     $changes{$prefix}{$type} = 1;
                   18470:                 }
                   18471:             }
                   18472:         }
                   18473:     }
                   18474:     my $nochgmsg = &mt('No changes made to trust settings.');
                   18475:     if (keys(%changes) > 0) {
                   18476:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18477:                                                  $dom);
                   18478:         if ($putresult eq 'ok') {
                   18479:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   18480:                 foreach my $prefix (@prefixes) {
                   18481:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   18482:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   18483:                     }
                   18484:                 }
                   18485:             }
                   18486:             my $cachetime = 24*60*60;
                   18487:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18488:             if (ref($lastactref) eq 'HASH') {
                   18489:                 $lastactref->{'domdefaults'} = 1;
                   18490:             }
                   18491:             if (keys(%changes) > 0) {
                   18492:                 my %lt = &trust_titles();
                   18493:                 $resulttext = &mt('Changes made:').'<ul>';
                   18494:                 foreach my $prefix (@prefixes) {
                   18495:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18496:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   18497:                         foreach my $type (@types) {
                   18498:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18499:                                 my ($newvalue,$notinuse);
1.279     raeburn  18500:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   18501:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   18502:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   18503:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   18504:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   18505:                                             }
1.344     raeburn  18506:                                         } else {
                   18507:                                             $notinuse = 1;
1.279     raeburn  18508:                                         }
                   18509:                                     }
                   18510:                                 }
1.344     raeburn  18511:                                 if ($notinuse) {
                   18512:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   18513:                                 } elsif ($newvalue eq '') {
1.279     raeburn  18514:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   18515:                                 } else {
                   18516:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   18517:                                 }
                   18518:                             }
                   18519:                         }
                   18520:                         $resulttext .= '</ul>';
                   18521:                     }
                   18522:                 }
                   18523:                 $resulttext .= '</ul>';
                   18524:             } else {
                   18525:                 $resulttext = $nochgmsg;
                   18526:             }
                   18527:         } else {
                   18528:             $resulttext = '<span class="LC_error">'.
                   18529:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18530:         }
                   18531:     } else {
                   18532:         $resulttext = $nochgmsg;
                   18533:     }
                   18534:     return $resulttext;
                   18535: }
                   18536: 
1.150     raeburn  18537: sub modify_loadbalancing {
                   18538:     my ($dom,%domconfig) = @_;
                   18539:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   18540:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   18541:     my ($othertitle,$usertypes,$types) =
                   18542:         &Apache::loncommon::sorted_inst_types($dom);
                   18543:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  18544:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  18545:     my @sparestypes = ('primary','default');
                   18546:     my %typetitles = &sparestype_titles();
                   18547:     my $resulttext;
1.342     raeburn  18548:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  18549:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18550:         %existing = %{$domconfig{'loadbalancing'}};
                   18551:     }
                   18552:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  18553:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  18554:     my ($saveloadbalancing,%defaultshash,%changes);
                   18555:     my ($alltypes,$othertypes,$titles) =
                   18556:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   18557:     my %ruletitles = &offloadtype_text();
                   18558:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   18559:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   18560:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   18561:         if ($balancer eq '') {
                   18562:             next;
                   18563:         }
1.210     raeburn  18564:         if (!exists($servers{$balancer})) {
1.171     raeburn  18565:             if (exists($currbalancer{$balancer})) {
                   18566:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  18567:             }
1.171     raeburn  18568:             next;
                   18569:         }
                   18570:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   18571:             push(@{$changes{'delete'}},$balancer);
                   18572:             next;
                   18573:         }
                   18574:         if (!exists($currbalancer{$balancer})) {
                   18575:             push(@{$changes{'add'}},$balancer);
                   18576:         }
                   18577:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   18578:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   18579:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   18580:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18581:             $saveloadbalancing = 1;
                   18582:         }
                   18583:         foreach my $sparetype (@sparestypes) {
                   18584:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   18585:             my @offloadto;
                   18586:             foreach my $target (@targets) {
                   18587:                 if (($servers{$target}) && ($target ne $balancer)) {
                   18588:                     if ($sparetype eq 'default') {
                   18589:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   18590:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  18591:                         }
                   18592:                     }
1.171     raeburn  18593:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   18594:                         push(@offloadto,$target);
                   18595:                     }
1.150     raeburn  18596:                 }
                   18597:             }
1.284     raeburn  18598:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   18599:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   18600:                     push(@offloadto,$balancer);
                   18601:                 }
                   18602:             }
                   18603:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  18604:         }
1.342     raeburn  18605:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   18606:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   18607:             if (exists($currbalancer{$balancer})) { 
                   18608:                 unless ($currcookies{$balancer}) {
                   18609:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18610:                 }
                   18611:             }
                   18612:         } elsif (exists($currbalancer{$balancer})) {
                   18613:             if ($currcookies{$balancer}) {
                   18614:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18615:             }
                   18616:         }
1.171     raeburn  18617:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  18618:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  18619:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   18620:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  18621:                     if (@targetdiffs > 0) {
1.171     raeburn  18622:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18623:                     }
1.171     raeburn  18624:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18625:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18626:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18627:                     }
                   18628:                 }
                   18629:             }
                   18630:         } else {
1.171     raeburn  18631:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  18632:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  18633:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18634:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18635:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   18636:                         }
1.150     raeburn  18637:                     }
                   18638:                 }
1.210     raeburn  18639:             }
1.150     raeburn  18640:         }
                   18641:         my $ishomedom;
1.171     raeburn  18642:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   18643:             $ishomedom = 1;
1.150     raeburn  18644:         }
                   18645:         if (ref($alltypes) eq 'ARRAY') {
                   18646:             foreach my $type (@{$alltypes}) {
                   18647:                 my $rule;
1.210     raeburn  18648:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  18649:                          (!$ishomedom)) {
1.171     raeburn  18650:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   18651:                 }
                   18652:                 if ($rule eq 'specific') {
1.255     raeburn  18653:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  18654:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  18655:                         $rule = $specifiedhost;
                   18656:                     }
1.150     raeburn  18657:                 }
1.171     raeburn  18658:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   18659:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   18660:                     if ($rule ne $currrules{$balancer}{$type}) {
                   18661:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18662:                     }
                   18663:                 } elsif ($rule ne '') {
1.171     raeburn  18664:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18665:                 }
                   18666:             }
                   18667:         }
1.171     raeburn  18668:     }
                   18669:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   18670:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   18671:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   18672:             $defaultshash{'loadbalancing'} = {};
                   18673:         }
                   18674:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   18675:                                                  \%defaultshash,$dom);
                   18676:         if ($putresult eq 'ok') {
                   18677:             if (keys(%changes) > 0) {
1.252     raeburn  18678:                 my %toupdate;
1.171     raeburn  18679:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   18680:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   18681:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  18682:                         $toupdate{$balancer} = 1;
1.150     raeburn  18683:                     }
1.171     raeburn  18684:                 }
                   18685:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  18686:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  18687:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  18688:                         $toupdate{$balancer} = 1;
1.171     raeburn  18689:                     }
                   18690:                 }
                   18691:                 if (ref($changes{'curr'}) eq 'HASH') {
                   18692:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  18693:                         $toupdate{$balancer} = 1;
1.171     raeburn  18694:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   18695:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   18696:                                 my %offloadstr;
                   18697:                                 foreach my $sparetype (@sparestypes) {
                   18698:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18699:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18700:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   18701:                                         }
                   18702:                                     }
1.150     raeburn  18703:                                 }
1.171     raeburn  18704:                                 if (keys(%offloadstr) == 0) {
                   18705:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  18706:                                 } else {
1.171     raeburn  18707:                                     my $showoffload;
                   18708:                                     foreach my $sparetype (@sparestypes) {
                   18709:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   18710:                                         if (defined($offloadstr{$sparetype})) {
                   18711:                                             $showoffload .= $offloadstr{$sparetype};
                   18712:                                         } else {
                   18713:                                             $showoffload .= &mt('None');
                   18714:                                         }
                   18715:                                         $showoffload .= ('&nbsp;'x3);
                   18716:                                     }
                   18717:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  18718:                                 }
                   18719:                             }
                   18720:                         }
1.171     raeburn  18721:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   18722:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   18723:                                 foreach my $type (@{$alltypes}) {
                   18724:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   18725:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   18726:                                         my $balancetext;
                   18727:                                         if ($rule eq '') {
                   18728:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  18729:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  18730:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  18731:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  18732:                                                 foreach my $sparetype (@sparestypes) {
                   18733:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18734:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   18735:                                                     }
                   18736:                                                 }
1.253     raeburn  18737:                                                 foreach my $item (@{$alltypes}) {
                   18738:                                                     next if ($item =~  /^_LC_ipchange/);
                   18739:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   18740:                                                     if ($hasrule eq 'homeserver') {
                   18741:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   18742:                                                     } else {
                   18743:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   18744:                                                             if ($servers{$hasrule}) {
                   18745:                                                                 $toupdate{$hasrule} = 1;
                   18746:                                                             }
                   18747:                                                         }
                   18748:                                                     }
                   18749:                                                 }
1.254     raeburn  18750:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   18751:                                                     $balancetext =  $ruletitles{$rule};
                   18752:                                                 } else {
                   18753:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   18754:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   18755:                                                     if ($receiver) {
                   18756:                                                         $toupdate{$receiver};
                   18757:                                                     }
                   18758:                                                 }
                   18759:                                             } else {
                   18760:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  18761:                                             }
1.171     raeburn  18762:                                         } else {
                   18763:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   18764:                                         }
1.210     raeburn  18765:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  18766:                                     }
                   18767:                                 }
                   18768:                             }
                   18769:                         }
1.342     raeburn  18770:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
                   18771:                             $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   18772:                                                       $balancer).'</li>'; 
                   18773:                         }
1.252     raeburn  18774:                         if (keys(%toupdate)) {
                   18775:                             my %thismachine;
                   18776:                             my $updatedhere;
                   18777:                             my $cachetime = 60*60*24;
                   18778:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   18779:                             foreach my $lonhost (keys(%toupdate)) {
                   18780:                                 if ($thismachine{$lonhost}) {
                   18781:                                     unless ($updatedhere) {
                   18782:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   18783:                                                                       $defaultshash{'loadbalancing'},
                   18784:                                                                       $cachetime);
                   18785:                                         $updatedhere = 1;
                   18786:                                     }
                   18787:                                 } else {
                   18788:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   18789:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   18790:                                 }
                   18791:                             }
                   18792:                         }
1.150     raeburn  18793:                     }
1.171     raeburn  18794:                 }
                   18795:                 if ($resulttext ne '') {
                   18796:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  18797:                 } else {
                   18798:                     $resulttext = $nochgmsg;
                   18799:                 }
                   18800:             } else {
1.171     raeburn  18801:                 $resulttext = $nochgmsg;
1.150     raeburn  18802:             }
                   18803:         } else {
1.171     raeburn  18804:             $resulttext = '<span class="LC_error">'.
                   18805:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  18806:         }
                   18807:     } else {
1.171     raeburn  18808:         $resulttext = $nochgmsg;
1.150     raeburn  18809:     }
                   18810:     return $resulttext;
                   18811: }
                   18812: 
1.48      raeburn  18813: sub recurse_check {
                   18814:     my ($chkcats,$categories,$depth,$name) = @_;
                   18815:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   18816:         my $chg = 0;
                   18817:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   18818:             my $category = $chkcats->[$depth]{$name}[$j];
                   18819:             my $item;
                   18820:             if ($category eq '') {
                   18821:                 $chg ++;
                   18822:             } else {
                   18823:                 my $deeper = $depth + 1;
                   18824:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   18825:                 if ($chg) {
                   18826:                     $categories->{$item} -= $chg;
                   18827:                 }
                   18828:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   18829:                 $deeper --;
                   18830:             }
                   18831:         }
                   18832:     }
                   18833:     return;
                   18834: }
                   18835: 
                   18836: sub recurse_cat_deletes {
                   18837:     my ($item,$coursecategories,$deletions) = @_;
                   18838:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   18839:     my $subdepth = $depth + 1;
                   18840:     if (ref($coursecategories) eq 'HASH') {
                   18841:         foreach my $subitem (keys(%{$coursecategories})) {
                   18842:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   18843:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   18844:                 delete($coursecategories->{$subitem});
                   18845:                 $deletions->{$subitem} = 1;
                   18846:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  18847:             }
1.48      raeburn  18848:         }
                   18849:     }
                   18850:     return;
                   18851: }
                   18852: 
1.125     raeburn  18853: sub active_dc_picker {
1.191     raeburn  18854:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  18855:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  18856:     my @domcoord = keys(%domcoords);
                   18857:     if (keys(%currhash)) {
                   18858:         foreach my $dc (keys(%currhash)) {
                   18859:             unless (exists($domcoords{$dc})) {
                   18860:                 push(@domcoord,$dc);
                   18861:             }
                   18862:         }
                   18863:     }
                   18864:     @domcoord = sort(@domcoord);
1.210     raeburn  18865:     my $numdcs = scalar(@domcoord);
1.191     raeburn  18866:     my $rows = 0;
                   18867:     my $table;
1.125     raeburn  18868:     if ($numdcs > 1) {
1.191     raeburn  18869:         $table = '<table>';
                   18870:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  18871:             my $rem = $i%($numinrow);
                   18872:             if ($rem == 0) {
                   18873:                 if ($i > 0) {
1.191     raeburn  18874:                     $table .= '</tr>';
1.125     raeburn  18875:                 }
1.191     raeburn  18876:                 $table .= '<tr>';
                   18877:                 $rows ++;
1.125     raeburn  18878:             }
1.191     raeburn  18879:             my $check = '';
                   18880:             if ($inputtype eq 'radio') {
                   18881:                 if (keys(%currhash) == 0) {
                   18882:                     if (!$i) {
                   18883:                         $check = ' checked="checked"';
                   18884:                     }
                   18885:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   18886:                     $check = ' checked="checked"';
                   18887:                 }
                   18888:             } else {
                   18889:                 if (exists($currhash{$domcoord[$i]})) {
                   18890:                     $check = ' checked="checked"';
1.125     raeburn  18891:                 }
                   18892:             }
1.191     raeburn  18893:             if ($i == @domcoord - 1) {
1.125     raeburn  18894:                 my $colsleft = $numinrow - $rem;
                   18895:                 if ($colsleft > 1) {
1.191     raeburn  18896:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  18897:                 } else {
1.191     raeburn  18898:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  18899:                 }
                   18900:             } else {
1.191     raeburn  18901:                 $table .= '<td class="LC_left_item">';
                   18902:             }
                   18903:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   18904:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   18905:             $table .= '<span class="LC_nobreak"><label>'.
                   18906:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   18907:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   18908:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  18909:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  18910:             }
1.219     raeburn  18911:             $table .= '</label></span></td>';
1.191     raeburn  18912:         }
                   18913:         $table .= '</tr></table>';
                   18914:     } elsif ($numdcs == 1) {
1.219     raeburn  18915:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   18916:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  18917:         if ($inputtype eq 'radio') {
1.247     raeburn  18918:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  18919:             if ($user ne $dcname.':'.$dcdom) {
                   18920:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   18921:             }
1.191     raeburn  18922:         } else {
                   18923:             my $check;
                   18924:             if (exists($currhash{$domcoord[0]})) {
                   18925:                 $check = ' checked="checked"';
1.125     raeburn  18926:             }
1.247     raeburn  18927:             $table = '<span class="LC_nobreak"><label>'.
                   18928:                      '<input type="checkbox" name="'.$name.'" '.
                   18929:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  18930:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  18931:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  18932:             }
1.220     raeburn  18933:             $table .= '</label></span>';
1.191     raeburn  18934:             $rows ++;
1.125     raeburn  18935:         }
                   18936:     }
1.191     raeburn  18937:     return ($numdcs,$table,$rows);
1.125     raeburn  18938: }
                   18939: 
1.137     raeburn  18940: sub usersession_titles {
                   18941:     return &Apache::lonlocal::texthash(
                   18942:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   18943:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  18944:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  18945:                version => 'LON-CAPA version requirement',
1.138     raeburn  18946:                excludedomain => 'Allow all, but exclude specific domains',
                   18947:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  18948:                primary => 'Primary (checked first)',
1.154     raeburn  18949:                default => 'Default',
1.137     raeburn  18950:            );
                   18951: }
                   18952: 
1.152     raeburn  18953: sub id_for_thisdom {
                   18954:     my (%servers) = @_;
                   18955:     my %altids;
                   18956:     foreach my $server (keys(%servers)) {
                   18957:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   18958:         if ($serverhome ne $server) {
                   18959:             $altids{$serverhome} = $server;
                   18960:         }
                   18961:     }
                   18962:     return %altids;
                   18963: }
                   18964: 
1.150     raeburn  18965: sub count_servers {
                   18966:     my ($currbalancer,%servers) = @_;
                   18967:     my (@spares,$numspares);
                   18968:     foreach my $lonhost (sort(keys(%servers))) {
                   18969:         next if ($currbalancer eq $lonhost);
                   18970:         push(@spares,$lonhost);
                   18971:     }
                   18972:     if ($currbalancer) {
                   18973:         $numspares = scalar(@spares);
                   18974:     } else {
                   18975:         $numspares = scalar(@spares) - 1;
                   18976:     }
                   18977:     return ($numspares,@spares);
                   18978: }
                   18979: 
                   18980: sub lonbalance_targets_js {
1.171     raeburn  18981:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  18982:     my $select = &mt('Select');
                   18983:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   18984:     if (ref($servers) eq 'HASH') {
                   18985:         $alltargets = join("','",sort(keys(%{$servers})));
                   18986:         my @homedoms;
                   18987:         foreach my $server (sort(keys(%{$servers}))) {
                   18988:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   18989:                 push(@homedoms,'1');
                   18990:             } else {
                   18991:                 push(@homedoms,'0');
                   18992:             }
                   18993:         }
                   18994:         $allishome = join("','",@homedoms);
                   18995:     }
                   18996:     if (ref($types) eq 'ARRAY') {
                   18997:         if (@{$types} > 0) {
                   18998:             @alltypes = @{$types};
                   18999:         }
                   19000:     }
                   19001:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   19002:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  19003:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  19004:     if (ref($settings) eq 'HASH') {
                   19005:         %existing = %{$settings};
                   19006:     }
                   19007:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  19008:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  19009:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  19010:     return <<"END";
                   19011: 
                   19012: <script type="text/javascript">
                   19013: // <![CDATA[
                   19014: 
1.171     raeburn  19015: currBalancers = new Array('$balancers');
                   19016: 
                   19017: function toggleTargets(balnum) {
                   19018:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19019:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   19020:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   19021:     var prevbalancer = prevhostitem.value;
                   19022:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19023:     prevhostitem.value = balancer;
                   19024:     if (prevbalancer != '') {
                   19025:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   19026:         if (prevIdx != -1) {
                   19027:             currBalancers.splice(prevIdx,1);
                   19028:         }
                   19029:     }
1.150     raeburn  19030:     if (balancer == '') {
1.171     raeburn  19031:         hideSpares(balnum);
1.150     raeburn  19032:     } else {
1.171     raeburn  19033:         var currIdx = currBalancers.indexOf(balancer);
                   19034:         if (currIdx == -1) {
                   19035:             currBalancers.push(balancer);
                   19036:         }
1.150     raeburn  19037:         var homedoms = new Array('$allishome');
1.171     raeburn  19038:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   19039:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  19040:     }
1.171     raeburn  19041:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  19042:     return;
                   19043: }
                   19044: 
1.171     raeburn  19045: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  19046:     var alltargets = new Array('$alltargets');
                   19047:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  19048:     var offloadtypes = new Array('primary','default');
                   19049: 
1.171     raeburn  19050:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   19051:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  19052:  
1.151     raeburn  19053:     for (var i=0; i<offloadtypes.length; i++) {
                   19054:         var count = 0;
                   19055:         for (var j=0; j<alltargets.length; j++) {
                   19056:             if (alltargets[j] != balancer) {
1.171     raeburn  19057:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   19058:                 item.value = alltargets[j];
                   19059:                 item.style.textAlign='left';
                   19060:                 item.style.textFace='normal';
                   19061:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   19062:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   19063:                     item.disabled = '';
                   19064:                 } else {
                   19065:                     item.disabled = 'disabled';
                   19066:                     item.checked = false;
                   19067:                 }
1.151     raeburn  19068:                 count ++;
                   19069:             }
1.150     raeburn  19070:         }
                   19071:     }
1.151     raeburn  19072:     for (var k=0; k<insttypes.length; k++) {
                   19073:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  19074:             if (ishomedom == 1) {
1.171     raeburn  19075:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19076:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19077:             } else {
1.171     raeburn  19078:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19079:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  19080:             }
                   19081:         } else {
1.171     raeburn  19082:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19083:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19084:         }
1.151     raeburn  19085:         if ((insttypes[k] != '_LC_external') && 
                   19086:             ((insttypes[k] != '_LC_internetdom') ||
                   19087:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  19088:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   19089:             item.options.length = 0;
                   19090:             item.options[0] = new Option("","",true,true);
1.210     raeburn  19091:             var idx = 0;
1.151     raeburn  19092:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  19093:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   19094:                     idx ++;
                   19095:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  19096:                 }
                   19097:             }
                   19098:         }
                   19099:     }
                   19100:     return;
                   19101: }
                   19102: 
1.171     raeburn  19103: function hideSpares(balnum) {
1.150     raeburn  19104:     var alltargets = new Array('$alltargets');
                   19105:     var insttypes = new Array('$allinsttypes');
                   19106:     var offloadtypes = new Array('primary','default');
                   19107: 
1.171     raeburn  19108:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   19109:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  19110: 
                   19111:     var total = alltargets.length - 1;
                   19112:     for (var i=0; i<offloadtypes; i++) {
                   19113:         for (var j=0; j<total; j++) {
1.171     raeburn  19114:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   19115:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   19116:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  19117:         }
1.150     raeburn  19118:     }
                   19119:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  19120:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19121:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  19122:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  19123:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   19124:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  19125:         }
                   19126:     }
                   19127:     return;
                   19128: }
                   19129: 
1.171     raeburn  19130: function checkOffloads(item,balnum,type) {
1.150     raeburn  19131:     var alltargets = new Array('$alltargets');
                   19132:     var offloadtypes = new Array('primary','default');
                   19133:     if (item.checked) {
                   19134:         var total = alltargets.length - 1;
                   19135:         var other;
                   19136:         if (type == offloadtypes[0]) {
1.151     raeburn  19137:             other = offloadtypes[1];
1.150     raeburn  19138:         } else {
1.151     raeburn  19139:             other = offloadtypes[0];
1.150     raeburn  19140:         }
                   19141:         for (var i=0; i<total; i++) {
1.171     raeburn  19142:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  19143:             if (server == item.value) {
1.171     raeburn  19144:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   19145:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  19146:                 }
                   19147:             }
                   19148:         }
                   19149:     }
                   19150:     return;
                   19151: }
                   19152: 
1.171     raeburn  19153: function singleServerToggle(balnum,type) {
                   19154:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  19155:     if (offloadtoSelIdx == 0) {
1.171     raeburn  19156:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   19157:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19158: 
                   19159:     } else {
1.171     raeburn  19160:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   19161:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  19162:     }
                   19163:     return;
                   19164: }
                   19165: 
1.171     raeburn  19166: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  19167:     if (type == '_LC_external') {
1.171     raeburn  19168:         return;
1.150     raeburn  19169:     }
1.171     raeburn  19170:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  19171:     for (var i=0; i<typesRules.length; i++) {
                   19172:         if (formname.elements[typesRules[i]].checked) {
                   19173:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  19174:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   19175:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19176:             } else {
1.171     raeburn  19177:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   19178:             }
                   19179:         }
                   19180:     }
                   19181:     return;
                   19182: }
                   19183: 
                   19184: function balancerDeleteChange(balnum) {
                   19185:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19186:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19187:     var addtarget;
                   19188:     var removetarget;
                   19189:     var action = 'delete';
                   19190:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   19191:         var lonhost = hostitem.value;
                   19192:         var currIdx = currBalancers.indexOf(lonhost);
                   19193:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   19194:             if (currIdx != -1) {
                   19195:                 currBalancers.splice(currIdx,1);
                   19196:             }
                   19197:             addtarget = lonhost;
                   19198:         } else {
                   19199:             if (currIdx == -1) {
                   19200:                 currBalancers.push(lonhost);
                   19201:             }
                   19202:             removetarget = lonhost;
                   19203:             action = 'undelete';
                   19204:         }
                   19205:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   19206:     }
                   19207:     return;
                   19208: }
                   19209: 
                   19210: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   19211:     if (baltotal > 1) {
                   19212:         var offloadtypes = new Array('primary','default');
                   19213:         var alltargets = new Array('$alltargets');
                   19214:         var insttypes = new Array('$allinsttypes');
                   19215:         for (var i=0; i<baltotal; i++) {
                   19216:             if (i != balnum) {
                   19217:                 for (var j=0; j<offloadtypes.length; j++) {
                   19218:                     var total = alltargets.length - 1;
                   19219:                     for (var k=0; k<total; k++) {
                   19220:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   19221:                         var server = serveritem.value;
                   19222:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   19223:                             if (server == addtarget) {
                   19224:                                 serveritem.disabled = '';
                   19225:                             }
                   19226:                         }
                   19227:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19228:                             if (server == removetarget) {
                   19229:                                 serveritem.disabled = 'disabled';
                   19230:                                 serveritem.checked = false;
                   19231:                             }
                   19232:                         }
                   19233:                     }
                   19234:                 }
                   19235:                 for (var j=0; j<insttypes.length; j++) {
                   19236:                     if (insttypes[j] != '_LC_external') {
                   19237:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   19238:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   19239:                             var currSel = singleserver.selectedIndex;
                   19240:                             var currVal = singleserver.options[currSel].value;
                   19241:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   19242:                                 var numoptions = singleserver.options.length;
                   19243:                                 var needsnew = 1;
                   19244:                                 for (var k=0; k<numoptions; k++) {
                   19245:                                     if (singleserver.options[k] == addtarget) {
                   19246:                                         needsnew = 0;
                   19247:                                         break;
                   19248:                                     }
                   19249:                                 }
                   19250:                                 if (needsnew == 1) {
                   19251:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   19252:                                 }
                   19253:                             }
                   19254:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19255:                                 singleserver.options.length = 0;
                   19256:                                 if ((currVal) && (currVal != removetarget)) {
                   19257:                                     singleserver.options[0] = new Option("","",false,false);
                   19258:                                 } else {
                   19259:                                     singleserver.options[0] = new Option("","",true,true);
                   19260:                                 }
                   19261:                                 var idx = 0;
                   19262:                                 for (var m=0; m<alltargets.length; m++) {
                   19263:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   19264:                                         idx ++;
                   19265:                                         if (currVal == alltargets[m]) {
                   19266:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   19267:                                         } else {
                   19268:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   19269:                                         }
                   19270:                                     }
                   19271:                                 }
                   19272:                             }
                   19273:                         }
                   19274:                     }
                   19275:                 }
1.150     raeburn  19276:             }
                   19277:         }
                   19278:     }
                   19279:     return;
                   19280: }
                   19281: 
1.152     raeburn  19282: // ]]>
                   19283: </script>
                   19284: 
                   19285: END
                   19286: }
                   19287: 
                   19288: sub new_spares_js {
                   19289:     my @sparestypes = ('primary','default');
                   19290:     my $types = join("','",@sparestypes);
                   19291:     my $select = &mt('Select');
                   19292:     return <<"END";
                   19293: 
                   19294: <script type="text/javascript">
                   19295: // <![CDATA[
                   19296: 
                   19297: function updateNewSpares(formname,lonhost) {
                   19298:     var types = new Array('$types');
                   19299:     var include = new Array();
                   19300:     var exclude = new Array();
                   19301:     for (var i=0; i<types.length; i++) {
                   19302:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   19303:         for (var j=0; j<spareboxes.length; j++) {
                   19304:             if (formname.elements[spareboxes[j]].checked) {
                   19305:                 exclude.push(formname.elements[spareboxes[j]].value);
                   19306:             } else {
                   19307:                 include.push(formname.elements[spareboxes[j]].value);
                   19308:             }
                   19309:         }
                   19310:     }
                   19311:     for (var i=0; i<types.length; i++) {
                   19312:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   19313:         var selIdx = newSpare.selectedIndex;
                   19314:         var currnew = newSpare.options[selIdx].value;
                   19315:         var okSpares = new Array();
                   19316:         for (var j=0; j<newSpare.options.length; j++) {
                   19317:             var possible = newSpare.options[j].value;
                   19318:             if (possible != '') {
                   19319:                 if (exclude.indexOf(possible) == -1) {
                   19320:                     okSpares.push(possible);
                   19321:                 } else {
                   19322:                     if (currnew == possible) {
                   19323:                         selIdx = 0;
                   19324:                     }
                   19325:                 }
                   19326:             }
                   19327:         }
                   19328:         for (var k=0; k<include.length; k++) {
                   19329:             if (okSpares.indexOf(include[k]) == -1) {
                   19330:                 okSpares.push(include[k]);
                   19331:             }
                   19332:         }
                   19333:         okSpares.sort();
                   19334:         newSpare.options.length = 0;
                   19335:         if (selIdx == 0) {
                   19336:             newSpare.options[0] = new Option("$select","",true,true);
                   19337:         } else {
                   19338:             newSpare.options[0] = new Option("$select","",false,false);
                   19339:         }
                   19340:         for (var m=0; m<okSpares.length; m++) {
                   19341:             var idx = m+1;
                   19342:             var selThis = 0;
                   19343:             if (selIdx != 0) {
                   19344:                 if (okSpares[m] == currnew) {
                   19345:                     selThis = 1;
                   19346:                 }
                   19347:             }
                   19348:             if (selThis == 1) {
                   19349:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   19350:             } else {
                   19351:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   19352:             }
                   19353:         }
                   19354:     }
                   19355:     return;
                   19356: }
                   19357: 
                   19358: function checkNewSpares(lonhost,type) {
                   19359:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   19360:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   19361:     if (chosen != '') { 
                   19362:         var othertype;
                   19363:         var othernewSpare;
                   19364:         if (type == 'primary') {
                   19365:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   19366:         }
                   19367:         if (type == 'default') {
                   19368:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   19369:         }
                   19370:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   19371:             othernewSpare.selectedIndex = 0;
                   19372:         }
                   19373:     }
                   19374:     return;
                   19375: }
                   19376: 
                   19377: // ]]>
                   19378: </script>
                   19379: 
                   19380: END
                   19381: 
                   19382: }
                   19383: 
                   19384: sub common_domprefs_js {
                   19385:     return <<"END";
                   19386: 
                   19387: <script type="text/javascript">
                   19388: // <![CDATA[
                   19389: 
1.150     raeburn  19390: function getIndicesByName(formname,item) {
1.152     raeburn  19391:     var group = new Array();
1.150     raeburn  19392:     for (var i=0;i<formname.elements.length;i++) {
                   19393:         if (formname.elements[i].name == item) {
1.152     raeburn  19394:             group.push(formname.elements[i].id);
1.150     raeburn  19395:         }
                   19396:     }
1.152     raeburn  19397:     return group;
1.150     raeburn  19398: }
                   19399: 
                   19400: // ]]>
                   19401: </script>
                   19402: 
                   19403: END
1.152     raeburn  19404: 
1.150     raeburn  19405: }
                   19406: 
1.165     raeburn  19407: sub recaptcha_js {
                   19408:     my %lt = &captcha_phrases();
                   19409:     return <<"END";
                   19410: 
                   19411: <script type="text/javascript">
                   19412: // <![CDATA[
                   19413: 
                   19414: function updateCaptcha(caller,context) {
                   19415:     var privitem;
                   19416:     var pubitem;
                   19417:     var privtext;
                   19418:     var pubtext;
1.269     raeburn  19419:     var versionitem;
                   19420:     var versiontext;
1.165     raeburn  19421:     if (document.getElementById(context+'_recaptchapub')) {
                   19422:         pubitem = document.getElementById(context+'_recaptchapub');
                   19423:     } else {
                   19424:         return;
                   19425:     }
                   19426:     if (document.getElementById(context+'_recaptchapriv')) {
                   19427:         privitem = document.getElementById(context+'_recaptchapriv');
                   19428:     } else {
                   19429:         return;
                   19430:     }
                   19431:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   19432:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   19433:     } else {
                   19434:         return;
                   19435:     }
                   19436:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   19437:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   19438:     } else {
                   19439:         return;
                   19440:     }
1.269     raeburn  19441:     if (document.getElementById(context+'_recaptchaversion')) {
                   19442:         versionitem = document.getElementById(context+'_recaptchaversion');
                   19443:     } else {
                   19444:         return;
                   19445:     }
                   19446:     if (document.getElementById(context+'_recaptchavertxt')) {
                   19447:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   19448:     } else {
                   19449:         return;
                   19450:     }
1.165     raeburn  19451:     if (caller.checked) {
                   19452:         if (caller.value == 'recaptcha') {
                   19453:             pubitem.type = 'text';
                   19454:             privitem.type = 'text';
                   19455:             pubitem.size = '40';
                   19456:             privitem.size = '40';
                   19457:             pubtext.innerHTML = "$lt{'pub'}";
                   19458:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  19459:             versionitem.type = 'text';
                   19460:             versionitem.size = '3';
1.289     raeburn  19461:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  19462:         } else {
                   19463:             pubitem.type = 'hidden';
                   19464:             privitem.type = 'hidden';
1.269     raeburn  19465:             versionitem.type = 'hidden';
1.165     raeburn  19466:             pubtext.innerHTML = '';
                   19467:             privtext.innerHTML = '';
1.269     raeburn  19468:             versiontext.innerHTML = '';
1.165     raeburn  19469:         }
                   19470:     }
                   19471:     return;
                   19472: }
                   19473: 
                   19474: // ]]>
                   19475: </script>
                   19476: 
                   19477: END
                   19478: 
                   19479: }
                   19480: 
1.236     raeburn  19481: sub toggle_display_js {
1.192     raeburn  19482:     return <<"END";
                   19483: 
                   19484: <script type="text/javascript">
                   19485: // <![CDATA[
                   19486: 
1.236     raeburn  19487: function toggleDisplay(domForm,caller) {
                   19488:     if (document.getElementById(caller)) {
                   19489:         var divitem = document.getElementById(caller);
                   19490:         var optionsElement = domForm.coursecredits;
1.264     raeburn  19491:         var checkval = 1;
                   19492:         var dispval = 'block';
1.303     raeburn  19493:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  19494:         if (caller == 'emailoptions') {
                   19495:             optionsElement = domForm.cancreate_email; 
                   19496:         }
1.257     raeburn  19497:         if (caller == 'studentsubmission') {
                   19498:             optionsElement = domForm.postsubmit;
                   19499:         }
1.264     raeburn  19500:         if (caller == 'cloneinstcode') {
                   19501:             optionsElement = domForm.canclone;
                   19502:             checkval = 'instcode';
                   19503:         }
1.303     raeburn  19504:         if (selfcreateRegExp.test(caller)) {
                   19505:             optionsElement = domForm.elements[caller];
                   19506:             checkval = 'other';
                   19507:             dispval = 'inline'
                   19508:         }
1.236     raeburn  19509:         if (optionsElement.length) {
1.192     raeburn  19510:             var currval;
1.236     raeburn  19511:             for (var i=0; i<optionsElement.length; i++) {
                   19512:                 if (optionsElement[i].checked) {
                   19513:                    currval = optionsElement[i].value;
1.192     raeburn  19514:                 }
                   19515:             }
1.264     raeburn  19516:             if (currval == checkval) {
                   19517:                 divitem.style.display = dispval;
1.192     raeburn  19518:             } else {
1.236     raeburn  19519:                 divitem.style.display = 'none';
1.192     raeburn  19520:             }
                   19521:         }
                   19522:     }
                   19523:     return;
                   19524: }
                   19525: 
                   19526: // ]]>
                   19527: </script>
                   19528: 
                   19529: END
                   19530: 
                   19531: }
                   19532: 
1.165     raeburn  19533: sub captcha_phrases {
                   19534:     return &Apache::lonlocal::texthash (
                   19535:                  priv => 'Private key',
                   19536:                  pub  => 'Public key',
                   19537:                  original  => 'original (CAPTCHA)',
                   19538:                  recaptcha => 'successor (ReCAPTCHA)',
                   19539:                  notused   => 'unused',
1.289     raeburn  19540:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  19541:     );
                   19542: }
                   19543: 
1.205     raeburn  19544: sub devalidate_remote_domconfs {
1.212     raeburn  19545:     my ($dom,$cachekeys) = @_;
                   19546:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  19547:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   19548:     my %thismachine;
                   19549:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  19550:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
                   19551:                       'directorysrch','passwdconf');
1.260     raeburn  19552:     if (keys(%servers)) {
1.205     raeburn  19553:         foreach my $server (keys(%servers)) {
                   19554:             next if ($thismachine{$server});
1.212     raeburn  19555:             my @cached;
                   19556:             foreach my $name (@posscached) {
                   19557:                 if ($cachekeys->{$name}) {
                   19558:                     push(@cached,&escape($name).':'.&escape($dom));
                   19559:                 }
                   19560:             }
                   19561:             if (@cached) {
                   19562:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   19563:             }
1.205     raeburn  19564:         }
                   19565:     }
                   19566:     return;
                   19567: }
                   19568: 
1.3       raeburn  19569: 1;

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