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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.369   ! raeburn     4: # $Id: domainprefs.pm,v 1.368 2019/10/15 03:26:00 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.369   ! raeburn   834:         my $leftnobr = '';
1.238     raeburn   835:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277     raeburn   836:             ($action eq 'directorysrch') ||
1.256     raeburn   837:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   838:             $colspan = ' colspan="2"';
                    839:         }
1.145     raeburn   840:         if ($action eq 'usersessions') {
                    841:             $rightcolspan = ' colspan="3"'; 
                    842:         }
1.369   ! raeburn   843:         if ($action eq 'passwords') {
        !           844:             $leftnobr = ' LC_nobreak';
        !           845:         }
1.30      raeburn   846:         $output .= '
1.3       raeburn   847:           <tr>
                    848:            <td>
                    849:             <table class="LC_nested">
                    850:              <tr class="LC_info_row">
1.369   ! raeburn   851:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   852:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   853:              </tr>';
1.69      raeburn   854:         $rowtotal ++;
1.230     raeburn   855:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   856:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277     raeburn   857:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286     raeburn   858:             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.357     raeburn   859:             ($action eq 'contacts') || ($action eq 'privacy')) {
1.230     raeburn   860:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354     raeburn   861:         } elsif ($action eq 'passwords') {
                    862:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   863:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   864:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346     raeburn   865:         } elsif ($action eq 'scantron') {
                    866:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   867:         } elsif ($action eq 'login') {
1.256     raeburn   868:             if ($numheaders == 4) {
1.168     raeburn   869:                 $colspan = ' colspan="2"';
                    870:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    871:             } else {
                    872:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    873:             }
1.230     raeburn   874:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   875:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       876:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   877:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   878:         }
1.30      raeburn   879:         $output .= '
1.6       raeburn   880:            </table>
                    881:           </td>
                    882:          </tr>
                    883:          <tr>
                    884:            <td>
                    885:             <table class="LC_nested">
                    886:              <tr class="LC_info_row">
1.230     raeburn   887:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    888:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   889:              </tr>';
                    890:             $rowtotal ++;
1.230     raeburn   891:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    892:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275     raeburn   893:             ($action eq 'usersessions') || ($action eq 'coursecategories') || 
1.357     raeburn   894:             ($action eq 'trust') || ($action eq 'contacts') ||
                    895:             ($action eq 'privacy') || ($action eq 'passwords')) {
1.369   ! raeburn   896:             my $leftnobr = ' LC_nobreak';
1.238     raeburn   897:             if ($action eq 'coursecategories') {
                    898:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    899:                 $colspan = ' colspan="2"';
1.279     raeburn   900:             } elsif ($action eq 'trust') {
                    901:                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354     raeburn   902:             } elsif ($action eq 'passwords') {
                    903:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238     raeburn   904:             } else {
                    905:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    906:             }
1.279     raeburn   907:             if ($action eq 'trust') {
                    908:                 $output .= '
                    909:             </table>
                    910:           </td>
                    911:          </tr>';
                    912:                 my @trusthdrs = qw(2 3 4 5 6 7);
                    913:                 my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
                    914:                 for (my $i=0; $i<@trusthdrs; $i++) {
                    915:                     $output .= '
                    916:          <tr>
                    917:            <td>
                    918:             <table class="LC_nested">
                    919:              <tr class="LC_info_row">
                    920:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
                    921:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
                    922:                            $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
                    923:             </table>
                    924:           </td>
                    925:          </tr>';
                    926:                 }
                    927:                 $output .= '
                    928:          <tr>
                    929:            <td>
                    930:             <table class="LC_nested">
                    931:              <tr class="LC_info_row">
                    932:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
                    933:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
                    934:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    935:             } else {
                    936:                 $output .= '
1.63      raeburn   937:            </table>
                    938:           </td>
                    939:          </tr>
                    940:          <tr>
                    941:            <td>
                    942:             <table class="LC_nested">
                    943:              <tr class="LC_info_row">
                    944:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   945:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn   946:              </tr>'."\n";
1.279     raeburn   947:                 if ($action eq 'coursecategories') {
                    948:                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.357     raeburn   949:                 } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
1.354     raeburn   950:                     if ($action eq 'passwords') {
                    951:                         $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                    952:                     } else {
                    953:                         $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                    954:                     }
                    955:                     $output .= '
1.340     raeburn   956:              </tr>
                    957:             </table>
                    958:            </td>
                    959:           </tr>
                    960:           <tr>
                    961:            <td>
                    962:             <table class="LC_nested">
                    963:              <tr class="LC_info_row">
1.369   ! raeburn   964:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354     raeburn   965:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                    966:                     if ($action eq 'passwords') {
                    967:                         $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                    968:                     } else {
                    969:                         $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    970:                     }
                    971:                     $output .= '
1.340     raeburn   972:             </table>
                    973:           </td>
                    974:          </tr>
                    975:          <tr>';
1.279     raeburn   976:                 } else {
                    977:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    978:                 }
1.238     raeburn   979:             }
1.63      raeburn   980:             $rowtotal ++;
1.236     raeburn   981:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.282     raeburn   982:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    983:                  ($action eq 'helpsettings')) {
1.230     raeburn   984:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346     raeburn   985:         } elsif ($action eq 'scantron') {
                    986:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293     raeburn   987:         } elsif ($action eq 'ssl') {
                    988:             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
                    989:             </table>
                    990:           </td>
                    991:          </tr>
                    992:          <tr>
                    993:            <td>
                    994:             <table class="LC_nested">
                    995:              <tr class="LC_info_row">
                    996:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    997:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
                    998:                            $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
                    999:             </table>
                   1000:           </td>
                   1001:          </tr>
                   1002:          <tr>
                   1003:            <td>
                   1004:             <table class="LC_nested">
                   1005:              <tr class="LC_info_row">
                   1006:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1007:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
                   1008:                            $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn  1009:         } elsif ($action eq 'login') {
1.256     raeburn  1010:             if ($numheaders == 4) {
1.168     raeburn  1011:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                   1012:            </table>
                   1013:           </td>
                   1014:          </tr>
                   1015:          <tr>
                   1016:            <td>
                   1017:             <table class="LC_nested">
                   1018:              <tr class="LC_info_row">
                   1019:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn  1020:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn  1021:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1022:                 $rowtotal ++;
                   1023:             } else {
                   1024:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                   1025:             }
1.256     raeburn  1026:             $output .= '
                   1027:            </table>
                   1028:           </td>
                   1029:          </tr>
                   1030:          <tr>
                   1031:            <td>
                   1032:             <table class="LC_nested">
                   1033:              <tr class="LC_info_row">';
                   1034:             if ($numheaders == 4) {
                   1035:                 $output .= '
                   1036:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1037:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1038:              </tr>';
                   1039:             } else {
                   1040:                 $output .= '
                   1041:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1042:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                   1043:              </tr>';
                   1044:             }
                   1045:             $rowtotal ++;
                   1046:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1047:         } elsif ($action eq 'requestcourses') {
1.247     raeburn  1048:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1049:             $rowtotal ++;
                   1050:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn  1051:            </table>
                   1052:           </td>
                   1053:          </tr>
                   1054:          <tr>
                   1055:            <td>
                   1056:             <table class="LC_nested">
                   1057:              <tr class="LC_info_row">
                   1058:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1059:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn  1060:                        &textbookcourses_javascript($settings).
                   1061:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1062:             </table>
                   1063:            </td>
                   1064:           </tr>
                   1065:          <tr>
                   1066:            <td>
                   1067:             <table class="LC_nested">
                   1068:              <tr class="LC_info_row">
                   1069:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1070:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1071:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn  1072:             </table>
                   1073:            </td>
                   1074:           </tr>
                   1075:           <tr>
                   1076:            <td>
                   1077:             <table class="LC_nested">
                   1078:              <tr class="LC_info_row">
1.306     raeburn  1079:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1080:               <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn  1081:              </tr>'.
                   1082:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn  1083:         } elsif ($action eq 'requestauthor') {
                   1084:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn  1085:             $rowtotal ++;
1.122     jms      1086:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1087:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1088:            </table>
                   1089:           </td>
                   1090:          </tr>
                   1091:          <tr>
                   1092:            <td>
                   1093:             <table class="LC_nested">
                   1094:              <tr class="LC_info_row">
1.306     raeburn  1095:               <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69      raeburn  1096:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306     raeburn  1097:               <td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1098:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1099:              </tr>'.
1.30      raeburn  1100:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1101:            </table>
                   1102:           </td>
                   1103:          </tr>
                   1104:          <tr>
                   1105:            <td>
                   1106:             <table class="LC_nested">
                   1107:              <tr class="LC_info_row">
1.59      bisitz   1108:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1109:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1110:              </tr>'.
1.30      raeburn  1111:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1112:             $rowtotal += 2;
1.6       raeburn  1113:         }
1.3       raeburn  1114:     } else {
1.30      raeburn  1115:         $output .= '
1.3       raeburn  1116:           <tr>
                   1117:            <td>
                   1118:             <table class="LC_nested">
1.30      raeburn  1119:              <tr class="LC_info_row">';
1.277     raeburn  1120:         if ($action eq 'login') {
1.30      raeburn  1121:             $output .= '  
1.59      bisitz   1122:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1123:         } elsif ($action eq 'serverstatuses') {
                   1124:             $output .= '
1.306     raeburn  1125:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69      raeburn  1126:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1127: 
1.6       raeburn  1128:         } else {
1.30      raeburn  1129:             $output .= '
1.306     raeburn  1130:               <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1131:         }
1.72      raeburn  1132:         if (defined($item->{'header'}->[0]->{'col3'})) {
1.306     raeburn  1133:             $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72      raeburn  1134:                        &mt($item->{'header'}->[0]->{'col2'});
                   1135:             if ($action eq 'serverstatuses') {
                   1136:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1137:             } 
1.69      raeburn  1138:         } else {
1.306     raeburn  1139:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69      raeburn  1140:                        &mt($item->{'header'}->[0]->{'col2'});
                   1141:         }
                   1142:         $output .= '</td>';
                   1143:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1144:             if (defined($item->{'header'}->[0]->{'col4'})) {
1.306     raeburn  1145:                 $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150     raeburn  1146:                             &mt($item->{'header'}->[0]->{'col3'});
                   1147:             } else {
1.306     raeburn  1148:                 $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1149:                            &mt($item->{'header'}->[0]->{'col3'});
                   1150:             }
1.69      raeburn  1151:             if ($action eq 'serverstatuses') {
                   1152:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1153:             }
                   1154:             $output .= '</td>';
1.6       raeburn  1155:         }
1.150     raeburn  1156:         if ($item->{'header'}->[0]->{'col4'}) {
1.306     raeburn  1157:             $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150     raeburn  1158:                        &mt($item->{'header'}->[0]->{'col4'});
                   1159:         }
1.69      raeburn  1160:         $output .= '</tr>';
1.48      raeburn  1161:         $rowtotal ++;
1.168     raeburn  1162:         if ($action eq 'quotas') {
1.86      raeburn  1163:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277     raeburn  1164:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.286     raeburn  1165:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
1.320     raeburn  1166:                  ($action eq 'ltitools') || ($action eq 'lti')) {
1.230     raeburn  1167:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1168:         }
1.3       raeburn  1169:     }
1.30      raeburn  1170:     $output .= '
1.3       raeburn  1171:    </table>
                   1172:   </td>
                   1173:  </tr>
1.30      raeburn  1174: </table><br />';
                   1175:     return ($output,$rowtotal);
1.1       raeburn  1176: }
                   1177: 
1.3       raeburn  1178: sub print_login {
1.168     raeburn  1179:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1180:     my ($css_class,$datatable);
1.6       raeburn  1181:     my %choices = &login_choices();
1.110     raeburn  1182: 
1.168     raeburn  1183:     if ($caller eq 'service') {
1.149     raeburn  1184:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1185:         my $choice = $choices{'disallowlogin'};
                   1186:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1187:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306     raeburn  1188:                       '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1189:                       '<th>'.$choices{'server'}.'</th>'.
                   1190:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1191:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1192:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1193:         my %disallowed;
                   1194:         if (ref($settings) eq 'HASH') {
                   1195:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1196:                %disallowed = %{$settings->{'loginvia'}};
                   1197:             }
                   1198:         }
                   1199:         foreach my $lonhost (sort(keys(%servers))) {
                   1200:             my $direct = 'selected="selected"';
1.128     raeburn  1201:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1202:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1203:                     $direct = '';
                   1204:                 }
1.110     raeburn  1205:             }
1.115     raeburn  1206:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1207:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1208:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1209:                           '</option>';
1.184     raeburn  1210:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1211:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1212:                 my $selected = '';
1.128     raeburn  1213:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1214:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1215:                         $selected = 'selected="selected"';
                   1216:                     }
1.110     raeburn  1217:                 }
                   1218:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1219:                               $servers{$hostid}.'</option>';
                   1220:             }
1.128     raeburn  1221:             $datatable .= '</select></td>'.
                   1222:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1223:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1224:                 my $pathname = $path;
                   1225:                 if ($path eq 'custom') {
                   1226:                     $pathname = &mt('Custom Path').' ->';
                   1227:                 }
                   1228:                 my $selected = '';
                   1229:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1230:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1231:                         $selected = 'selected="selected"';
                   1232:                     }
                   1233:                 } elsif ($path eq '') {
                   1234:                     $selected = 'selected="selected"';
                   1235:                 }
                   1236:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1237:             }
                   1238:             $datatable .= '</select></td>';
                   1239:             my ($custom,$exempt);
                   1240:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1241:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1242:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1243:             }
                   1244:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1245:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1246:                           '</tr>';
1.110     raeburn  1247:         }
                   1248:         $datatable .= '</table></td></tr>';
                   1249:         return $datatable;
1.168     raeburn  1250:     } elsif ($caller eq 'page') {
                   1251:         my %defaultchecked = ( 
                   1252:                                'coursecatalog' => 'on',
1.188     raeburn  1253:                                'helpdesk'      => 'on',
1.168     raeburn  1254:                                'adminmail'     => 'off',
                   1255:                                'newuser'       => 'off',
                   1256:                              );
1.188     raeburn  1257:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1258:         my (%checkedon,%checkedoff);
1.42      raeburn  1259:         foreach my $item (@toggles) {
1.168     raeburn  1260:             if ($defaultchecked{$item} eq 'on') { 
                   1261:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1262:                 $checkedoff{$item} = ' ';
1.168     raeburn  1263:             } elsif ($defaultchecked{$item} eq 'off') {
                   1264:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1265:                 $checkedon{$item} = ' ';
                   1266:             }
1.1       raeburn  1267:         }
1.168     raeburn  1268:         my @images = ('img','logo','domlogo','login');
                   1269:         my @logintext = ('textcol','bgcol');
                   1270:         my @bgs = ('pgbg','mainbg','sidebg');
                   1271:         my @links = ('link','alink','vlink');
                   1272:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1273:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1274:         my (%is_custom,%designs);
                   1275:         my %defaults = (
                   1276:                        font => $defaultdesign{'login.font'},
                   1277:                        );
1.6       raeburn  1278:         foreach my $item (@images) {
1.168     raeburn  1279:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1280:             $defaults{'showlogo'}{$item} = 1;
                   1281:         }
                   1282:         foreach my $item (@bgs) {
                   1283:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1284:         }
1.41      raeburn  1285:         foreach my $item (@logintext) {
1.168     raeburn  1286:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1287:         }
1.168     raeburn  1288:         foreach my $item (@links) {
                   1289:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1290:         }
1.168     raeburn  1291:         if (ref($settings) eq 'HASH') {
                   1292:             foreach my $item (@toggles) {
                   1293:                 if ($settings->{$item} eq '1') {
                   1294:                     $checkedon{$item} =  ' checked="checked" ';
                   1295:                     $checkedoff{$item} = ' ';
                   1296:                 } elsif ($settings->{$item} eq '0') {
                   1297:                     $checkedoff{$item} =  ' checked="checked" ';
                   1298:                     $checkedon{$item} = ' ';
                   1299:                 }
                   1300:             }
                   1301:             foreach my $item (@images) {
                   1302:                 if (defined($settings->{$item})) {
                   1303:                     $designs{$item} = $settings->{$item};
                   1304:                     $is_custom{$item} = 1;
                   1305:                 }
                   1306:                 if (defined($settings->{'showlogo'}{$item})) {
                   1307:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1308:                 }
                   1309:             }
                   1310:             foreach my $item (@logintext) {
                   1311:                 if ($settings->{$item} ne '') {
                   1312:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1313:                     $is_custom{$item} = 1;
                   1314:                 }
                   1315:             }
                   1316:             if ($settings->{'font'} ne '') {
                   1317:                 $designs{'font'} = $settings->{'font'};
                   1318:                 $is_custom{'font'} = 1;
                   1319:             }
                   1320:             foreach my $item (@bgs) {
                   1321:                 if ($settings->{$item} ne '') {
                   1322:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1323:                     $is_custom{$item} = 1;
                   1324:                 }
                   1325:             }
                   1326:             foreach my $item (@links) {
                   1327:                 if ($settings->{$item} ne '') {
                   1328:                     $designs{'links'}{$item} = $settings->{$item};
                   1329:                     $is_custom{$item} = 1;
                   1330:                 }
                   1331:             }
                   1332:         } else {
                   1333:             if ($designhash{$dom.'.login.font'} ne '') {
                   1334:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1335:                 $is_custom{'font'} = 1;
                   1336:             }
                   1337:             foreach my $item (@images) {
                   1338:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1339:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1340:                     $is_custom{$item} = 1;
                   1341:                 }
                   1342:             }
                   1343:             foreach my $item (@bgs) {
                   1344:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1345:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1346:                     $is_custom{$item} = 1;
                   1347:                 }
1.6       raeburn  1348:             }
1.168     raeburn  1349:             foreach my $item (@links) {
                   1350:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1351:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1352:                     $is_custom{$item} = 1;
                   1353:                 }
1.6       raeburn  1354:             }
                   1355:         }
1.168     raeburn  1356:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1357:                                                       logo => 'Institution Logo',
                   1358:                                                       domlogo => 'Domain Logo',
                   1359:                                                       login => 'Login box');
                   1360:         my $itemcount = 1;
                   1361:         foreach my $item (@toggles) {
                   1362:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1363:             $datatable .=  
                   1364:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1365:                 '</td><td>'.
                   1366:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1367:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1368:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1369:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1370:                 '</tr>';
                   1371:             $itemcount ++;
1.6       raeburn  1372:         }
1.168     raeburn  1373:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1374:         $datatable .= '</tr></table></td></tr>';
                   1375:     } elsif ($caller eq 'help') {
                   1376:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1377:         my $switchserver = &check_switchserver($dom,$confname);
                   1378:         my $itemcount = 1;
                   1379:         $defaulturl = '/adm/loginproblems.html';
                   1380:         $defaulttype = 'default';
                   1381:         %lt = &Apache::lonlocal::texthash (
                   1382:                      del     => 'Delete?',
                   1383:                      rep     => 'Replace:',
                   1384:                      upl     => 'Upload:',
                   1385:                      default => 'Default',
                   1386:                      custom  => 'Custom',
                   1387:                                              );
                   1388:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1389:         my @currlangs;
                   1390:         if (ref($settings) eq 'HASH') {
                   1391:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1392:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1393:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1394:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1395:                     $type{$key} = 'custom';
                   1396:                     unless ($key eq 'nolang') {
                   1397:                         push(@currlangs,$key);
                   1398:                     }
                   1399:                 }
                   1400:             } elsif ($settings->{'helpurl'} ne '') {
                   1401:                 $type{'nolang'} = 'custom';
                   1402:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1403:             }
                   1404:         }
1.168     raeburn  1405:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1406:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1407:             $datatable .= '<tr'.$css_class.'>';
                   1408:             if ($url{$lang} eq '') {
                   1409:                 $url{$lang} = $defaulturl;
                   1410:             }
                   1411:             if ($type{$lang} eq '') {
                   1412:                 $type{$lang} = $defaulttype;
                   1413:             }
                   1414:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1415:             if ($lang eq 'nolang') {
                   1416:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1417:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1418:             } else {
                   1419:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1420:                                   $langchoices{$lang},
                   1421:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1422:             }
                   1423:             $datatable .= '</span></td>'."\n".
                   1424:                           '<td class="LC_left_item">';
                   1425:             if ($type{$lang} eq 'custom') {
                   1426:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1427:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1428:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1429:             } else {
                   1430:                 $datatable .= $lt{'upl'};
                   1431:             }
                   1432:             $datatable .='<br />';
                   1433:             if ($switchserver) {
                   1434:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1435:             } else {
                   1436:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1437:             }
1.168     raeburn  1438:             $datatable .= '</td></tr>';
                   1439:             $itemcount ++;
1.6       raeburn  1440:         }
1.168     raeburn  1441:         my @addlangs;
                   1442:         foreach my $lang (sort(keys(%langchoices))) {
                   1443:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1444:             push(@addlangs,$lang);
                   1445:         }
                   1446:         if (@addlangs > 0) {
                   1447:             my %toadd;
                   1448:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1449:             $toadd{''} = &mt('Select');
                   1450:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1451:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1452:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1453:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1454:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1455:             if ($switchserver) {
                   1456:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1457:             } else {
                   1458:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1459:             }
1.168     raeburn  1460:             $datatable .= '</td></tr>';
1.169     raeburn  1461:             $itemcount ++;
1.6       raeburn  1462:         }
1.169     raeburn  1463:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1464:     } elsif ($caller eq 'headtag') {
                   1465:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1466:         my $choice = $choices{'headtag'};
                   1467:         $css_class = ' class="LC_odd_row"';
                   1468:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306     raeburn  1469:                       '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256     raeburn  1470:                       '<th>'.$choices{'current'}.'</th>'.
                   1471:                       '<th>'.$choices{'action'}.'</th>'.
                   1472:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1473:         my (%currurls,%currexempt);
                   1474:         if (ref($settings) eq 'HASH') {
                   1475:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1476:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1477:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1478:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1479:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1480:                     }
                   1481:                 }
                   1482:             }
                   1483:         }
                   1484:         my %lt = &Apache::lonlocal::texthash(
                   1485:                                                del  => 'Delete?',
                   1486:                                                rep  => 'Replace:',
                   1487:                                                upl  => 'Upload:',
                   1488:                                                curr => 'View contents',
                   1489:                                                none => 'None',
                   1490:         );
                   1491:         my $switchserver = &check_switchserver($dom,$confname);
                   1492:         foreach my $lonhost (sort(keys(%domservers))) {
                   1493:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1494:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1495:             if ($currurls{$lonhost}) {
                   1496:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1497:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1498:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1499:                               '">'.$lt{'curr'}.'</a></td>'.
                   1500:                               '<td><span class="LC_nobreak"><label>'.
                   1501:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1502:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1503:             } else {
                   1504:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1505:             }
                   1506:             $datatable .='<br />';
                   1507:             if ($switchserver) {
                   1508:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1509:             } else {
                   1510:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1511:             }
1.330     raeburn  1512:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256     raeburn  1513:         }
                   1514:         $datatable .= '</table></td></tr>';
1.1       raeburn  1515:     }
1.6       raeburn  1516:     return $datatable;
                   1517: }
                   1518: 
                   1519: sub login_choices {
                   1520:     my %choices =
                   1521:         &Apache::lonlocal::texthash (
1.116     bisitz   1522:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1523:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1524:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1525:             disallowlogin => "Login page requests redirected",
                   1526:             hostid        => "Server",
1.128     raeburn  1527:             server        => "Redirect to:",
                   1528:             serverpath    => "Path",
                   1529:             custompath    => "Custom", 
                   1530:             exempt        => "Exempt IP(s)",
1.110     raeburn  1531:             directlogin   => "No redirect",
                   1532:             newuser       => "Link to create a user account",
                   1533:             img           => "Header",
                   1534:             logo          => "Main Logo",
                   1535:             domlogo       => "Domain Logo",
                   1536:             login         => "Log-in Header", 
                   1537:             textcol       => "Text color",
                   1538:             bgcol         => "Box color",
                   1539:             bgs           => "Background colors",
                   1540:             links         => "Link colors",
                   1541:             font          => "Font color",
                   1542:             pgbg          => "Header",
                   1543:             mainbg        => "Page",
                   1544:             sidebg        => "Login box",
                   1545:             link          => "Link",
                   1546:             alink         => "Active link",
                   1547:             vlink         => "Visited link",
1.256     raeburn  1548:             headtag       => "Custom markup",
                   1549:             action        => "Action",
                   1550:             current       => "Current",
1.6       raeburn  1551:         );
                   1552:     return %choices;
                   1553: }
                   1554: 
                   1555: sub print_rolecolors {
1.30      raeburn  1556:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1557:     my %choices = &color_font_choices();
                   1558:     my @bgs = ('pgbg','tabbg','sidebg');
                   1559:     my @links = ('link','alink','vlink');
                   1560:     my @images = ('img');
                   1561:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1562:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1563:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1564:     my (%is_custom,%designs);
1.200     raeburn  1565:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1566:     if (ref($settings) eq 'HASH') {
                   1567:         if (ref($settings->{$role}) eq 'HASH') {
                   1568:             if ($settings->{$role}->{'img'} ne '') {
                   1569:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1570:                 $is_custom{'img'} = 1;
                   1571:             }
                   1572:             if ($settings->{$role}->{'font'} ne '') {
                   1573:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1574:                 $is_custom{'font'} = 1;
                   1575:             }
1.97      tempelho 1576:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1577:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1578:                 $is_custom{'fontmenu'} = 1;
                   1579:             }
1.6       raeburn  1580:             foreach my $item (@bgs) {
                   1581:                 if ($settings->{$role}->{$item} ne '') {
                   1582:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1583:                     $is_custom{$item} = 1;
                   1584:                 }
                   1585:             }
                   1586:             foreach my $item (@links) {
                   1587:                 if ($settings->{$role}->{$item} ne '') {
                   1588:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1589:                     $is_custom{$item} = 1;
                   1590:                 }
                   1591:             }
                   1592:         }
                   1593:     } else {
                   1594:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1595:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1596:             $is_custom{'img'} = 1;
                   1597:         }
1.97      tempelho 1598:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1599:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1600:             $is_custom{'fontmenu'} = 1; 
                   1601:         }
1.6       raeburn  1602:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1603:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1604:             $is_custom{'font'} = 1;
                   1605:         }
                   1606:         foreach my $item (@bgs) {
                   1607:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1608:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1609:                 $is_custom{$item} = 1;
                   1610:             
                   1611:             }
                   1612:         }
                   1613:         foreach my $item (@links) {
                   1614:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1615:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1616:                 $is_custom{$item} = 1;
                   1617:             }
                   1618:         }
                   1619:     }
                   1620:     my $itemcount = 1;
1.30      raeburn  1621:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1622:     $datatable .= '</tr></table></td></tr>';
                   1623:     return $datatable;
                   1624: }
                   1625: 
1.200     raeburn  1626: sub role_defaults {
                   1627:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1628:     my %defaults;
                   1629:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1630:         return %defaults;
                   1631:     }
                   1632:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1633:     if ($role eq 'login') {
                   1634:         %defaults = (
                   1635:                        font => $defaultdesign{$role.'.font'},
                   1636:                     );
                   1637:         if (ref($logintext) eq 'ARRAY') {
                   1638:             foreach my $item (@{$logintext}) {
                   1639:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1640:             }
                   1641:         }
                   1642:         foreach my $item (@{$images}) {
                   1643:             $defaults{'showlogo'}{$item} = 1;
                   1644:         }
                   1645:     } else {
                   1646:         %defaults = (
                   1647:                        img => $defaultdesign{$role.'.img'},
                   1648:                        font => $defaultdesign{$role.'.font'},
                   1649:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1650:                     );
                   1651:     }
                   1652:     foreach my $item (@{$bgs}) {
                   1653:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1654:     }
                   1655:     foreach my $item (@{$links}) {
                   1656:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1657:     }
                   1658:     foreach my $item (@{$images}) {
                   1659:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1660:     }
                   1661:     return %defaults;
                   1662: }
                   1663: 
1.6       raeburn  1664: sub display_color_options {
1.9       raeburn  1665:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1666:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1667:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1668:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1669:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1670:         '<td>'.$choices->{'font'}.'</td>';
                   1671:     if (!$is_custom->{'font'}) {
1.329     raeburn  1672:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1673:     } else {
                   1674:         $datatable .= '<td>&nbsp;</td>';
                   1675:     }
1.174     foxr     1676:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1677: 
1.8       raeburn  1678:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1679:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1680:                   ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  1681:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1682:     unless ($role eq 'login') { 
                   1683:         $datatable .= '<tr'.$css_class.'>'.
                   1684:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1685:         if (!$is_custom->{'fontmenu'}) {
1.329     raeburn  1686:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1687:         } else {
                   1688:             $datatable .= '<td>&nbsp;</td>';
                   1689:         }
1.202     raeburn  1690: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1691: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1692:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1693:                       '<input class="colorchooser" type="text" size="10" name="'
                   1694: 		      .$role.'_fontmenu"'.
                   1695:                       ' value="'.$current_color.'" />&nbsp;'.
1.329     raeburn  1696:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1697:     }
1.9       raeburn  1698:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1699:     foreach my $img (@{$images}) {
1.18      albertel 1700: 	$itemcount ++;
1.6       raeburn  1701:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1702:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1703:                       '<td>'.$choices->{$img};
1.41      raeburn  1704:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1705:         if ($role eq 'login') {
                   1706:             if ($img eq 'login') {
                   1707:                 $login_hdr_pick =
1.135     bisitz   1708:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1709:                 $logincolors =
                   1710:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1711:                                        $designs,$defaults);
1.70      raeburn  1712:             } elsif ($img ne 'domlogo') {
                   1713:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1714:             }
                   1715:         }
                   1716:         $datatable .= '</td>';
1.6       raeburn  1717:         if ($designs->{$img} ne '') {
                   1718:             $imgfile = $designs->{$img};
1.18      albertel 1719: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1720:         } else {
                   1721:             $imgfile = $defaults->{$img};
                   1722:         }
                   1723:         if ($imgfile) {
1.9       raeburn  1724:             my ($showfile,$fullsize);
                   1725:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1726:                 my $urldir = $1;
                   1727:                 my $filename = $2;
                   1728:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1729:                 if (@info) {
                   1730:                     my $thumbfile = 'tn-'.$filename;
                   1731:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1732:                     if (@thumb) {
                   1733:                         $showfile = $urldir.'/'.$thumbfile;
                   1734:                     } else {
                   1735:                         $showfile = $imgfile;
                   1736:                     }
                   1737:                 } else {
                   1738:                     $showfile = '';
                   1739:                 }
                   1740:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1741:                 $showfile = $imgfile;
1.6       raeburn  1742:                 my $imgdir = $1;
                   1743:                 my $filename = $2;
1.159     raeburn  1744:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1745:                     $showfile = "/$imgdir/tn-".$filename;
                   1746:                 } else {
1.159     raeburn  1747:                     my $input = $londocroot.$imgfile;
                   1748:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1749:                     if (!-e $output) {
1.9       raeburn  1750:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1751:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1752:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1753:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1754:                                 my $size = $width.'x'.$height;
1.316     raeburn  1755:                                 my @args = ('convert','-sample',$size,$input,$output);
                   1756:                                 system({$args[0]} @args);
1.159     raeburn  1757:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1758:                             }
                   1759:                         }
1.6       raeburn  1760:                     }
                   1761:                 }
1.16      raeburn  1762:             }
1.6       raeburn  1763:             if ($showfile) {
1.40      raeburn  1764:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1765:                     if ($showfile =~ m{^/res/}) {
                   1766:                         my $local_showfile =
                   1767:                             &Apache::lonnet::filelocation('',$showfile);
                   1768:                         &Apache::lonnet::repcopy($local_showfile);
                   1769:                     }
                   1770:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1771:                 }
                   1772:                 if ($imgfile) {
                   1773:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1774:                         if ($imgfile =~ m{^/res/}) {
                   1775:                             my $local_imgfile =
                   1776:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1777:                             &Apache::lonnet::repcopy($local_imgfile);
                   1778:                         }
                   1779:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1780:                     } else {
                   1781:                         $fullsize = $imgfile;
                   1782:                     }
                   1783:                 }
1.41      raeburn  1784:                 $datatable .= '<td>';
                   1785:                 if ($img eq 'login') {
1.135     bisitz   1786:                     $datatable .= $login_hdr_pick;
                   1787:                 } 
1.41      raeburn  1788:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1789:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1790:             } else {
1.201     raeburn  1791:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1792:                               &mt('Upload:').'<br />';
1.6       raeburn  1793:             }
                   1794:         } else {
1.201     raeburn  1795:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1796:                           &mt('Upload:').'<br />';
1.6       raeburn  1797:         }
1.9       raeburn  1798:         if ($switchserver) {
                   1799:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1800:         } else {
1.135     bisitz   1801:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1802:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1803:             }
1.9       raeburn  1804:         }
                   1805:         $datatable .= '</td></tr>';
1.6       raeburn  1806:     }
                   1807:     $itemcount ++;
                   1808:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1809:     $datatable .= '<tr'.$css_class.'>'.
                   1810:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1811:     my $bgs_def;
                   1812:     foreach my $item (@{$bgs}) {
                   1813:         if (!$is_custom->{$item}) {
1.329     raeburn  1814:             $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  1815:         }
                   1816:     }
                   1817:     if ($bgs_def) {
1.8       raeburn  1818:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1819:     } else {
                   1820:         $datatable .= '<td>&nbsp;</td>';
                   1821:     }
                   1822:     $datatable .= '<td class="LC_right_item">'.
                   1823:                   '<table border="0"><tr>';
1.174     foxr     1824: 
1.6       raeburn  1825:     foreach my $item (@{$bgs}) {
1.306     raeburn  1826:         $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174     foxr     1827: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1828:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1829:             $datatable .= '&nbsp;';
1.6       raeburn  1830:         }
1.174     foxr     1831:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1832:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1833:     }
                   1834:     $datatable .= '</tr></table></td></tr>';
                   1835:     $itemcount ++;
                   1836:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1837:     $datatable .= '<tr'.$css_class.'>'.
                   1838:                   '<td>'.$choices->{'links'}.'</td>';
                   1839:     my $links_def;
                   1840:     foreach my $item (@{$links}) {
                   1841:         if (!$is_custom->{$item}) {
1.329     raeburn  1842:             $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  1843:         }
                   1844:     }
                   1845:     if ($links_def) {
1.8       raeburn  1846:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1847:     } else {
                   1848:         $datatable .= '<td>&nbsp;</td>';
                   1849:     }
                   1850:     $datatable .= '<td class="LC_right_item">'.
                   1851:                   '<table border="0"><tr>';
                   1852:     foreach my $item (@{$links}) {
1.234     raeburn  1853: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306     raeburn  1854:         $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6       raeburn  1855:         if ($designs->{'links'}{$item}) {
1.174     foxr     1856:             $datatable.='&nbsp;';
1.6       raeburn  1857:         }
1.174     foxr     1858:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1859:                       '" /></td>';
                   1860:     }
1.30      raeburn  1861:     $$rowtotal += $itemcount;
1.3       raeburn  1862:     return $datatable;
                   1863: }
                   1864: 
1.70      raeburn  1865: sub logo_display_options {
                   1866:     my ($img,$defaults,$designs) = @_;
                   1867:     my $checkedon;
                   1868:     if (ref($defaults) eq 'HASH') {
                   1869:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1870:             if ($defaults->{'showlogo'}{$img}) {
                   1871:                 $checkedon = 'checked="checked" ';     
                   1872:             }
                   1873:         } 
                   1874:     }
                   1875:     if (ref($designs) eq 'HASH') {
                   1876:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1877:             if (defined($designs->{'showlogo'}{$img})) {
                   1878:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1879:                     $checkedon = '';
                   1880:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1881:                     $checkedon = 'checked="checked" ';
                   1882:                 }
                   1883:             }
                   1884:         }
                   1885:     }
                   1886:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1887:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1888:            &mt('show').'</label>'."\n";
                   1889: }
                   1890: 
1.41      raeburn  1891: sub login_header_options  {
1.135     bisitz   1892:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1893:     my $output = '';
1.41      raeburn  1894:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1895:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1896:         if (!$is_custom->{'textcol'}) {
                   1897:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1898:                        '&nbsp;&nbsp;&nbsp;';
                   1899:         }
                   1900:         if (!$is_custom->{'bgcol'}) {
                   1901:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1902:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1903:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1904:         }
                   1905:         $output .= '<br />';
                   1906:     }
                   1907:     $output .='<br />';
                   1908:     return $output;
                   1909: }
                   1910: 
                   1911: sub login_text_colors {
1.201     raeburn  1912:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1913:     my $color_menu = '<table border="0"><tr>';
                   1914:     foreach my $item (@{$logintext}) {
1.306     raeburn  1915:         $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201     raeburn  1916:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1917:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1918:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1919:     }
                   1920:     $color_menu .= '</tr></table><br />';
                   1921:     return $color_menu;
                   1922: }
                   1923: 
                   1924: sub image_changes {
                   1925:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1926:     my $output;
1.135     bisitz   1927:     if ($img eq 'login') {
1.331     raeburn  1928:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   1929:     } elsif (!$is_custom) {
1.70      raeburn  1930:         if ($img ne 'domlogo') {
1.331     raeburn  1931:             $output = &mt('Default image:').'<br />';
1.41      raeburn  1932:         } else {
1.331     raeburn  1933:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  1934:         }
                   1935:     }
1.331     raeburn  1936:     if ($img ne 'login') {
1.135     bisitz   1937:         if ($img_import) {
                   1938:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1939:         }
                   1940:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1941:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1942:         if ($is_custom) {
                   1943:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1944:                        '<input type="checkbox" name="'.
                   1945:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1946:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1947:         } else {
1.306     raeburn  1948:             $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1949:         }
1.41      raeburn  1950:     }
                   1951:     return $output;
                   1952: }
                   1953: 
1.3       raeburn  1954: sub print_quotas {
1.86      raeburn  1955:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1956:     my $context;
                   1957:     if ($action eq 'quotas') {
                   1958:         $context = 'tools';
                   1959:     } else {
                   1960:         $context = $action;
                   1961:     }
1.197     raeburn  1962:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1963:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1964:     my $typecount = 0;
1.101     raeburn  1965:     my ($css_class,%titles);
1.86      raeburn  1966:     if ($context eq 'requestcourses') {
1.325     raeburn  1967:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  1968:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1969:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1970:         %titles = &courserequest_titles();
1.163     raeburn  1971:     } elsif ($context eq 'requestauthor') {
                   1972:         @usertools = ('author');
                   1973:         @options = ('norequest','approval','automatic');
1.210     raeburn  1974:         %titles = &authorrequest_titles();
1.86      raeburn  1975:     } else {
1.162     raeburn  1976:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1977:         %titles = &tool_titles();
1.86      raeburn  1978:     }
1.26      raeburn  1979:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1980:         foreach my $type (@{$types}) {
1.197     raeburn  1981:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1982:             unless (($context eq 'requestcourses') ||
                   1983:                     ($context eq 'requestauthor')) {
1.86      raeburn  1984:                 if (ref($settings) eq 'HASH') {
                   1985:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1986:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1987:                     } else {
                   1988:                         $currdefquota = $settings->{$type};
                   1989:                     }
1.197     raeburn  1990:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1991:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1992:                     }
1.78      raeburn  1993:                 }
1.72      raeburn  1994:             }
1.3       raeburn  1995:             if (defined($usertypes->{$type})) {
                   1996:                 $typecount ++;
                   1997:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1998:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1999:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2000:                               '<td class="LC_left_item">';
1.101     raeburn  2001:                 if ($context eq 'requestcourses') {
                   2002:                     $datatable .= '<table><tr>';
                   2003:                 }
                   2004:                 my %cell;  
1.72      raeburn  2005:                 foreach my $item (@usertools) {
1.101     raeburn  2006:                     if ($context eq 'requestcourses') {
                   2007:                         my ($curroption,$currlimit);
                   2008:                         if (ref($settings) eq 'HASH') {
                   2009:                             if (ref($settings->{$item}) eq 'HASH') {
                   2010:                                 $curroption = $settings->{$item}->{$type};
                   2011:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2012:                                     $currlimit = $1; 
                   2013:                                 }
                   2014:                             }
                   2015:                         }
                   2016:                         if (!$curroption) {
                   2017:                             $curroption = 'norequest';
                   2018:                         }
                   2019:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2020:                         foreach my $option (@options) {
                   2021:                             my $val = $option;
                   2022:                             if ($option eq 'norequest') {
                   2023:                                 $val = 0;  
                   2024:                             }
                   2025:                             if ($option eq 'validate') {
                   2026:                                 my $canvalidate = 0;
                   2027:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2028:                                     if ($validations{$item}{$type}) {
                   2029:                                         $canvalidate = 1;
                   2030:                                     }
                   2031:                                 }
                   2032:                                 next if (!$canvalidate);
                   2033:                             }
                   2034:                             my $checked = '';
                   2035:                             if ($option eq $curroption) {
                   2036:                                 $checked = ' checked="checked"';
                   2037:                             } elsif ($option eq 'autolimit') {
                   2038:                                 if ($curroption =~ /^autolimit/) {
                   2039:                                     $checked = ' checked="checked"';
                   2040:                                 }                       
                   2041:                             } 
                   2042:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2043:                                   '<input type="radio" name="crsreq_'.$item.
                   2044:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2045:                                   $titles{$option}.'</label>';
1.101     raeburn  2046:                             if ($option eq 'autolimit') {
1.127     raeburn  2047:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2048:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2049:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2050:                             }
1.127     raeburn  2051:                             $cell{$item} .= '</span> ';
1.103     raeburn  2052:                             if ($option eq 'autolimit') {
1.127     raeburn  2053:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2054:                             }
1.101     raeburn  2055:                         }
1.163     raeburn  2056:                     } elsif ($context eq 'requestauthor') {
                   2057:                         my $curroption;
                   2058:                         if (ref($settings) eq 'HASH') {
                   2059:                             $curroption = $settings->{$type};
                   2060:                         }
                   2061:                         if (!$curroption) {
                   2062:                             $curroption = 'norequest';
                   2063:                         }
                   2064:                         foreach my $option (@options) {
                   2065:                             my $val = $option;
                   2066:                             if ($option eq 'norequest') {
                   2067:                                 $val = 0;
                   2068:                             }
                   2069:                             my $checked = '';
                   2070:                             if ($option eq $curroption) {
                   2071:                                 $checked = ' checked="checked"';
                   2072:                             }
                   2073:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2074:                                   '<input type="radio" name="authorreq_'.$type.
                   2075:                                   '" value="'.$val.'"'.$checked.' />'.
                   2076:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2077:                         }
1.101     raeburn  2078:                     } else {
                   2079:                         my $checked = 'checked="checked" ';
                   2080:                         if (ref($settings) eq 'HASH') {
                   2081:                             if (ref($settings->{$item}) eq 'HASH') {
                   2082:                                 if ($settings->{$item}->{$type} == 0) {
                   2083:                                     $checked = '';
                   2084:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2085:                                     $checked =  'checked="checked" ';
                   2086:                                 }
1.78      raeburn  2087:                             }
1.72      raeburn  2088:                         }
1.101     raeburn  2089:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2090:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2091:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2092:                                       '</label></span>&nbsp; ';
1.72      raeburn  2093:                     }
1.101     raeburn  2094:                 }
                   2095:                 if ($context eq 'requestcourses') {
                   2096:                     $datatable .= '</tr><tr>';
                   2097:                     foreach my $item (@usertools) {
1.106     raeburn  2098:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2099:                     }
                   2100:                     $datatable .= '</tr></table>';
1.72      raeburn  2101:                 }
1.86      raeburn  2102:                 $datatable .= '</td>';
1.163     raeburn  2103:                 unless (($context eq 'requestcourses') ||
                   2104:                         ($context eq 'requestauthor')) {
1.86      raeburn  2105:                     $datatable .= 
1.197     raeburn  2106:                               '<td class="LC_right_item">'.
                   2107:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2108:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2109:                               '" value="'.$currdefquota.
1.197     raeburn  2110:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2111:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2112:                               '<input type="text" name="authorquota_'.$type.
                   2113:                               '" value="'.$currauthorquota.
                   2114:                               '" size="5" /></span></td>';
1.86      raeburn  2115:                 }
                   2116:                 $datatable .= '</tr>';
1.3       raeburn  2117:             }
                   2118:         }
                   2119:     }
1.163     raeburn  2120:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2121:         $defaultquota = '20';
1.197     raeburn  2122:         $authorquota = '500';
1.86      raeburn  2123:         if (ref($settings) eq 'HASH') {
                   2124:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2125:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2126:             } elsif (defined($settings->{'default'})) {
                   2127:                 $defaultquota = $settings->{'default'};
                   2128:             }
1.197     raeburn  2129:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2130:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2131:             }
1.3       raeburn  2132:         }
                   2133:     }
                   2134:     $typecount ++;
                   2135:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2136:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2137:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2138:                   '<td class="LC_left_item">';
1.101     raeburn  2139:     if ($context eq 'requestcourses') {
                   2140:         $datatable .= '<table><tr>';
                   2141:     }
                   2142:     my %defcell;
1.72      raeburn  2143:     foreach my $item (@usertools) {
1.101     raeburn  2144:         if ($context eq 'requestcourses') {
                   2145:             my ($curroption,$currlimit);
                   2146:             if (ref($settings) eq 'HASH') {
                   2147:                 if (ref($settings->{$item}) eq 'HASH') {
                   2148:                     $curroption = $settings->{$item}->{'default'};
                   2149:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2150:                         $currlimit = $1;
                   2151:                     }
                   2152:                 }
                   2153:             }
                   2154:             if (!$curroption) {
                   2155:                 $curroption = 'norequest';
                   2156:             }
                   2157:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2158:             foreach my $option (@options) {
                   2159:                 my $val = $option;
                   2160:                 if ($option eq 'norequest') {
                   2161:                     $val = 0;
                   2162:                 }
                   2163:                 if ($option eq 'validate') {
                   2164:                     my $canvalidate = 0;
                   2165:                     if (ref($validations{$item}) eq 'HASH') {
                   2166:                         if ($validations{$item}{'default'}) {
                   2167:                             $canvalidate = 1;
                   2168:                         }
                   2169:                     }
                   2170:                     next if (!$canvalidate);
                   2171:                 }
                   2172:                 my $checked = '';
                   2173:                 if ($option eq $curroption) {
                   2174:                     $checked = ' checked="checked"';
                   2175:                 } elsif ($option eq 'autolimit') {
                   2176:                     if ($curroption =~ /^autolimit/) {
                   2177:                         $checked = ' checked="checked"';
                   2178:                     }
                   2179:                 }
                   2180:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2181:                                   '<input type="radio" name="crsreq_'.$item.
                   2182:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2183:                                   $titles{$option}.'</label>';
                   2184:                 if ($option eq 'autolimit') {
1.127     raeburn  2185:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2186:                                        $item.'_limit_default" size="1" '.
                   2187:                                        'value="'.$currlimit.'" />';
                   2188:                 }
1.127     raeburn  2189:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2190:                 if ($option eq 'autolimit') {
1.127     raeburn  2191:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2192:                 }
1.101     raeburn  2193:             }
1.163     raeburn  2194:         } elsif ($context eq 'requestauthor') {
                   2195:             my $curroption;
                   2196:             if (ref($settings) eq 'HASH') {
1.172     raeburn  2197:                 $curroption = $settings->{'default'};
1.163     raeburn  2198:             }
                   2199:             if (!$curroption) {
                   2200:                 $curroption = 'norequest';
                   2201:             }
                   2202:             foreach my $option (@options) {
                   2203:                 my $val = $option;
                   2204:                 if ($option eq 'norequest') {
                   2205:                     $val = 0;
                   2206:                 }
                   2207:                 my $checked = '';
                   2208:                 if ($option eq $curroption) {
                   2209:                     $checked = ' checked="checked"';
                   2210:                 }
                   2211:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2212:                               '<input type="radio" name="authorreq_default"'.
                   2213:                               ' value="'.$val.'"'.$checked.' />'.
                   2214:                               $titles{$option}.'</label></span>&nbsp; ';
                   2215:             }
1.101     raeburn  2216:         } else {
                   2217:             my $checked = 'checked="checked" ';
                   2218:             if (ref($settings) eq 'HASH') {
                   2219:                 if (ref($settings->{$item}) eq 'HASH') {
                   2220:                     if ($settings->{$item}->{'default'} == 0) {
                   2221:                         $checked = '';
                   2222:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2223:                         $checked = 'checked="checked" ';
                   2224:                     }
1.78      raeburn  2225:                 }
1.72      raeburn  2226:             }
1.101     raeburn  2227:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2228:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2229:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2230:                           '</label></span>&nbsp; ';
                   2231:         }
                   2232:     }
                   2233:     if ($context eq 'requestcourses') {
                   2234:         $datatable .= '</tr><tr>';
                   2235:         foreach my $item (@usertools) {
1.106     raeburn  2236:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2237:         }
1.101     raeburn  2238:         $datatable .= '</tr></table>';
1.72      raeburn  2239:     }
1.86      raeburn  2240:     $datatable .= '</td>';
1.163     raeburn  2241:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2242:         $datatable .= '<td class="LC_right_item">'.
                   2243:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2244:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2245:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2246:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2247:                       '<input type="text" name="authorquota" value="'.
                   2248:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2249:     }
                   2250:     $datatable .= '</tr>';
1.72      raeburn  2251:     $typecount ++;
                   2252:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2253:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2254:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2255:     if ($context eq 'requestcourses') {
1.109     raeburn  2256:         $datatable .= &mt('(overrides affiliation, if set)').
                   2257:                       '</td>'.
                   2258:                       '<td class="LC_left_item">'.
                   2259:                       '<table><tr>';
1.101     raeburn  2260:     } else {
1.109     raeburn  2261:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2262:                       '</td>'.
                   2263:                       '<td class="LC_left_item" colspan="2">'.
                   2264:                       '<br />';
1.101     raeburn  2265:     }
                   2266:     my %advcell;
1.72      raeburn  2267:     foreach my $item (@usertools) {
1.101     raeburn  2268:         if ($context eq 'requestcourses') {
                   2269:             my ($curroption,$currlimit);
                   2270:             if (ref($settings) eq 'HASH') {
                   2271:                 if (ref($settings->{$item}) eq 'HASH') {
                   2272:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2273:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2274:                         $currlimit = $1;
                   2275:                     }
                   2276:                 }
                   2277:             }
                   2278:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2279:             my $checked = '';
                   2280:             if ($curroption eq '') {
                   2281:                 $checked = ' checked="checked"';
                   2282:             }
                   2283:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2284:                                '<input type="radio" name="crsreq_'.$item.
                   2285:                                '__LC_adv" value=""'.$checked.' />'.
                   2286:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2287:             foreach my $option (@options) {
                   2288:                 my $val = $option;
                   2289:                 if ($option eq 'norequest') {
                   2290:                     $val = 0;
                   2291:                 }
                   2292:                 if ($option eq 'validate') {
                   2293:                     my $canvalidate = 0;
                   2294:                     if (ref($validations{$item}) eq 'HASH') {
                   2295:                         if ($validations{$item}{'_LC_adv'}) {
                   2296:                             $canvalidate = 1;
                   2297:                         }
                   2298:                     }
                   2299:                     next if (!$canvalidate);
                   2300:                 }
                   2301:                 my $checked = '';
1.104     raeburn  2302:                 if ($val eq $curroption) {
1.101     raeburn  2303:                     $checked = ' checked="checked"';
                   2304:                 } elsif ($option eq 'autolimit') {
                   2305:                     if ($curroption =~ /^autolimit/) {
                   2306:                         $checked = ' checked="checked"';
                   2307:                     }
                   2308:                 }
                   2309:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2310:                                   '<input type="radio" name="crsreq_'.$item.
                   2311:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2312:                                   $titles{$option}.'</label>';
                   2313:                 if ($option eq 'autolimit') {
1.127     raeburn  2314:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2315:                                        $item.'_limit__LC_adv" size="1" '.
                   2316:                                        'value="'.$currlimit.'" />';
                   2317:                 }
1.127     raeburn  2318:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2319:                 if ($option eq 'autolimit') {
1.127     raeburn  2320:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2321:                 }
1.101     raeburn  2322:             }
1.163     raeburn  2323:         } elsif ($context eq 'requestauthor') {
                   2324:             my $curroption;
                   2325:             if (ref($settings) eq 'HASH') {
                   2326:                 $curroption = $settings->{'_LC_adv'};
                   2327:             }
                   2328:             my $checked = '';
                   2329:             if ($curroption eq '') {
                   2330:                 $checked = ' checked="checked"';
                   2331:             }
                   2332:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2333:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2334:                           ' value=""'.$checked.' />'.
                   2335:                           &mt('No override set').'</label></span>&nbsp; ';
                   2336:             foreach my $option (@options) {
                   2337:                 my $val = $option;
                   2338:                 if ($option eq 'norequest') {
                   2339:                     $val = 0;
                   2340:                 }
                   2341:                 my $checked = '';
                   2342:                 if ($val eq $curroption) {
                   2343:                     $checked = ' checked="checked"';
                   2344:                 }
                   2345:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2346:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2347:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2348:                               $titles{$option}.'</label></span>&nbsp; ';
                   2349:             }
1.101     raeburn  2350:         } else {
                   2351:             my $checked = 'checked="checked" ';
                   2352:             if (ref($settings) eq 'HASH') {
                   2353:                 if (ref($settings->{$item}) eq 'HASH') {
                   2354:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2355:                         $checked = '';
                   2356:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2357:                         $checked = 'checked="checked" ';
                   2358:                     }
1.79      raeburn  2359:                 }
1.72      raeburn  2360:             }
1.101     raeburn  2361:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2362:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2363:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2364:                           '</label></span>&nbsp; ';
                   2365:         }
                   2366:     }
                   2367:     if ($context eq 'requestcourses') {
                   2368:         $datatable .= '</tr><tr>';
                   2369:         foreach my $item (@usertools) {
1.106     raeburn  2370:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2371:         }
1.101     raeburn  2372:         $datatable .= '</tr></table>';
1.72      raeburn  2373:     }
1.98      raeburn  2374:     $datatable .= '</td></tr>';
1.30      raeburn  2375:     $$rowtotal += $typecount;
1.3       raeburn  2376:     return $datatable;
                   2377: }
                   2378: 
1.163     raeburn  2379: sub print_requestmail {
1.305     raeburn  2380:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208     raeburn  2381:     my ($now,$datatable,%currapp);
1.102     raeburn  2382:     $now = time;
                   2383:     if (ref($settings) eq 'HASH') {
                   2384:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2385:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2386:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2387:             }
                   2388:         }
                   2389:     }
1.191     raeburn  2390:     my $numinrow = 2;
1.224     raeburn  2391:     my $css_class;
1.305     raeburn  2392:     if ($$rowtotal%2) {
                   2393:         $css_class = 'LC_odd_row';
                   2394:     }
                   2395:     if ($customcss) {
                   2396:         $css_class .= " $customcss";
                   2397:     }
                   2398:     $css_class =~ s/^\s+//;
                   2399:     if ($css_class) {
                   2400:         $css_class = ' class="'.$css_class.'"';
                   2401:     }
                   2402:     if ($rowstyle) {
                   2403:         $css_class .= ' style="'.$rowstyle.'"';
                   2404:     }
1.163     raeburn  2405:     my $text;
                   2406:     if ($action eq 'requestcourses') {
                   2407:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2408:     } elsif ($action eq 'requestauthor') {
                   2409:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2410:     } else {
1.224     raeburn  2411:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2412:     }
1.224     raeburn  2413:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2414:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2415:                  ' <td class="LC_left_item">';
1.191     raeburn  2416:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2417:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2418:     if ($numdc > 0) {
                   2419:         $datatable .= $table;
1.102     raeburn  2420:     } else {
                   2421:         $datatable .= &mt('There are no active Domain Coordinators');
                   2422:     }
                   2423:     $datatable .='</td></tr>';
                   2424:     return $datatable;
                   2425: }
                   2426: 
1.216     raeburn  2427: sub print_studentcode {
                   2428:     my ($settings,$rowtotal) = @_;
                   2429:     my $rownum = 0; 
1.218     raeburn  2430:     my ($output,%current);
1.325     raeburn  2431:     my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248     raeburn  2432:     if (ref($settings) eq 'HASH') {
                   2433:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2434:             foreach my $type (@crstypes) {
                   2435:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2436:             }
1.218     raeburn  2437:         }
                   2438:     }
                   2439:     $output .= '<tr>'.
                   2440:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2441:                '<td class="LC_left_item">';
                   2442:     foreach my $type (@crstypes) {
                   2443:         my $check = ' ';
                   2444:         if ($current{$type}) {
                   2445:             $check = ' checked="checked" ';
                   2446:         }
                   2447:         $output .= '<span class="LC_nobreak"><label>'.
                   2448:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2449:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2450:     }
                   2451:     $output .= '</td></tr>';
                   2452:     $$rowtotal ++;
                   2453:     return $output;
1.216     raeburn  2454: }
                   2455: 
                   2456: sub print_textbookcourses {
1.242     raeburn  2457:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2458:     my $rownum = 0;
                   2459:     my $css_class;
                   2460:     my $itemcount = 1;
                   2461:     my $maxnum = 0;
                   2462:     my $bookshash;
                   2463:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2464:         $bookshash = $settings->{$type};
1.216     raeburn  2465:     }
                   2466:     my %ordered;
                   2467:     if (ref($bookshash) eq 'HASH') {
                   2468:         foreach my $item (keys(%{$bookshash})) {
                   2469:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2470:                 my $num = $bookshash->{$item}{'order'};
                   2471:                 $ordered{$num} = $item;
                   2472:             }
                   2473:         }
                   2474:     }
                   2475:     my $confname = $dom.'-domainconfig';
                   2476:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2477:     my $maxnum = scalar(keys(%ordered));
                   2478:     my $datatable;
1.216     raeburn  2479:     if (keys(%ordered)) {
                   2480:         my @items = sort { $a <=> $b } keys(%ordered);
                   2481:         for (my $i=0; $i<@items; $i++) {
                   2482:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2483:             my $key = $ordered{$items[$i]};
                   2484:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2485:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2486:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2487:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2488:                 $subject = $bookshash->{$key}->{'subject'};
                   2489:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2490:                 if ($type eq 'textbooks') {
1.243     raeburn  2491:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2492:                     $author = $bookshash->{$key}->{'author'};
                   2493:                     $image = $bookshash->{$key}->{'image'};
                   2494:                     if ($image ne '') {
                   2495:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2496:                         my $imagethumb = "$path/tn-".$imagefile;
                   2497:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2498:                     }
1.216     raeburn  2499:                 }
                   2500:             }
1.242     raeburn  2501:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2502:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2503:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2504:             for (my $k=0; $k<=$maxnum; $k++) {
                   2505:                 my $vpos = $k+1;
                   2506:                 my $selstr;
                   2507:                 if ($k == $i) {
                   2508:                     $selstr = ' selected="selected" ';
                   2509:                 }
                   2510:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2511:             }
                   2512:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2513:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2514:                 &mt('Delete?').'</label></span></td>'.
                   2515:                 '<td colspan="2">'.
1.242     raeburn  2516:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2517:                 ('&nbsp;'x2).
1.242     raeburn  2518:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2519:             if ($type eq 'textbooks') {
                   2520:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2521:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2522:                               ('&nbsp;'x2).
1.242     raeburn  2523:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2524:                               ('&nbsp;'x2).
                   2525:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2526:                 if ($image) {
1.267     raeburn  2527:                     $datatable .= $imgsrc.
1.242     raeburn  2528:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2529:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2530:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2531:                 }
                   2532:                 if ($switchserver) {
                   2533:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2534:                 } else {
                   2535:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2536:                 }
1.216     raeburn  2537:             }
1.242     raeburn  2538:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2539:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2540:                           $coursetitle.'</span></td></tr>'."\n";
                   2541:             $itemcount ++;
                   2542:         }
                   2543:     }
                   2544:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2545:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2546:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2547:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2548:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2549:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2550:         my $vpos = $k+1;
                   2551:         my $selstr;
                   2552:         if ($k == $maxnum) {
                   2553:             $selstr = ' selected="selected" ';
                   2554:         }
                   2555:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2556:     }
                   2557:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  2558:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216     raeburn  2559:                   '<td colspan="2">'.
1.242     raeburn  2560:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2561:                   ('&nbsp;'x2).
1.242     raeburn  2562:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2563:                   ('&nbsp;'x2);
                   2564:     if ($type eq 'textbooks') {
1.243     raeburn  2565:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2566:                       ('&nbsp;'x2).
                   2567:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2568:                       ('&nbsp;'x2).
                   2569:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2570:         if ($switchserver) {
                   2571:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2572:         } else {
                   2573:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2574:         }
1.334     raeburn  2575:         $datatable .= '</span>'."\n";
1.216     raeburn  2576:     }
1.334     raeburn  2577:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2578:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2579:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2580:                   &Apache::loncommon::selectcourse_link
1.334     raeburn  2581:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216     raeburn  2582:                   '</span></td>'."\n".
                   2583:                   '</tr>'."\n";
                   2584:     $itemcount ++;
                   2585:     return $datatable;
                   2586: }
                   2587: 
1.217     raeburn  2588: sub textbookcourses_javascript {
1.242     raeburn  2589:     my ($settings) = @_;
                   2590:     return unless(ref($settings) eq 'HASH');
                   2591:     my (%ordered,%total,%jstext);
                   2592:     foreach my $type ('textbooks','templates') {
                   2593:         $total{$type} = 0;
                   2594:         if (ref($settings->{$type}) eq 'HASH') {
                   2595:             foreach my $item (keys(%{$settings->{$type}})) {
                   2596:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2597:                     my $num = $settings->{$type}->{$item}{'order'};
                   2598:                     $ordered{$type}{$num} = $item;
                   2599:                 }
                   2600:             }
                   2601:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2602:         }
                   2603:         my @jsarray = ();
                   2604:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2605:             push(@jsarray,$ordered{$type}{$item});
                   2606:         }
                   2607:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2608:     }
                   2609:     return <<"ENDSCRIPT";
                   2610: <script type="text/javascript">
                   2611: // <![CDATA[
1.242     raeburn  2612: function reorderBooks(form,item,caller) {
1.217     raeburn  2613:     var changedVal;
1.242     raeburn  2614: $jstext{'textbooks'};
                   2615: $jstext{'templates'};
                   2616:     var newpos;
                   2617:     var maxh;
                   2618:     if (caller == 'textbooks') {  
                   2619:         newpos = 'textbooks_addbook_pos';
                   2620:         maxh = 1 + $total{'textbooks'};
                   2621:     } else {
                   2622:         newpos = 'templates_addbook_pos';
                   2623:         maxh = 1 + $total{'templates'};
                   2624:     }
1.217     raeburn  2625:     var current = new Array;
                   2626:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2627:     if (item == newpos) {
                   2628:         changedVal = newitemVal;
                   2629:     } else {
                   2630:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2631:         current[newitemVal] = newpos;
                   2632:     }
1.242     raeburn  2633:     if (caller == 'textbooks') {
                   2634:         for (var i=0; i<textbooks.length; i++) {
                   2635:             var elementName = 'textbooks_'+textbooks[i];
                   2636:             if (elementName != item) {
                   2637:                 if (form.elements[elementName]) {
                   2638:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2639:                     current[currVal] = elementName;
                   2640:                 }
                   2641:             }
                   2642:         }
                   2643:     }
                   2644:     if (caller == 'templates') {
                   2645:         for (var i=0; i<templates.length; i++) {
                   2646:             var elementName = 'templates_'+templates[i];
                   2647:             if (elementName != item) {
                   2648:                 if (form.elements[elementName]) {
                   2649:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2650:                     current[currVal] = elementName;
                   2651:                 }
1.217     raeburn  2652:             }
                   2653:         }
                   2654:     }
                   2655:     var oldVal;
                   2656:     for (var j=0; j<maxh; j++) {
                   2657:         if (current[j] == undefined) {
                   2658:             oldVal = j;
                   2659:         }
                   2660:     }
                   2661:     if (oldVal < changedVal) {
                   2662:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2663:            var elementName = current[k];
                   2664:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2665:         }
                   2666:     } else {
                   2667:         for (var k=changedVal; k<oldVal; k++) {
                   2668:             var elementName = current[k];
                   2669:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2670:         }
                   2671:     }
                   2672:     return;
                   2673: }
                   2674: 
                   2675: // ]]>
                   2676: </script>
                   2677: 
                   2678: ENDSCRIPT
                   2679: }
                   2680: 
1.267     raeburn  2681: sub ltitools_javascript {
                   2682:     my ($settings) = @_;
1.319     raeburn  2683:     my $togglejs = &ltitools_toggle_js();
                   2684:     unless (ref($settings) eq 'HASH') {
                   2685:         return $togglejs;
                   2686:     }
1.267     raeburn  2687:     my (%ordered,$total,%jstext);
                   2688:     $total = 0;
                   2689:     foreach my $item (keys(%{$settings})) {
                   2690:         if (ref($settings->{$item}) eq 'HASH') {
                   2691:             my $num = $settings->{$item}{'order'};
                   2692:             $ordered{$num} = $item;
                   2693:         }
                   2694:     }
                   2695:     $total = scalar(keys(%{$settings}));
                   2696:     my @jsarray = ();
                   2697:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2698:         push(@jsarray,$ordered{$item});
                   2699:     }
                   2700:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2701:     return <<"ENDSCRIPT";
                   2702: <script type="text/javascript">
                   2703: // <![CDATA[
1.319     raeburn  2704: function reorderLTITools(form,item) {
1.267     raeburn  2705:     var changedVal;
                   2706: $jstext
                   2707:     var newpos = 'ltitools_add_pos';
                   2708:     var maxh = 1 + $total;
                   2709:     var current = new Array;
                   2710:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2711:     if (item == newpos) {
                   2712:         changedVal = newitemVal;
                   2713:     } else {
                   2714:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2715:         current[newitemVal] = newpos;
                   2716:     }
                   2717:     for (var i=0; i<ltitools.length; i++) {
                   2718:         var elementName = 'ltitools_'+ltitools[i];
                   2719:         if (elementName != item) {
                   2720:             if (form.elements[elementName]) {
                   2721:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2722:                 current[currVal] = elementName;
                   2723:             }
                   2724:         }
                   2725:     }
                   2726:     var oldVal;
                   2727:     for (var j=0; j<maxh; j++) {
                   2728:         if (current[j] == undefined) {
                   2729:             oldVal = j;
                   2730:         }
                   2731:     }
                   2732:     if (oldVal < changedVal) {
                   2733:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2734:            var elementName = current[k];
                   2735:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2736:         }
                   2737:     } else {
                   2738:         for (var k=changedVal; k<oldVal; k++) {
                   2739:             var elementName = current[k];
                   2740:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2741:         }
                   2742:     }
                   2743:     return;
                   2744: }
                   2745: 
                   2746: // ]]>
                   2747: </script>
                   2748: 
1.319     raeburn  2749: $togglejs
                   2750: 
                   2751: ENDSCRIPT
                   2752: }
                   2753: 
                   2754: sub ltitools_toggle_js {
                   2755:     return <<"ENDSCRIPT";
                   2756: <script type="text/javascript">
                   2757: // <![CDATA[
                   2758: 
                   2759: function toggleLTITools(form,setting,item) {
                   2760:     var radioname = '';
                   2761:     var divid = '';
                   2762:     if ((setting == 'passback') || (setting == 'roster')) {
                   2763:         radioname = 'ltitools_'+setting+'_'+item;
                   2764:         divid = 'ltitools_'+setting+'time_'+item;
                   2765:         var num = form.elements[radioname].length;
                   2766:         if (num) {
                   2767:             var setvis = '';
                   2768:             for (var i=0; i<num; i++) {
                   2769:                 if (form.elements[radioname][i].checked) {
                   2770:                     if (form.elements[radioname][i].value == '1') {
                   2771:                         if (document.getElementById(divid)) {
                   2772:                             document.getElementById(divid).style.display = 'inline-block';
                   2773:                         }
                   2774:                         setvis = 1;
                   2775:                     }
                   2776:                     break;
                   2777:                 }
                   2778:             }
                   2779:         }
                   2780:         if (!setvis) {
                   2781:             if (document.getElementById(divid)) {
                   2782:                 document.getElementById(divid).style.display = 'none';
                   2783:             }
                   2784:         }
                   2785:     }
1.324     raeburn  2786:     if (setting == 'user') {
                   2787:         divid = 'ltitools_'+setting+'_div_'+item;
                   2788:         var checkid = 'ltitools_'+setting+'_field_'+item;
                   2789:         if (document.getElementById(divid)) {
                   2790:             if (document.getElementById(checkid)) {
                   2791:                 if (document.getElementById(checkid).checked) {
                   2792:                     document.getElementById(divid).style.display = 'inline-block';
                   2793:                 } else {
                   2794:                     document.getElementById(divid).style.display = 'none';
                   2795:                 }
                   2796:             }
                   2797:         }
                   2798:     }
1.319     raeburn  2799:     return;
                   2800: }
                   2801: // ]]>
                   2802: </script>
                   2803: 
1.267     raeburn  2804: ENDSCRIPT
                   2805: }
                   2806: 
1.320     raeburn  2807: sub lti_javascript {
                   2808:     my ($settings) = @_;
                   2809:     my $togglejs = &lti_toggle_js();
                   2810:     unless (ref($settings) eq 'HASH') {
                   2811:         return $togglejs;
                   2812:     }
                   2813:     my (%ordered,$total,%jstext);
                   2814:     $total = 0;
                   2815:     foreach my $item (keys(%{$settings})) {
                   2816:         if (ref($settings->{$item}) eq 'HASH') {
                   2817:             my $num = $settings->{$item}{'order'};
                   2818:             $ordered{$num} = $item;
                   2819:         }
                   2820:     }
                   2821:     $total = scalar(keys(%{$settings}));
                   2822:     my @jsarray = ();
                   2823:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2824:         push(@jsarray,$ordered{$item});
                   2825:     }
                   2826:     my $jstext = '    var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2827:     return <<"ENDSCRIPT";
                   2828: <script type="text/javascript">
                   2829: // <![CDATA[
                   2830: function reorderLTI(form,item) {
                   2831:     var changedVal;
                   2832: $jstext
                   2833:     var newpos = 'lti_pos_add';
                   2834:     var maxh = 1 + $total;
                   2835:     var current = new Array;
                   2836:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2837:     if (item == newpos) {
                   2838:         changedVal = newitemVal;
                   2839:     } else {
                   2840:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2841:         current[newitemVal] = newpos;
                   2842:     }
                   2843:     for (var i=0; i<lti.length; i++) {
                   2844:         var elementName = 'lti_pos_'+lti[i];
                   2845:         if (elementName != item) {
                   2846:             if (form.elements[elementName]) {
                   2847:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2848:                 current[currVal] = elementName;
                   2849:             }
                   2850:         }
                   2851:     }
                   2852:     var oldVal;
                   2853:     for (var j=0; j<maxh; j++) {
                   2854:         if (current[j] == undefined) {
                   2855:             oldVal = j;
                   2856:         }
                   2857:     }
                   2858:     if (oldVal < changedVal) {
                   2859:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2860:            var elementName = current[k];
                   2861:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2862:         }
                   2863:     } else {
                   2864:         for (var k=changedVal; k<oldVal; k++) {
                   2865:             var elementName = current[k];
                   2866:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2867:         }
                   2868:     }
                   2869:     return;
                   2870: }
                   2871: // ]]>
                   2872: </script>
                   2873: 
                   2874: $togglejs
                   2875: 
                   2876: ENDSCRIPT
                   2877: }
                   2878: 
                   2879: sub lti_toggle_js {
1.325     raeburn  2880:     my %lcauthparmtext = &Apache::lonlocal::texthash (
                   2881:                             localauth => 'Local auth argument',
                   2882:                             krb       => 'Kerberos domain',
                   2883:                          );
1.320     raeburn  2884:     return <<"ENDSCRIPT";
                   2885: <script type="text/javascript">
                   2886: // <![CDATA[
                   2887: 
                   2888: function toggleLTI(form,setting,item) {
1.345     raeburn  2889:     if (setting == 'requser') {
                   2890:         var fieldsets = document.getElementsByClassName('ltioption_'+item);
                   2891:         if (fieldsets.length) {
                   2892:             var radioname = 'lti_'+setting+'_'+item;
                   2893:             var num = form.elements[radioname].length;
                   2894:             if (num) {
                   2895:                 var setvis = '';
                   2896:                 for (var i=0; i<num; i++) {
                   2897:                     if (form.elements[radioname][i].checked) {
                   2898:                         if (form.elements[radioname][i].value == '1') {
                   2899:                            setvis = 1;
                   2900:                            break;
                   2901:                         }
                   2902:                     }
                   2903:                 }
1.352     raeburn  2904:                 for (var j=0; j<fieldsets.length; j++) {
1.345     raeburn  2905:                     if (setvis) {
                   2906:                         fieldsets[j].style.display = 'block';
                   2907:                     } else {
                   2908:                         fieldsets[j].style.display = 'none';
                   2909:                     }
                   2910:                 }
                   2911:             }
                   2912:         }
1.363     raeburn  2913:     } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320     raeburn  2914:         var radioname = '';
                   2915:         var divid = '';
                   2916:         if (setting == 'user') {
                   2917:             radioname = 'lti_mapuser_'+item;
                   2918:             divid = 'lti_userfield_'+item;
1.343     raeburn  2919:         } else if (setting == 'crs') {
1.320     raeburn  2920:             radioname = 'lti_mapcrs_'+item;
                   2921:             divid = 'lti_crsfield_'+item;
1.363     raeburn  2922:         } else if (setting == 'callback') {
                   2923:             radioname = 'lti_callback_'+item;
                   2924:             divid = 'lti_callbackfield_'+item;
1.337     raeburn  2925:         } else {
1.351     raeburn  2926:             radioname = 'lti_passback_'+item;
1.337     raeburn  2927:             divid =  'lti_passback_'+item;
1.320     raeburn  2928:         }
                   2929:         var num = form.elements[radioname].length;
                   2930:         if (num) {
                   2931:             var setvis = '';
                   2932:             for (var i=0; i<num; i++) {
                   2933:                if (form.elements[radioname][i].checked) {
1.363     raeburn  2934:                    if ((setting == 'passback') || (setting == 'callback')) {
1.337     raeburn  2935:                        if (form.elements[radioname][i].value == '1') {
                   2936:                            if (document.getElementById(divid)) {
                   2937:                                document.getElementById(divid).style.display = 'inline-block';
                   2938:                            }
                   2939:                            setvis = 1;
                   2940:                            break;
                   2941:                        }
                   2942:                    } else {
                   2943:                        if (form.elements[radioname][i].value == 'other') {
                   2944:                            if (document.getElementById(divid)) {
                   2945:                                document.getElementById(divid).style.display = 'inline-block';
                   2946:                            }
                   2947:                            setvis = 1;
                   2948:                            break;
1.320     raeburn  2949:                        }
                   2950:                    }
                   2951:                } 
                   2952:             }
                   2953:             if (!setvis) {
                   2954:                 if (document.getElementById(divid)) {
                   2955:                     document.getElementById(divid).style.display = 'none';
                   2956:                 }
                   2957:             }
                   2958:         }
                   2959:     } else if ((setting == 'sec') || (setting == 'secsrc')) {
                   2960:         var numsec = form.elements['lti_crssec_'+item].length;
                   2961:         if (numsec) {
                   2962:             var setvis = '';
                   2963:             for (var i=0; i<numsec; i++) {
                   2964:                 if (form.elements['lti_crssec_'+item][i].checked) {
                   2965:                     if (form.elements['lti_crssec_'+item][i].value == '1') {
                   2966:                         if (document.getElementById('lti_crssecfield_'+item)) {
                   2967:                             document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
                   2968:                             setvis = 1;
                   2969:                             var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
                   2970:                             if (numsrcsec) {
                   2971:                                 var setsrcvis = '';
                   2972:                                 for (var j=0; j<numsrcsec; j++) {
                   2973:                                     if (form.elements['lti_crssecsrc_'+item][j].checked) {
                   2974:                                         if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
                   2975:                                             if (document.getElementById('lti_secsrcfield_'+item)) {
                   2976:                                                 document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
                   2977:                                                 setsrcvis = 1;
                   2978:                                             }
                   2979:                                         }
                   2980:                                     }
                   2981:                                 }
                   2982:                                 if (!setsrcvis) {
                   2983:                                     if (document.getElementById('lti_secsrcfield_'+item)) {
                   2984:                                         document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   2985:                                     }
                   2986:                                 }
                   2987:                             }
                   2988:                         }
                   2989:                     }
                   2990:                 }
                   2991:             }
                   2992:             if (!setvis) {
                   2993:                 if (document.getElementById('lti_crssecfield_'+item)) {
                   2994:                     document.getElementById('lti_crssecfield_'+item).style.display = 'none';
                   2995:                 }
                   2996:                 if (document.getElementById('lti_secsrcfield_'+item)) {
                   2997:                     document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
                   2998:                 }
                   2999:             }
                   3000:         }
1.325     raeburn  3001:     } else if (setting == 'lcauth') {
                   3002:         var numauth = form.elements['lti_lcauth_'+item].length;
                   3003:         if (numauth) {
                   3004:             for (var i=0; i<numauth; i++) {
                   3005:                 if (form.elements['lti_lcauth_'+item][i].checked) {
                   3006:                     if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                   3007:                         if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                   3008:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                   3009:                         } else {
                   3010:                             document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                   3011:                             if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                   3012:                                 if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                   3013:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                   3014:                                 } else {
                   3015:                                     document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                   3016:                                 }
                   3017:                             }
                   3018:                         }
                   3019:                     }
                   3020:                 }
                   3021:             }
                   3022:         }
1.326     raeburn  3023:     } else if (setting == 'lcmenu') {
                   3024:         var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
                   3025:         var divid = 'lti_menufield_'+item;
                   3026:         var setvis = '';
                   3027:         for (var i=0; i<menus.length; i++) {
                   3028:             var radioname = menus[i];  
                   3029:             var num = form.elements[radioname].length;
                   3030:             if (num) {
                   3031:                 for (var j=0; j<num; j++) {
                   3032:                     if (form.elements[radioname][j].checked) {
                   3033:                         if (form.elements[radioname][j].value == '1') {
                   3034:                             if (document.getElementById(divid)) {
                   3035:                                 document.getElementById(divid).style.display = 'inline-block';
                   3036:                             }
                   3037:                             setvis = 1;
                   3038:                             break;
                   3039:                         }
                   3040:                     }
                   3041:                 }
                   3042:             }
                   3043:             if (setvis == 1) {
                   3044:                 break;
                   3045:             }
                   3046:         }
                   3047:         if (!setvis) {
                   3048:             if (document.getElementById(divid)) {
                   3049:                 document.getElementById(divid).style.display = 'none';
                   3050:             }
                   3051:         }
1.320     raeburn  3052:     }
                   3053:     return;
                   3054: }
                   3055: // ]]>
                   3056: </script>
                   3057: 
                   3058: ENDSCRIPT
                   3059: }
                   3060: 
1.3       raeburn  3061: sub print_autoenroll {
1.30      raeburn  3062:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3063:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.274     raeburn  3064:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  3065:     if (ref($settings) eq 'HASH') {
                   3066:         if (exists($settings->{'run'})) {
                   3067:             if ($settings->{'run'} eq '0') {
                   3068:                 $runoff = ' checked="checked" ';
                   3069:                 $runon = ' ';
                   3070:             } else {
                   3071:                 $runon = ' checked="checked" ';
                   3072:                 $runoff = ' ';
                   3073:             }
                   3074:         } else {
                   3075:             if ($autorun) {
                   3076:                 $runon = ' checked="checked" ';
                   3077:                 $runoff = ' ';
                   3078:             } else {
                   3079:                 $runoff = ' checked="checked" ';
                   3080:                 $runon = ' ';
                   3081:             }
                   3082:         }
1.129     raeburn  3083:         if (exists($settings->{'co-owners'})) {
                   3084:             if ($settings->{'co-owners'} eq '0') {
                   3085:                 $coownersoff = ' checked="checked" ';
                   3086:                 $coownerson = ' ';
                   3087:             } else {
                   3088:                 $coownerson = ' checked="checked" ';
                   3089:                 $coownersoff = ' ';
                   3090:             }
                   3091:         } else {
                   3092:             $coownersoff = ' checked="checked" ';
                   3093:             $coownerson = ' ';
                   3094:         }
1.3       raeburn  3095:         if (exists($settings->{'sender_domain'})) {
                   3096:             $defdom = $settings->{'sender_domain'};
                   3097:         }
1.274     raeburn  3098:         if (exists($settings->{'autofailsafe'})) {
                   3099:             $failsafe = $settings->{'autofailsafe'};
                   3100:         }
1.14      raeburn  3101:     } else {
                   3102:         if ($autorun) {
                   3103:             $runon = ' checked="checked" ';
                   3104:             $runoff = ' ';
                   3105:         } else {
                   3106:             $runoff = ' checked="checked" ';
                   3107:             $runon = ' ';
                   3108:         }
1.3       raeburn  3109:     }
                   3110:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3111:     my $notif_sender;
                   3112:     if (ref($settings) eq 'HASH') {
                   3113:         $notif_sender = $settings->{'sender_uname'};
                   3114:     }
1.3       raeburn  3115:     my $datatable='<tr class="LC_odd_row">'.
                   3116:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3117:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3118:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3119:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3120:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3121:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3122:                   '</tr><tr>'.
                   3123:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3124:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3125:                   &mt('username').':&nbsp;'.
                   3126:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3127:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3128:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3129:                   '<tr class="LC_odd_row">'.
                   3130:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3131:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3132:                   '<input type="radio" name="autoassign_coowners"'.
                   3133:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3134:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3135:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274     raeburn  3136:                   '</tr><tr>'.
                   3137:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   3138:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3139:                   '<input type="text" name="autoenroll_failsafe"'.
1.333     raeburn  3140:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.274     raeburn  3141:     $$rowtotal += 4;
1.3       raeburn  3142:     return $datatable;
                   3143: }
                   3144: 
                   3145: sub print_autoupdate {
1.30      raeburn  3146:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  3147:     my $datatable;
                   3148:     if ($position eq 'top') {
                   3149:         my $updateon = ' ';
                   3150:         my $updateoff = ' checked="checked" ';
                   3151:         my $classlistson = ' ';
                   3152:         my $classlistsoff = ' checked="checked" ';
                   3153:         if (ref($settings) eq 'HASH') {
                   3154:             if ($settings->{'run'} eq '1') {
                   3155:                 $updateon = $updateoff;
                   3156:                 $updateoff = ' ';
                   3157:             }
                   3158:             if ($settings->{'classlists'} eq '1') {
                   3159:                 $classlistson = $classlistsoff;
                   3160:                 $classlistsoff = ' ';
                   3161:             }
                   3162:         }
                   3163:         my %title = (
                   3164:                    run => 'Auto-update active?',
                   3165:                    classlists => 'Update information in classlists?',
                   3166:                     );
                   3167:         $datatable = '<tr class="LC_odd_row">'. 
                   3168:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  3169:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3170:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  3171:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3172:                   '<label><input type="radio" name="autoupdate_run"'.
                   3173:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3174:                   '</tr><tr>'.
                   3175:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  3176:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3177:                   '<label><input type="radio" name="classlists"'.
                   3178:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3179:                   '<label><input type="radio" name="classlists"'.
                   3180:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3181:                   '</tr>';
1.30      raeburn  3182:         $$rowtotal += 2;
1.131     raeburn  3183:     } elsif ($position eq 'middle') {
                   3184:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3185:         my $numinrow = 3;
                   3186:         my $locknamesettings;
                   3187:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   3188:                                      $dom,$numinrow,$othertitle,
1.305     raeburn  3189:                                     'lockablenames',$rowtotal);
1.131     raeburn  3190:         $$rowtotal ++;
1.3       raeburn  3191:     } else {
1.44      raeburn  3192:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  3193:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  3194:                       'permanentemail','id');
1.33      raeburn  3195:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  3196:         my $numrows = 0;
1.26      raeburn  3197:         if (ref($types) eq 'ARRAY') {
                   3198:             if (@{$types} > 0) {
                   3199:                 $datatable = 
                   3200:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   3201:                                          \@fields,$types,\$numrows);
1.30      raeburn  3202:                     $$rowtotal += @{$types}; 
1.26      raeburn  3203:             }
1.3       raeburn  3204:         }
                   3205:         $datatable .= 
                   3206:             &usertype_update_row($settings,{'default' => $othertitle},
                   3207:                                  \%fieldtitles,\@fields,['default'],
                   3208:                                  \$numrows);
1.30      raeburn  3209:         $$rowtotal ++;     
1.3       raeburn  3210:     }
                   3211:     return $datatable;
                   3212: }
                   3213: 
1.125     raeburn  3214: sub print_autocreate {
                   3215:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  3216:     my (%createon,%createoff,%currhash);
1.125     raeburn  3217:     my @types = ('xml','req');
                   3218:     if (ref($settings) eq 'HASH') {
                   3219:         foreach my $item (@types) {
                   3220:             $createoff{$item} = ' checked="checked" ';
                   3221:             $createon{$item} = ' ';
                   3222:             if (exists($settings->{$item})) {
                   3223:                 if ($settings->{$item}) {
                   3224:                     $createon{$item} = ' checked="checked" ';
                   3225:                     $createoff{$item} = ' ';
                   3226:                 }
                   3227:             }
                   3228:         }
1.210     raeburn  3229:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  3230:             $currhash{$settings->{'xmldc'}} = 1;
                   3231:         }
1.125     raeburn  3232:     } else {
                   3233:         foreach my $item (@types) {
                   3234:             $createoff{$item} = ' checked="checked" ';
                   3235:             $createon{$item} = ' ';
                   3236:         }
                   3237:     }
                   3238:     $$rowtotal += 2;
1.191     raeburn  3239:     my $numinrow = 2;
1.125     raeburn  3240:     my $datatable='<tr class="LC_odd_row">'.
                   3241:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   3242:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3243:                   '<input type="radio" name="autocreate_xml"'.
                   3244:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3245:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  3246:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   3247:                   '</td></tr><tr>'.
                   3248:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   3249:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3250:                   '<input type="radio" name="autocreate_req"'.
                   3251:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3252:                   '<label><input type="radio" name="autocreate_req"'.
                   3253:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  3254:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   3255:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  3256:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  3257:     if ($numdc > 1) {
1.247     raeburn  3258:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   3259:                       '</td><td class="LC_left_item">';
1.125     raeburn  3260:     } else {
1.247     raeburn  3261:         $datatable .= &mt('Course creation processed as:').
                   3262:                       '</td><td class="LC_right_item">';
1.125     raeburn  3263:     }
1.247     raeburn  3264:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  3265:     $$rowtotal += $rows;
1.125     raeburn  3266:     return $datatable;
                   3267: }
                   3268: 
1.23      raeburn  3269: sub print_directorysrch {
1.277     raeburn  3270:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3271:     my $datatable;
                   3272:     if ($position eq 'top') {
                   3273:         my $instsrchon = ' ';
                   3274:         my $instsrchoff = ' checked="checked" ';
                   3275:         my ($exacton,$containson,$beginson);
                   3276:         my $instlocalon = ' ';
                   3277:         my $instlocaloff = ' checked="checked" ';
                   3278:         if (ref($settings) eq 'HASH') {
                   3279:             if ($settings->{'available'} eq '1') {
                   3280:                 $instsrchon = $instsrchoff;
                   3281:                 $instsrchoff = ' ';
                   3282:             }
                   3283:             if ($settings->{'localonly'} eq '1') {
                   3284:                 $instlocalon = $instlocaloff;
                   3285:                 $instlocaloff = ' ';
                   3286:             }
                   3287:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   3288:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   3289:                     if ($type eq 'exact') {
                   3290:                         $exacton = ' checked="checked" ';
                   3291:                     } elsif ($type eq 'contains') {
                   3292:                         $containson = ' checked="checked" ';
                   3293:                     } elsif ($type eq 'begins') {
                   3294:                         $beginson = ' checked="checked" ';
                   3295:                     }
                   3296:                 }
                   3297:             } else {
                   3298:                 if ($settings->{'searchtypes'} eq 'exact') {
                   3299:                     $exacton = ' checked="checked" ';
                   3300:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   3301:                     $containson = ' checked="checked" ';
                   3302:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  3303:                     $exacton = ' checked="checked" ';
                   3304:                     $containson = ' checked="checked" ';
                   3305:                 }
                   3306:             }
1.277     raeburn  3307:         }
                   3308:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   3309:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3310: 
                   3311:         my $numinrow = 4;
                   3312:         my $cansrchrow = 0;
                   3313:         $datatable='<tr class="LC_odd_row">'.
                   3314:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   3315:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3316:                    '<input type="radio" name="dirsrch_available"'.
                   3317:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3318:                    '<label><input type="radio" name="dirsrch_available"'.
                   3319:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3320:                    '</tr><tr>'.
                   3321:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   3322:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3323:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   3324:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3325:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   3326:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3327:                    '</tr>';
                   3328:         $$rowtotal += 2;
                   3329:         if (ref($usertypes) eq 'HASH') {
                   3330:             if (keys(%{$usertypes}) > 0) {
                   3331:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305     raeburn  3332:                                              $numinrow,$othertitle,'cansearch',
                   3333:                                              $rowtotal);
1.277     raeburn  3334:                 $cansrchrow = 1;
1.25      raeburn  3335:             }
1.23      raeburn  3336:         }
1.277     raeburn  3337:         if ($cansrchrow) {
                   3338:             $$rowtotal ++;
                   3339:             $datatable .= '<tr>';
                   3340:         } else {
                   3341:             $datatable .= '<tr class="LC_odd_row">';
1.26      raeburn  3342:         }
1.277     raeburn  3343:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   3344:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   3345:         foreach my $title (@{$titleorder}) {
                   3346:             if (defined($searchtitles->{$title})) {
                   3347:                 my $check = ' ';
                   3348:                 if (ref($settings) eq 'HASH') {
                   3349:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   3350:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   3351:                             $check = ' checked="checked" ';
                   3352:                         }
1.39      raeburn  3353:                     }
1.25      raeburn  3354:                 }
1.277     raeburn  3355:                 $datatable .= '<td class="LC_left_item">'.
                   3356:                               '<span class="LC_nobreak"><label>'.
                   3357:                               '<input type="checkbox" name="searchby" '.
                   3358:                               'value="'.$title.'"'.$check.'/>'.
                   3359:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  3360:             }
                   3361:         }
1.277     raeburn  3362:         $datatable .= '</tr></table></td></tr>';
                   3363:         $$rowtotal ++;
                   3364:         if ($cansrchrow) {
                   3365:             $datatable .= '<tr class="LC_odd_row">';
                   3366:         } else {
                   3367:             $datatable .= '<tr>';
                   3368:         }
                   3369:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   3370:                       '<td class="LC_left_item" colspan="2">'.
                   3371:                       '<span class="LC_nobreak"><label>'.
                   3372:                       '<input type="checkbox" name="searchtypes" '.
                   3373:                       $exacton.' value="exact" />'.&mt('Exact match').
                   3374:                       '</label>&nbsp;'.
                   3375:                       '<label><input type="checkbox" name="searchtypes" '.
                   3376:                       $beginson.' value="begins" />'.&mt('Begins with').
                   3377:                       '</label>&nbsp;'.
                   3378:                       '<label><input type="checkbox" name="searchtypes" '.
                   3379:                       $containson.' value="contains" />'.&mt('Contains').
                   3380:                       '</label></span></td></tr>';
                   3381:         $$rowtotal ++;
1.26      raeburn  3382:     } else {
1.277     raeburn  3383:         my $domsrchon = ' checked="checked" ';
                   3384:         my $domsrchoff = ' ';
                   3385:         my $domlocalon = ' ';
                   3386:         my $domlocaloff = ' checked="checked" ';
                   3387:         if (ref($settings) eq 'HASH') {
                   3388:             if ($settings->{'lclocalonly'} eq '1') {
                   3389:                 $domlocalon = $domlocaloff;
                   3390:                 $domlocaloff = ' ';
                   3391:             }
                   3392:             if ($settings->{'lcavailable'} eq '0') {
                   3393:                 $domsrchoff = $domsrchon;
                   3394:                 $domsrchon = ' ';
                   3395:             }
                   3396:         }
                   3397:         $datatable='<tr class="LC_odd_row">'.
                   3398:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   3399:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3400:                       '<input type="radio" name="dirsrch_domavailable"'.
                   3401:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3402:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   3403:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3404:                       '</tr><tr>'.
                   3405:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   3406:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3407:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   3408:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3409:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   3410:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3411:                       '</tr>';
                   3412:         $$rowtotal += 2;
1.26      raeburn  3413:     }
1.25      raeburn  3414:     return $datatable;
                   3415: }
                   3416: 
1.28      raeburn  3417: sub print_contacts {
1.286     raeburn  3418:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  3419:     my $datatable;
                   3420:     my @contacts = ('adminemail','supportemail');
1.286     raeburn  3421:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340     raeburn  3422:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286     raeburn  3423:     if ($position eq 'top') {
                   3424:         if (ref($settings) eq 'HASH') {
                   3425:             foreach my $item (@contacts) {
                   3426:                 if (exists($settings->{$item})) {
                   3427:                     $to{$item} = $settings->{$item};
                   3428:                 }
                   3429:             }
                   3430:         }
                   3431:     } elsif ($position eq 'middle') {
                   3432:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350     raeburn  3433:                      'updatesmail','idconflictsmail','hostipmail');
1.288     raeburn  3434:         foreach my $type (@mailings) {
                   3435:             $otheremails{$type} = '';
                   3436:         }
1.340     raeburn  3437:     } elsif ($position eq 'lower') {
                   3438:         if (ref($settings) eq 'HASH') {
                   3439:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   3440:                 %lonstatus = %{$settings->{'lonstatus'}};
                   3441:             }
                   3442:         }
1.286     raeburn  3443:     } else {
                   3444:         @mailings = ('helpdeskmail','otherdomsmail');
1.288     raeburn  3445:         foreach my $type (@mailings) {
                   3446:             $otheremails{$type} = '';
                   3447:         }
1.286     raeburn  3448:         $bccemails{'helpdeskmail'} = '';
                   3449:         $bccemails{'otherdomsmail'} = '';
                   3450:         $includestr{'helpdeskmail'} = '';
                   3451:         $includestr{'otherdomsmail'} = '';
                   3452:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   3453:     }
1.28      raeburn  3454:     if (ref($settings) eq 'HASH') {
1.340     raeburn  3455:         unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  3456:             foreach my $type (@mailings) {
                   3457:                 if (exists($settings->{$type})) {
                   3458:                     if (ref($settings->{$type}) eq 'HASH') {
                   3459:                         foreach my $item (@contacts) {
                   3460:                             if ($settings->{$type}{$item}) {
                   3461:                                 $checked{$type}{$item} = ' checked="checked" ';
                   3462:                             }
                   3463:                         }
                   3464:                         $otheremails{$type} = $settings->{$type}{'others'};
                   3465:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3466:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   3467:                             if ($settings->{$type}{'include'} ne '') {
                   3468:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3469:                                 $includestr{$type} = &unescape($includestr{$type});
                   3470:                             }
                   3471:                         }
                   3472:                     }
                   3473:                 } elsif ($type eq 'lonstatusmail') {
                   3474:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3475:                 }
1.28      raeburn  3476:             }
                   3477:         }
1.286     raeburn  3478:         if ($position eq 'bottom') {
                   3479:             foreach my $type (@mailings) {
                   3480:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   3481:                 if ($settings->{$type}{'include'} ne '') {
                   3482:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3483:                     $includestr{$type} = &unescape($includestr{$type});
                   3484:                 }
                   3485:             }
                   3486:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   3487:                 if (ref($fields) eq 'ARRAY') {
                   3488:                     foreach my $field (@{$fields}) {
                   3489:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  3490:                     }
1.286     raeburn  3491:                 }
                   3492:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   3493:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   3494:                 } else {
1.289     raeburn  3495:                     $maxsize = '1.0';
1.286     raeburn  3496:                 }
                   3497:             } else {
                   3498:                 if (ref($fields) eq 'ARRAY') {
                   3499:                     foreach my $field (@{$fields}) {
                   3500:                         $currfield{$field} = 'yes';
1.134     raeburn  3501:                     }
1.28      raeburn  3502:                 }
1.286     raeburn  3503:                 $maxsize = '1.0';
1.28      raeburn  3504:             }
                   3505:         }
                   3506:     } else {
1.286     raeburn  3507:         if ($position eq 'top') {
                   3508:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   3509:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   3510:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   3511:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289     raeburn  3512:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  3513:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   3514:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   3515:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350     raeburn  3516:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286     raeburn  3517:         } elsif ($position eq 'bottom') {
                   3518:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   3519:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   3520:             if (ref($fields) eq 'ARRAY') {
                   3521:                 foreach my $field (@{$fields}) {
                   3522:                     $currfield{$field} = 'yes';
                   3523:                 }
                   3524:             }
                   3525:             $maxsize = '1.0';
                   3526:         }
1.28      raeburn  3527:     }
                   3528:     my ($titles,$short_titles) = &contact_titles();
                   3529:     my $rownum = 0;
                   3530:     my $css_class;
1.286     raeburn  3531:     if ($position eq 'top') {
                   3532:         foreach my $item (@contacts) {
                   3533:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3534:             $datatable .= '<tr'.$css_class.'>'. 
                   3535:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3536:                           '</span></td><td class="LC_right_item">'.
                   3537:                           '<input type="text" name="'.$item.'" value="'.
                   3538:                           $to{$item}.'" /></td></tr>';
                   3539:             $rownum ++;
                   3540:         }
1.315     raeburn  3541:     } elsif ($position eq 'bottom') {
                   3542:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3543:         $datatable .= '<tr'.$css_class.'>'.
                   3544:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   3545:                       &mt('(e-mail, subject, and description always shown)').
                   3546:                       '</td><td class="LC_left_item">';
                   3547:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3548:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3549:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3550:             foreach my $field (@{$fields}) {
                   3551:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3552:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3553:                     $datatable .= ' '.&mt('(logged-in users)');
                   3554:                 }
                   3555:                 $datatable .='</td><td>';
                   3556:                 my $clickaction;
                   3557:                 if ($field eq 'screenshot') {
                   3558:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3559:                 }
                   3560:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3561:                     foreach my $option (@{$possoptions->{$field}}) {
                   3562:                         my $checked;
                   3563:                         if ($currfield{$field} eq $option) {
                   3564:                             $checked = ' checked="checked"';
                   3565:                         }
                   3566:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3567:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3568:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3569:                                       '</label></span>'.('&nbsp;'x2);
                   3570:                     }
                   3571:                 }
                   3572:                 if ($field eq 'screenshot') {
                   3573:                     my $display;
                   3574:                     if ($currfield{$field} eq 'no') {
                   3575:                         $display = ' style="display:none"';
                   3576:                     }
1.334     raeburn  3577:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315     raeburn  3578:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3579:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3580:                 }
                   3581:                 $datatable .= '</td></tr>';
                   3582:             }
                   3583:             $datatable .= '</table>';
                   3584:         }
                   3585:         $datatable .= '</td></tr>'."\n";
                   3586:         $rownum ++;
                   3587:     }
1.340     raeburn  3588:     unless (($position eq 'top') || ($position eq 'lower')) {
1.286     raeburn  3589:         foreach my $type (@mailings) {
                   3590:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3591:             $datatable .= '<tr'.$css_class.'>'.
                   3592:                           '<td><span class="LC_nobreak">'.
                   3593:                           $titles->{$type}.': </span></td>'.
                   3594:                           '<td class="LC_left_item">';
                   3595:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3596:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3597:             }
                   3598:             $datatable .= '<span class="LC_nobreak">';
                   3599:             foreach my $item (@contacts) {
                   3600:                 $datatable .= '<label>'.
                   3601:                               '<input type="checkbox" name="'.$type.'"'.
                   3602:                               $checked{$type}{$item}.
                   3603:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3604:                               '</label>&nbsp;';
                   3605:             }
                   3606:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3607:                           '<input type="text" name="'.$type.'_others" '.
                   3608:                           'value="'.$otheremails{$type}.'"  />';
                   3609:             my %locchecked;
                   3610:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3611:                 foreach my $loc ('s','b') {
                   3612:                     if ($includeloc{$type} eq $loc) {
                   3613:                         $locchecked{$loc} = ' checked="checked"';
                   3614:                         last;
                   3615:                     }
                   3616:                 }
                   3617:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3618:                               '<input type="text" name="'.$type.'_bcc" '.
                   3619:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3620:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3621:                               &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  3622:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286     raeburn  3623:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3624:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3625:                               ('&nbsp;'x2).
                   3626:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3627:                               '</span></fieldset>';
                   3628:             }
                   3629:             $datatable .= '</td></tr>'."\n";
                   3630:             $rownum ++;
                   3631:         }
1.28      raeburn  3632:     }
1.286     raeburn  3633:     if ($position eq 'middle') {
                   3634:         my %choices;
1.340     raeburn  3635:         my $corelink = &core_link_msu();
                   3636:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286     raeburn  3637:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340     raeburn  3638:                                         $corelink);
                   3639:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   3640:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286     raeburn  3641:         my %defaultchecked = ('reporterrors'  => 'on',
1.340     raeburn  3642:                               'reportupdates' => 'on',
                   3643:                               'reportstatus'  => 'on');
1.286     raeburn  3644:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3645:                                                    \%choices,$rownum);
                   3646:         $datatable .= $reports;
1.340     raeburn  3647:     } elsif ($position eq 'lower') {
                   3648:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3649:         my ($threshold,$sysmail,%excluded,%weights);
                   3650:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   3651:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
                   3652:             $threshold = $lonstatus{'threshold'};
                   3653:         } else {
                   3654:             $threshold = $defaults->{'threshold'};
                   3655:         }
                   3656:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
                   3657:             $sysmail = $lonstatus{'sysmail'};
                   3658:         } else {
                   3659:             $sysmail = $defaults->{'sysmail'};
                   3660:         }
                   3661:         if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341     raeburn  3662:             foreach my $type ('E','W','N','U') {
1.340     raeburn  3663:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   3664:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   3665:                 } else {
                   3666:                     $weights{$type} = $defaults->{$type};
                   3667:                 }
                   3668:             }
                   3669:         } else {
1.341     raeburn  3670:             foreach my $type ('E','W','N','U') {
1.340     raeburn  3671:                 $weights{$type} = $defaults->{$type};
                   3672:             }
                   3673:         }
                   3674:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   3675:             if (@{$lonstatus{'excluded'}} > 0) {
                   3676:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   3677:             }
                   3678:         }
                   3679:         $datatable .= '<tr'.$css_class.'>'.
                   3680:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3681:                       $titles->{'errorthreshold'}.
                   3682:                       '</span></td><td class="LC_left_item">'.
                   3683:                       '<input type="text" name="errorthreshold" value="'.
                   3684:                       $threshold.'" size="5" /></td></tr>';
                   3685:         $rownum ++;
                   3686:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3687:         $datatable .= '<tr'.$css_class.'>'.
                   3688:                       '<td class="LC_left_item">'.
                   3689:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   3690:                       '</span></td><td class="LC_left_item"><table><tr>';
1.341     raeburn  3691:         foreach my $type ('E','W','N','U') {
1.340     raeburn  3692:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   3693:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   3694:                           $weights{$type}.'" size="5" /></td>';
                   3695:         }
                   3696:         $datatable .= '</tr></table></tr>';
                   3697:         $rownum ++;
                   3698:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3699:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   3700:                       $titles->{'errorexcluded'}.'</td>'.
                   3701:                       '<td class="LC_left_item"><table>';
                   3702:         my $numinrow = 4;
                   3703:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   3704:         for (my $i=0; $i<@ids; $i++) {
                   3705:             my $rem = $i%($numinrow);
                   3706:             if ($rem == 0) {
                   3707:                 if ($i > 0) {
                   3708:                     $datatable .= '</tr>';
                   3709:                 }
                   3710:                 $datatable .= '<tr>';
                   3711:             }
                   3712:             my $check;
                   3713:             if ($excluded{$ids[$i]}) {
                   3714:                 $check = ' checked="checked" ';
                   3715:             }
                   3716:             $datatable .= '<td class="LC_left_item">'.
                   3717:                           '<span class="LC_nobreak"><label>'.
                   3718:                           '<input type="checkbox" name="errorexcluded" '.
                   3719:                           'value="'.$ids[$i].'"'.$check.' />'.
                   3720:                           $ids[$i].'</label></span></td>';
                   3721:         }
                   3722:         my $colsleft = $numinrow - @ids%($numinrow);
                   3723:         if ($colsleft > 1 ) {
                   3724:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3725:                           '&nbsp;</td>';
                   3726:         } elsif ($colsleft == 1) {
                   3727:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   3728:         }
                   3729:         $datatable .= '</tr></table></td></tr>';
                   3730:         $rownum ++;
                   3731:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3732:         $datatable .= '<tr'.$css_class.'>'.
                   3733:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3734:                       $titles->{'errorsysmail'}.
                   3735:                       '</span></td><td class="LC_left_item">'.
                   3736:                       '<input type="text" name="errorsysmail" value="'.
                   3737:                       $sysmail.'" size="5" /></td></tr>';
                   3738:         $rownum ++;
1.286     raeburn  3739:     } elsif ($position eq 'bottom') {
1.315     raeburn  3740:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3741:         my (@posstypes,%usertypeshash);
                   3742:         if (ref($types) eq 'ARRAY') {
                   3743:             @posstypes = @{$types};
                   3744:         }
                   3745:         if (@posstypes) {
                   3746:             if (ref($usertypes) eq 'HASH') {
                   3747:                 %usertypeshash = %{$usertypes};
                   3748:             }
                   3749:             my @overridden;
                   3750:             my $numinrow = 4;
                   3751:             if (ref($settings) eq 'HASH') {
                   3752:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   3753:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   3754:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   3755:                             push(@overridden,$key);
                   3756:                             foreach my $item (@contacts) {
                   3757:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   3758:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   3759:                                 }
                   3760:                             }
                   3761:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   3762:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   3763:                             $includeloc{'override_'.$key} = '';
                   3764:                             $includestr{'override_'.$key} = '';
                   3765:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   3766:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) = 
                   3767:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   3768:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   3769:                             }
1.286     raeburn  3770:                         }
                   3771:                     }
                   3772:                 }
1.315     raeburn  3773:             }
                   3774:             my $customclass = 'LC_helpdesk_override';
                   3775:             my $optionsprefix = 'LC_options_helpdesk_';
                   3776: 
                   3777:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   3778:  
                   3779:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   3780:                                          $numinrow,$othertitle,'overrides',
                   3781:                                          \$rownum,$onclicktypes,$customclass);
                   3782:             $rownum ++;
                   3783:             $usertypeshash{'default'} = $othertitle;
                   3784:             foreach my $status (@posstypes) {
                   3785:                 my $css_class;
                   3786:                 if ($rownum%2) {
                   3787:                     $css_class = 'LC_odd_row ';
                   3788:                 }
                   3789:                 $css_class .= $customclass;
                   3790:                 my $rowid = $optionsprefix.$status;
                   3791:                 my $hidden = 1;
                   3792:                 my $currstyle = 'display:none';
                   3793:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   3794:                     $currstyle = 'display:table-row';
                   3795:                     $hidden = 0;
                   3796:                 }
                   3797:                 my $key = 'override_'.$status;
                   3798:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   3799:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   3800:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   3801:                                                   \@contacts,$short_titles);
                   3802:                 unless ($hidden) {
                   3803:                     $rownum ++;
1.286     raeburn  3804:                 }
                   3805:             }
1.134     raeburn  3806:         }
1.28      raeburn  3807:     }
1.30      raeburn  3808:     $$rowtotal += $rownum;
1.28      raeburn  3809:     return $datatable;
                   3810: }
                   3811: 
1.340     raeburn  3812: sub core_link_msu {
                   3813:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3814:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   3815: }
                   3816: 
1.315     raeburn  3817: sub overridden_helpdesk {
                   3818:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   3819:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   3820:     my $class = 'LC_left_item';
                   3821:     if ($css_class) {
                   3822:         $css_class = ' class="'.$css_class.'"';
                   3823:     }
                   3824:     if ($rowid) {
                   3825:         $rowid = ' id="'.$rowid.'"';
                   3826:     }
                   3827:     if ($rowstyle) {
                   3828:         $rowstyle = ' style="'.$rowstyle.'"';
                   3829:     }
                   3830:     my ($output,$description);
                   3831:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   3832:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   3833:               "<td>$description</td>\n".
                   3834:               '<td class="'.$class.'" colspan="2">'.
                   3835:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   3836:               '<span class="LC_nobreak">';
                   3837:     if (ref($contacts) eq 'ARRAY') {
                   3838:         foreach my $item (@{$contacts}) {
                   3839:             my $check;
                   3840:             if (ref($checked) eq 'HASH') {
                   3841:                $check = $checked->{$item};
                   3842:             }
                   3843:             my $title;
                   3844:             if (ref($short_titles) eq 'HASH') {
                   3845:                 $title = $short_titles->{$item}; 
                   3846:             }
                   3847:             $output .= '<label>'.
                   3848:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   3849:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   3850:         }
                   3851:     }
                   3852:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3853:                '<input type="text" name="override_'.$type.'_others" '.
                   3854:                'value="'.$otheremails.'"  />';
                   3855:     my %locchecked;
                   3856:     foreach my $loc ('s','b') {
                   3857:         if ($includeloc eq $loc) {
                   3858:             $locchecked{$loc} = ' checked="checked"';
                   3859:             last;
                   3860:         }
                   3861:     }
                   3862:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3863:                '<input type="text" name="override_'.$type.'_bcc" '.
                   3864:                'value="'.$bccemails.'"  /></fieldset>'.
                   3865:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3866:                &mt('Text automatically added to e-mail:').' '.
1.334     raeburn  3867:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315     raeburn  3868:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3869:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3870:                ('&nbsp;'x2).
                   3871:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3872:                '</span></fieldset>'.
                   3873:                '</td></tr>'."\n";
                   3874:     return $output;
                   3875: }
                   3876: 
1.286     raeburn  3877: sub contacts_javascript {
                   3878:     return <<"ENDSCRIPT";
                   3879: 
                   3880: <script type="text/javascript">
                   3881: // <![CDATA[
                   3882: 
                   3883: function screenshotSize(field) {
                   3884:     if (document.getElementById('help_screenshotsize')) {
                   3885:         if (field.value == 'no') {
1.289     raeburn  3886:             document.getElementById('help_screenshotsize').style.display="none";
1.286     raeburn  3887:         } else {
                   3888:             document.getElementById('help_screenshotsize').style.display="";
                   3889:         }
                   3890:     }
                   3891:     return;
                   3892: }
                   3893: 
1.315     raeburn  3894: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   3895:     if (form.elements[checkbox].length != undefined) {
                   3896:         var count = 0;
                   3897:         if (docount) {
                   3898:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   3899:                 if (form.elements[checkbox][i].checked) {
                   3900:                     count ++;
                   3901:                 }
                   3902:             }
                   3903:         }
                   3904:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3905:             var type = form.elements[checkbox][i].value;
                   3906:             if (document.getElementById(prefix+type)) {
                   3907:                 if (form.elements[checkbox][i].checked) {
                   3908:                     document.getElementById(prefix+type).style.display = 'table-row';
                   3909:                     if (count % 2 == 1) {
                   3910:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   3911:                     } else {
                   3912:                         document.getElementById(prefix+type).className = target;
                   3913:                     }
                   3914:                     count ++;
                   3915:                 } else {
                   3916:                     document.getElementById(prefix+type).style.display = 'none';
                   3917:                 }
                   3918:             }
                   3919:         }
                   3920:     }
                   3921:     return;
                   3922: }
                   3923: 
                   3924: 
1.286     raeburn  3925: // ]]>
                   3926: </script>
                   3927: 
                   3928: ENDSCRIPT
                   3929: }
                   3930: 
1.118     jms      3931: sub print_helpsettings {
1.282     raeburn  3932:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3933:     my $confname = $dom.'-domainconfig';
1.285     raeburn  3934:     my $formname = 'display';
1.168     raeburn  3935:     my ($datatable,$itemcount);
1.282     raeburn  3936:     if ($position eq 'top') {
                   3937:         $itemcount = 1;
                   3938:         my (%choices,%defaultchecked,@toggles);
                   3939:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3940:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3941:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3942:         %defaultchecked = ('submitbugs' => 'on');
                   3943:         @toggles = ('submitbugs');
                   3944:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3945:                                                      \%choices,$itemcount);
                   3946:         $$rowtotal ++;
                   3947:     } else {
                   3948:         my $css_class;
                   3949:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  3950:         my (%customroles,%ordered,%current);
1.301     raeburn  3951:         if (ref($settings) eq 'HASH') {
                   3952:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3953:                 %current = %{$settings->{'adhoc'}};
                   3954:             }
1.285     raeburn  3955:         }
                   3956:         my $count = 0;
                   3957:         foreach my $key (sort(keys(%existing))) {
1.282     raeburn  3958:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3959:                 my $rolename = $1;
1.285     raeburn  3960:                 my (%privs,$order);
1.282     raeburn  3961:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3962:                 $customroles{$rolename} = \%privs;
1.285     raeburn  3963:                 if (ref($current{$rolename}) eq 'HASH') {
                   3964:                     $order = $current{$rolename}{'order'};
                   3965:                 }
                   3966:                 if ($order eq '') {
                   3967:                     $order = $count;
                   3968:                 }
                   3969:                 $ordered{$order} = $rolename;
                   3970:                 $count++;
                   3971:             }
                   3972:         }
                   3973:         my $maxnum = scalar(keys(%ordered));
                   3974:         my @roles_by_num = ();
                   3975:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3976:             push(@roles_by_num,$item);
                   3977:         }
                   3978:         my $context = 'domprefs';
                   3979:         my $crstype = 'Course';
                   3980:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  3981:         my @accesstypes = ('all','dh','da','none');
1.285     raeburn  3982:         my ($numstatustypes,@jsarray);
                   3983:         if (ref($types) eq 'ARRAY') {
                   3984:             if (@{$types} > 0) {
                   3985:                 $numstatustypes = scalar(@{$types});
                   3986:                 push(@accesstypes,'status');
                   3987:                 @jsarray = ('bystatus');
1.282     raeburn  3988:             }
                   3989:         }
1.290     raeburn  3990:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  3991:         if (keys(%domhelpdesk)) {
                   3992:             push(@accesstypes,('inc','exc'));
                   3993:             push(@jsarray,('notinc','notexc'));
                   3994:         }
                   3995:         my $hiddenstr = join("','",@jsarray);
1.282     raeburn  3996:         my $context = 'domprefs';
                   3997:         my $crstype = 'Course';
1.285     raeburn  3998:         my $prefix = 'helproles_';
                   3999:         my $add_class = 'LC_hidden';
                   4000:         foreach my $num (@roles_by_num) {
                   4001:             my $role = $ordered{$num};
                   4002:             my ($desc,$access,@statuses);
                   4003:             if (ref($current{$role}) eq 'HASH') {
                   4004:                 $desc = $current{$role}{'desc'};
                   4005:                 $access = $current{$role}{'access'};
                   4006:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4007:                     @statuses = @{$current{$role}{'insttypes'}};
                   4008:                 }
                   4009:             }
                   4010:             if ($desc eq '') {
                   4011:                 $desc = $role;
                   4012:             }
                   4013:             my $identifier = 'custhelp'.$num;
1.282     raeburn  4014:             my %full=();
                   4015:             my %levels= (
                   4016:                          course => {},
                   4017:                          domain => {},
                   4018:                          system => {},
                   4019:                         );
                   4020:             my %levelscurrent=(
                   4021:                                course => {},
                   4022:                                domain => {},
                   4023:                                system => {},
                   4024:                               );
                   4025:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4026:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4027:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285     raeburn  4028:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306     raeburn  4029:             $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285     raeburn  4030:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4031:             for (my $k=0; $k<=$maxnum; $k++) {
                   4032:                 my $vpos = $k+1;
                   4033:                 my $selstr;
                   4034:                 if ($k == $num) {
                   4035:                     $selstr = ' selected="selected" ';
                   4036:                 }
                   4037:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4038:             }
                   4039:             $datatable .= '</select>'.('&nbsp;'x2).
                   4040:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4041:                           '</td>'.
                   4042:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4043:                           &mt('Name shown to users:').
                   4044:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4045:                           '</fieldset>'.
                   4046:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4047:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4048:                           '<fieldset>'.
                   4049:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282     raeburn  4050:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285     raeburn  4051:                                                                    \%levelscurrent,$identifier,
                   4052:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4053:                           '</fieldset></td>';
1.282     raeburn  4054:             $itemcount ++;
                   4055:         }
                   4056:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4057:         my $newcust = 'custhelp'.$count;
                   4058:         my (%privs,%levelscurrent);
                   4059:         my %full=();
                   4060:         my %levels= (
                   4061:                      course => {},
                   4062:                      domain => {},
                   4063:                      system => {},
                   4064:                     );
                   4065:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4066:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285     raeburn  4067:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306     raeburn  4068:         $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285     raeburn  4069:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4070:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4071:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4072:             my $vpos = $k+1;
                   4073:             my $selstr;
                   4074:             if ($k == $maxnum) {
                   4075:                 $selstr = ' selected="selected" ';
                   4076:             }
                   4077:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4078:         }
                   4079:         $datatable .= '</select>&nbsp;'."\n".
1.282     raeburn  4080:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4081:                       '</label></span></td>'.
1.285     raeburn  4082:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4083:                       '<span class="LC_nobreak">'.
                   4084:                       &mt('Internal name:').
                   4085:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4086:                       '</span>'.('&nbsp;'x4).
                   4087:                       '<span class="LC_nobreak">'.
                   4088:                       &mt('Name shown to users:').
                   4089:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4090:                       '</span></fieldset>'.
                   4091:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4092:                                              $usertypes,$types,\%domhelpdesk).
                   4093:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282     raeburn  4094:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4095:                                                                 \@templateroles,$newcust).
                   4096:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4097:                                                                \%levelscurrent,$newcust).
1.334     raeburn  4098:                       '</fieldset>'.
                   4099:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4100:                       '</td></tr>';
1.282     raeburn  4101:         $count ++;
                   4102:         $$rowtotal += $count;
                   4103:     }
1.166     raeburn  4104:     return $datatable;
1.121     raeburn  4105: }
                   4106: 
1.285     raeburn  4107: sub adhocbutton {
                   4108:     my ($prefix,$num,$field,$visibility) = @_;
                   4109:     my %lt = &Apache::lonlocal::texthash(
                   4110:                                           show => 'Show details',
                   4111:                                           hide => 'Hide details',
                   4112:                                         );
                   4113:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4114:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4115:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4116:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4117: }
                   4118: 
                   4119: sub helpsettings_javascript {
                   4120:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4121:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4122:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4123:                                           show => 'Show details',
                   4124:                                           hide => 'Hide details',
                   4125:                                         );
                   4126:     &html_escape(\%html_js_lt);
                   4127:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4128:     return <<"ENDSCRIPT";
                   4129: <script type="text/javascript">
                   4130: // <![CDATA[
                   4131: 
                   4132: function reorderHelpRoles(form,item) {
                   4133:     var changedVal;
                   4134: $jstext
                   4135:     var newpos = 'helproles_${total}_pos';
                   4136:     var maxh = 1 + $total;
                   4137:     var current = new Array();
                   4138:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4139:     if (item == newpos) {
                   4140:         changedVal = newitemVal;
                   4141:     } else {
                   4142:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4143:         current[newitemVal] = newpos;
                   4144:     }
                   4145:     for (var i=0; i<helproles.length; i++) {
                   4146:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4147:         if (elementName != item) {
                   4148:             if (form.elements[elementName]) {
                   4149:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4150:                 current[currVal] = elementName;
                   4151:             }
                   4152:         }
                   4153:     }
                   4154:     var oldVal;
                   4155:     for (var j=0; j<maxh; j++) {
                   4156:         if (current[j] == undefined) {
                   4157:             oldVal = j;
                   4158:         }
                   4159:     }
                   4160:     if (oldVal < changedVal) {
                   4161:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4162:            var elementName = current[k];
                   4163:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4164:         }
                   4165:     } else {
                   4166:         for (var k=changedVal; k<oldVal; k++) {
                   4167:             var elementName = current[k];
                   4168:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4169:         }
                   4170:     }
                   4171:     return;
                   4172: }
                   4173: 
                   4174: function helpdeskAccess(num) {
                   4175:     var curraccess = null;
                   4176:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   4177:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   4178:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   4179:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   4180:             }
                   4181:         }
                   4182:     }
                   4183:     var shown = Array();
                   4184:     var hidden = Array();
                   4185:     if (curraccess == 'none') {
                   4186:         hidden = Array('$hiddenstr');
                   4187:     } else {
                   4188:         if (curraccess == 'status') {
                   4189:             shown = Array('bystatus');
                   4190:             hidden = Array('notinc','notexc');
                   4191:         } else {
                   4192:             if (curraccess == 'exc') {
                   4193:                 shown = Array('notexc');
                   4194:                 hidden = Array('notinc','bystatus');
                   4195:             }
                   4196:             if (curraccess == 'inc') {
                   4197:                 shown = Array('notinc');
                   4198:                 hidden = Array('notexc','bystatus');
                   4199:             }
1.293     raeburn  4200:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285     raeburn  4201:                 hidden = Array('notinc','notexc','bystatus');
                   4202:             }
                   4203:         }
                   4204:     }
                   4205:     if (hidden.length > 0) {
                   4206:         for (var i=0; i<hidden.length; i++) {
                   4207:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   4208:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   4209:             }
                   4210:         }
                   4211:     }
                   4212:     if (shown.length > 0) {
                   4213:         for (var i=0; i<shown.length; i++) {
                   4214:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   4215:                 if (shown[i] == 'privs') {
                   4216:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   4217:                 } else {
                   4218:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   4219:                 }
                   4220:             }
                   4221:         }
                   4222:     }
                   4223:     return;
                   4224: }
                   4225: 
                   4226: function toggleHelpdeskItem(num,field) {
                   4227:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   4228:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289     raeburn  4229:             document.getElementById('helproles_'+num+'_'+field).className =
1.285     raeburn  4230:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   4231:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4232:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   4233:             }
                   4234:         } else {
                   4235:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   4236:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4237:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   4238:             }
                   4239:         }
                   4240:     }
                   4241:     return;
                   4242: }
                   4243: 
                   4244: // ]]>
                   4245: </script>
                   4246: 
                   4247: ENDSCRIPT
                   4248: }
                   4249: 
                   4250: sub helpdeskroles_access {
                   4251:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   4252:         $usertypes,$types,$domhelpdesk) = @_;
                   4253:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   4254:     my %lt = &Apache::lonlocal::texthash(
                   4255:                     'rou'    => 'Role usage',
                   4256:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.292     raeburn  4257:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   4258:                     'dh'     => 'All with domain helpdesk role',
                   4259:                     'da'     => 'All with domain helpdesk assistant role',
1.285     raeburn  4260:                     'none'   => 'None',
                   4261:                     'status' => 'Determined based on institutional status',
                   4262:                     'inc'    => 'Include all, but exclude specific personnel',
                   4263:                     'exc'    => 'Exclude all, but include specific personnel',
                   4264:                   );
                   4265:     my %usecheck = (
                   4266:                      all => ' checked="checked"',
                   4267:                    );
                   4268:     my %displaydiv = (
                   4269:                       status => 'none',
                   4270:                       inc    => 'none',
                   4271:                       exc    => 'none',
                   4272:                       priv   => 'block',
                   4273:                      );
                   4274:     my $output;
                   4275:     if (ref($current) eq 'HASH') {
                   4276:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   4277:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   4278:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   4279:                 delete($usecheck{'all'});
                   4280:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   4281:                     my $access = $1;
                   4282:                     $displaydiv{$access} = 'inline';
                   4283:                 } elsif ($current->{access} eq 'none') {
                   4284:                     $displaydiv{'priv'} = 'none';
                   4285:                 }
                   4286:             }
                   4287:         }
                   4288:     }
                   4289:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   4290:               '<p>'.$lt{'whi'}.'</p>';
                   4291:     foreach my $access (@{$accesstypes}) {
                   4292:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   4293:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   4294:                    $lt{$access}.'</label>';
                   4295:         if ($access eq 'status') {
                   4296:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   4297:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   4298:                                                                  $othertitle,$usertypes,$types).
                   4299:                        '</div>';
                   4300:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   4301:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   4302:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4303:                        '</div>';
                   4304:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   4305:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   4306:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4307:                        '</div>';
                   4308:         }
                   4309:         $output .= '</p>';
                   4310:     }
                   4311:     $output .= '</fieldset>';
                   4312:     return $output;
                   4313: }
                   4314: 
1.121     raeburn  4315: sub radiobutton_prefs {
1.192     raeburn  4316:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257     raeburn  4317:         $additional,$align) = @_;
1.121     raeburn  4318:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   4319:                    (ref($choices) eq 'HASH'));
                   4320: 
1.170     raeburn  4321:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  4322: 
                   4323:     foreach my $item (@{$toggles}) {
                   4324:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      4325:             $checkedon{$item} = ' checked="checked" ';
                   4326:             $checkedoff{$item} = ' ';
1.121     raeburn  4327:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      4328:             $checkedoff{$item} = ' checked="checked" ';
                   4329:             $checkedon{$item} = ' ';
                   4330:         }
                   4331:     }
                   4332:     if (ref($settings) eq 'HASH') {
1.121     raeburn  4333:         foreach my $item (@{$toggles}) {
1.118     jms      4334:             if ($settings->{$item} eq '1') {
                   4335:                 $checkedon{$item} =  ' checked="checked" ';
                   4336:                 $checkedoff{$item} = ' ';
                   4337:             } elsif ($settings->{$item} eq '0') {
                   4338:                 $checkedoff{$item} =  ' checked="checked" ';
                   4339:                 $checkedon{$item} = ' ';
                   4340:             }
                   4341:         }
1.121     raeburn  4342:     }
1.192     raeburn  4343:     if ($onclick) {
                   4344:         $onclick = ' onclick="'.$onclick.'"';
                   4345:     }
1.121     raeburn  4346:     foreach my $item (@{$toggles}) {
1.118     jms      4347:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  4348:         $datatable .=
1.306     raeburn  4349:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192     raeburn  4350:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  4351:             '</span></td>';
                   4352:         if ($align eq 'left') {
                   4353:             $datatable .= '<td class="LC_left_item">';
                   4354:         } else {
                   4355:             $datatable .= '<td class="LC_right_item">';
                   4356:         }
1.289     raeburn  4357:         $datatable .=
1.257     raeburn  4358:             '<span class="LC_nobreak">'.
1.118     jms      4359:             '<label><input type="radio" name="'.
1.192     raeburn  4360:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      4361:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  4362:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   4363:             '</span>'.$additional.
                   4364:             '</td>'.
1.118     jms      4365:             '</tr>';
                   4366:         $itemcount ++;
1.121     raeburn  4367:     }
                   4368:     return ($datatable,$itemcount);
                   4369: }
                   4370: 
1.267     raeburn  4371: sub print_ltitools {
                   4372:     my ($dom,$settings,$rowtotal) = @_;
                   4373:     my $rownum = 0;
                   4374:     my $css_class;
                   4375:     my $itemcount = 1;
                   4376:     my $maxnum = 0;
                   4377:     my %ordered;
                   4378:     if (ref($settings) eq 'HASH') {
                   4379:         foreach my $item (keys(%{$settings})) {
                   4380:             if (ref($settings->{$item}) eq 'HASH') {
                   4381:                 my $num = $settings->{$item}{'order'};
                   4382:                 $ordered{$num} = $item;
                   4383:             }
                   4384:         }
                   4385:     }
                   4386:     my $confname = $dom.'-domainconfig';
                   4387:     my $switchserver = &check_switchserver($dom,$confname);
                   4388:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  4389:     my $datatable;
1.267     raeburn  4390:     my %lt = &ltitools_names();
                   4391:     my @courseroles = ('cc','in','ta','ep','st');
                   4392:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
1.324     raeburn  4393:     my @fields = ('fullname','firstname','lastname','email','roles','user');
1.267     raeburn  4394:     if (keys(%ordered)) {
                   4395:         my @items = sort { $a <=> $b } keys(%ordered);
                   4396:         for (my $i=0; $i<@items; $i++) {
                   4397:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4398:             my $item = $ordered{$items[$i]};
1.323     raeburn  4399:             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
1.267     raeburn  4400:             if (ref($settings->{$item}) eq 'HASH') {
                   4401:                 $title = $settings->{$item}->{'title'};
                   4402:                 $url = $settings->{$item}->{'url'};
                   4403:                 $key = $settings->{$item}->{'key'};
                   4404:                 $secret = $settings->{$item}->{'secret'};
1.322     raeburn  4405:                 $lifetime = $settings->{$item}->{'lifetime'};
1.267     raeburn  4406:                 my $image = $settings->{$item}->{'image'};
                   4407:                 if ($image ne '') {
                   4408:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   4409:                 }
1.323     raeburn  4410:                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   4411:                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   4412:                 } else {
                   4413:                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   4414:                 }
1.267     raeburn  4415:             }
1.319     raeburn  4416:             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
1.267     raeburn  4417:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4418:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   4419:             for (my $k=0; $k<=$maxnum; $k++) {
                   4420:                 my $vpos = $k+1;
                   4421:                 my $selstr;
                   4422:                 if ($k == $i) {
                   4423:                     $selstr = ' selected="selected" ';
                   4424:                 }
                   4425:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4426:             }
                   4427:             $datatable .= '</select>'.('&nbsp;'x2).
                   4428:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   4429:                 &mt('Delete?').'</label></span></td>'.
                   4430:                 '<td colspan="2">'.
                   4431:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  4432:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
1.267     raeburn  4433:                 ('&nbsp;'x2).
                   4434:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   4435:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   4436:                 ('&nbsp;'x2).
                   4437:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   4438:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  4439:                 ('&nbsp;'x2).
                   4440:                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   4441:                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   4442:                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
1.267     raeburn  4443:                 '<br /><br />'.
1.323     raeburn  4444:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
1.267     raeburn  4445:                 ' value="'.$url.'" /></span>'.
                   4446:                 ('&nbsp;'x2).
1.319     raeburn  4447:                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
1.267     raeburn  4448:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   4449:                 ('&nbsp;'x2).
1.322     raeburn  4450:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   4451:                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   4452:                 ('&nbsp;'x2).
1.267     raeburn  4453:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   4454:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   4455:                 '<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>'.
                   4456:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   4457:                 '</fieldset>'.
                   4458:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4459:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   4460:             my %currdisp;
                   4461:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   4462:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   4463:                     $currdisp{'window'} = ' checked="checked"';
1.298     raeburn  4464:                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   4465:                     $currdisp{'tab'} = ' checked="checked"';
1.267     raeburn  4466:                 } else {
                   4467:                     $currdisp{'iframe'} = ' checked="checked"';
                   4468:                 }
                   4469:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   4470:                     $currdisp{'width'} = $1;
                   4471:                 }
                   4472:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   4473:                      $currdisp{'height'} = $1;
                   4474:                 }
1.296     raeburn  4475:                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   4476:                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
1.267     raeburn  4477:             } else {
                   4478:                 $currdisp{'iframe'} = ' checked="checked"';
                   4479:             }
1.298     raeburn  4480:             foreach my $disp ('iframe','tab','window') {
1.267     raeburn  4481:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   4482:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4483:             }
                   4484:             $datatable .= ('&nbsp;'x4);
                   4485:             foreach my $dimen ('width','height') {
                   4486:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4487:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   4488:                               ('&nbsp;'x2);
                   4489:             }
1.334     raeburn  4490:             $datatable .= '</span><br />'.
1.296     raeburn  4491:                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  4492:                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
1.296     raeburn  4493:                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   4494:                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   4495:                           '</textarea></div><div style=""></div><br />';
1.319     raeburn  4496:             my %units = (
                   4497:                           'passback' => 'days',
                   4498:                           'roster'   => 'seconds',
                   4499:                         );
1.267     raeburn  4500:             foreach my $extra ('passback','roster') {
1.319     raeburn  4501:                 my $validsty = 'none';
                   4502:                 my $currvalid;
1.267     raeburn  4503:                 my $checkedon = '';
                   4504:                 my $checkedoff = ' checked="checked"';
                   4505:                 if ($settings->{$item}->{$extra}) {
                   4506:                     $checkedon = $checkedoff;
                   4507:                     $checkedoff = '';
1.319     raeburn  4508:                     $validsty = 'inline-block';
                   4509:                     if ($settings->{$item}->{$extra.'valid'} =~ /^\d+\.?\d*$/) {
                   4510:                         $currvalid = $settings->{$item}->{$extra.'valid'};
                   4511:                     }
                   4512:                 }
                   4513:                 my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','$i'".');"';
                   4514:                 $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   4515:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.$onclick.' />'.
                   4516:                               &mt('No').'</label>'.('&nbsp;'x2).
                   4517:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.$onclick.' />'.
                   4518:                               &mt('Yes').'</label></span></div>'.
                   4519:                               '<div class="LC_floatleft" style="display:'.$validsty.';" id="ltitools_'.$extra.'time_'.$i.'">'.
                   4520:                               '<span class="LC_nobreak">'.
                   4521:                               &mt("at least [_1] $units{$extra} after launch",
                   4522:                                   '<input type="text" name="ltitools_'.$extra.'valid_'.$i.'" value="'.$currvalid.'" />').
                   4523:                               '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  4524:             }
1.319     raeburn  4525:             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
1.267     raeburn  4526:             if ($imgsrc) {
                   4527:                 $datatable .= $imgsrc.
                   4528:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   4529:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   4530:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   4531:             } else {
                   4532:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4533:             }
                   4534:             if ($switchserver) {
                   4535:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4536:             } else {
                   4537:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   4538:             }
                   4539:             $datatable .= '</span></fieldset>';
1.324     raeburn  4540:             my (%checkedfields,%rolemaps,$userincdom);
1.267     raeburn  4541:             if (ref($settings->{$item}) eq 'HASH') {
                   4542:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   4543:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   4544:                 }
1.324     raeburn  4545:                 $userincdom = $settings->{$item}->{'incdom'};
1.267     raeburn  4546:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   4547:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   4548:                     $checkedfields{'roles'} = 1;
                   4549:                 }
                   4550:             }
                   4551:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4552:                           '<span class="LC_nobreak">';
1.324     raeburn  4553:             my $userfieldstyle = 'display:none;';
                   4554:             my $seluserdom = '';
                   4555:             my $unseluserdom = ' selected="selected"';
1.267     raeburn  4556:             foreach my $field (@fields) {
1.324     raeburn  4557:                 my ($checked,$onclick,$id,$spacer);
1.267     raeburn  4558:                 if ($checkedfields{$field}) {
                   4559:                     $checked = ' checked="checked"';
                   4560:                 }
1.324     raeburn  4561:                 if ($field eq 'user') {
                   4562:                     $id = ' id="ltitools_user_field_'.$i.'"';
                   4563:                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   4564:                     if ($checked) {
                   4565:                         $userfieldstyle = 'display:inline-block';
                   4566:                         if ($userincdom) {
                   4567:                             $seluserdom = $unseluserdom;
                   4568:                             $unseluserdom = '';
                   4569:                         }
                   4570:                     }
                   4571:                 } else {
                   4572:                     $spacer = ('&nbsp;' x2);
                   4573:                 }
1.267     raeburn  4574:                 $datatable .= '<label>'.
1.324     raeburn  4575:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   4576:                               $lt{$field}.'</label>'.$spacer;
1.267     raeburn  4577:             }
1.324     raeburn  4578:             $datatable .= '</span>';
                   4579:             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   4580:                           '<span class="LC_nobreak"> : '.
                   4581:                           '<select name="ltitools_userincdom_'.$i.'">'.
                   4582:                           '<option value="">'.&mt('Select').'</option>'.
                   4583:                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   4584:                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   4585:                           '</select></span></div>';
                   4586:             $datatable .= '</fieldset>'.
1.267     raeburn  4587:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   4588:             foreach my $role (@courseroles) {
                   4589:                 my ($selected,$selectnone);
                   4590:                 if (!$rolemaps{$role}) {
                   4591:                     $selectnone = ' selected="selected"';
                   4592:                 }
1.306     raeburn  4593:                 $datatable .= '<td style="text-align: center">'. 
1.267     raeburn  4594:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4595:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   4596:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   4597:                 foreach my $ltirole (@ltiroles) {
                   4598:                     unless ($selectnone) {
                   4599:                         if ($rolemaps{$role} eq $ltirole) {
                   4600:                             $selected = ' selected="selected"';
                   4601:                         } else {
                   4602:                             $selected = '';
                   4603:                         }
                   4604:                     }
                   4605:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   4606:                 }
                   4607:                 $datatable .= '</select></td>';
                   4608:             }
1.273     raeburn  4609:             $datatable .= '</tr></table></fieldset>';
                   4610:             my %courseconfig;
                   4611:             if (ref($settings->{$item}) eq 'HASH') {
                   4612:                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   4613:                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   4614:                 }
                   4615:             }
                   4616:             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  4617:             foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  4618:                 my $checked;
                   4619:                 if ($courseconfig{$item}) {
                   4620:                     $checked = ' checked="checked"';
                   4621:                 }
                   4622:                 $datatable .= '<label>'.
                   4623:                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   4624:                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   4625:             }
                   4626:             $datatable .= '</span></fieldset>'.
1.267     raeburn  4627:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4628:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   4629:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   4630:                 my %custom = %{$settings->{$item}->{'custom'}};
                   4631:                 if (keys(%custom) > 0) {
                   4632:                     foreach my $key (sort(keys(%custom))) {
                   4633:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4634:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   4635:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   4636:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   4637:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   4638:                     }
                   4639:                 }
                   4640:             }
                   4641:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4642:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   4643:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   4644:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   4645:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   4646:             $itemcount ++;
                   4647:         }
                   4648:     }
                   4649:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.319     raeburn  4650:     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
1.267     raeburn  4651:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4652:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   4653:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   4654:     for (my $k=0; $k<$maxnum+1; $k++) {
                   4655:         my $vpos = $k+1;
                   4656:         my $selstr;
                   4657:         if ($k == $maxnum) {
                   4658:             $selstr = ' selected="selected" ';
                   4659:         }
                   4660:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4661:     }
                   4662:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  4663:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.267     raeburn  4664:                   '<td colspan="2">'.
                   4665:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
1.323     raeburn  4666:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
1.267     raeburn  4667:                   ('&nbsp;'x2).
                   4668:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   4669:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4670:                   ('&nbsp;'x2).
                   4671:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   4672:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
1.323     raeburn  4673:                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   4674:                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   4675:                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
1.267     raeburn  4676:                   '<br />'.
1.323     raeburn  4677:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
1.267     raeburn  4678:                   ('&nbsp;'x2).
                   4679:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   4680:                   ('&nbsp;'x2).
1.322     raeburn  4681:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   4682:                   ('&nbsp;'x2).
1.267     raeburn  4683:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   4684:                   '<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".
                   4685:                   '</fieldset>'.
                   4686:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4687:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   4688:     my %defaultdisp;
                   4689:     $defaultdisp{'iframe'} = ' checked="checked"';
1.298     raeburn  4690:     foreach my $disp ('iframe','tab','window') {
1.267     raeburn  4691:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   4692:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4693:     }
                   4694:     $datatable .= ('&nbsp;'x4);
                   4695:     foreach my $dimen ('width','height') {
                   4696:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4697:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   4698:                       ('&nbsp;'x2);
                   4699:     }
1.334     raeburn  4700:     $datatable .= '</span><br />'.
1.296     raeburn  4701:                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
1.334     raeburn  4702:                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
1.296     raeburn  4703:                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
1.334     raeburn  4704:                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
1.296     raeburn  4705:                   '</div><div style=""></div><br />';
1.319     raeburn  4706:     my %units = (
                   4707:                   'passback' => 'days',
                   4708:                   'roster'   => 'seconds',
                   4709:                 );
                   4710:     my %defaulttimes = (
                   4711:                      'passback' => '7',
1.322     raeburn  4712:                      'roster'   => '300',
1.319     raeburn  4713:                    );
1.267     raeburn  4714:     foreach my $extra ('passback','roster') {
1.319     raeburn  4715:         my $onclick = ' onclick="toggleLTITools(this.form,'."'$extra','add'".');"';
                   4716:         $datatable .= '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{$extra}.'&nbsp;'.
                   4717:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="0" checked="checked"'.$onclick.' />'.
                   4718:                       &mt('No').'</label></span>'.('&nbsp;'x2).'<span class="LC_nobreak">'.
                   4719:                       '<label><input type="radio" name="ltitools_'.$extra.'_add" value="1"'.$onclick.' />'.
                   4720:                       &mt('Yes').'</label></span></div>'.
                   4721:                       '<div class="LC_floatleft" style="display:none;" id="ltitools_'.$extra.'time_add">'.
                   4722:                       '<span class="LC_nobreak">'.
                   4723:                       &mt("at least [_1] $units{$extra} after launch",
                   4724:                           '<input type="text" name="ltitools_'.$extra.'valid_add" value="'.$defaulttimes{$extra}.'" />').
                   4725:                       '</span></div><div style="padding:0;clear:both;margin:0;border:0"></div>';
1.267     raeburn  4726:     }
1.319     raeburn  4727:     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
1.267     raeburn  4728:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4729:     if ($switchserver) {
                   4730:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4731:     } else {
                   4732:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   4733:     }
                   4734:     $datatable .= '</span></fieldset>'.
                   4735:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4736:                   '<span class="LC_nobreak">';
                   4737:     foreach my $field (@fields) {
1.324     raeburn  4738:         my ($id,$onclick,$spacer);
                   4739:         if ($field eq 'user') {
                   4740:             $id = ' id="ltitools_user_field_add"';
                   4741:             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   4742:         } else {
                   4743:             $spacer = ('&nbsp;' x2);
                   4744:         }
1.267     raeburn  4745:         $datatable .= '<label>'.
1.324     raeburn  4746:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   4747:                       $lt{$field}.'</label>'.$spacer;
1.267     raeburn  4748:     }
1.324     raeburn  4749:     $datatable .= '</span>'.
                   4750:                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   4751:                   '<span class="LC_nobreak"> : '.
                   4752:                   '<select name="ltitools_userincdom_add">'.
                   4753:                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   4754:                   '<option value="0">'.&mt('username').'</option>'.
                   4755:                   '<option value="1">'.&mt('username:domain').'</option>'.
                   4756:                   '</select></span></div></fieldset>';
                   4757:     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
1.267     raeburn  4758:     foreach my $role (@courseroles) {
                   4759:         my ($checked,$checkednone);
1.306     raeburn  4760:         $datatable .= '<td style="text-align: center">'.
1.267     raeburn  4761:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4762:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   4763:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   4764:         foreach my $ltirole (@ltiroles) {
                   4765:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   4766:         }
                   4767:         $datatable .= '</select></td>';
                   4768:     }
                   4769:     $datatable .= '</tr></table></fieldset>'.
1.273     raeburn  4770:                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
1.318     raeburn  4771:     foreach my $item ('label','title','target','linktext','explanation','append') {
1.296     raeburn  4772:         $datatable .= '<label>'.
                   4773:                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   4774:                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
1.273     raeburn  4775:     }
                   4776:     $datatable .= '</span></fieldset>'.
1.267     raeburn  4777:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4778:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   4779:                   '<tr><td><span class="LC_nobreak">'.
                   4780:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   4781:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   4782:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
1.334     raeburn  4783:                   '</table></fieldset>'."\n".
1.267     raeburn  4784:                   '</td>'."\n".
                   4785:                   '</tr>'."\n";
                   4786:     $itemcount ++;
                   4787:     return $datatable;
                   4788: }
                   4789: 
                   4790: sub ltitools_names {
                   4791:     my %lt = &Apache::lonlocal::texthash(
1.296     raeburn  4792:                                           'title'          => 'Title',
                   4793:                                           'version'        => 'Version',
                   4794:                                           'msgtype'        => 'Message Type',
1.323     raeburn  4795:                                           'sigmethod'      => 'Signature Method',
1.296     raeburn  4796:                                           'url'            => 'URL',
                   4797:                                           'key'            => 'Key',
1.322     raeburn  4798:                                           'lifetime'       => 'Nonce lifetime (s)',
1.296     raeburn  4799:                                           'secret'         => 'Secret',
                   4800:                                           'icon'           => 'Icon',   
1.324     raeburn  4801:                                           'user'           => 'User',
1.296     raeburn  4802:                                           'fullname'       => 'Full Name',
                   4803:                                           'firstname'      => 'First Name',
                   4804:                                           'lastname'       => 'Last Name',
                   4805:                                           'email'          => 'E-mail',
                   4806:                                           'roles'          => 'Role',
1.298     raeburn  4807:                                           'window'         => 'Window',
                   4808:                                           'tab'            => 'Tab',
1.296     raeburn  4809:                                           'iframe'         => 'iFrame',
                   4810:                                           'height'         => 'Height',
                   4811:                                           'width'          => 'Width',
                   4812:                                           'linktext'       => 'Default Link Text',
                   4813:                                           'explanation'    => 'Default Explanation',
                   4814:                                           'passback'       => 'Tool can return grades:',
                   4815:                                           'roster'         => 'Tool can retrieve roster:',
                   4816:                                           'crstarget'      => 'Display target',
                   4817:                                           'crslabel'       => 'Course label',
                   4818:                                           'crstitle'       => 'Course title', 
                   4819:                                           'crslinktext'    => 'Link Text',
                   4820:                                           'crsexplanation' => 'Explanation',
1.318     raeburn  4821:                                           'crsappend'      => 'Provider URL',
1.267     raeburn  4822:                                         );
                   4823:     return %lt;
                   4824: }
                   4825: 
1.320     raeburn  4826: sub print_lti {
                   4827:     my ($dom,$settings,$rowtotal) = @_;
                   4828:     my $itemcount = 1;
                   4829:     my $maxnum = 0;
                   4830:     my $css_class;
                   4831:     my %ordered;
                   4832:     if (ref($settings) eq 'HASH') {
                   4833:         foreach my $item (keys(%{$settings})) {
                   4834:             if (ref($settings->{$item}) eq 'HASH') {
                   4835:                 my $num = $settings->{$item}{'order'};
                   4836:                 $ordered{$num} = $item;
                   4837:             }
                   4838:         }
                   4839:     }
                   4840:     my $maxnum = scalar(keys(%ordered));
1.334     raeburn  4841:     my $datatable;
1.320     raeburn  4842:     my %lt = &lti_names();
                   4843:     if (keys(%ordered)) {
                   4844:         my @items = sort { $a <=> $b } keys(%ordered);
                   4845:         for (my $i=0; $i<@items; $i++) {
                   4846:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4847:             my $item = $ordered{$items[$i]};
1.345     raeburn  4848:             my ($key,$secret,$lifetime,$consumer,$requser,$current);
1.320     raeburn  4849:             if (ref($settings->{$item}) eq 'HASH') {
                   4850:                 $key = $settings->{$item}->{'key'};
                   4851:                 $secret = $settings->{$item}->{'secret'};
                   4852:                 $lifetime = $settings->{$item}->{'lifetime'};
                   4853:                 $consumer = $settings->{$item}->{'consumer'};
1.345     raeburn  4854:                 $requser = $settings->{$item}->{'requser'};
1.320     raeburn  4855:                 $current = $settings->{$item};
                   4856:             }
1.345     raeburn  4857:             my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
                   4858:             my %checkedrequser = (
                   4859:                                    yes => ' checked="checked"',
                   4860:                                    no  => '',
                   4861:                                  );
                   4862:             if (!$requser) {
                   4863:                 $checkedrequser{'no'} = $checkedrequser{'yes'};
                   4864:                 $checkedrequser{'yes'} = '';
1.352     raeburn  4865:             }
1.320     raeburn  4866:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
                   4867:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4868:                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
                   4869:             for (my $k=0; $k<=$maxnum; $k++) {
                   4870:                 my $vpos = $k+1;
                   4871:                 my $selstr;
                   4872:                 if ($k == $i) {
                   4873:                     $selstr = ' selected="selected" ';
                   4874:                 }
                   4875:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4876:             }
                   4877:             $datatable .= '</select>'.('&nbsp;'x2).
                   4878:                 '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
                   4879:                 &mt('Delete?').'</label></span></td>'.
                   4880:                 '<td colspan="2">'.
                   4881:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4882:                 '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  4883:                 ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
1.320     raeburn  4884:                 ('&nbsp;'x2).
                   4885:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                   4886:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   4887:                 ('&nbsp;'x2).
                   4888:                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.345     raeburn  4889:                 'value="'.$lifetime.'" size="3" /></span>'.
                   4890:                 ('&nbsp;'x2).
                   4891:                  '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   4892:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                   4893:                  '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  4894:                 '<br /><br />'.
                   4895:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   4896:                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
                   4897:                 ('&nbsp;'x2).
                   4898:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   4899:                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                   4900:                 '<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>'.
                   4901:                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
1.325     raeburn  4902:                 '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
1.320     raeburn  4903:             $itemcount ++;
                   4904:         }
                   4905:     }
                   4906:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4907:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
                   4908:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4909:                   '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
                   4910:                   '<select name="lti_pos_add"'.$chgstr.'>';
                   4911:     for (my $k=0; $k<$maxnum+1; $k++) {
                   4912:         my $vpos = $k+1;
                   4913:         my $selstr;
                   4914:         if ($k == $maxnum) {
                   4915:             $selstr = ' selected="selected" ';
                   4916:         }
                   4917:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4918:     }
                   4919:     $datatable .= '</select>&nbsp;'."\n".
1.334     raeburn  4920:                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1.320     raeburn  4921:                   '<td colspan="2">'.
                   4922:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4923:                   '<span class="LC_nobreak">'.$lt{'consumer'}.
1.345     raeburn  4924:                   ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
1.320     raeburn  4925:                   ('&nbsp;'x2).
                   4926:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   4927:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4928:                   ('&nbsp;'x2).
1.345     raeburn  4929:                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                   4930:                   ('&nbsp;'x2).
                   4931:                   '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                   4932:                   '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                   4933:                   '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
1.320     raeburn  4934:                   '<br /><br />'.
                   4935:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   4936:                   ('&nbsp;'x2).
                   4937:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   4938:                   '<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  4939:                   '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
1.320     raeburn  4940:                   '</td>'."\n".
                   4941:                   '</tr>'."\n";
                   4942:     $$rowtotal ++;
                   4943:     return $datatable;;
                   4944: }
                   4945: 
                   4946: sub lti_names {
                   4947:     my %lt = &Apache::lonlocal::texthash(
                   4948:                                           'version'   => 'LTI Version',
                   4949:                                           'url'       => 'URL',
                   4950:                                           'key'       => 'Key',
1.322     raeburn  4951:                                           'lifetime'  => 'Nonce lifetime (s)',
1.345     raeburn  4952:                                           'consumer'  => 'Consumer',
1.320     raeburn  4953:                                           'secret'    => 'Secret',
1.345     raeburn  4954:                                           'requser'   => "User's identity sent",
1.320     raeburn  4955:                                           'email'     => 'Email address',
                   4956:                                           'sourcedid' => 'User ID',
                   4957:                                           'other'     => 'Other',
                   4958:                                           'passback'  => 'Can return grades to Consumer:',
                   4959:                                           'roster'    => 'Can retrieve roster from Consumer:',
1.326     raeburn  4960:                                           'topmenu'   => 'Display LON-CAPA page header',
1.345     raeburn  4961:                                           'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320     raeburn  4962:                                         );
                   4963:     return %lt;
                   4964: }
                   4965: 
                   4966: sub lti_options {
1.325     raeburn  4967:     my ($num,$current,$itemcount,%lt) = @_;
1.363     raeburn  4968:     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320     raeburn  4969:     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
                   4970:     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
                   4971:     $checked{'makecrs'}{'N'} = '  checked="checked"';
                   4972:     $checked{'mapcrstype'} = {};
                   4973:     $checked{'makeuser'} = {};
                   4974:     $checked{'selfenroll'} = {};
                   4975:     $checked{'crssec'} = {};
                   4976:     $checked{'crssecsrc'} = {};
1.325     raeburn  4977:     $checked{'lcauth'} = {};
1.326     raeburn  4978:     $checked{'menuitem'} = {};
1.325     raeburn  4979:     if ($num eq 'add') {
                   4980:         $checked{'lcauth'}{'lti'} = ' checked="checked"';
                   4981:     }
1.320     raeburn  4982:     my $userfieldsty = 'none';
                   4983:     my $crsfieldsty = 'none';
                   4984:     my $crssecfieldsty = 'none';
                   4985:     my $secsrcfieldsty = 'none';
1.363     raeburn  4986:     my $callbacksty = 'none';
1.337     raeburn  4987:     my $passbacksty = 'none';
1.345     raeburn  4988:     my $optionsty = 'block';
1.325     raeburn  4989:     my $lcauthparm;
                   4990:     my $lcauthparmstyle = 'display:none';
                   4991:     my $lcauthparmtext;
1.326     raeburn  4992:     my $menusty;
1.325     raeburn  4993:     my $numinrow = 4;
1.326     raeburn  4994:     my %menutitles = &ltimenu_titles();
1.320     raeburn  4995: 
                   4996:     if (ref($current) eq 'HASH') {
1.345     raeburn  4997:         if (!$current->{'requser'}) {
                   4998:             $optionsty = 'none';
                   4999:         }
1.320     raeburn  5000:         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
                   5001:             $checked{'mapuser'}{'sourcedid'} = '';
                   5002:             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
                   5003:                 $checked{'mapuser'}{'email'} = ' checked="checked"'; 
                   5004:             } else {
                   5005:                 $checked{'mapuser'}{'other'} = ' checked="checked"';
                   5006:                 $userfield = $current->{'mapuser'};
                   5007:                 $userfieldsty = 'inline-block';
                   5008:             }
                   5009:         }
                   5010:         if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
                   5011:             $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
                   5012:             if ($current->{'mapcrs'} eq 'context_id') {
                   5013:                 $checked{'mapcrs'}{'context_id'} = ' checked="checked"'; 
                   5014:             } else {
                   5015:                 $checked{'mapcrs'}{'other'} = ' checked="checked"';
                   5016:                 $cidfield = $current->{'mapcrs'};
                   5017:                 $crsfieldsty = 'inline-block';
                   5018:             }
                   5019:         }
                   5020:         if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
                   5021:             foreach my $type (@{$current->{'mapcrstype'}}) {
                   5022:                 $checked{'mapcrstype'}{$type} = ' checked="checked"';
                   5023:             }
                   5024:         }
1.345     raeburn  5025:         if ($current->{'makecrs'}) {
1.320     raeburn  5026:             $checked{'makecrs'}{'Y'} = '  checked="checked"';
1.326     raeburn  5027:         }
1.320     raeburn  5028:         if (ref($current->{'makeuser'}) eq 'ARRAY') {
                   5029:             foreach my $role (@{$current->{'makeuser'}}) {
                   5030:                 $checked{'makeuser'}{$role} = ' checked="checked"';
                   5031:             }
                   5032:         }
1.325     raeburn  5033:         if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
                   5034:             $checked{'lcauth'}{$1} = ' checked="checked"';
                   5035:             unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   5036:                 $lcauthparm = $current->{'lcauthparm'};
                   5037:                 $lcauthparmstyle = 'display:table-row'; 
                   5038:                 if ($current->{'lcauth'} eq 'localauth') {
                   5039:                     $lcauthparmtext = &mt('Local auth argument');
                   5040:                 } else {
                   5041:                     $lcauthparmtext = &mt('Kerberos domain');
                   5042:                 }
                   5043:             }
                   5044:         }
1.320     raeburn  5045:         if (ref($current->{'selfenroll'}) eq 'ARRAY') {
                   5046:             foreach my $role (@{$current->{'selfenroll'}}) {
                   5047:                 $checked{'selfenroll'}{$role} = ' checked="checked"';
                   5048:             }
                   5049:         }
                   5050:         if (ref($current->{'maproles'}) eq 'HASH') {
                   5051:             %rolemaps = %{$current->{'maproles'}};
                   5052:         }
                   5053:         if ($current->{'section'} ne '') {
                   5054:             $checked{'crssec'}{'Y'} = '  checked="checked"'; 
                   5055:             $crssecfieldsty = 'inline-block';
                   5056:             if ($current->{'section'} eq 'course_section_sourcedid') {
                   5057:                 $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
                   5058:             } else {
                   5059:                 $checked{'crssecsrc'}{'other'} = ' checked="checked"';
                   5060:                 $crssecsrc = $current->{'section'};
                   5061:                 $secsrcfieldsty = 'inline-block';
                   5062:             }
                   5063:         } else {
                   5064:             $checked{'crssec'}{'N'} = ' checked="checked"';
                   5065:         }
1.363     raeburn  5066:         if ($current->{'callback'} ne '') {
                   5067:             $callback = $current->{'callback'};
                   5068:             $checked{'callback'}{'Y'} = ' checked="checked"';
                   5069:             $callbacksty = 'inline-block';
                   5070:         } else {
                   5071:             $checked{'callback'}{'N'} = ' checked="checked"';
                   5072:         }
1.326     raeburn  5073:         if ($current->{'topmenu'}) {
                   5074:             $checked{'topmenu'}{'Y'} = ' checked="checked"';
                   5075:         } else {
                   5076:             $checked{'topmenu'}{'N'} = ' checked="checked"';
                   5077:         }
                   5078:         if ($current->{'inlinemenu'}) {
                   5079:             $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
                   5080:         } else {
                   5081:             $checked{'inlinemenu'}{'N'} = ' checked="checked"';
                   5082:         }
                   5083:         if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
                   5084:             $menusty = 'inline-block';
                   5085:             if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   5086:                 foreach my $item (@{$current->{'lcmenu'}}) {
                   5087:                     if (exists($menutitles{$item})) {
                   5088:                         $checked{'menuitem'}{$item} = ' checked="checked"';
                   5089:                     }
                   5090:                 }
                   5091:             }
                   5092:         } else {
                   5093:             $menusty = 'none';
                   5094:         }
1.320     raeburn  5095:     } else {
                   5096:         $checked{'makecrs'}{'N'} = ' checked="checked"';
                   5097:         $checked{'crssec'}{'N'} = ' checked="checked"';
1.363     raeburn  5098:         $checked{'callback'}{'N'} = ' checked="checked"';
1.326     raeburn  5099:         $checked{'topmenu'}{'N'} = ' checked="checked"';
                   5100:         $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
                   5101:         $checked{'menuitem'}{'grades'} = ' checked="checked"';
                   5102:         $menusty = 'inline-block'; 
1.320     raeburn  5103:     }
1.325     raeburn  5104:     my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320     raeburn  5105:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   5106:                                official   => 'Official',
                   5107:                                unofficial => 'Unofficial',
                   5108:                                community  => 'Community',
                   5109:                                textbook   => 'Textbook',
                   5110:                                placement  => 'Placement Test',
1.325     raeburn  5111:                                lti        => 'LTI Provider',
1.320     raeburn  5112:     );
1.325     raeburn  5113:     my @authtypes = ('internal','krb4','krb5','localauth');
                   5114:     my %shortauth = (
                   5115:                      internal => 'int',
                   5116:                      krb4 => 'krb4',
                   5117:                      krb5 => 'krb5',
                   5118:                      localauth  => 'loc'
                   5119:                     );
                   5120:     my %authnames = &authtype_names();
1.320     raeburn  5121:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   5122:     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
                   5123:     my @courseroles = ('cc','in','ta','ep','st');
                   5124:     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
                   5125:     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
                   5126:     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363     raeburn  5127:     my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320     raeburn  5128:     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325     raeburn  5129:     my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326     raeburn  5130:     my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.345     raeburn  5131:     my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320     raeburn  5132:                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
                   5133:     foreach my $option ('sourcedid','email','other') {
                   5134:         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
                   5135:                    $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
                   5136:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   5137:     }
                   5138:     $output .= '</span></div>'.
                   5139:                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                   5140:                '<input type="text" name="lti_customuser_'.$num.'" '.
                   5141:                'value="'.$userfield.'" /></div></fieldset>'. 
1.345     raeburn  5142:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
1.320     raeburn  5143:     foreach my $ltirole (@lticourseroles) {
                   5144:         my ($selected,$selectnone);
                   5145:         if ($rolemaps{$ltirole} eq '') {
                   5146:             $selectnone = ' selected="selected"';
                   5147:         }
                   5148:         $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
                   5149:                    '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
                   5150:                    '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5151:         foreach my $role (@courseroles) {
                   5152:             unless ($selectnone) {
                   5153:                 if ($rolemaps{$ltirole} eq $role) {
                   5154:                     $selected = ' selected="selected"';
                   5155:                 } else {
                   5156:                     $selected = '';
                   5157:                 }
                   5158:             }
                   5159:             $output .= '<option value="'.$role.'"'.$selected.'>'.
                   5160:                        &Apache::lonnet::plaintext($role,'Course').
                   5161:                        '</option>';
                   5162:         }
                   5163:         $output .= '</select></td>';
                   5164:     }
                   5165:     $output .= '</tr></table></fieldset>'.
1.345     raeburn  5166:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320     raeburn  5167:     foreach my $ltirole (@ltiroles) {
                   5168:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                   5169:                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
                   5170:     }
                   5171:     $output .= '</fieldset>'.
1.345     raeburn  5172:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325     raeburn  5173:                '<table>'.
                   5174:                &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                   5175:                '</table>'.
                   5176:                '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                   5177:                '<td class="LC_left_item">';
                   5178:     foreach my $auth ('lti',@authtypes) {
                   5179:         my $authtext;
                   5180:         if ($auth eq 'lti') {
                   5181:             $authtext = &mt('None');
                   5182:         } else {
                   5183:             $authtext = $authnames{$shortauth{$auth}};
                   5184:         }
                   5185:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                   5186:                    '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                   5187:                    $authtext.'</label></span> &nbsp;';
                   5188:     }
                   5189:     $output .= '</td></tr>'.
                   5190:                '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                   5191:                '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                   5192:                '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                   5193:                '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                   5194:                '</table></fieldset>'.
1.345     raeburn  5195:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320     raeburn  5196:                '<div class="LC_floatleft"><span class="LC_nobreak">'.
                   5197:                &mt('Unique course identifier').':&nbsp;';
                   5198:     foreach my $option ('course_offering_sourcedid','context_id','other') {
                   5199:         $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
                   5200:                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                   5201:                    ($option eq 'other' ? '' : ('&nbsp;'x2) );
                   5202:     }
1.334     raeburn  5203:     $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320     raeburn  5204:                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                   5205:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   5206:                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
                   5207:     foreach my $type (@coursetypes) {
                   5208:         $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
                   5209:                    $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
                   5210:                    ('&nbsp;'x2);
                   5211:     }
                   5212:     $output .= '</span></fieldset>'.
1.345     raeburn  5213:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320     raeburn  5214:                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                   5215:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                   5216:                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5217:                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                   5218:                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                   5219:                '</fieldset>'.
1.345     raeburn  5220:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320     raeburn  5221:     foreach my $lticrsrole (@lticourseroles) {
                   5222:         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                   5223:                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
                   5224:     }
                   5225:     $output .= '</fieldset>'.
1.345     raeburn  5226:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
1.320     raeburn  5227:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                   5228:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                   5229:                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5230:                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334     raeburn  5231:                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320     raeburn  5232:                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                   5233:                '<span class="LC_nobreak">'.&mt('From').':<label>'.
                   5234:                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
                   5235:                $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
                   5236:                &mt('Standard field').'</label>'.('&nbsp;'x2).
                   5237:                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                   5238:                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334     raeburn  5239:                '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320     raeburn  5240:                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337     raeburn  5241:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
                   5242:     my ($pb1p1chk,$pb1p0chk,$onclickpb);
                   5243:     foreach my $extra ('roster','passback') {
1.320     raeburn  5244:         my $checkedon = '';
                   5245:         my $checkedoff = ' checked="checked"';
1.337     raeburn  5246:         if ($extra eq 'passback') {
                   5247:             $pb1p1chk = ' checked="checked"';
                   5248:             $pb1p0chk = '';
                   5249:             $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
                   5250:         } else {
                   5251:             $onclickpb = ''; 
                   5252:         }
1.320     raeburn  5253:         if (ref($current) eq 'HASH') {
                   5254:             if (($current->{$extra})) {
                   5255:                 $checkedon = $checkedoff;
                   5256:                 $checkedoff = '';
1.337     raeburn  5257:                 if ($extra eq 'passback') {
                   5258:                     $passbacksty = 'inline-block';
                   5259:                 }
                   5260:                 if ($current->{'passbackformat'} eq '1.0') {
                   5261:                     $pb1p0chk =  ' checked="checked"';
                   5262:                     $pb1p1chk = '';
                   5263:                 }
1.320     raeburn  5264:             }
                   5265:         }
                   5266:         $output .= $lt{$extra}.'&nbsp;'.
1.337     raeburn  5267:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320     raeburn  5268:                    &mt('No').'</label>'.('&nbsp;'x2).
1.339     raeburn  5269:                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320     raeburn  5270:                    &mt('Yes').'</label><br />';
                   5271:     }
1.337     raeburn  5272:     $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                   5273:                '<span class="LC_nobreak">'.&mt('Grade format').
                   5274:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                   5275:                &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                   5276:                '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363     raeburn  5277:                &mt('Outcomes Extension (1.0)').'</label></span></div>'.
                   5278:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   5279:                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').':&nbsp;'.
                   5280:                '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                   5281:                $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5282:                '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                   5283:                $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                   5284:                '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                   5285:                '<span class="LC_nobreak">'.&mt('Parameter').': '.
                   5286:                '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                   5287:                '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
1.345     raeburn  5288:                '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
1.326     raeburn  5289:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                   5290:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                   5291:                $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5292:                '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
1.334     raeburn  5293:                $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
1.326     raeburn  5294:                '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                   5295:                '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                   5296:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                   5297:                $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                   5298:                '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
1.334     raeburn  5299:                $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
1.326     raeburn  5300:      $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'. 
                   5301:                '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                   5302:                '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
                   5303:     foreach my $type ('fullname','coursetitle','role','logout','grades') {
                   5304:         $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                   5305:                    $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                   5306:                    ('&nbsp;'x2);
                   5307:     }
1.334     raeburn  5308:     $output .= '</span></div></fieldset>';
1.320     raeburn  5309: #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
                   5310: #
                   5311: #    $output .= '</fieldset>'.
                   5312: #        '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
                   5313:     return $output;
                   5314: }
                   5315: 
1.326     raeburn  5316: sub ltimenu_titles {
                   5317:     return &Apache::lonlocal::texthash(
                   5318:                                         fullname    => 'Full name',
                   5319:                                         coursetitle => 'Course title',
                   5320:                                         role        => 'Role',
                   5321:                                         logout      => 'Logout',
                   5322:                                         grades      => 'Grades',
                   5323:     );
                   5324: }
                   5325: 
1.121     raeburn  5326: sub print_coursedefaults {
1.139     raeburn  5327:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  5328:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  5329:     my $itemcount = 1;
1.192     raeburn  5330:     my %choices =  &Apache::lonlocal::texthash (
                   5331:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  5332:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  5333:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   5334:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  5335:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   5336:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.314     raeburn  5337:         texengine            => 'Default method to display mathematics',
1.257     raeburn  5338:         postsubmit           => 'Disable submit button/keypress following student submission',
1.276     raeburn  5339:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
                   5340:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.192     raeburn  5341:     );
1.198     raeburn  5342:     my %staticdefaults = (
                   5343:                            anonsurvey_threshold => 10,
                   5344:                            uploadquota          => 500,
1.257     raeburn  5345:                            postsubmit           => 60,
1.276     raeburn  5346:                            mysqltables          => 172800,
1.198     raeburn  5347:                          );
1.139     raeburn  5348:     if ($position eq 'top') {
1.257     raeburn  5349:         %defaultchecked = (
                   5350:                             'canuse_pdfforms' => 'off',
                   5351:                             'uselcmath'       => 'on',
                   5352:                             'usejsme'         => 'on',
1.289     raeburn  5353:                             'canclone'        => 'none',
1.257     raeburn  5354:                           );
                   5355:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.349     raeburn  5356:         my $deftex = $Apache::lonnet::deftex;
1.314     raeburn  5357:         if (ref($settings) eq 'HASH') {
                   5358:             if ($settings->{'texengine'}) {
                   5359:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   5360:                     $deftex = $settings->{'texengine'};
                   5361:                 }
                   5362:             }
                   5363:         }
                   5364:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5365:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   5366:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   5367:                        '</span></td><td class="LC_right_item">'.
                   5368:                        '<select name="texengine">'."\n";
                   5369:         my %texoptions = (
                   5370:                             MathJax  => 'MathJax',
                   5371:                             mimetex  => &mt('Convert to Images'),
                   5372:                             tth      => &mt('TeX to HTML'),
                   5373:                          );
                   5374:         foreach my $renderer ('MathJax','mimetex','tth') {
                   5375:             my $selected = '';
                   5376:             if ($renderer eq $deftex) {
                   5377:                 $selected = ' selected="selected"';
                   5378:             }
                   5379:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   5380:         }
                   5381:         $mathdisp .= '</select></td></tr>'."\n";
                   5382:         $itemcount ++;
1.139     raeburn  5383:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  5384:                                                      \%choices,$itemcount);
1.314     raeburn  5385:         $datatable = $mathdisp.$datatable;
1.264     raeburn  5386:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5387:         $datatable .=
1.306     raeburn  5388:             '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264     raeburn  5389:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   5390:             '</span></td><td class="LC_left_item">';
                   5391:         my $currcanclone = 'none';
                   5392:         my $onclick;
                   5393:         my @cloneoptions = ('none','domain');
                   5394:         my %clonetitles = (
                   5395:                              none     => 'No additional course requesters',
                   5396:                              domain   => "Any course requester in course's domain",
                   5397:                              instcode => 'Course requests for official courses ...',
                   5398:                           );
                   5399:         my (%codedefaults,@code_order,@posscodes);
                   5400:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   5401:                                                     \@code_order) eq 'ok') {
                   5402:             if (@code_order > 0) {
                   5403:                 push(@cloneoptions,'instcode');
                   5404:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   5405:             }
                   5406:         }
                   5407:         if (ref($settings) eq 'HASH') {
                   5408:             if ($settings->{'canclone'}) {
                   5409:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   5410:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   5411:                         if (@code_order > 0) {
                   5412:                             $currcanclone = 'instcode';
                   5413:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   5414:                         }
                   5415:                     }
                   5416:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   5417:                     $currcanclone = $settings->{'canclone'};
                   5418:                 }
                   5419:             }
1.289     raeburn  5420:         }
1.264     raeburn  5421:         foreach my $option (@cloneoptions) {
                   5422:             my ($checked,$additional);
                   5423:             if ($currcanclone eq $option) {
                   5424:                 $checked = ' checked="checked"';
                   5425:             }
                   5426:             if ($option eq 'instcode') {
                   5427:                 if (@code_order) {
                   5428:                     my $show = 'none';
                   5429:                     if ($checked) {
                   5430:                         $show = 'block';
                   5431:                     }
1.317     raeburn  5432:                     $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264     raeburn  5433:                                   &mt('Institutional codes for new and cloned course have identical:').
                   5434:                                   '<br />';
                   5435:                     foreach my $item (@code_order) {
                   5436:                         my $codechk;
                   5437:                         if ($checked) {
                   5438:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   5439:                                 $codechk = ' checked="checked"';
                   5440:                             }
                   5441:                         }
                   5442:                         $additional .= '<label>'.
                   5443:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   5444:                                        $item.'</label>';
                   5445:                     }
                   5446:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   5447:                 }
                   5448:             }
                   5449:             $datatable .=
                   5450:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   5451:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   5452:                 '</label>&nbsp;'.$additional.'</span><br />';
                   5453:         }
                   5454:         $datatable .= '</td>'.
                   5455:                       '</tr>';
                   5456:         $itemcount ++;
1.139     raeburn  5457:     } else {
                   5458:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276     raeburn  5459:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192     raeburn  5460:         my $currusecredits = 0;
1.257     raeburn  5461:         my $postsubmitclient = 1;
1.271     raeburn  5462:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  5463:         if (ref($settings) eq 'HASH') {
                   5464:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  5465:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   5466:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   5467:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   5468:                 }
                   5469:             }
1.192     raeburn  5470:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  5471:                 foreach my $type (@types) {
                   5472:                     next if ($type eq 'community');
                   5473:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   5474:                     if ($defcredits{$type} ne '') {
                   5475:                         $currusecredits = 1;
                   5476:                     }
                   5477:                 }
                   5478:             }
                   5479:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   5480:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   5481:                     $postsubmitclient = 0;
                   5482:                     foreach my $type (@types) {
                   5483:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5484:                     }
                   5485:                 } else {
                   5486:                     foreach my $type (@types) {
                   5487:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   5488:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289     raeburn  5489:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257     raeburn  5490:                             } else {
                   5491:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5492:                             }
                   5493:                         } else {
                   5494:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5495:                         }
                   5496:                     }
                   5497:                 }
                   5498:             } else {
                   5499:                 foreach my $type (@types) {
                   5500:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  5501:                 }
                   5502:             }
1.276     raeburn  5503:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   5504:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   5505:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   5506:                 }
                   5507:             } else {
                   5508:                 foreach my $type (@types) {
                   5509:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   5510:                 }
                   5511:             }
1.258     raeburn  5512:         } else {
                   5513:             foreach my $type (@types) {
                   5514:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5515:             }
1.139     raeburn  5516:         }
                   5517:         if (!$currdefresponder) {
1.198     raeburn  5518:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  5519:         } elsif ($currdefresponder < 1) {
                   5520:             $currdefresponder = 1;
                   5521:         }
1.198     raeburn  5522:         foreach my $type (@types) {
                   5523:             if ($curruploadquota{$type} eq '') {
                   5524:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   5525:             }
                   5526:         }
1.139     raeburn  5527:         $datatable .=
1.192     raeburn  5528:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5529:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  5530:                 '</span></td>'.
                   5531:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5532:                 '<input type="text" name="anonsurvey_threshold"'.
                   5533:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  5534:                 '</td></tr>'."\n";
                   5535:         $itemcount ++;
                   5536:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5537:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5538:                       $choices{'uploadquota'}.
                   5539:                       '</span></td>'.
1.306     raeburn  5540:                       '<td style="text-align: right" class="LC_right_item">'.
1.230     raeburn  5541:                       '<table><tr>';
1.198     raeburn  5542:         foreach my $type (@types) {
1.306     raeburn  5543:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198     raeburn  5544:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   5545:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   5546:         }
                   5547:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  5548:         $itemcount ++;
1.236     raeburn  5549:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  5550:         my $display = 'none';
1.192     raeburn  5551:         if ($currusecredits) {
                   5552:             $display = 'block';
                   5553:         }
                   5554:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  5555:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   5556:         foreach my $type (@types) {
                   5557:             next if ($type eq 'community');
1.306     raeburn  5558:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  5559:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  5560:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  5561:         }
                   5562:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  5563:         %defaultchecked = ('coursecredits' => 'off');
                   5564:         @toggles = ('coursecredits');
                   5565:         my $current = {
                   5566:                         'coursecredits' => $currusecredits,
                   5567:                       };
                   5568:         (my $table,$itemcount) =
                   5569:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  5570:                                \%choices,$itemcount,$onclick,$additional,'left');
                   5571:         $datatable .= $table;
                   5572:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   5573:         my $display = 'none';
                   5574:         if ($postsubmitclient) {
                   5575:             $display = 'block';
                   5576:         }
                   5577:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  5578:                       &mt('Number of seconds submit is disabled').'<br />'.
                   5579:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   5580:                       '<table><tr>';
1.257     raeburn  5581:         foreach my $type (@types) {
1.306     raeburn  5582:             $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257     raeburn  5583:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   5584:                            $deftimeout{$type}.'" size="5" /></td>';
                   5585:         }
                   5586:         $additional .= '</tr></table></div>'."\n";
                   5587:         %defaultchecked = ('postsubmit' => 'on');
                   5588:         @toggles = ('postsubmit');
1.280     raeburn  5589:         $current = {
                   5590:                        'postsubmit' => $postsubmitclient,
                   5591:                    };
1.257     raeburn  5592:         ($table,$itemcount) =
                   5593:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   5594:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  5595:         $datatable .= $table;
1.276     raeburn  5596:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5597:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5598:                       $choices{'mysqltables'}.
                   5599:                       '</span></td>'.
1.306     raeburn  5600:                       '<td style="text-align: right" class="LC_right_item">'.
1.276     raeburn  5601:                       '<table><tr>';
                   5602:         foreach my $type (@types) {
1.306     raeburn  5603:             $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276     raeburn  5604:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.295     raeburn  5605:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276     raeburn  5606:         }
                   5607:         $datatable .= '</tr></table></td></tr>'."\n";
                   5608:         $itemcount ++;
                   5609: 
1.139     raeburn  5610:     }
1.192     raeburn  5611:     $$rowtotal += $itemcount;
1.121     raeburn  5612:     return $datatable;
1.118     jms      5613: }
                   5614: 
1.231     raeburn  5615: sub print_selfenrollment {
                   5616:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5617:     my ($css_class,$datatable);
                   5618:     my $itemcount = 1;
1.271     raeburn  5619:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  5620:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  5621:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   5622:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  5623:         my @rows;
                   5624:         my $key;
                   5625:         if ($position eq 'top') {
                   5626:             $key = 'admin'; 
                   5627:             if (ref($rowsref) eq 'ARRAY') {
                   5628:                 @rows = @{$rowsref};
                   5629:             }
                   5630:         } elsif ($position eq 'middle') {
                   5631:             $key = 'default';
                   5632:             @rows = ('types','registered','approval','limit');
                   5633:         }
                   5634:         foreach my $row (@rows) {
                   5635:             if (defined($titlesref->{$row})) {
                   5636:                 $itemcount ++;
                   5637:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5638:                 $datatable .= '<tr'.$css_class.'>'.
                   5639:                               '<td>'.$titlesref->{$row}.'</td>'.
                   5640:                               '<td class="LC_left_item">'.
                   5641:                               '<table><tr>';
                   5642:                 my (%current,%currentcap);
                   5643:                 if (ref($settings) eq 'HASH') {
                   5644:                     if (ref($settings->{$key}) eq 'HASH') {
                   5645:                         foreach my $type (@types) {
                   5646:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5647:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   5648:                             }
                   5649:                             if (($row eq 'limit') && ($key eq 'default')) {
                   5650:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5651:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   5652:                                 }
                   5653:                             }
                   5654:                         }
                   5655:                     }
                   5656:                 }
                   5657:                 my %roles = (
                   5658:                              '0' => &Apache::lonnet::plaintext('dc'),
                   5659:                             ); 
                   5660:             
                   5661:                 foreach my $type (@types) {
                   5662:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   5663:                         $datatable .= '<th>'.&mt($type).'</th>';
                   5664:                     }
                   5665:                 }
                   5666:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   5667:                     $datatable .= '</tr><tr>';
                   5668:                 }
                   5669:                 foreach my $type (@types) {
                   5670:                     if ($type eq 'community') {
                   5671:                         $roles{'1'} = &mt('Community personnel');
                   5672:                     } else {
                   5673:                         $roles{'1'} = &mt('Course personnel');
                   5674:                     }
                   5675:                     $datatable .= '<td style="vertical-align: top">';
                   5676:                     if ($position eq 'top') {
                   5677:                         my %checked;
                   5678:                         if ($current{$type} eq '0') {
                   5679:                             $checked{'0'} = ' checked="checked"';
                   5680:                         } else {
                   5681:                             $checked{'1'} = ' checked="checked"';
                   5682:                         }
                   5683:                         foreach my $role ('1','0') {
                   5684:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   5685:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   5686:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   5687:                                           $roles{$role}.'</label></span> ';
                   5688:                         }
                   5689:                     } else {
                   5690:                         if ($row eq 'types') {
                   5691:                             my %checked;
                   5692:                             if ($current{$type} =~ /^(all|dom)$/) {
                   5693:                                 $checked{$1} = ' checked="checked"';
                   5694:                             } else {
                   5695:                                 $checked{''} = ' checked="checked"';
                   5696:                             }
                   5697:                             foreach my $val ('','dom','all') {
                   5698:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5699:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5700:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5701:                             }
                   5702:                         } elsif ($row eq 'registered') {
                   5703:                             my %checked;
                   5704:                             if ($current{$type} eq '1') {
                   5705:                                 $checked{'1'} = ' checked="checked"';
                   5706:                             } else {
                   5707:                                 $checked{'0'} = ' checked="checked"';
                   5708:                             }
                   5709:                             foreach my $val ('0','1') {
                   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:                         } elsif ($row eq 'approval') {
                   5715:                             my %checked;
                   5716:                             if ($current{$type} =~ /^([12])$/) {
                   5717:                                 $checked{$1} = ' checked="checked"';
                   5718:                             } else {
                   5719:                                 $checked{'0'} = ' checked="checked"';
                   5720:                             }
                   5721:                             for my $val (0..2) {
                   5722:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5723:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5724:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5725:                             }
                   5726:                         } elsif ($row eq 'limit') {
                   5727:                             my %checked;
                   5728:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   5729:                                 $checked{$1} = ' checked="checked"';
                   5730:                             } else {
                   5731:                                 $checked{'none'} = ' checked="checked"';
                   5732:                             }
                   5733:                             my $cap;
                   5734:                             if ($currentcap{$type} =~ /^\d+$/) {
                   5735:                                 $cap = $currentcap{$type};
                   5736:                             }
                   5737:                             foreach my $val ('none','allstudents','selfenrolled') {
                   5738:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5739:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5740:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5741:                             }
                   5742:                             $datatable .= '<br />'.
                   5743:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   5744:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   5745:                                           '</span>'; 
                   5746:                         }
                   5747:                     }
                   5748:                     $datatable .= '</td>';
                   5749:                 }
                   5750:                 $datatable .= '</tr>';
                   5751:             }
                   5752:             $datatable .= '</table></td></tr>';
                   5753:         }
                   5754:     } elsif ($position eq 'bottom') {
1.235     raeburn  5755:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   5756:     }
                   5757:     $$rowtotal += $itemcount;
                   5758:     return $datatable;
                   5759: }
                   5760: 
                   5761: sub print_validation_rows {
                   5762:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   5763:     my ($itemsref,$namesref,$fieldsref);
                   5764:     if ($caller eq 'selfenroll') { 
                   5765:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   5766:     } elsif ($caller eq 'requestcourses') {
                   5767:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   5768:     }
                   5769:     my %currvalidation;
                   5770:     if (ref($settings) eq 'HASH') {
                   5771:         if (ref($settings->{'validation'}) eq 'HASH') {
                   5772:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  5773:         }
1.235     raeburn  5774:     }
                   5775:     my $datatable;
                   5776:     my $itemcount = 0;
                   5777:     foreach my $item (@{$itemsref}) {
                   5778:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5779:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5780:                       $namesref->{$item}.
                   5781:                       '</span></td>'.
                   5782:                       '<td class="LC_left_item">';
                   5783:         if (($item eq 'url') || ($item eq 'button')) {
                   5784:             $datatable .= '<span class="LC_nobreak">'.
                   5785:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   5786:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   5787:         } elsif ($item eq 'fields') {
                   5788:             my @currfields;
                   5789:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   5790:                 @currfields = @{$currvalidation{$item}};
                   5791:             }
                   5792:             foreach my $field (@{$fieldsref}) {
                   5793:                 my $check = '';
                   5794:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   5795:                     $check = ' checked="checked"';
                   5796:                 }
                   5797:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5798:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   5799:                               ' value="'.$field.'"'.$check.' />'.$field.
                   5800:                               '</label></span> ';
                   5801:             }
                   5802:         } elsif ($item eq 'markup') {
1.334     raeburn  5803:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235     raeburn  5804:                            $currvalidation{$item}.
1.231     raeburn  5805:                               '</textarea>';
1.235     raeburn  5806:         }
                   5807:         $datatable .= '</td></tr>'."\n";
                   5808:         if (ref($rowtotal)) {
1.231     raeburn  5809:             $itemcount ++;
                   5810:         }
                   5811:     }
1.235     raeburn  5812:     if ($caller eq 'requestcourses') {
                   5813:         my %currhash;
1.248     raeburn  5814:         if (ref($settings) eq 'HASH') {
                   5815:             if (ref($settings->{'validation'}) eq 'HASH') {
                   5816:                 if ($settings->{'validation'}{'dc'} ne '') {
                   5817:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   5818:                 }
1.235     raeburn  5819:             }
                   5820:         }
                   5821:         my $numinrow = 2;
                   5822:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   5823:                                                        'validationdc',%currhash);
1.247     raeburn  5824:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334     raeburn  5825:         $datatable .= '<tr'.$css_class.'><td>';
1.235     raeburn  5826:         if ($numdc > 1) {
1.247     raeburn  5827:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  5828:         } else {
1.247     raeburn  5829:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  5830:         }
1.247     raeburn  5831:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  5832:         $itemcount ++;
                   5833:     }
                   5834:     if (ref($rowtotal)) {
                   5835:         $$rowtotal += $itemcount;
                   5836:     }
1.231     raeburn  5837:     return $datatable;
                   5838: }
                   5839: 
1.357     raeburn  5840: sub print_privacy {
                   5841:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5842:     my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
                   5843:     my $itemcount = 0;
                   5844:     unless ($position eq 'top') {
                   5845:         @items = ('domain','author','course','community');
                   5846:         %names = &Apache::lonlocal::texthash (
                   5847:                      domain => 'Assigned domain role(s)',
                   5848:                      author => 'Assigned co-author role(s)',
                   5849:                      course => 'Assigned course role(s)',
                   5850:                      community => 'Assigned community role',
                   5851:                  );
                   5852:         $numinrow = 4;
                   5853:         ($othertitle,$usertypes,$types) =
                   5854:             &Apache::loncommon::sorted_inst_types($dom);
                   5855:     }
                   5856:     if (($position eq 'top') || ($position eq 'middle')) {
                   5857:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   5858:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   5859:         if ($position eq 'top') {
                   5860:             my %curr;
                   5861:             my @options = ('none','user','domain','auto');
                   5862:             my %titles = &Apache::lonlocal::texthash (
                   5863:                 none   => 'Not allowed',
                   5864:                 user   => 'User authorizes',
                   5865:                 domain => 'DC authorizes',
                   5866:                 auto   => 'Unrestricted',
                   5867:                 instdom => 'Other domain shares institution/provider',
                   5868:                 extdom => 'Other domain has different institution/provider',
                   5869:             );
                   5870:             my %names = &Apache::lonlocal::texthash (
                   5871:                 domain => 'Domain role',
                   5872:                 author => 'Co-author role',
                   5873:                 course => 'Course role',
                   5874:                 community => 'Community role',
                   5875:             );
                   5876:             my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5877:             my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5878:             foreach my $domtype ('instdom','extdom') {
                   5879:                 my (%checked,$skip);
                   5880:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5881:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                   5882:                               '<td class="LC_left_item">';
                   5883:                 if ($domtype eq 'instdom') {
                   5884:                     unless (@instdoms > 1) {
                   5885:                         $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                   5886:                         $skip = 1;
                   5887:                     }
                   5888:                 } elsif ($domtype eq 'extdom') {
                   5889:                     if (keys(%by_location) == 0) {
                   5890:                         $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                   5891:                         $skip = 1;
                   5892:                     }
                   5893:                 }
                   5894:                 unless ($skip) {
                   5895:                     foreach my $roletype ('domain','author','course','community') {
                   5896:                         $checked{'auto'} = ' checked="checked"';
                   5897:                         if (ref($settings) eq 'HASH') {
                   5898:                             if (ref($settings->{approval}) eq 'HASH') {
                   5899:                                 if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                   5900:                                     if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                   5901:                                         $checked{$1} = ' checked="checked"';
                   5902:                                         $checked{'auto'} = '';
                   5903:                                     }
                   5904:                                 }
                   5905:                             }
                   5906:                         }
                   5907:                         $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                   5908:                         foreach my $option (@options) {
                   5909:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   5910:                                           '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                   5911:                                           'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   5912:                                           '</label></span>&nbsp; ';
                   5913:                         }
                   5914:                         $datatable .= '</fieldset>';
                   5915:                     }
                   5916:                 }
                   5917:                 $datatable .= '</td></tr>';
                   5918:                 $itemcount ++;
                   5919:             }
                   5920:         } elsif ($position eq 'middle') {
                   5921:             if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   5922:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   5923:                     foreach my $item (@{$types}) {
                   5924:                         $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                   5925:                                                                $numinrow,$itemcount,'','','','','',
                   5926:                                                                '',$usertypes->{$item});
                   5927:                         $itemcount ++;
                   5928:                     }
                   5929:                 }
                   5930:                 $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                   5931:                                                        $numinrow,$itemcount,'','','','','',
                   5932:                                                        '',$othertitle);
                   5933:                 $itemcount ++;
                   5934:             } else {
1.360     raeburn  5935:                 my (@insttypes,%insttitles);
                   5936:                 if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   5937:                     @insttypes = @{$types};
                   5938:                     %insttitles = %{$usertypes};
                   5939:                 }
                   5940:                 foreach my $item (@insttypes,'default') {
                   5941:                     my $title;
                   5942:                     if ($item eq 'default') {
                   5943:                         $title = $othertitle;
                   5944:                     } else {
                   5945:                         $title = $insttitles{$item};
                   5946:                     }
                   5947:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5948:                     $datatable .= '<tr'.$css_class.'>'.
                   5949:                                   '<td class="LC_left_item">'.$title.'</td>'.
                   5950:                                   '<td class="LC_left_item">'.
                   5951:                                   &mt('Nothing to set here, as there are no other domains').
                   5952:                                   '</td></tr>';
                   5953:                     $itemcount ++;
                   5954:                 }
1.357     raeburn  5955:             }
                   5956:         }
                   5957:     } else {
                   5958:         my $prefix;
                   5959:         if ($position eq 'lower') {
                   5960:             $prefix = 'priv';
                   5961:         } else {
                   5962:             $prefix = 'unpriv';
                   5963:         }
                   5964:         foreach my $item (@items) {
                   5965:             $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                   5966:                                                    $numinrow,$itemcount,'','','','','',
                   5967:                                                    '',$names{$item});
                   5968:             $itemcount ++;
                   5969:         }
                   5970:     }
                   5971:     if (ref($rowtotal)) {
                   5972:         $$rowtotal += $itemcount;
                   5973:     }
                   5974:     return $datatable;
                   5975: }
                   5976: 
1.354     raeburn  5977: sub print_passwords {
                   5978:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   5979:     my ($datatable,$css_class);
                   5980:     my $itemcount = 0;
                   5981:     my %titles = &Apache::lonlocal::texthash (
                   5982:         captcha        => '"Forgot Password" CAPTCHA validation',
                   5983:         link           => 'Reset link expiration (hours)',
                   5984:         case           => 'Case-sensitive usernames/e-mail',
                   5985:         prelink        => 'Information required (form 1)',
                   5986:         postlink       => 'Information required (form 2)',
                   5987:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   5988:         customtext     => 'Domain specific text (HTML)',
                   5989:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   5990:         intauth_check  => 'Check bcrypt cost if authenticated',
                   5991:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   5992:         permanent      => 'Permanent e-mail address',
                   5993:         critical       => 'Critical notification address',
                   5994:         notify         => 'Notification address',
                   5995:         min            => 'Minimum password length',
                   5996:         max            => 'Maximum password length',
                   5997:         chars          => 'Required characters',
                   5998:         expire         => 'Password expiration (days)',
1.356     raeburn  5999:         numsaved       => 'Number of previous passwords to save and disallow reuse',
1.354     raeburn  6000:     );
                   6001:     if ($position eq 'top') {
                   6002:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6003:         my $shownlinklife = 2;
                   6004:         my $prelink = 'both';
                   6005:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   6006:         if (ref($settings) eq 'HASH') {
                   6007:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   6008:                 $shownlinklife = $settings->{resetlink};
                   6009:             }
                   6010:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   6011:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   6012:             }
                   6013:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   6014:                 $prelink = $settings->{resetprelink};
                   6015:             }
                   6016:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   6017:                 %postlink = %{$settings->{resetpostlink}};
                   6018:             }
                   6019:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   6020:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   6021:             }
                   6022:             if ($settings->{resetremove}) {
                   6023:                 $nostdtext = 1;
                   6024:             }
                   6025:             if ($settings->{resetcustom}) {
                   6026:                 $customurl = $settings->{resetcustom};
                   6027:             }
                   6028:         } else {
                   6029:             if (ref($types) eq 'ARRAY') {
                   6030:                 foreach my $item (@{$types}) {
                   6031:                     $casesens{$item} = 1;
                   6032:                     $postlink{$item} = ['username','email'];
                   6033:                 }
                   6034:             }
                   6035:             $casesens{'default'} = 1;
                   6036:             $postlink{'default'} = ['username','email'];
                   6037:             $prelink = 'both';
                   6038:             %emailsrc = (
                   6039:                           permanent => 1,
                   6040:                           critical  => 1,
                   6041:                           notify    => 1,
                   6042:             );
                   6043:         }
                   6044:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   6045:         $itemcount ++;
                   6046:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6047:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   6048:                       '<td class="LC_left_item">'.
                   6049:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   6050:                       'name="passwords_link" size="3" /></td></tr>';
                   6051:         $itemcount ++;
                   6052:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6053:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   6054:                       '<td class="LC_left_item">';
                   6055:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6056:             foreach my $item (@{$types}) {
                   6057:                 my $checkedcase;
                   6058:                 if ($casesens{$item}) {
                   6059:                     $checkedcase = ' checked="checked"';
                   6060:                 }
                   6061:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   6062:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   6063:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369   ! raeburn  6064:                               '</span>&nbsp;&nbsp; ';
1.354     raeburn  6065:             }
                   6066:         }
                   6067:         my $checkedcase;
                   6068:         if ($casesens{'default'}) {
                   6069:             $checkedcase = ' checked="checked"';
                   6070:         }
                   6071:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   6072:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   6073:                       $othertitle.'</label></span></td>';
                   6074:         $itemcount ++;
                   6075:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6076:         my %checkedpre = (
                   6077:                              both => ' checked="checked"',
                   6078:                              either => '',
                   6079:                          );
                   6080:         if ($prelink eq 'either') {
                   6081:             $checkedpre{either} = ' checked="checked"';
                   6082:             $checkedpre{both} = '';
                   6083:         }
                   6084:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   6085:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6086:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   6087:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   6088:                       '<span class="LC_nobreak"><label>'.
                   6089:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   6090:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   6091:         $itemcount ++;
                   6092:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6093:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   6094:                       '<td class="LC_left_item">';
                   6095:         my %postlinked;
                   6096:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6097:             foreach my $item (@{$types}) {
                   6098:                 undef(%postlinked);
                   6099:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   6100:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   6101:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   6102:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   6103:                 }
                   6104:                 foreach my $field ('email','username') {
                   6105:                     my $checked;
                   6106:                     if ($postlinked{$field}) {
                   6107:                         $checked = ' checked="checked"';
                   6108:                     }
                   6109:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   6110:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   6111:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   6112:                                   '<span>&nbsp;&nbsp; ';
                   6113:                 }
                   6114:                 $datatable .= '</fieldset>';
                   6115:             }
                   6116:         }
                   6117:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   6118:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   6119:         }
                   6120:         $datatable .= '<fieldset style="display: inline-block;">'.
                   6121:                       '<legend>'.$othertitle.'</legend>';
                   6122:         foreach my $field ('email','username') {
                   6123:             my $checked;
                   6124:             if ($postlinked{$field}) {
                   6125:                 $checked = ' checked="checked"';
                   6126:             }
                   6127:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6128:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   6129:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   6130:                           '<span>&nbsp;&nbsp; ';
                   6131:         }
                   6132:         $datatable .= '</fieldset></td></tr>';
                   6133:         $itemcount ++;
                   6134:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6135:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   6136:                       '<td class="LC_left_item">';
                   6137:         foreach my $type ('permanent','critical','notify') {
                   6138:             my $checkedemail;
                   6139:             if ($emailsrc{$type}) {
                   6140:                 $checkedemail = ' checked="checked"';
                   6141:             }
                   6142:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6143:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   6144:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   6145:                           '<span>&nbsp;&nbsp; ';
                   6146:         }
                   6147:         $datatable .= '</td></tr>';
                   6148:         $itemcount ++;
                   6149:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6150:         my $switchserver = &check_switchserver($dom,$confname);
                   6151:         my ($showstd,$noshowstd);
                   6152:         if ($nostdtext) {
                   6153:             $noshowstd = ' checked="checked"';
                   6154:         } else {
                   6155:             $showstd = ' checked="checked"';
                   6156:         }
                   6157:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   6158:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6159:                       &mt('Retain standard text:').
                   6160:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   6161:                       &mt('Yes').'</label>'.'&nbsp;'.
                   6162:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   6163:                       &mt('No').'</label></span><br />'.
                   6164:                       '<span class="LC_fontsize_small">'.
                   6165:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   6166:                       &mt('Include custom text:');
                   6167:         if ($customurl) {
1.369   ! raeburn  6168:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354     raeburn  6169:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   6170:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   6171:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   6172:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   6173:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   6174:         }
                   6175:         if ($switchserver) {
                   6176:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   6177:         } else {
                   6178:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   6179:                          '<input type="file" name="passwords_customfile" /></span>';
                   6180:         }
                   6181:         $datatable .= '</td></tr>';
                   6182:     } elsif ($position eq 'middle') {
                   6183:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   6184:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   6185:         my %defaults;
                   6186:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   6187:             %defaults = %{$domconf{'defaults'}};
                   6188:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   6189:                 $defaults{'intauth_cost'} = 10;
                   6190:             }
                   6191:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   6192:                 $defaults{'intauth_check'} = 0;
                   6193:             }
                   6194:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   6195:                 $defaults{'intauth_switch'} = 0;
                   6196:             }
                   6197:         } else {
                   6198:             %defaults = (
                   6199:                           'intauth_cost'   => 10,
                   6200:                           'intauth_check'  => 0,
                   6201:                           'intauth_switch' => 0,
                   6202:                         );
                   6203:         }
                   6204:         foreach my $item (@items) {
                   6205:             if ($itemcount%2) {
                   6206:                 $css_class = '';
                   6207:             } else {
                   6208:                 $css_class = ' class="LC_odd_row" ';
                   6209:             }
                   6210:             $datatable .= '<tr'.$css_class.'>'.
                   6211:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   6212:                           '</span></td><td class="LC_left_item" colspan="3">';
                   6213:             if ($item eq 'intauth_switch') {
                   6214:                 my @options = (0,1,2);
                   6215:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6216:                                    0 => 'No',
                   6217:                                    1 => 'Yes',
                   6218:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   6219:                                  );
                   6220:                 $datatable .= '<table width="100%">';
                   6221:                 foreach my $option (@options) {
                   6222:                     my $checked = ' ';
                   6223:                     if ($defaults{$item} eq $option) {
                   6224:                         $checked = ' checked="checked"';
                   6225:                     }
                   6226:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6227:                                   '<label><input type="radio" name="'.$item.
                   6228:                                   '" value="'.$option.'"'.$checked.' />'.
                   6229:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6230:                 }
                   6231:                 $datatable .= '</table>';
                   6232:             } elsif ($item eq 'intauth_check') {
                   6233:                 my @options = (0,1,2);
                   6234:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6235:                                    0 => 'No',
                   6236:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   6237:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   6238:                                  );
                   6239:                 $datatable .= '<table width="100%">';
                   6240:                 foreach my $option (@options) {
                   6241:                     my $checked = ' ';
                   6242:                     my $onclick;
                   6243:                     if ($defaults{$item} eq $option) {
                   6244:                         $checked = ' checked="checked"';
                   6245:                     }
                   6246:                     if ($option == 2) {
                   6247:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   6248:                     }
                   6249:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6250:                                   '<label><input type="radio" name="'.$item.
                   6251:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   6252:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6253:                 }
                   6254:                 $datatable .= '</table>';
                   6255:             } else {
                   6256:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6257:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   6258:             }
                   6259:             $datatable .= '</td></tr>';
                   6260:             $itemcount ++;
                   6261:         }
                   6262:     } elsif ($position eq 'lower') {
1.356     raeburn  6263:         my ($min,$max,%chars,$expire,$numsaved);
1.365     raeburn  6264:         $min = $Apache::lonnet::passwdmin;
1.354     raeburn  6265:         if (ref($settings) eq 'HASH') {
                   6266:             if ($settings->{min}) {
                   6267:                 $min = $settings->{min};
                   6268:             }
                   6269:             if ($settings->{max}) {
                   6270:                 $max = $settings->{max};
                   6271:             }
                   6272:             if (ref($settings->{chars}) eq 'ARRAY') {
                   6273:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   6274:             }
                   6275:             if ($settings->{expire}) {
                   6276:                 $expire = $settings->{expire};
                   6277:             }
1.358     raeburn  6278:             if ($settings->{numsaved}) {
                   6279:                 $numsaved = $settings->{numsaved};
1.356     raeburn  6280:             }
1.354     raeburn  6281:         }
                   6282:         my %rulenames = &Apache::lonlocal::texthash(
                   6283:                                                      uc => 'At least one upper case letter',
                   6284:                                                      lc => 'At least one lower case letter',
                   6285:                                                      num => 'At least one number',
                   6286:                                                      spec => 'At least one non-alphanumeric',
                   6287:                                                    );
                   6288:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6289:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   6290:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  6291:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   6292:                       'onblur="javascript:warnIntPass(this);" />'.
                   6293:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.354     raeburn  6294:                       '</span></td></tr>';
                   6295:         $itemcount ++;
                   6296:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6297:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   6298:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  6299:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   6300:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  6301:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   6302:                       '</span></td></tr>';
                   6303:         $itemcount ++;
                   6304:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6305:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   6306:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   6307:                       '</span></td>';
                   6308:         my $numinrow = 2;
                   6309:         my @possrules = ('uc','lc','num','spec');
                   6310:         $datatable .= '<td class="LC_left_item"><table>';
                   6311:         for (my $i=0; $i<@possrules; $i++) {
                   6312:             my ($rem,$checked);
                   6313:             if ($chars{$possrules[$i]}) {
                   6314:                 $checked = ' checked="checked"';
                   6315:             }
                   6316:             $rem = $i%($numinrow);
                   6317:             if ($rem == 0) {
                   6318:                 if ($i > 0) {
                   6319:                     $datatable .= '</tr>';
                   6320:                 }
                   6321:                 $datatable .= '<tr>';
                   6322:             }
                   6323:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   6324:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   6325:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   6326:         }
                   6327:         my $rem = @possrules%($numinrow);
                   6328:         my $colsleft = $numinrow - $rem;
                   6329:         if ($colsleft > 1 ) {
                   6330:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6331:                           '&nbsp;</td>';
                   6332:         } elsif ($colsleft == 1) {
                   6333:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   6334:         }
                   6335:         $datatable .='</table></td></tr>';
                   6336:         $itemcount ++;
                   6337:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6338:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                   6339:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.365     raeburn  6340:                       '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
                   6341:                       'onblur="javascript:warnIntPass(this);" />'.
1.354     raeburn  6342:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                   6343:                       '</span></td></tr>';
1.356     raeburn  6344:         $itemcount ++;
                   6345:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6346:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   6347:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.367     raeburn  6348:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
                   6349:                       'onblur="javascript:warnIntPass(this);" />'. 
1.356     raeburn  6350:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   6351:                       '</span></td></tr>';
1.354     raeburn  6352:     } else {
1.359     raeburn  6353:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6354:         my %ownerchg = (
                   6355:                           by  => {},
                   6356:                           for => {},
                   6357:                        );
                   6358:         my %ownertitles = &Apache::lonlocal::texthash (
                   6359:                             by  => 'Course owner status(es) allowed',
                   6360:                             for => 'Student status(es) allowed',
                   6361:                           );
1.354     raeburn  6362:         if (ref($settings) eq 'HASH') {
1.359     raeburn  6363:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   6364:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   6365:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   6366:                 }
                   6367:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   6368:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   6369:                 }
1.354     raeburn  6370:             }
                   6371:         }
                   6372:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6373:         $datatable .= '<tr '.$css_class.'>'.
                   6374:                       '<td>'.
                   6375:                       &mt('Requirements').'<ul>'.
1.359     raeburn  6376:                       '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354     raeburn  6377:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   6378:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359     raeburn  6379:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354     raeburn  6380:                       '</ul>'.
                   6381:                       '</td>'.
1.359     raeburn  6382:                       '<td class="LC_left_item">';
                   6383:         foreach my $item ('by','for') {
                   6384:             $datatable .= '<fieldset style="display: inline-block;">'.
                   6385:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   6386:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6387:                 foreach my $type (@{$types}) {
                   6388:                     my $checked;
                   6389:                     if ($ownerchg{$item}{$type}) {
                   6390:                         $checked = ' checked="checked"';
                   6391:                     }
                   6392:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   6393:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   6394:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369   ! raeburn  6395:                                   '</span>&nbsp;&nbsp; ';
1.359     raeburn  6396:                 }
                   6397:             }
                   6398:             my $checked;
                   6399:             if ($ownerchg{$item}{'default'}) {
                   6400:                 $checked = ' checked="checked"';
                   6401:             }
                   6402:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   6403:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   6404:                           $othertitle.'</label></span></fieldset>';
                   6405:         }
                   6406:         $datatable .= '</td></tr>';
1.354     raeburn  6407:     }
                   6408:     return $datatable;
                   6409: }
                   6410: 
1.137     raeburn  6411: sub print_usersessions {
                   6412:     my ($position,$dom,$settings,$rowtotal) = @_;
1.279     raeburn  6413:     my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275     raeburn  6414:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   6415:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145     raeburn  6416: 
                   6417:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  6418:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  6419:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  6420:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  6421:     if ($position eq 'top') {
1.152     raeburn  6422:         if (keys(%serverhomes) > 1) {
1.145     raeburn  6423:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.261     raeburn  6424:             my $curroffloadnow;
                   6425:             if (ref($settings) eq 'HASH') {
                   6426:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   6427:                     $curroffloadnow = $settings->{'offloadnow'};
                   6428:                 }
                   6429:             }
                   6430:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  6431:         } else {
1.140     raeburn  6432:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279     raeburn  6433:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
                   6434:                           '</td></tr>';
1.140     raeburn  6435:         }
1.137     raeburn  6436:     } else {
1.279     raeburn  6437:         my %titles = &usersession_titles();
                   6438:         my ($prefix,@types);
                   6439:         if ($position eq 'bottom') {
                   6440:             $prefix = 'remote';
                   6441:             @types = ('version','excludedomain','includedomain');
1.145     raeburn  6442:         } else {
1.279     raeburn  6443:             $prefix = 'hosted';
                   6444:             @types = ('excludedomain','includedomain');
                   6445:         }
                   6446:         ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   6447:     }
                   6448:     $$rowtotal += $itemcount;
                   6449:     return $datatable;
                   6450: }
                   6451: 
                   6452: sub rules_by_location {
                   6453:     my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_; 
                   6454:     my ($datatable,$itemcount,$css_class);
                   6455:     if (keys(%{$by_location}) == 0) {
                   6456:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6457:         $datatable = '<tr'.$css_class.'><td colspan="2">'.
                   6458:                      &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
                   6459:                      '</td></tr>';
                   6460:         $itemcount = 1;
                   6461:     } else {
                   6462:         $itemcount = 0;
                   6463:         my $numinrow = 5;
                   6464:         my (%current,%checkedon,%checkedoff);
                   6465:         my @locations = sort(keys(%{$by_location}));
                   6466:         foreach my $type (@{$types}) {
                   6467:             $checkedon{$type} = '';
                   6468:             $checkedoff{$type} = ' checked="checked"';
                   6469:         }
                   6470:         if (ref($settings) eq 'HASH') {
                   6471:             if (ref($settings->{$prefix}) eq 'HASH') {
                   6472:                 foreach my $key (keys(%{$settings->{$prefix}})) {
                   6473:                     $current{$key} = $settings->{$prefix}{$key};
                   6474:                     if ($key eq 'version') {
                   6475:                         if ($current{$key} ne '') {
1.145     raeburn  6476:                             $checkedon{$key} = ' checked="checked"';
                   6477:                             $checkedoff{$key} = '';
                   6478:                         }
1.279     raeburn  6479:                     } elsif (ref($current{$key}) eq 'ARRAY') {
                   6480:                         $checkedon{$key} = ' checked="checked"';
                   6481:                         $checkedoff{$key} = '';
1.137     raeburn  6482:                     }
                   6483:                 }
                   6484:             }
1.279     raeburn  6485:         }
                   6486:         foreach my $type (@{$types}) {
                   6487:             next if ($type ne 'version' && !@locations);
                   6488:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6489:             $datatable .= '<tr'.$css_class.'>
                   6490:                            <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
                   6491:                            <span class="LC_nobreak">&nbsp;
                   6492:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   6493:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   6494:             if ($type eq 'version') {
                   6495:                 my @lcversions = &Apache::lonnet::all_loncaparevs();
                   6496:                 my $selector = '<select name="'.$prefix.'_version">';
                   6497:                 foreach my $version (@lcversions) {
                   6498:                     my $selected = '';
                   6499:                     if ($current{'version'} eq $version) {
                   6500:                         $selected = ' selected="selected"';
1.145     raeburn  6501:                     }
1.279     raeburn  6502:                     $selector .= ' <option value="'.$version.'"'.
                   6503:                                  $selected.'>'.$version.'</option>';
                   6504:                 }
                   6505:                 $selector .= '</select> ';
                   6506:                 $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   6507:             } else {
                   6508:                 $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   6509:                              'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   6510:                              ' />'.('&nbsp;'x2).
                   6511:                              '<input type="button" value="'.&mt('uncheck all').'" '.
                   6512:                              'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   6513:                              "\n".
                   6514:                              '</div><div><table>';
                   6515:                 my $rem;
                   6516:                 for (my $i=0; $i<@locations; $i++) {
                   6517:                     my ($showloc,$value,$checkedtype);
                   6518:                     if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
                   6519:                         my $ip = $by_location->{$locations[$i]}->[0];
                   6520:                         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6521:                             $value = join(':',@{$by_ip->{$ip}});
                   6522:                             $showloc = join(', ',@{$by_ip->{$ip}});
                   6523:                             if (ref($current{$type}) eq 'ARRAY') {
                   6524:                                 foreach my $loc (@{$by_ip->{$ip}}) {
                   6525:                                     if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   6526:                                         $checkedtype = ' checked="checked"';
                   6527:                                         last;
1.145     raeburn  6528:                                     }
1.138     raeburn  6529:                                 }
                   6530:                             }
                   6531:                         }
1.137     raeburn  6532:                     }
1.279     raeburn  6533:                     $rem = $i%($numinrow);
                   6534:                     if ($rem == 0) {
                   6535:                         if ($i > 0) {
                   6536:                             $datatable .= '</tr>';
                   6537:                         }
                   6538:                         $datatable .= '<tr>';
                   6539:                     }
                   6540:                     $datatable .= '<td class="LC_left_item">'.
                   6541:                                   '<span class="LC_nobreak"><label>'.
                   6542:                                   '<input type="checkbox" name="'.$prefix.'_'.$type.
                   6543:                                   '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   6544:                                   '</label></span></td>';
                   6545:                 }
                   6546:                 $rem = @locations%($numinrow);
                   6547:                 my $colsleft = $numinrow - $rem;
                   6548:                 if ($colsleft > 1 ) {
                   6549:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6550:                                   '&nbsp;</td>';
                   6551:                 } elsif ($colsleft == 1) {
                   6552:                     $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  6553:                 }
1.279     raeburn  6554:                 $datatable .= '</tr></table>';
1.137     raeburn  6555:             }
1.279     raeburn  6556:             $datatable .= '</td></tr>';
                   6557:             $itemcount ++;
1.137     raeburn  6558:         }
                   6559:     }
1.279     raeburn  6560:     return ($datatable,$itemcount);
1.137     raeburn  6561: }
                   6562: 
1.275     raeburn  6563: sub print_ssl {
                   6564:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6565:     my ($css_class,$datatable);
                   6566:     my $itemcount = 1;
                   6567:     if ($position eq 'top') {
1.281     raeburn  6568:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   6569:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   6570:         my $same_institution;
                   6571:         if ($intdom ne '') {
                   6572:             my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
                   6573:             if (ref($internet_names) eq 'ARRAY') {
                   6574:                 if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
                   6575:                     $same_institution = 1;
                   6576:                 }
                   6577:             }
                   6578:         }
1.275     raeburn  6579:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281     raeburn  6580:         $datatable = '<tr'.$css_class.'><td colspan="2">';
                   6581:         if ($same_institution) {
                   6582:             my %domservers = &Apache::lonnet::get_servers($dom);
                   6583:             $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
                   6584:         } else {
                   6585:             $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.");
                   6586:         }
                   6587:         $datatable .= '</td></tr>';
1.275     raeburn  6588:         $itemcount ++;
                   6589:     } else {
                   6590:         my %titles = &ssl_titles();
                   6591:         my (%by_ip,%by_location,@intdoms,@instdoms);
                   6592:         &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   6593:         my @alldoms = &Apache::lonnet::all_domains();
                   6594:         my %serverhomes = %Apache::lonnet::serverhomeIDs;
                   6595:         my @domservers = &Apache::lonnet::get_servers($dom);
                   6596:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   6597:         my %altids = &id_for_thisdom(%servers);
1.293     raeburn  6598:         if (($position eq 'connto') || ($position eq 'connfrom')) {
                   6599:             my $legacy;
                   6600:             unless (ref($settings) eq 'HASH') {
                   6601:                 my $name;
                   6602:                 if ($position eq 'connto') {
                   6603:                     $name = 'loncAllowInsecure';
                   6604:                 } else {
                   6605:                     $name = 'londAllowInsecure';
                   6606:                 }
                   6607:                 my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
                   6608:                 my @ids=&Apache::lonnet::current_machine_ids();
                   6609:                 if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
                   6610:                     my %what = (
                   6611:                                    $name => 1,
                   6612:                                );
                   6613:                     my ($result,$returnhash) =
                   6614:                         &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
                   6615:                     if ($result eq 'ok') {
                   6616:                         if (ref($returnhash) eq 'HASH') {
                   6617:                             $legacy = $returnhash->{$name};
                   6618:                         }
                   6619:                     }
                   6620:                 } else {
                   6621:                     $legacy = $Apache::lonnet::perlvar{$name};
                   6622:                 }
                   6623:             }
1.275     raeburn  6624:             foreach my $type ('dom','intdom','other') {
                   6625:                 my %checked;
                   6626:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6627:                 $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
                   6628:                               '<td class="LC_right_item">';
                   6629:                 my $skip; 
                   6630:                 if ($type eq 'dom') {
                   6631:                     unless (keys(%servers) > 1) {
                   6632:                         $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');    
                   6633:                         $skip = 1;
                   6634:                     }
                   6635:                 }
                   6636:                 if ($type eq 'intdom') {
                   6637:                     unless (@instdoms > 1) {
                   6638:                         $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
                   6639:                         $skip = 1;
                   6640:                     } 
                   6641:                 } elsif ($type eq 'other') {
                   6642:                     if (keys(%by_location) == 0) {
                   6643:                         $datatable .= &mt('Nothing to set here, as there are no other institutions');
                   6644:                         $skip = 1;
                   6645:                     }
                   6646:                 }
                   6647:                 unless ($skip) {
                   6648:                     $checked{'yes'} = ' checked="checked"'; 
                   6649:                     if (ref($settings) eq 'HASH') {
1.293     raeburn  6650:                         if (ref($settings->{$position}) eq 'HASH') {
                   6651:                             if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275     raeburn  6652:                                 $checked{$1} = $checked{'yes'};
                   6653:                                 delete($checked{'yes'}); 
                   6654:                             }
                   6655:                         }
1.293     raeburn  6656:                     } else {
                   6657:                         if ($legacy == 0) {
                   6658:                             $checked{'req'} = $checked{'yes'};
                   6659:                             delete($checked{'yes'});    
                   6660:                         }
1.275     raeburn  6661:                     }
                   6662:                     foreach my $option ('no','yes','req') {
                   6663:                         $datatable .= '<span class="LC_nobreak"><label>'.
1.293     raeburn  6664:                                       '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275     raeburn  6665:                                       'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                   6666:                                       '</label></span>'.('&nbsp;'x2);
                   6667:                     }
                   6668:                 }
                   6669:                 $datatable .= '</td></tr>';
                   6670:                 $itemcount ++; 
                   6671:             }
                   6672:         } else {
                   6673:             my $prefix = 'replication';
                   6674:             my @types = ('certreq','nocertreq');
1.279     raeburn  6675:             if (keys(%by_location) == 0) {
                   6676:                 $datatable .= '<tr'.$css_class.'><td>'.
                   6677:                               &mt('Nothing to set here, as there are no other institutions').
                   6678:                               '</td></tr>';
                   6679:                 $itemcount ++;
1.275     raeburn  6680:             } else {
1.279     raeburn  6681:                 ($datatable,$itemcount) = 
                   6682:                     &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275     raeburn  6683:             }
                   6684:         }
                   6685:     }
                   6686:     $$rowtotal += $itemcount;
                   6687:     return $datatable;
                   6688: }
                   6689: 
                   6690: sub ssl_titles {
                   6691:     return &Apache::lonlocal::texthash (
                   6692:                dom           => 'LON-CAPA servers/VMs from same domain',
                   6693:                intdom        => 'LON-CAPA servers/VMs from same "internet" domain',
                   6694:                other         => 'External LON-CAPA servers/VMs',
1.293     raeburn  6695:                connto        => 'Connections to other servers',
                   6696:                connfrom      => 'Connections from other servers',
1.275     raeburn  6697:                replication   => 'Replicating content to other institutions',
                   6698:                certreq       => 'Client certificate required, but specific domains exempt',
                   6699:                nocertreq     => 'No client certificate required, except for specific domains',
                   6700:                no            => 'SSL not used',
                   6701:                yes           => 'SSL Optional (used if available)',
                   6702:                req           => 'SSL Required',
                   6703:     );
1.279     raeburn  6704: }
                   6705: 
                   6706: sub print_trust {
                   6707:     my ($prefix,$dom,$settings,$rowtotal) = @_;
                   6708:     my ($css_class,$datatable,%checked,%choices);
                   6709:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   6710:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   6711:     my $itemcount = 1;
                   6712:     my %titles = &trust_titles();
                   6713:     my @types = ('exc','inc');
                   6714:     if ($prefix eq 'top') {
                   6715:         $prefix = 'content';
                   6716:     } elsif ($prefix eq 'bottom') {
                   6717:         $prefix = 'msg';
                   6718:     }
                   6719:     ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
                   6720:     $$rowtotal += $itemcount;
                   6721:     return $datatable;
                   6722: }
                   6723: 
                   6724: sub trust_titles {
                   6725:     return &Apache::lonlocal::texthash(
                   6726:                content  => "Access to this domain's content by others",
                   6727:                shared   => "Access to other domain's content by this domain",
                   6728:                enroll   => "Enrollment in this domain's courses by others", 
                   6729:                othcoau  => "Co-author roles in this domain for others",
                   6730:                coaurem  => "Co-author roles for this domain's users elsewhere", 
                   6731:                domroles => "Domain roles in this domain assignable to others",
                   6732:                catalog  => "Course Catalog for this domain displayed elsewhere",
                   6733:                reqcrs   => "Requests for creation of courses in this domain by others",
                   6734:                msg      => "Users in other domains can send messages to this domain",
                   6735:                exc      => "Allow all, but exclude specific domains",
                   6736:                inc      => "Deny all, but include specific domains",
                   6737:            );
1.275     raeburn  6738: } 
                   6739: 
1.138     raeburn  6740: sub build_location_hashes {
1.275     raeburn  6741:     my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138     raeburn  6742:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275     raeburn  6743:                   (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138     raeburn  6744:     my %iphost = &Apache::lonnet::get_iphost();
                   6745:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   6746:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   6747:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   6748:         foreach my $id (@{$iphost{$primary_ip}}) {
                   6749:             my $intdom = &Apache::lonnet::internet_dom($id);
                   6750:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   6751:                 push(@{$intdoms},$intdom);
                   6752:             }
                   6753:         }
                   6754:     }
                   6755:     foreach my $ip (keys(%iphost)) {
                   6756:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   6757:             foreach my $id (@{$iphost{$ip}}) {
                   6758:                 my $location = &Apache::lonnet::internet_dom($id);
                   6759:                 if ($location) {
1.275     raeburn  6760:                     if (grep(/^\Q$location\E$/,@{$intdoms})) {
                   6761:                         my $dom = &Apache::lonnet::host_domain($id);
                   6762:                         unless (grep(/^\Q$dom\E/,@{$instdoms})) {
                   6763:                             push(@{$instdoms},$dom);
                   6764:                         }
                   6765:                         next;
                   6766:                     }
1.138     raeburn  6767:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6768:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   6769:                             push(@{$by_ip->{$ip}},$location);
                   6770:                         }
                   6771:                     } else {
                   6772:                         $by_ip->{$ip} = [$location];
                   6773:                     }
                   6774:                 }
                   6775:             }
                   6776:         }
                   6777:     }
                   6778:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   6779:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6780:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   6781:             my $first = $by_ip->{$ip}->[0];
                   6782:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   6783:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   6784:                     push(@{$by_location->{$first}},$ip);
                   6785:                 }
                   6786:             } else {
                   6787:                 $by_location->{$first} = [$ip];
                   6788:             }
                   6789:         }
                   6790:     }
                   6791:     return;
                   6792: }
                   6793: 
1.145     raeburn  6794: sub current_offloads_to {
                   6795:     my ($dom,$settings,$servers) = @_;
                   6796:     my (%spareid,%otherdomconfigs);
1.152     raeburn  6797:     if (ref($servers) eq 'HASH') {
1.145     raeburn  6798:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   6799:             my $gotspares;
1.152     raeburn  6800:             if (ref($settings) eq 'HASH') {
                   6801:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   6802:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   6803:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   6804:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   6805:                         $gotspares = 1;
                   6806:                     }
1.145     raeburn  6807:                 }
                   6808:             }
                   6809:             unless ($gotspares) {
                   6810:                 my $gotspares;
                   6811:                 my $serverhomeID =
                   6812:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   6813:                 my $serverhomedom =
                   6814:                     &Apache::lonnet::host_domain($serverhomeID);
                   6815:                 if ($serverhomedom ne $dom) {
                   6816:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   6817:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6818:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6819:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6820:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6821:                                 $gotspares = 1;
                   6822:                             }
                   6823:                         }
                   6824:                     } else {
                   6825:                         $otherdomconfigs{$serverhomedom} =
                   6826:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   6827:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   6828:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6829:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6830:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   6831:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6832:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6833:                                         $gotspares = 1;
                   6834:                                     }
                   6835:                                 }
                   6836:                             }
                   6837:                         }
                   6838:                     }
                   6839:                 }
                   6840:             }
                   6841:             unless ($gotspares) {
                   6842:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6843:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6844:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6845:                } else {
                   6846:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   6847:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   6848:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6849:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6850:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6851:                     } else {
1.150     raeburn  6852:                         my %what = (
                   6853:                              spareid => 1,
                   6854:                         );
                   6855:                         my ($result,$returnhash) = 
                   6856:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   6857:                         if ($result eq 'ok') { 
                   6858:                             if (ref($returnhash) eq 'HASH') {
                   6859:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   6860:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   6861:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   6862:                                 }
                   6863:                             }
1.145     raeburn  6864:                         }
                   6865:                     }
                   6866:                 }
                   6867:             }
                   6868:         }
                   6869:     }
                   6870:     return %spareid;
                   6871: }
                   6872: 
                   6873: sub spares_row {
1.261     raeburn  6874:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  6875:     my $css_class;
                   6876:     my $numinrow = 4;
                   6877:     my $itemcount = 1;
                   6878:     my $datatable;
1.152     raeburn  6879:     my %typetitles = &sparestype_titles();
                   6880:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  6881:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  6882:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   6883:             my ($othercontrol,$serverdom);
                   6884:             if ($serverhome ne $server) {
                   6885:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   6886:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6887:             } else {
                   6888:                 $serverdom = &Apache::lonnet::host_domain($server);
                   6889:                 if ($serverdom ne $dom) {
                   6890:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6891:                 }
                   6892:             }
                   6893:             next unless (ref($spareid->{$server}) eq 'HASH');
1.261     raeburn  6894:             my $checkednow;
                   6895:             if (ref($curroffloadnow) eq 'HASH') {
                   6896:                 if ($curroffloadnow->{$server}) {
                   6897:                     $checkednow = ' checked="checked"';
                   6898:                 }
                   6899:             }
1.145     raeburn  6900:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6901:             $datatable .= '<tr'.$css_class.'>
                   6902:                            <td rowspan="2">
1.183     bisitz   6903:                             <span class="LC_nobreak">'.
                   6904:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  6905:                               ,'<b>'.$server.'</b>').'</span><br />'.
1.289     raeburn  6906:                           '<span class="LC_nobreak">'."\n".
1.261     raeburn  6907:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   6908:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.183     bisitz   6909:                           "\n";
1.145     raeburn  6910:             my (%current,%canselect);
1.152     raeburn  6911:             my @choices = 
                   6912:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   6913:             foreach my $type ('primary','default') {
                   6914:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  6915:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   6916:                         my @spares = @{$spareid->{$server}{$type}};
                   6917:                         if (@spares > 0) {
1.152     raeburn  6918:                             if ($othercontrol) {
                   6919:                                 $current{$type} = join(', ',@spares);
                   6920:                             } else {
                   6921:                                 $current{$type} .= '<table>';
                   6922:                                 my $numspares = scalar(@spares);
                   6923:                                 for (my $i=0;  $i<@spares; $i++) {
                   6924:                                     my $rem = $i%($numinrow);
                   6925:                                     if ($rem == 0) {
                   6926:                                         if ($i > 0) {
                   6927:                                             $current{$type} .= '</tr>';
                   6928:                                         }
                   6929:                                         $current{$type} .= '<tr>';
1.145     raeburn  6930:                                     }
1.152     raeburn  6931:                                     $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;'.
                   6932:                                                        $spareid->{$server}{$type}[$i].
                   6933:                                                        '</label></td>'."\n";
                   6934:                                 }
                   6935:                                 my $rem = @spares%($numinrow);
                   6936:                                 my $colsleft = $numinrow - $rem;
                   6937:                                 if ($colsleft > 1 ) {
                   6938:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   6939:                                                        '" class="LC_left_item">'.
                   6940:                                                        '&nbsp;</td>';
                   6941:                                 } elsif ($colsleft == 1) {
                   6942:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  6943:                                 }
1.152     raeburn  6944:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  6945:                             }
1.145     raeburn  6946:                         }
                   6947:                     }
                   6948:                     if ($current{$type} eq '') {
                   6949:                         $current{$type} = &mt('None specified');
                   6950:                     }
1.152     raeburn  6951:                     if ($othercontrol) {
                   6952:                         if ($type eq 'primary') {
                   6953:                             $canselect{$type} = $othercontrol;
                   6954:                         }
                   6955:                     } else {
                   6956:                         $canselect{$type} = 
                   6957:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   6958:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   6959:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   6960:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   6961:                         if (@choices > 0) {
                   6962:                             foreach my $lonhost (@choices) {
                   6963:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   6964:                             }
                   6965:                         }
                   6966:                         $canselect{$type} .= '</select>'."\n";
                   6967:                     }
                   6968:                 } else {
                   6969:                     $current{$type} = &mt('Could not be determined');
                   6970:                     if ($type eq 'primary') {
                   6971:                         $canselect{$type} =  $othercontrol;
                   6972:                     }
1.145     raeburn  6973:                 }
1.152     raeburn  6974:                 if ($type eq 'default') {
                   6975:                     $datatable .= '<tr'.$css_class.'>';
                   6976:                 }
                   6977:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   6978:                               '<td>'.$current{$type}.'</td>'."\n".
                   6979:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  6980:             }
                   6981:             $itemcount ++;
                   6982:         }
                   6983:     }
                   6984:     $$rowtotal += $itemcount;
                   6985:     return $datatable;
                   6986: }
                   6987: 
1.152     raeburn  6988: sub possible_newspares {
                   6989:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   6990:     my $serverhostname = &Apache::lonnet::hostname($server);
                   6991:     my %excluded;
                   6992:     if ($serverhostname ne '') {
                   6993:         %excluded = (
                   6994:                        $serverhostname => 1,
                   6995:                     );
                   6996:     }
                   6997:     if (ref($currspares) eq 'HASH') {
                   6998:         foreach my $type (keys(%{$currspares})) {
                   6999:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   7000:                 if (@{$currspares->{$type}} > 0) {
                   7001:                     foreach my $curr (@{$currspares->{$type}}) {
                   7002:                         my $hostname = &Apache::lonnet::hostname($curr);
                   7003:                         $excluded{$hostname} = 1;
                   7004:                     }
                   7005:                 }
                   7006:             }
                   7007:         }
                   7008:     }
                   7009:     my @choices;
                   7010:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   7011:         if (keys(%{$serverhomes}) > 1) {
                   7012:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   7013:                 unless ($excluded{$name}) {
                   7014:                     if (exists($altids->{$serverhomes->{$name}})) {
                   7015:                         push(@choices,$altids->{$serverhomes->{$name}});
                   7016:                     } else {
                   7017:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  7018:                     }
                   7019:                 }
                   7020:             }
                   7021:         }
                   7022:     }
1.152     raeburn  7023:     return sort(@choices);
1.145     raeburn  7024: }
                   7025: 
1.150     raeburn  7026: sub print_loadbalancing {
                   7027:     my ($dom,$settings,$rowtotal) = @_;
                   7028:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7029:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7030:     my $numinrow = 1;
                   7031:     my $datatable;
                   7032:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342     raeburn  7033:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  7034:     if (ref($settings) eq 'HASH') {
                   7035:         %existing = %{$settings};
                   7036:     }
                   7037:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   7038:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  7039:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  7040:     } else {
                   7041:         return;
                   7042:     }
                   7043:     my ($othertitle,$usertypes,$types) =
                   7044:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  7045:     my $rownum = 8;
1.150     raeburn  7046:     if (ref($types) eq 'ARRAY') {
                   7047:         $rownum += scalar(@{$types});
                   7048:     }
1.171     raeburn  7049:     my @css_class = ('LC_odd_row','LC_even_row');
                   7050:     my $balnum = 0;
                   7051:     my $islast;
                   7052:     my (@toshow,$disabledtext);
                   7053:     if (keys(%currbalancer) > 0) {
                   7054:         @toshow = sort(keys(%currbalancer));
                   7055:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   7056:             push(@toshow,'');
                   7057:         }
                   7058:     } else {
                   7059:         @toshow = ('');
                   7060:         $disabledtext = &mt('No existing load balancer');
                   7061:     }
                   7062:     foreach my $lonhost (@toshow) {
                   7063:         if ($balnum == scalar(@toshow)-1) {
                   7064:             $islast = 1;
                   7065:         } else {
                   7066:             $islast = 0;
                   7067:         }
                   7068:         my $cssidx = $balnum%2;
                   7069:         my $targets_div_style = 'display: none';
                   7070:         my $disabled_div_style = 'display: block';
                   7071:         my $homedom_div_style = 'display: none';
                   7072:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306     raeburn  7073:                       '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  7074:                       '<p>';
                   7075:         if ($lonhost eq '') {
1.210     raeburn  7076:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  7077:             if (keys(%currbalancer) > 0) {
                   7078:                 $datatable .= &mt('Add balancer:');
                   7079:             } else {
                   7080:                 $datatable .= &mt('Enable balancer:');
                   7081:             }
                   7082:             $datatable .= '&nbsp;'.
                   7083:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   7084:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   7085:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   7086:                           '<option value="" selected="selected">'.&mt('None').
                   7087:                           '</option>'."\n";
                   7088:             foreach my $server (sort(keys(%servers))) {
                   7089:                 next if ($currbalancer{$server});
                   7090:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   7091:             }
1.210     raeburn  7092:             $datatable .=
1.171     raeburn  7093:                 '</select>'."\n".
                   7094:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   7095:         } else {
                   7096:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   7097:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   7098:                            &mt('Stop balancing').'</label>'.
                   7099:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   7100:             $targets_div_style = 'display: block';
                   7101:             $disabled_div_style = 'display: none';
                   7102:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   7103:                 $homedom_div_style = 'display: block';
                   7104:             }
                   7105:         }
1.306     raeburn  7106:         $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171     raeburn  7107:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   7108:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   7109:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   7110:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   7111:         my @sparestypes = ('primary','default');
                   7112:         my %typetitles = &sparestype_titles();
1.284     raeburn  7113:         my %hostherechecked = (
                   7114:                                   no => ' checked="checked"',
                   7115:                               );
1.342     raeburn  7116:         my %balcookiechecked = (
                   7117:                                   no => ' checked="checked"', 
                   7118:                                );
1.171     raeburn  7119:         foreach my $sparetype (@sparestypes) {
                   7120:             my $targettable;
                   7121:             for (my $i=0; $i<$numspares; $i++) {
                   7122:                 my $checked;
                   7123:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7124:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7125:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7126:                             $checked = ' checked="checked"';
                   7127:                         }
                   7128:                     }
                   7129:                 }
                   7130:                 my ($chkboxval,$disabled);
                   7131:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   7132:                     $chkboxval = $spares[$i];
                   7133:                 }
                   7134:                 if (exists($currbalancer{$spares[$i]})) {
                   7135:                     $disabled = ' disabled="disabled"';
                   7136:                 }
1.210     raeburn  7137:                 $targettable .=
1.253     raeburn  7138:                     '<td><span class="LC_nobreak"><label>'.
                   7139:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  7140:                     $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  7141:                     '</span></label></span></td>';
1.171     raeburn  7142:                 my $rem = $i%($numinrow);
                   7143:                 if ($rem == 0) {
                   7144:                     if (($i > 0) && ($i < $numspares-1)) {
                   7145:                         $targettable .= '</tr>';
                   7146:                     }
                   7147:                     if ($i < $numspares-1) {
                   7148:                         $targettable .= '<tr>';
1.150     raeburn  7149:                     }
                   7150:                 }
                   7151:             }
1.171     raeburn  7152:             if ($targettable ne '') {
                   7153:                 my $rem = $numspares%($numinrow);
                   7154:                 my $colsleft = $numinrow - $rem;
                   7155:                 if ($colsleft > 1 ) {
                   7156:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7157:                                     '&nbsp;</td>';
                   7158:                 } elsif ($colsleft == 1) {
                   7159:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   7160:                 }
                   7161:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   7162:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   7163:             }
1.284     raeburn  7164:             $hostherechecked{$sparetype} = '';
                   7165:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7166:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7167:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7168:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   7169:                         $hostherechecked{'no'} = '';
                   7170:                     }
                   7171:                 }
                   7172:             }
                   7173:         }
1.342     raeburn  7174:         if ($currcookies{$lonhost}) {
                   7175:             %balcookiechecked = (
                   7176:                                     yes => ' checked="checked"',
                   7177:                                 );
                   7178:         }
1.284     raeburn  7179:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   7180:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   7181:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   7182:         foreach my $sparetype (@sparestypes) {
                   7183:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   7184:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   7185:                           '</i></label><br />';
1.171     raeburn  7186:         }
1.342     raeburn  7187:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   7188:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   7189:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   7190:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   7191:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   7192:                       '</div></td></tr>'.
1.171     raeburn  7193:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   7194:                                            $othertitle,$usertypes,$types,\%servers,
                   7195:                                            \%currbalancer,$lonhost,
                   7196:                                            $targets_div_style,$homedom_div_style,
                   7197:                                            $css_class[$cssidx],$balnum,$islast);
                   7198:         $$rowtotal += $rownum;
                   7199:         $balnum ++;
                   7200:     }
                   7201:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   7202:     return $datatable;
                   7203: }
                   7204: 
                   7205: sub get_loadbalancers_config {
1.342     raeburn  7206:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171     raeburn  7207:     return unless ((ref($servers) eq 'HASH') &&
                   7208:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342     raeburn  7209:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   7210:                    (ref($currcookies) eq 'HASH'));
1.171     raeburn  7211:     if (keys(%{$existing}) > 0) {
                   7212:         my $oldlonhost;
                   7213:         foreach my $key (sort(keys(%{$existing}))) {
                   7214:             if ($key eq 'lonhost') {
                   7215:                 $oldlonhost = $existing->{'lonhost'};
                   7216:                 $currbalancer->{$oldlonhost} = 1;
                   7217:             } elsif ($key eq 'targets') {
                   7218:                 if ($oldlonhost) {
                   7219:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   7220:                 }
                   7221:             } elsif ($key eq 'rules') {
                   7222:                 if ($oldlonhost) {
                   7223:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   7224:                 }
                   7225:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   7226:                 $currbalancer->{$key} = 1;
                   7227:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   7228:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.342     raeburn  7229:                 if ($existing->{$key}{'cookie'}) {
                   7230:                     $currcookies->{$key} = 1;
                   7231:                 }
1.150     raeburn  7232:             }
                   7233:         }
1.171     raeburn  7234:     } else {
                   7235:         my ($balancerref,$targetsref) =
                   7236:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   7237:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   7238:             foreach my $server (sort(keys(%{$balancerref}))) {
                   7239:                 $currbalancer->{$server} = 1;
                   7240:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  7241:             }
                   7242:         }
                   7243:     }
1.171     raeburn  7244:     return;
1.150     raeburn  7245: }
                   7246: 
                   7247: sub loadbalancing_rules {
                   7248:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  7249:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   7250:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  7251:     my $output;
1.171     raeburn  7252:     my $num = 0;
1.210     raeburn  7253:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  7254:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7255:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   7256:         foreach my $type (@{$alltypes}) {
1.171     raeburn  7257:             $num ++;
1.150     raeburn  7258:             my $current;
                   7259:             if (ref($currrules) eq 'HASH') {
                   7260:                 $current = $currrules->{$type};
                   7261:             }
1.253     raeburn  7262:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  7263:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  7264:                     $current = '';
                   7265:                 }
                   7266:             }
                   7267:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  7268:                                              $servers,$currbalancer,$lonhost,$dom,
                   7269:                                              $targets_div_style,$homedom_div_style,
                   7270:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  7271:         }
                   7272:     }
                   7273:     return $output;
                   7274: }
                   7275: 
                   7276: sub loadbalancing_titles {
                   7277:     my ($dom,$intdom,$usertypes,$types) = @_;
                   7278:     my %othertypes = (
                   7279:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   7280:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   7281:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   7282:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  7283:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   7284:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  7285:                      );
1.209     raeburn  7286:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302     raeburn  7287:     my @available;
1.150     raeburn  7288:     if (ref($types) eq 'ARRAY') {
1.302     raeburn  7289:         @available = @{$types};
1.150     raeburn  7290:     }
1.302     raeburn  7291:     unless (grep(/^default$/,@available)) {
                   7292:         push(@available,'default');
                   7293:     }
                   7294:     unshift(@alltypes,@available);
1.150     raeburn  7295:     my %titles;
                   7296:     foreach my $type (@alltypes) {
                   7297:         if ($type =~ /^_LC_/) {
                   7298:             $titles{$type} = $othertypes{$type};
                   7299:         } elsif ($type eq 'default') {
                   7300:             $titles{$type} = &mt('All users from [_1]',$dom);
                   7301:             if (ref($types) eq 'ARRAY') {
                   7302:                 if (@{$types} > 0) {
                   7303:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   7304:                 }
                   7305:             }
                   7306:         } elsif (ref($usertypes) eq 'HASH') {
                   7307:             $titles{$type} = $usertypes->{$type};
                   7308:         }
                   7309:     }
                   7310:     return (\@alltypes,\%othertypes,\%titles);
                   7311: }
                   7312: 
                   7313: sub loadbalance_rule_row {
1.171     raeburn  7314:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   7315:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  7316:     my @rulenames;
1.150     raeburn  7317:     my %ruletitles = &offloadtype_text();
1.209     raeburn  7318:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  7319:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  7320:     } else {
1.209     raeburn  7321:         @rulenames = ('default','homeserver');
                   7322:         if ($type eq '_LC_external') {
                   7323:             push(@rulenames,'externalbalancer');
                   7324:         } else {
                   7325:             push(@rulenames,'specific');
                   7326:         }
                   7327:         push(@rulenames,'none');
1.150     raeburn  7328:     }
                   7329:     my $style = $targets_div_style;
1.253     raeburn  7330:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  7331:         $style = $homedom_div_style;
                   7332:     }
1.171     raeburn  7333:     my $space;
                   7334:     if ($islast && $num == 1) {
1.317     raeburn  7335:         $space = '<div style="display:inline-block;">&nbsp;</div>';
1.171     raeburn  7336:     }
1.210     raeburn  7337:     my $output =
1.306     raeburn  7338:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171     raeburn  7339:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   7340:         '<td valaign="top">'.$space.
                   7341:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  7342:     for (my $i=0; $i<@rulenames; $i++) {
                   7343:         my $rule = $rulenames[$i];
                   7344:         my ($checked,$extra);
                   7345:         if ($rulenames[$i] eq 'default') {
                   7346:             $rule = '';
                   7347:         }
                   7348:         if ($rulenames[$i] eq 'specific') {
                   7349:             if (ref($servers) eq 'HASH') {
                   7350:                 my $default;
                   7351:                 if (($current ne '') && (exists($servers->{$current}))) {
                   7352:                     $checked = ' checked="checked"';
                   7353:                 }
                   7354:                 unless ($checked) {
                   7355:                     $default = ' selected="selected"';
                   7356:                 }
1.210     raeburn  7357:                 $extra =
1.171     raeburn  7358:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7359:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7360:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   7361:                     '<option value=""'.$default.'></option>'."\n";
                   7362:                 foreach my $server (sort(keys(%{$servers}))) {
                   7363:                     if (ref($currbalancer) eq 'HASH') {
                   7364:                         next if (exists($currbalancer->{$server}));
                   7365:                     }
1.150     raeburn  7366:                     my $selected;
1.171     raeburn  7367:                     if ($server eq $current) {
1.150     raeburn  7368:                         $selected = ' selected="selected"';
                   7369:                     }
1.171     raeburn  7370:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  7371:                 }
                   7372:                 $extra .= '</select>';
                   7373:             }
                   7374:         } elsif ($rule eq $current) {
                   7375:             $checked = ' checked="checked"';
                   7376:         }
                   7377:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  7378:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   7379:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   7380:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  7381:                    ')"'.$checked.' />&nbsp;';
                   7382:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   7383:             $output .= $ruletitles{'particular'};
                   7384:         } else {
                   7385:             $output .= $ruletitles{$rulenames[$i]};
                   7386:         }
                   7387:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  7388:     }
                   7389:     $output .= '</div></td></tr>'."\n";
                   7390:     return $output;
                   7391: }
                   7392: 
                   7393: sub offloadtype_text {
                   7394:     my %ruletitles = &Apache::lonlocal::texthash (
                   7395:            'default'          => 'Offloads to default destinations',
                   7396:            'homeserver'       => "Offloads to user's home server",
                   7397:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   7398:            'specific'         => 'Offloads to specific server',
1.161     raeburn  7399:            'none'             => 'No offload',
1.209     raeburn  7400:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   7401:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  7402:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  7403:     );
                   7404:     return %ruletitles;
                   7405: }
                   7406: 
                   7407: sub sparestype_titles {
                   7408:     my %typestitles = &Apache::lonlocal::texthash (
                   7409:                           'primary' => 'primary',
                   7410:                           'default' => 'default',
                   7411:                       );
                   7412:     return %typestitles;
                   7413: }
                   7414: 
1.28      raeburn  7415: sub contact_titles {
                   7416:     my %titles = &Apache::lonlocal::texthash (
1.286     raeburn  7417:                    'supportemail'    => 'Support E-mail address',
                   7418:                    'adminemail'      => 'Default Server Admin E-mail address',
                   7419:                    'errormail'       => 'Error reports to be e-mailed to',
                   7420:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.315     raeburn  7421:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   7422:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.286     raeburn  7423:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   7424:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   7425:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  7426:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350     raeburn  7427:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.340     raeburn  7428:                    'errorthreshold'  => 'Error/warning threshold for status e-mail',
                   7429:                    'errorsysmail'    => 'Error threshold for e-mail to core group',
                   7430:                    'errorweights'    => 'Weights used to compute error count',
                   7431:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  7432:                  );
                   7433:     my %short_titles = &Apache::lonlocal::texthash (
                   7434:                            adminemail   => 'Admin E-mail address',
                   7435:                            supportemail => 'Support E-mail',
                   7436:                        );   
                   7437:     return (\%titles,\%short_titles);
                   7438: }
                   7439: 
1.286     raeburn  7440: sub helpform_fields {
                   7441:     my %titles =  &Apache::lonlocal::texthash (
                   7442:                        'username'   => 'Name',
                   7443:                        'user'       => 'Username/domain',
                   7444:                        'phone'      => 'Phone',
                   7445:                        'cc'         => 'Cc e-mail',
                   7446:                        'course'     => 'Course Details',
                   7447:                        'section'    => 'Sections',
1.289     raeburn  7448:                        'screenshot' => 'File upload',
1.286     raeburn  7449:     );
                   7450:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   7451:     my %possoptions = (
                   7452:                         username     => ['yes','no','req'],
1.289     raeburn  7453:                         phone        => ['yes','no','req'],
1.286     raeburn  7454:                         user         => ['yes','no'],
1.289     raeburn  7455:                         cc           => ['yes','no'],
1.286     raeburn  7456:                         course       => ['yes','no'],
                   7457:                         section      => ['yes','no'],
                   7458:                         screenshot   => ['yes','no'],
                   7459:                       );
                   7460:     my %fieldoptions = &Apache::lonlocal::texthash (
                   7461:                          'yes'  => 'Optional',
                   7462:                          'req'  => 'Required',
                   7463:                          'no'   => "Not shown",
                   7464:     );
                   7465:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   7466: }
                   7467: 
1.72      raeburn  7468: sub tool_titles {
                   7469:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  7470:                      aboutme    => 'Personal web page',
1.86      raeburn  7471:                      blog       => 'Blog',
1.162     raeburn  7472:                      webdav     => 'WebDAV',
1.86      raeburn  7473:                      portfolio  => 'Portfolio',
1.88      bisitz   7474:                      official   => 'Official courses (with institutional codes)',
                   7475:                      unofficial => 'Unofficial courses',
1.98      raeburn  7476:                      community  => 'Communities',
1.216     raeburn  7477:                      textbook   => 'Textbook courses',
1.271     raeburn  7478:                      placement  => 'Placement tests',
1.86      raeburn  7479:                  );
1.72      raeburn  7480:     return %titles;
                   7481: }
                   7482: 
1.101     raeburn  7483: sub courserequest_titles {
                   7484:     my %titles = &Apache::lonlocal::texthash (
                   7485:                                    official   => 'Official',
                   7486:                                    unofficial => 'Unofficial',
                   7487:                                    community  => 'Communities',
1.216     raeburn  7488:                                    textbook   => 'Textbook',
1.271     raeburn  7489:                                    placement  => 'Placement tests',
1.325     raeburn  7490:                                    lti        => 'LTI Provider',
1.101     raeburn  7491:                                    norequest  => 'Not allowed',
1.325     raeburn  7492:                                    approval   => 'Approval by DC',
1.101     raeburn  7493:                                    validate   => 'With validation',
                   7494:                                    autolimit  => 'Numerical limit',
1.103     raeburn  7495:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  7496:                  );
                   7497:     return %titles;
                   7498: }
                   7499: 
1.163     raeburn  7500: sub authorrequest_titles {
                   7501:     my %titles = &Apache::lonlocal::texthash (
                   7502:                                    norequest  => 'Not allowed',
                   7503:                                    approval   => 'Approval by Dom. Coord.',
                   7504:                                    automatic  => 'Automatic approval',
                   7505:                  );
                   7506:     return %titles;
1.210     raeburn  7507: }
1.163     raeburn  7508: 
1.101     raeburn  7509: sub courserequest_conditions {
                   7510:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  7511:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   7512:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  7513:                  );
                   7514:     return %conditions;
                   7515: }
                   7516: 
                   7517: 
1.27      raeburn  7518: sub print_usercreation {
1.30      raeburn  7519:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  7520:     my $numinrow = 4;
1.28      raeburn  7521:     my $datatable;
                   7522:     if ($position eq 'top') {
1.30      raeburn  7523:         $$rowtotal ++;
1.34      raeburn  7524:         my $rowcount = 0;
1.32      raeburn  7525:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  7526:         if (ref($rules) eq 'HASH') {
                   7527:             if (keys(%{$rules}) > 0) {
1.32      raeburn  7528:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   7529:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  7530:                 $$rowtotal ++;
1.32      raeburn  7531:                 $rowcount ++;
                   7532:             }
                   7533:         }
                   7534:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   7535:         if (ref($idrules) eq 'HASH') {
                   7536:             if (keys(%{$idrules}) > 0) {
                   7537:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   7538:                                                 $idruleorder,$numinrow,$rowcount);
                   7539:                 $$rowtotal ++;
                   7540:                 $rowcount ++;
1.28      raeburn  7541:             }
                   7542:         }
1.39      raeburn  7543:         if ($rowcount == 0) {
                   7544:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   7545:             $$rowtotal ++;
                   7546:             $rowcount ++;
                   7547:         }
1.34      raeburn  7548:     } elsif ($position eq 'middle') {
1.224     raeburn  7549:         my @creators = ('author','course','requestcrs');
1.37      raeburn  7550:         my ($rules,$ruleorder) =
                   7551:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  7552:         my %lt = &usercreation_types();
                   7553:         my %checked;
                   7554:         if (ref($settings) eq 'HASH') {
                   7555:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7556:                 foreach my $item (@creators) {
                   7557:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   7558:                 }
                   7559:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   7560:                 foreach my $item (@creators) {
                   7561:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   7562:                         $checked{$item} = 'none';
                   7563:                     }
                   7564:                 }
                   7565:             }
                   7566:         }
                   7567:         my $rownum = 0;
                   7568:         foreach my $item (@creators) {
                   7569:             $rownum ++;
1.224     raeburn  7570:             if ($checked{$item} eq '') {
                   7571:                 $checked{$item} = 'any';
1.34      raeburn  7572:             }
                   7573:             my $css_class;
                   7574:             if ($rownum%2) {
                   7575:                 $css_class = '';
                   7576:             } else {
                   7577:                 $css_class = ' class="LC_odd_row" ';
                   7578:             }
                   7579:             $datatable .= '<tr'.$css_class.'>'.
                   7580:                          '<td><span class="LC_nobreak">'.$lt{$item}.
1.306     raeburn  7581:                          '</span></td><td style="text-align: right">';
1.224     raeburn  7582:             my @options = ('any');
                   7583:             if (ref($rules) eq 'HASH') {
                   7584:                 if (keys(%{$rules}) > 0) {
                   7585:                     push(@options,('official','unofficial'));
1.37      raeburn  7586:                 }
                   7587:             }
1.224     raeburn  7588:             push(@options,'none');
1.37      raeburn  7589:             foreach my $option (@options) {
1.50      raeburn  7590:                 my $type = 'radio';
1.34      raeburn  7591:                 my $check = ' ';
1.224     raeburn  7592:                 if ($checked{$item} eq $option) {
                   7593:                     $check = ' checked="checked" ';
1.34      raeburn  7594:                 } 
                   7595:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  7596:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  7597:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   7598:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   7599:             }
                   7600:             $datatable .= '</td></tr>';
                   7601:         }
1.28      raeburn  7602:     } else {
                   7603:         my @contexts = ('author','course','domain');
1.325     raeburn  7604:         my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  7605:         my %checked;
                   7606:         if (ref($settings) eq 'HASH') {
                   7607:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   7608:                 foreach my $item (@contexts) {
                   7609:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   7610:                         foreach my $auth (@authtypes) {
                   7611:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   7612:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   7613:                             }
                   7614:                         }
                   7615:                     }
                   7616:                 }
1.27      raeburn  7617:             }
1.35      raeburn  7618:         } else {
                   7619:             foreach my $item (@contexts) {
1.36      raeburn  7620:                 foreach my $auth (@authtypes) {
1.35      raeburn  7621:                     $checked{$item}{$auth} = ' checked="checked" ';
                   7622:                 }
                   7623:             }
1.27      raeburn  7624:         }
1.28      raeburn  7625:         my %title = &context_names();
                   7626:         my %authname = &authtype_names();
                   7627:         my $rownum = 0;
                   7628:         my $css_class; 
                   7629:         foreach my $item (@contexts) {
                   7630:             if ($rownum%2) {
                   7631:                 $css_class = '';
                   7632:             } else {
                   7633:                 $css_class = ' class="LC_odd_row" ';
                   7634:             }
1.30      raeburn  7635:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  7636:                             '<td>'.$title{$item}.
                   7637:                             '</td><td class="LC_left_item">'.
                   7638:                             '<span class="LC_nobreak">';
                   7639:             foreach my $auth (@authtypes) {
                   7640:                 $datatable .= '<label>'. 
                   7641:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   7642:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   7643:                               $authname{$auth}.'</label>&nbsp;';
                   7644:             }
                   7645:             $datatable .= '</span></td></tr>';
                   7646:             $rownum ++;
1.27      raeburn  7647:         }
1.30      raeburn  7648:         $$rowtotal += $rownum;
1.27      raeburn  7649:     }
                   7650:     return $datatable;
                   7651: }
                   7652: 
1.224     raeburn  7653: sub print_selfcreation {
                   7654:     my ($position,$dom,$settings,$rowtotal) = @_;
1.305     raeburn  7655:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   7656:         $emaildomain,$datatable);
1.224     raeburn  7657:     if (ref($settings) eq 'HASH') {
                   7658:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7659:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  7660:             if (ref($createsettings) eq 'HASH') {
                   7661:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   7662:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   7663:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   7664:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   7665:                         @selfcreate = ('email','login','sso');
                   7666:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   7667:                         @selfcreate = ($createsettings->{'selfcreate'});
                   7668:                     }
                   7669:                 }
                   7670:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   7671:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  7672:                 }
1.305     raeburn  7673:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   7674:                     $emailoptions = $createsettings->{'emailoptions'};
                   7675:                 }
1.303     raeburn  7676:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   7677:                     $emailverified = $createsettings->{'emailverified'};
                   7678:                 }
                   7679:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   7680:                     $emaildomain = $createsettings->{'emaildomain'};
                   7681:                 }
1.224     raeburn  7682:             }
                   7683:         }
                   7684:     }
                   7685:     my %radiohash;
                   7686:     my $numinrow = 4;
                   7687:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302     raeburn  7688:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224     raeburn  7689:     if ($position eq 'top') {
                   7690:         my %choices = &Apache::lonlocal::texthash (
                   7691:                                                       cancreate_login      => 'Institutional Login',
                   7692:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   7693:                                                   );
                   7694:         my @toggles = sort(keys(%choices));
                   7695:         my %defaultchecked = (
                   7696:                                'cancreate_login' => 'off',
                   7697:                                'cancreate_sso'   => 'off',
                   7698:                              );
1.228     raeburn  7699:         my ($onclick,$itemcount);
1.224     raeburn  7700:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7701:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  7702:         $$rowtotal += $itemcount;
                   7703:         
1.224     raeburn  7704:         if (ref($usertypes) eq 'HASH') {
                   7705:             if (keys(%{$usertypes}) > 0) {
                   7706:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   7707:                                              $dom,$numinrow,$othertitle,
1.305     raeburn  7708:                                              'statustocreate',$rowtotal);
1.224     raeburn  7709:                 $$rowtotal ++;
                   7710:             }
                   7711:         }
1.240     raeburn  7712:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   7713:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7714:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   7715:         my $rem;
                   7716:         my $numperrow = 2;
                   7717:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   7718:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  7719:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  7720:                      '<td class="LC_left_item">'."\n".
1.334     raeburn  7721:                      '<table>'."\n";
1.240     raeburn  7722:         for (my $i=0; $i<@fields; $i++) {
                   7723:             $rem = $i%($numperrow);
                   7724:             if ($rem == 0) {
                   7725:                 if ($i > 0) {
                   7726:                     $datatable .= '</tr>';
                   7727:                 }
                   7728:                 $datatable .= '<tr>';
                   7729:             }
                   7730:             my $currval;
1.248     raeburn  7731:             if (ref($createsettings) eq 'HASH') {
                   7732:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   7733:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   7734:                 }
1.240     raeburn  7735:             }
                   7736:             $datatable .= '<td class="LC_left_item">'.
                   7737:                           '<span class="LC_nobreak">'.
                   7738:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   7739:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   7740:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   7741:         }
                   7742:         my $colsleft = $numperrow - $rem;
                   7743:         if ($colsleft > 1 ) {
                   7744:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7745:                          '&nbsp;</td>';
                   7746:         } elsif ($colsleft == 1) {
                   7747:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7748:         }
                   7749:         $datatable .= '</tr></table></td></tr>';
                   7750:         $$rowtotal ++;
1.224     raeburn  7751:     } elsif ($position eq 'middle') {
                   7752:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302     raeburn  7753:         my @posstypes;
1.224     raeburn  7754:         if (ref($types) eq 'ARRAY') {
1.302     raeburn  7755:             @posstypes = @{$types};
                   7756:         }
                   7757:         unless (grep(/^default$/,@posstypes)) {
                   7758:             push(@posstypes,'default');
                   7759:         }
                   7760:         my %usertypeshash;
                   7761:         if (ref($usertypes) eq 'HASH') {
                   7762:             %usertypeshash = %{$usertypes};
                   7763:         }
                   7764:         $usertypeshash{'default'} = $othertitle;
                   7765:         foreach my $status (@posstypes) {
                   7766:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   7767:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   7768:             $$rowtotal ++;
1.224     raeburn  7769:         }
                   7770:     } else {
1.236     raeburn  7771:         my %choices = &Apache::lonlocal::texthash (
1.305     raeburn  7772:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236     raeburn  7773:                                                   );
                   7774:         my @toggles = sort(keys(%choices));
                   7775:         my %defaultchecked = (
                   7776:                                'cancreate_email' => 'off',
                   7777:                              );
1.305     raeburn  7778:         my $customclass = 'LC_selfcreate_email';
                   7779:         my $classprefix = 'LC_canmodify_emailusername_';
                   7780:         my $optionsprefix = 'LC_options_emailusername_';
1.236     raeburn  7781:         my $display = 'none';
1.305     raeburn  7782:         my $rowstyle = 'display:none';
1.236     raeburn  7783:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   7784:             $display = 'block';
1.305     raeburn  7785:             $rowstyle = 'display:table-row';
1.236     raeburn  7786:         }
1.305     raeburn  7787:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   7788:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7789:                                                      \%choices,$$rowtotal,$onclick);
                   7790:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   7791:                                          $rowstyle);
                   7792:         $$rowtotal ++;
                   7793:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   7794:                                       $rowstyle);
                   7795:         $$rowtotal ++;
                   7796:         my (@ordered,@posstypes,%usertypeshash);
1.236     raeburn  7797:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305     raeburn  7798:         my ($emailrules,$emailruleorder) =
                   7799:             &Apache::lonnet::inst_userrules($dom,'email');
                   7800:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7801:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7802:         if (ref($types) eq 'ARRAY') {
                   7803:             @posstypes = @{$types};
                   7804:         }
                   7805:         if (@posstypes) {
                   7806:             unless (grep(/^default$/,@posstypes)) {
                   7807:                 push(@posstypes,'default');
1.302     raeburn  7808:             }
                   7809:             if (ref($usertypes) eq 'HASH') {
                   7810:                 %usertypeshash = %{$usertypes};
                   7811:             }
1.305     raeburn  7812:             my $currassign;
                   7813:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   7814:                 $currassign = {
                   7815:                                   selfassign => $domdefaults{'inststatusguest'},
                   7816:                               };
                   7817:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   7818:             } else {
                   7819:                 $currassign = { selfassign => [] };
                   7820:             }
                   7821:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   7822:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   7823:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   7824:                                          $numinrow,$othertitle,'selfassign',
                   7825:                                          $rowtotal,$onclicktypes,$customclass,
                   7826:                                          $rowstyle);
                   7827:             $$rowtotal ++;
1.302     raeburn  7828:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  7829:             foreach my $status (@posstypes) {
                   7830:                 my $css_class;
                   7831:                 if ($$rowtotal%2) {
                   7832:                     $css_class = 'LC_odd_row ';
                   7833:                 }
                   7834:                 $css_class .= $customclass;
                   7835:                 my $rowid = $optionsprefix.$status;
                   7836:                 my $hidden = 1;
                   7837:                 my $currstyle = 'display:none';
                   7838:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   7839:                     $currstyle = $rowstyle;
                   7840:                     $hidden = 0; 
                   7841:                 }
                   7842:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7843:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   7844:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   7845:                 unless ($hidden) {
                   7846:                     $$rowtotal ++;
                   7847:                 }
1.224     raeburn  7848:             }
1.302     raeburn  7849:         } else {
1.305     raeburn  7850:             my $css_class;
                   7851:             if ($$rowtotal%2) {
                   7852:                 $css_class = 'LC_odd_row ';
                   7853:             }
                   7854:             $css_class .= $customclass;
1.302     raeburn  7855:             $usertypeshash{'default'} = $othertitle;
1.305     raeburn  7856:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7857:                                          $emailrules,$emailruleorder,$settings,'default','',
                   7858:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   7859:             $$rowtotal ++;
1.224     raeburn  7860:         }
                   7861:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  7862:         $numinrow = 1;
1.305     raeburn  7863:         if (@posstypes) {
                   7864:             foreach my $status (@posstypes) {
                   7865:                 my $rowid = $classprefix.$status;
                   7866:                 my $datarowstyle = 'display:none';
                   7867:                 if (grep(/^\Q$status\E$/,@ordered)) { 
                   7868:                     $datarowstyle = $rowstyle; 
                   7869:                 }
                   7870:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   7871:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7872:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   7873:                 unless ($datarowstyle eq 'display:none') {
                   7874:                     $$rowtotal ++;
                   7875:                 }
1.224     raeburn  7876:             }
1.305     raeburn  7877:         } else {
                   7878:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   7879:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7880:                                                    $infotitles,'',$customclass,$rowstyle);
1.224     raeburn  7881:         }
                   7882:     }
                   7883:     return $datatable;
                   7884: }
                   7885: 
1.305     raeburn  7886: sub selfcreate_javascript {
                   7887:     return <<"ENDSCRIPT";
                   7888: 
                   7889: <script type="text/javascript">
                   7890: // <![CDATA[
                   7891: 
                   7892: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   7893:     var x = document.getElementsByClassName(target);
                   7894:     var insttypes = 0;
                   7895:     var insttypeRegExp = new RegExp(prefix);
                   7896:     if ((x.length != undefined) && (x.length > 0)) {
                   7897:         if (form.elements[radio].length != undefined) {
                   7898:             for (var i=0; i<form.elements[radio].length; i++) {
                   7899:                 if (form.elements[radio][i].checked) {
                   7900:                     if (form.elements[radio][i].value == 1) {
                   7901:                         for (var j=0; j<x.length; j++) {
                   7902:                             if (x[j].id == 'undefined') {
                   7903:                                 x[j].style.display = 'table-row';
                   7904:                             } else if (insttypeRegExp.test(x[j].id)) {
                   7905:                                 insttypes ++;
                   7906:                             } else {
                   7907:                                 x[j].style.display = 'table-row';
                   7908:                             }
                   7909:                         }
                   7910:                     } else {
                   7911:                         for (var j=0; j<x.length; j++) {
                   7912:                             x[j].style.display = 'none';
                   7913:                         }
1.236     raeburn  7914:                     }
1.305     raeburn  7915:                     break;
                   7916:                 }
                   7917:             }
                   7918:             if (insttypes > 0) {
                   7919:                 toggleDataRow(form,checkbox,target,altprefix);
                   7920:                 toggleDataRow(form,checkbox,target,prefix,1);
                   7921:             }
                   7922:         }
                   7923:     }
                   7924:     return;
                   7925: }
                   7926: 
                   7927: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   7928:     if (form.elements[checkbox].length != undefined) {
                   7929:         var count = 0;
                   7930:         if (docount) {
                   7931:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   7932:                 if (form.elements[checkbox][i].checked) {
                   7933:                     count ++;
1.236     raeburn  7934:                 }
1.305     raeburn  7935:             }
                   7936:         }
                   7937:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   7938:             var type = form.elements[checkbox][i].value;
                   7939:             if (document.getElementById(prefix+type)) {
                   7940:                 if (form.elements[checkbox][i].checked) {
                   7941:                     document.getElementById(prefix+type).style.display = 'table-row';
                   7942:                     if (count % 2 == 1) {
                   7943:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   7944:                     } else {
                   7945:                         document.getElementById(prefix+type).className = target;
1.236     raeburn  7946:                     }
1.305     raeburn  7947:                     count ++;
1.236     raeburn  7948:                 } else {
1.305     raeburn  7949:                     document.getElementById(prefix+type).style.display = 'none';
                   7950:                 }
                   7951:             }
                   7952:         }
                   7953:     }
                   7954:     return;
                   7955: }
                   7956: 
                   7957: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   7958:     var caller = radio+'_'+status;
                   7959:     if (form.elements[caller].length != undefined) {
                   7960:         for (var i=0; i<form.elements[caller].length; i++) {
                   7961:             if (form.elements[caller][i].checked) {
                   7962:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   7963:                     var curr = form.elements[caller][i].value;
                   7964:                     if (prefix) {
                   7965:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   7966:                     }
                   7967:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   7968:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   7969:                     if (curr == 'custom') {
                   7970:                         if (prefix) { 
                   7971:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   7972:                         }
                   7973:                     } else if (curr == 'inst') {
                   7974:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   7975:                     } else if (curr == 'noninst') {
                   7976:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236     raeburn  7977:                     }
1.305     raeburn  7978:                     break;
1.236     raeburn  7979:                 }
                   7980:             }
                   7981:         }
                   7982:     }
                   7983: }
                   7984: 
1.305     raeburn  7985: // ]]>
                   7986: </script>
                   7987: 
                   7988: ENDSCRIPT
                   7989: }
                   7990: 
                   7991: sub noninst_users {
                   7992:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   7993:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_; 
                   7994:     my $class = 'LC_left_item';
                   7995:     if ($css_class) {
                   7996:         $css_class = ' class="'.$css_class.'"'; 
                   7997:     }
                   7998:     if ($rowid) {
                   7999:         $rowid = ' id="'.$rowid.'"';
                   8000:     }
                   8001:     if ($rowstyle) {
                   8002:         $rowstyle = ' style="'.$rowstyle.'"';
                   8003:     }
                   8004:     my ($output,$description);
                   8005:     if ($type eq 'default') {
                   8006:         $description = &mt('Requests for: [_1]',$typetitle);
                   8007:     } else {
                   8008:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   8009:     }
                   8010:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   8011:               "<td>$description</td>\n".           
                   8012:               '<td class="'.$class.'" colspan="2">'.
                   8013:               '<table><tr>';
                   8014:     my %headers = &Apache::lonlocal::texthash( 
                   8015:               approve  => 'Processing',
                   8016:               email    => 'E-mail',
                   8017:               username => 'Username',
                   8018:     );
                   8019:     foreach my $item ('approve','email','username') {
                   8020:         $output .= '<th>'.$headers{$item}.'</th>';
1.303     raeburn  8021:     }
1.305     raeburn  8022:     $output .= '</tr><tr>';
                   8023:     foreach my $item ('approve','email','username') {
1.306     raeburn  8024:         $output .= '<td style="vertical-align: top">';
1.305     raeburn  8025:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   8026:         if ($item eq 'approve') {
                   8027:             %choices = &Apache::lonlocal::texthash (
                   8028:                                                      automatic => 'Automatically approved',
                   8029:                                                      approval  => 'Queued for approval',
                   8030:                                                    );
                   8031:             @options = ('automatic','approval');
                   8032:             $hashref = $processing;
                   8033:             $defoption = 'automatic';
                   8034:             $name = 'cancreate_emailprocess_'.$type;
                   8035:         } elsif ($item eq 'email') {
                   8036:             %choices = &Apache::lonlocal::texthash (
                   8037:                                                      any     => 'Any e-mail',
                   8038:                                                      inst    => 'Institutional only',
                   8039:                                                      noninst => 'Non-institutional only',
                   8040:                                                      custom  => 'Custom restrictions',
                   8041:                                                    );
                   8042:             @options = ('any','inst','noninst');
                   8043:             my $showcustom;
                   8044:             if (ref($emailrules) eq 'HASH') {
                   8045:                 if (keys(%{$emailrules}) > 0) {
                   8046:                     push(@options,'custom');
                   8047:                     $showcustom = 'cancreate_emailrule';
                   8048:                     if (ref($settings) eq 'HASH') {
                   8049:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   8050:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   8051:                                 if (exists($emailrules->{$rule})) {
                   8052:                                     $hascustom ++;
                   8053:                                 }
                   8054:                             }
                   8055:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   8056:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   8057:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   8058:                                     if (exists($emailrules->{$rule})) {
                   8059:                                         $hascustom ++;
                   8060:                                     }
                   8061:                                 }
                   8062:                             }
                   8063:                         }
                   8064:                     }
                   8065:                 }
                   8066:             }
                   8067:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   8068:                                                      "'cancreate_emaildomain','$type'".');"';
                   8069:             $hashref = $emailoptions;
                   8070:             $defoption = 'any';
                   8071:             $name = 'cancreate_emailoptions_'.$type;
                   8072:         } elsif ($item eq 'username') {
                   8073:             %choices = &Apache::lonlocal::texthash (
                   8074:                                                      all    => 'Same as e-mail',
                   8075:                                                      first  => 'Omit @domain',
                   8076:                                                      free   => 'Free to choose',
                   8077:                                                    );
                   8078:             @options = ('all','first','free');
                   8079:             $hashref = $emailverified;
                   8080:             $defoption = 'all';
                   8081:             $name = 'cancreate_usernameoptions_'.$type;
                   8082:         }
                   8083:         foreach my $option (@options) {
                   8084:             my $checked;
                   8085:             if (ref($hashref) eq 'HASH') {
                   8086:                 if ($type eq '') {
                   8087:                     if (!exists($hashref->{'default'})) {
                   8088:                         if ($option eq $defoption) {
                   8089:                             $checked = ' checked="checked"';
                   8090:                         }
                   8091:                     } else {
                   8092:                         if ($hashref->{'default'} eq $option) {
                   8093:                             $checked = ' checked="checked"';
                   8094:                         }
1.303     raeburn  8095:                     }
                   8096:                 } else {
1.305     raeburn  8097:                     if (!exists($hashref->{$type})) {
                   8098:                         if ($option eq $defoption) {
                   8099:                             $checked = ' checked="checked"';
                   8100:                         }
                   8101:                     } else {
                   8102:                         if ($hashref->{$type} eq $option) {
                   8103:                             $checked = ' checked="checked"';
                   8104:                         }
1.303     raeburn  8105:                     }
                   8106:                 }
1.305     raeburn  8107:             } elsif (($item eq 'email') && ($hascustom)) {
                   8108:                 if ($option eq 'custom') {
                   8109:                     $checked = ' checked="checked"';
                   8110:                 }
                   8111:             } elsif ($option eq $defoption) {
                   8112:                 $checked = ' checked="checked"';
                   8113:             }
                   8114:             $output .= '<span class="LC_nobreak"><label>'.
                   8115:                        '<input type="radio" name="'.$name.'"'.
                   8116:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   8117:                        $choices{$option}.'</label></span><br />';
                   8118:             if ($item eq 'email') {
                   8119:                 if ($option eq 'custom') {
                   8120:                     my $id = 'cancreate_emailrule_'.$type;
                   8121:                     my $display = 'none';
                   8122:                     if ($checked) {
                   8123:                         $display = 'inline';
1.303     raeburn  8124:                     }
1.305     raeburn  8125:                     my $numinrow = 2;
                   8126:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   8127:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   8128:                                &user_formats_row('email',$settings,$emailrules,
                   8129:                                                  $emailruleorder,$numinrow,'',$type);
                   8130:                               '</table></fieldset>';
                   8131:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   8132:                     my %text = &Apache::lonlocal::texthash (
                   8133:                                                              inst    => 'must end:',
                   8134:                                                              noninst => 'cannot end:',
                   8135:                                                            );
                   8136:                     my $value;
                   8137:                     if (ref($emaildomain) eq 'HASH') {
                   8138:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   8139:                             $value = $emaildomain->{$type}->{$option}; 
1.303     raeburn  8140:                         }
                   8141:                     }
1.305     raeburn  8142:                     if ($value eq '') {
                   8143:                         $value = '@'.$intdom;
                   8144:                     }
                   8145:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   8146:                     my $display = 'none';
                   8147:                     if ($checked) {
                   8148:                         $display = 'inline';
                   8149:                     }
                   8150:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   8151:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   8152:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   8153:                                '</div>';
1.303     raeburn  8154:                 }
                   8155:             }
                   8156:         }
1.305     raeburn  8157:         $output .= '</td>'."\n";
1.303     raeburn  8158:     }
1.305     raeburn  8159:     $output .= "</tr></table></td></tr>\n";
1.303     raeburn  8160:     return $output;
                   8161: }
                   8162: 
1.165     raeburn  8163: sub captcha_choice {
1.305     raeburn  8164:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269     raeburn  8165:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   8166:         $vertext,$currver);
1.165     raeburn  8167:     my %lt = &captcha_phrases();
                   8168:     $keyentry = 'hidden';
1.354     raeburn  8169:     my $colspan=2;
1.165     raeburn  8170:     if ($context eq 'cancreate') {
1.224     raeburn  8171:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  8172:     } elsif ($context eq 'login') {
                   8173:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.354     raeburn  8174:     } elsif ($context eq 'passwords') {
                   8175:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   8176:         $colspan=1;
1.165     raeburn  8177:     }
                   8178:     if (ref($settings) eq 'HASH') {
                   8179:         if ($settings->{'captcha'}) {
                   8180:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   8181:         } else {
                   8182:             $checked{'original'} = ' checked="checked"';
                   8183:         }
                   8184:         if ($settings->{'captcha'} eq 'recaptcha') {
                   8185:             $pubtext = $lt{'pub'};
                   8186:             $privtext = $lt{'priv'};
                   8187:             $keyentry = 'text';
1.269     raeburn  8188:             $vertext = $lt{'ver'};
                   8189:             $currver = $settings->{'recaptchaversion'};
                   8190:             if ($currver ne '2') {
                   8191:                 $currver = 1;
                   8192:             }
1.165     raeburn  8193:         }
                   8194:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   8195:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   8196:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   8197:         }
                   8198:     } else {
                   8199:         $checked{'original'} = ' checked="checked"';
                   8200:     }
1.305     raeburn  8201:     my $css_class;
                   8202:     if ($itemcount%2) {
                   8203:         $css_class = 'LC_odd_row';
                   8204:     }
                   8205:     if ($customcss) {
                   8206:         $css_class .= " $customcss";
                   8207:     }
                   8208:     $css_class =~ s/^\s+//;
                   8209:     if ($css_class) {
                   8210:         $css_class = ' class="'.$css_class.'"';
                   8211:     }
                   8212:     if ($rowstyle) {
                   8213:         $css_class .= ' style="'.$rowstyle.'"';
                   8214:     }
1.169     raeburn  8215:     my $output = '<tr'.$css_class.'>'.
1.354     raeburn  8216:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165     raeburn  8217:                  '<table><tr><td>'."\n";
                   8218:     foreach my $option ('original','recaptcha','notused') {
                   8219:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   8220:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   8221:                    $lt{$option}.'</label></span>';
                   8222:         unless ($option eq 'notused') {
                   8223:             $output .= ('&nbsp;'x2)."\n";
                   8224:         }
                   8225:     }
                   8226: #
                   8227: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   8228: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  8229: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  8230: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  8231: #
1.165     raeburn  8232:     $output .= '</td></tr>'."\n".
1.305     raeburn  8233:                '<tr><td class="LC_zero_height">'."\n".
1.165     raeburn  8234:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   8235:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   8236:                $currpub.'" size="40" /></span><br />'."\n".
                   8237:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   8238:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  8239:                $currpriv.'" size="40" /></span><br />'.
                   8240:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   8241:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   8242:                $currver.'" size="3" /></span><br />'.
                   8243:                '</td></tr></table>'."\n".
1.165     raeburn  8244:                '</td></tr>';
                   8245:     return $output;
                   8246: }
                   8247: 
1.32      raeburn  8248: sub user_formats_row {
1.305     raeburn  8249:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  8250:     my $output;
                   8251:     my %text = (
                   8252:                    'username' => 'new usernames',
                   8253:                    'id'       => 'IDs',
                   8254:                );
1.305     raeburn  8255:     unless ($type eq 'email') {
                   8256:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   8257:         $output = '<tr '.$css_class.'>'.
                   8258:                   '<td><span class="LC_nobreak">'.
                   8259:                   &mt("Format rules to check for $text{$type}: ").
                   8260:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  8261:     }
1.27      raeburn  8262:     my $rem;
                   8263:     if (ref($ruleorder) eq 'ARRAY') {
                   8264:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   8265:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   8266:                 my $rem = $i%($numinrow);
                   8267:                 if ($rem == 0) {
                   8268:                     if ($i > 0) {
                   8269:                         $output .= '</tr>';
                   8270:                     }
                   8271:                     $output .= '<tr>';
                   8272:                 }
                   8273:                 my $check = ' ';
1.39      raeburn  8274:                 if (ref($settings) eq 'HASH') {
                   8275:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   8276:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   8277:                             $check = ' checked="checked" ';
                   8278:                         }
1.305     raeburn  8279:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   8280:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   8281:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   8282:                                 $check = ' checked="checked" ';
                   8283:                             }
                   8284:                         }
1.27      raeburn  8285:                     }
                   8286:                 }
1.305     raeburn  8287:                 my $name = $type.'_rule';
                   8288:                 if ($type eq 'email') {
                   8289:                     $name .= '_'.$status;
                   8290:                 }
1.27      raeburn  8291:                 $output .= '<td class="LC_left_item">'.
                   8292:                            '<span class="LC_nobreak"><label>'.
1.311     raeburn  8293:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  8294:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   8295:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   8296:             }
                   8297:         }
                   8298:         $rem = @{$ruleorder}%($numinrow);
                   8299:     }
1.305     raeburn  8300:     my $colsleft;
                   8301:     if ($rem) {
                   8302:         $colsleft = $numinrow - $rem;
                   8303:     }
1.27      raeburn  8304:     if ($colsleft > 1 ) {
                   8305:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8306:                    '&nbsp;</td>';
                   8307:     } elsif ($colsleft == 1) {
                   8308:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   8309:     }
1.305     raeburn  8310:     $output .= '</tr></table>';
                   8311:     unless ($type eq 'email') {
                   8312:         $output .= '</td></tr>';
                   8313:     }
1.27      raeburn  8314:     return $output;
                   8315: }
                   8316: 
1.34      raeburn  8317: sub usercreation_types {
                   8318:     my %lt = &Apache::lonlocal::texthash (
                   8319:                     author     => 'When adding a co-author',
                   8320:                     course     => 'When adding a user to a course',
1.100     raeburn  8321:                     requestcrs => 'When requesting a course',
1.34      raeburn  8322:                     any        => 'Any',
                   8323:                     official   => 'Institutional only ',
                   8324:                     unofficial => 'Non-institutional only',
                   8325:                     none       => 'None',
                   8326:     );
                   8327:     return %lt;
1.48      raeburn  8328: }
1.34      raeburn  8329: 
1.224     raeburn  8330: sub selfcreation_types {
                   8331:     my %lt = &Apache::lonlocal::texthash (
                   8332:                     selfcreate => 'User creates own account',
                   8333:                     any        => 'Any',
                   8334:                     official   => 'Institutional only ',
                   8335:                     unofficial => 'Non-institutional only',
                   8336:                     email      => 'E-mail address',
                   8337:                     login      => 'Institutional Login',
                   8338:                     sso        => 'SSO',
                   8339:              );
                   8340: }
                   8341: 
1.28      raeburn  8342: sub authtype_names {
                   8343:     my %lt = &Apache::lonlocal::texthash(
                   8344:                       int    => 'Internal',
                   8345:                       krb4   => 'Kerberos 4',
                   8346:                       krb5   => 'Kerberos 5',
                   8347:                       loc    => 'Local',
1.325     raeburn  8348:                       lti    => 'LTI',
1.28      raeburn  8349:                   );
                   8350:     return %lt;
                   8351: }
                   8352: 
                   8353: sub context_names {
                   8354:     my %context_title = &Apache::lonlocal::texthash(
                   8355:        author => 'Creating users when an Author',
                   8356:        course => 'Creating users when in a course',
                   8357:        domain => 'Creating users when a Domain Coordinator',
                   8358:     );
                   8359:     return %context_title;
                   8360: }
                   8361: 
1.33      raeburn  8362: sub print_usermodification {
                   8363:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8364:     my $numinrow = 4;
                   8365:     my ($context,$datatable,$rowcount);
                   8366:     if ($position eq 'top') {
                   8367:         $rowcount = 0;
                   8368:         $context = 'author'; 
                   8369:         foreach my $role ('ca','aa') {
                   8370:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8371:                                                    $numinrow,$rowcount);
                   8372:             $$rowtotal ++;
                   8373:             $rowcount ++;
                   8374:         }
1.230     raeburn  8375:     } elsif ($position eq 'bottom') {
1.33      raeburn  8376:         $context = 'course';
                   8377:         $rowcount = 0;
                   8378:         foreach my $role ('st','ep','ta','in','cr') {
                   8379:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8380:                                                    $numinrow,$rowcount);
                   8381:             $$rowtotal ++;
                   8382:             $rowcount ++;
                   8383:         }
                   8384:     }
                   8385:     return $datatable;
                   8386: }
                   8387: 
1.43      raeburn  8388: sub print_defaults {
1.236     raeburn  8389:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  8390:     my $rownum = 0;
1.294     raeburn  8391:     my ($datatable,$css_class,$titles);
                   8392:     unless ($position eq 'bottom') {
                   8393:         $titles = &defaults_titles($dom);
                   8394:     }
1.236     raeburn  8395:     if ($position eq 'top') {
                   8396:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   8397:                      'datelocale_def','portal_def');
                   8398:         my %defaults;
                   8399:         if (ref($settings) eq 'HASH') {
                   8400:             %defaults = %{$settings};
1.43      raeburn  8401:         } else {
1.236     raeburn  8402:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8403:             foreach my $item (@items) {
                   8404:                 $defaults{$item} = $domdefaults{$item};
                   8405:             }
1.43      raeburn  8406:         }
1.236     raeburn  8407:         foreach my $item (@items) {
                   8408:             if ($rownum%2) {
                   8409:                 $css_class = '';
                   8410:             } else {
                   8411:                 $css_class = ' class="LC_odd_row" ';
                   8412:             }
                   8413:             $datatable .= '<tr'.$css_class.'>'.
                   8414:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   8415:                           '</span></td><td class="LC_right_item" colspan="3">';
                   8416:             if ($item eq 'auth_def') {
1.325     raeburn  8417:                 my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236     raeburn  8418:                 my %shortauth = (
                   8419:                                  internal => 'int',
                   8420:                                  krb4 => 'krb4',
                   8421:                                  krb5 => 'krb5',
1.325     raeburn  8422:                                  localauth  => 'loc',
                   8423:                                  lti => 'lti',
1.236     raeburn  8424:                                 );
                   8425:                 my %authnames = &authtype_names();
                   8426:                 foreach my $auth (@authtypes) {
                   8427:                     my $checked = ' ';
                   8428:                     if ($defaults{$item} eq $auth) {
                   8429:                         $checked = ' checked="checked" ';
                   8430:                     }
                   8431:                     $datatable .= '<label><input type="radio" name="'.$item.
                   8432:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   8433:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   8434:                 }
                   8435:             } elsif ($item eq 'timezone_def') {
                   8436:                 my $includeempty = 1;
                   8437:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   8438:             } elsif ($item eq 'datelocale_def') {
                   8439:                 my $includeempty = 1;
                   8440:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   8441:             } elsif ($item eq 'lang_def') {
1.263     raeburn  8442:                 my $includeempty = 1;
                   8443:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  8444:             } else {
                   8445:                 my $size;
                   8446:                 if ($item eq 'portal_def') {
                   8447:                     $size = ' size="25"';
                   8448:                 }
                   8449:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   8450:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  8451:             }
1.236     raeburn  8452:             $datatable .= '</td></tr>';
                   8453:             $rownum ++;
                   8454:         }
1.354     raeburn  8455:     } else {
1.294     raeburn  8456:         my %defaults;
                   8457:         if (ref($settings) eq 'HASH') {
1.354     raeburn  8458:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   8459:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   8460:                 for (my $i=0; $i<$maxnum; $i++) {
                   8461:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8462:                     my $item = $settings->{'inststatusorder'}->[$i];
                   8463:                     my $title = $settings->{'inststatustypes'}->{$item};
                   8464:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   8465:                     $datatable .= '<tr'.$css_class.'>'.
                   8466:                                   '<td><span class="LC_nobreak">'.
                   8467:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   8468:                     for (my $k=0; $k<=$maxnum; $k++) {
                   8469:                         my $vpos = $k+1;
                   8470:                         my $selstr;
                   8471:                         if ($k == $i) {
                   8472:                             $selstr = ' selected="selected" ';
                   8473:                         }
                   8474:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8475:                     }
                   8476:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   8477:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   8478:                                   &mt('delete').'</span></td>'.
                   8479:                                   '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed:').
                   8480:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   8481:                                   '</span></td></tr>';
                   8482:                 }
                   8483:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8484:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   8485:                 $datatable .= '<tr '.$css_class.'>'.
                   8486:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   8487:                 for (my $k=0; $k<=$maxnum; $k++) {
                   8488:                     my $vpos = $k+1;
                   8489:                     my $selstr;
                   8490:                     if ($k == $maxnum) {
                   8491:                         $selstr = ' selected="selected" ';
                   8492:                     }
                   8493:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8494:                 }
                   8495:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
                   8496:                               '<input type="text" size="10" name="addinststatus" value="" />'.
                   8497:                               '&nbsp;'.&mt('(new)').
                   8498:                               '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
                   8499:                               &mt('Name displayed:').
                   8500:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   8501:                               '</tr>'."\n";
                   8502:                 $rownum ++;
1.294     raeburn  8503:             }
1.354     raeburn  8504:         }
                   8505:     }
                   8506:     $$rowtotal += $rownum;
1.43      raeburn  8507:     return $datatable;
                   8508: }
                   8509: 
1.168     raeburn  8510: sub get_languages_hash {
                   8511:     my %langchoices;
                   8512:     foreach my $id (&Apache::loncommon::languageids()) {
                   8513:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   8514:         if ($code ne '') {
                   8515:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   8516:         }
                   8517:     }
                   8518:     return %langchoices;
                   8519: }
                   8520: 
1.43      raeburn  8521: sub defaults_titles {
1.141     raeburn  8522:     my ($dom) = @_;
1.43      raeburn  8523:     my %titles = &Apache::lonlocal::texthash (
                   8524:                    'auth_def'      => 'Default authentication type',
                   8525:                    'auth_arg_def'  => 'Default authentication argument',
                   8526:                    'lang_def'      => 'Default language',
1.54      raeburn  8527:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  8528:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  8529:                    'portal_def'     => 'Portal/Default URL',
1.294     raeburn  8530:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   8531:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   8532:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  8533:                  );
1.141     raeburn  8534:     if ($dom) {
                   8535:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   8536:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   8537:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   8538:         $protocol = 'http' if ($protocol ne 'https');
                   8539:         if ($uint_dom) {
                   8540:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   8541:                                          $uint_dom);
                   8542:         }
                   8543:     }
1.43      raeburn  8544:     return (\%titles);
                   8545: }
                   8546: 
1.346     raeburn  8547: sub print_scantron {
                   8548:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   8549:     if ($position eq 'top') {
                   8550:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   8551:     } else {
                   8552:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   8553:     }
                   8554: }
                   8555: 
                   8556: sub scantron_javascript {
                   8557:     return <<"ENDSCRIPT";
                   8558: 
                   8559: <script type="text/javascript">
                   8560: // <![CDATA[
                   8561: 
                   8562: function toggleScantron(form) {
1.347     raeburn  8563:     var csvfieldset = new Array();
1.346     raeburn  8564:     if (document.getElementById('scantroncsv_cols')) {
1.347     raeburn  8565:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   8566:     }
                   8567:     if (document.getElementById('scantroncsv_options')) {
                   8568:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   8569:     }
                   8570:     if (csvfieldset.length) {
1.346     raeburn  8571:         if (document.getElementById('scantronconfcsv')) {
1.347     raeburn  8572:             var scantroncsv = document.getElementById('scantronconfcsv');
1.346     raeburn  8573:             if (scantroncsv.checked) {
1.347     raeburn  8574:                 for (var i=0; i<csvfieldset.length; i++) {
                   8575:                     csvfieldset[i].style.display = 'block';
                   8576:                 }
1.346     raeburn  8577:             } else {
1.347     raeburn  8578:                 for (var i=0; i<csvfieldset.length; i++) {
                   8579:                     csvfieldset[i].style.display = 'none';
                   8580:                 }
1.346     raeburn  8581:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   8582:                 if (csvselects.length) {
                   8583:                     for (var j=0; j<csvselects.length; j++) {
                   8584:                         csvselects[j].selectedIndex = 0;
                   8585:                     }
                   8586:                 }
                   8587:             }
                   8588:         }
                   8589:     }
                   8590:     return;
                   8591: }
                   8592: // ]]>
                   8593: </script>
                   8594: 
                   8595: ENDSCRIPT
                   8596: 
                   8597: }
                   8598: 
1.46      raeburn  8599: sub print_scantronformat {
                   8600:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   8601:     my $itemcount = 1;
1.60      raeburn  8602:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   8603:         %confhash);
1.46      raeburn  8604:     my $switchserver = &check_switchserver($dom,$confname);
                   8605:     my %lt = &Apache::lonlocal::texthash (
1.95      www      8606:                 default => 'Default bubblesheet format file error',
                   8607:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  8608:              );
                   8609:     my %scantronfiles = (
                   8610:         default => 'default.tab',
                   8611:         custom => 'custom.tab',
                   8612:     );
                   8613:     foreach my $key (keys(%scantronfiles)) {
                   8614:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   8615:                               .$scantronfiles{$key};
                   8616:     }
                   8617:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   8618:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   8619:         if (!$switchserver) {
                   8620:             my $servadm = $r->dir_config('lonAdmEMail');
                   8621:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   8622:             if ($configuserok eq 'ok') {
                   8623:                 if ($author_ok eq 'ok') {
                   8624:                     my %legacyfile = (
1.346     raeburn  8625:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   8626:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  8627:                     );
                   8628:                     my %md5chk;
                   8629:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  8630:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   8631:                         chomp($md5chk{$type});
1.46      raeburn  8632:                     }
                   8633:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   8634:                         foreach my $type (keys(%legacyfile)) {
1.346     raeburn  8635:                             ($scantronurls{$type},my $error) =
1.46      raeburn  8636:                                 &legacy_scantronformat($r,$dom,$confname,
                   8637:                                                  $type,$legacyfile{$type},
                   8638:                                                  $scantronurls{$type},
                   8639:                                                  $scantronfiles{$type});
1.60      raeburn  8640:                             if ($error ne '') {
                   8641:                                 $error{$type} = $error;
                   8642:                             }
                   8643:                         }
                   8644:                         if (keys(%error) == 0) {
                   8645:                             $is_custom = 1;
1.346     raeburn  8646:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  8647:                                 $scantronurls{'custom'};
1.346     raeburn  8648:                             my $putresult =
1.60      raeburn  8649:                                 &Apache::lonnet::put_dom('configuration',
                   8650:                                                          \%confhash,$dom);
                   8651:                             if ($putresult ne 'ok') {
1.346     raeburn  8652:                                 $error{'custom'} =
1.60      raeburn  8653:                                     '<span class="LC_error">'.
                   8654:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8655:                             }
1.46      raeburn  8656:                         }
                   8657:                     } else {
1.60      raeburn  8658:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  8659:                             &legacy_scantronformat($r,$dom,$confname,
                   8660:                                           'default',$legacyfile{'default'},
                   8661:                                           $scantronurls{'default'},
                   8662:                                           $scantronfiles{'default'});
1.60      raeburn  8663:                         if ($error eq '') {
                   8664:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   8665:                             my $putresult =
                   8666:                                 &Apache::lonnet::put_dom('configuration',
                   8667:                                                          \%confhash,$dom);
                   8668:                             if ($putresult ne 'ok') {
                   8669:                                 $error{'default'} =
                   8670:                                     '<span class="LC_error">'.
                   8671:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8672:                             }
                   8673:                         } else {
                   8674:                             $error{'default'} = $error;
                   8675:                         }
1.46      raeburn  8676:                     }
                   8677:                 }
                   8678:             }
                   8679:         } else {
1.95      www      8680:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  8681:         }
                   8682:     }
                   8683:     if (ref($settings) eq 'HASH') {
                   8684:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   8685:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   8686:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   8687:                 $scantronurl = '';
                   8688:             } else {
                   8689:                 $scantronurl = $settings->{'scantronformat'};
                   8690:             }
                   8691:             $is_custom = 1;
                   8692:         } else {
                   8693:             $scantronurl = $scantronurls{'default'};
                   8694:         }
                   8695:     } else {
1.60      raeburn  8696:         if ($is_custom) {
                   8697:             $scantronurl = $scantronurls{'custom'};
                   8698:         } else {
                   8699:             $scantronurl = $scantronurls{'default'};
                   8700:         }
1.46      raeburn  8701:     }
                   8702:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8703:     $datatable .= '<tr'.$css_class.'>';
                   8704:     if (!$is_custom) {
1.65      raeburn  8705:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   8706:                       '<span class="LC_nobreak">';
1.46      raeburn  8707:         if ($scantronurl) {
1.199     raeburn  8708:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   8709:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  8710:         } else {
                   8711:             $datatable = &mt('File unavailable for display');
                   8712:         }
1.65      raeburn  8713:         $datatable .= '</span></td>';
1.60      raeburn  8714:         if (keys(%error) == 0) { 
1.306     raeburn  8715:             $datatable .= '<td style="vertical-align: bottom">';
1.60      raeburn  8716:             if (!$switchserver) {
                   8717:                 $datatable .= &mt('Upload:').'<br />';
                   8718:             }
                   8719:         } else {
                   8720:             my $errorstr;
                   8721:             foreach my $key (sort(keys(%error))) {
                   8722:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8723:             }
                   8724:             $datatable .= '<td>'.$errorstr;
                   8725:         }
1.46      raeburn  8726:     } else {
                   8727:         if (keys(%error) > 0) {
                   8728:             my $errorstr;
                   8729:             foreach my $key (sort(keys(%error))) {
                   8730:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8731:             } 
1.60      raeburn  8732:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  8733:         } elsif ($scantronurl) {
1.199     raeburn  8734:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   8735:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  8736:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  8737:                           $link.
                   8738:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   8739:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  8740:                           '<td><span class="LC_nobreak">&nbsp;'.
                   8741:                           &mt('Replace:').'</span><br />';
1.46      raeburn  8742:         }
                   8743:     }
                   8744:     if (keys(%error) == 0) {
                   8745:         if ($switchserver) {
                   8746:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   8747:         } else {
1.65      raeburn  8748:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   8749:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  8750:         }
                   8751:     }
                   8752:     $datatable .= '</td></tr>';
                   8753:     $$rowtotal ++;
                   8754:     return $datatable;
                   8755: }
                   8756: 
                   8757: sub legacy_scantronformat {
                   8758:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   8759:     my ($url,$error);
                   8760:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   8761:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   8762:         (my $result,$url) =
                   8763:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   8764:                          '','',$newfile);
                   8765:         if ($result ne 'ok') {
1.130     raeburn  8766:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  8767:         }
                   8768:     }
                   8769:     return ($url,$error);
                   8770: }
1.43      raeburn  8771: 
1.346     raeburn  8772: sub print_scantronconfig {
                   8773:     my ($dom,$settings,$rowtotal) = @_;
                   8774:     my $itemcount = 2;
                   8775:     my $is_checked = ' checked="checked"';
1.347     raeburn  8776:     my %optionson = (
                   8777:                      hdr => ' checked="checked"',
                   8778:                      pad => ' checked="checked"',
                   8779:                      rem => ' checked="checked"',
                   8780:                     );
                   8781:     my %optionsoff = (
                   8782:                       hdr => '',
                   8783:                       pad => '',
                   8784:                       rem => '',
                   8785:                      );
1.346     raeburn  8786:     my $currcsvsty = 'none';
1.347     raeburn  8787:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346     raeburn  8788:     my @fields = &scantroncsv_fields();
                   8789:     my %titles = &scantronconfig_titles();
                   8790:     if (ref($settings) eq 'HASH') {
                   8791:         if (ref($settings->{config}) eq 'HASH') {
                   8792:             if ($settings->{config}->{dat}) {
                   8793:                 $checked{'dat'} = $is_checked;
                   8794:             }
                   8795:             if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347     raeburn  8796:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   8797:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   8798:                     if (keys(%csvfields) > 0) {
                   8799:                         $checked{'csv'} = $is_checked;
                   8800:                         $currcsvsty = 'block';
                   8801:                     }
                   8802:                 }
                   8803:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   8804:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   8805:                     foreach my $option (keys(%optionson)) {
                   8806:                         unless ($csvoptions{$option}) {
                   8807:                             $optionsoff{$option} = $optionson{$option};
                   8808:                             $optionson{$option} = '';
                   8809:                         }
                   8810:                     }
1.346     raeburn  8811:                 }
                   8812:             }
                   8813:         } else {
                   8814:             $checked{'dat'} = $is_checked;
                   8815:         }
                   8816:     } else {
                   8817:         $checked{'dat'} = $is_checked;
                   8818:     }
                   8819:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   8820:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   8821:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   8822:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   8823:     foreach my $item ('dat','csv') {
                   8824:         my $id;
                   8825:         if ($item eq 'csv') {
                   8826:             $id = 'id="scantronconfcsv" ';
1.347     raeburn  8827:         }
1.346     raeburn  8828:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   8829:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   8830:         if ($item eq 'csv') {
                   8831:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   8832:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   8833:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   8834:             foreach my $col (@fields) {
                   8835:                 my $selnone;
                   8836:                 if ($csvfields{$col} eq '') {
                   8837:                     $selnone = ' selected="selected"';
                   8838:                 }
                   8839:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   8840:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   8841:                               '<option value=""'.$selnone.'></option>';
                   8842:                 for (my $i=0; $i<20; $i++) {
                   8843:                     my $shown = $i+1;
                   8844:                     my $sel;
                   8845:                     unless ($selnone) {
                   8846:                         if (exists($csvfields{$col})) {
                   8847:                             if ($csvfields{$col} == $i) {
                   8848:                                 $sel = ' selected="selected"';
                   8849:                             }
                   8850:                         }
                   8851:                     }
                   8852:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   8853:                 }
                   8854:                 $datatable .= '</select></td></tr>';
                   8855:            }
1.347     raeburn  8856:            $datatable .= '</table></fieldset>'.
                   8857:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   8858:                          '<legend>'.&mt('CSV Options').'</legend>';
                   8859:            foreach my $option ('hdr','pad','rem') {
                   8860:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   8861:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   8862:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   8863:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   8864:            }
                   8865:            $datatable .= '</fieldset>';
1.346     raeburn  8866:            $itemcount ++;
                   8867:         }
                   8868:     }
                   8869:     $datatable .= '</td></tr>';
                   8870:     $$rowtotal ++;
                   8871:     return $datatable;
                   8872: }
                   8873: 
                   8874: sub scantronconfig_titles {
                   8875:     return &Apache::lonlocal::texthash(
                   8876:                                           dat => 'Standard format (.dat)',
                   8877:                                           csv => 'Comma separated values (.csv)',
1.347     raeburn  8878:                                           hdr => 'Remove first line in file (contains column titles)',
                   8879:                                           pad => 'Prepend 0s to PaperID',
1.348     raeburn  8880:                                           rem => 'Remove leading spaces (except Question Response columns)',
1.346     raeburn  8881:                                           CODE => 'CODE',
                   8882:                                           ID   => 'Student ID',
                   8883:                                           PaperID => 'Paper ID',
                   8884:                                           FirstName => 'First Name',
                   8885:                                           LastName => 'Last Name',
                   8886:                                           FirstQuestion => 'First Question Response',
                   8887:                                           Section => 'Section',
                   8888:     );
                   8889: }
                   8890: 
                   8891: sub scantroncsv_fields {
                   8892:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   8893: }
                   8894: 
1.49      raeburn  8895: sub print_coursecategories {
1.57      raeburn  8896:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   8897:     my $datatable;
                   8898:     if ($position eq 'top') {
1.238     raeburn  8899:         my (%checked);
                   8900:         my @catitems = ('unauth','auth');
                   8901:         my @cattypes = ('std','domonly','codesrch','none');
                   8902:         $checked{'unauth'} = 'std';
                   8903:         $checked{'auth'} = 'std';
                   8904:         if (ref($settings) eq 'HASH') {
                   8905:             foreach my $type (@cattypes) {
                   8906:                 if ($type eq $settings->{'unauth'}) {
                   8907:                     $checked{'unauth'} = $type;
                   8908:                 }
                   8909:                 if ($type eq $settings->{'auth'}) {
                   8910:                     $checked{'auth'} = $type;
                   8911:                 }
                   8912:             }
                   8913:         }
                   8914:         my %lt = &Apache::lonlocal::texthash (
                   8915:                                                unauth   => 'Catalog type for unauthenticated users',
                   8916:                                                auth     => 'Catalog type for authenticated users',
                   8917:                                                none     => 'No catalog',
                   8918:                                                std      => 'Standard catalog',
                   8919:                                                domonly  => 'Domain-only catalog',
                   8920:                                                codesrch => "Code search form",
                   8921:                                              );
                   8922:        my $itemcount = 0;
                   8923:        foreach my $item (@catitems) {
                   8924:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   8925:            $datatable .= '<tr '.$css_class.'>'.
                   8926:                          '<td>'.$lt{$item}.'</td>'.
                   8927:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   8928:            foreach my $type (@cattypes) {
                   8929:                my $ischecked;
                   8930:                if ($checked{$item} eq $type) {
                   8931:                    $ischecked=' checked="checked"';
                   8932:                }
                   8933:                $datatable .= '<label>'.
                   8934:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   8935:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   8936:            }
1.327     raeburn  8937:            $datatable .= '</span></td></tr>';
1.238     raeburn  8938:            $itemcount ++;
                   8939:         }
                   8940:         $$rowtotal += $itemcount;
                   8941:     } elsif ($position eq 'middle') {
1.57      raeburn  8942:         my $toggle_cats_crs = ' ';
                   8943:         my $toggle_cats_dom = ' checked="checked" ';
                   8944:         my $can_cat_crs = ' ';
                   8945:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  8946:         my $toggle_catscomm_comm = ' ';
                   8947:         my $toggle_catscomm_dom = ' checked="checked" ';
                   8948:         my $can_catcomm_comm = ' ';
                   8949:         my $can_catcomm_dom = ' checked="checked" ';
1.272     raeburn  8950:         my $toggle_catsplace_place = ' ';
                   8951:         my $toggle_catsplace_dom = ' checked="checked" ';
                   8952:         my $can_catplace_place = ' ';
                   8953:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  8954: 
1.57      raeburn  8955:         if (ref($settings) eq 'HASH') {
                   8956:             if ($settings->{'togglecats'} eq 'crs') {
                   8957:                 $toggle_cats_crs = $toggle_cats_dom;
                   8958:                 $toggle_cats_dom = ' ';
                   8959:             }
                   8960:             if ($settings->{'categorize'} eq 'crs') {
                   8961:                 $can_cat_crs = $can_cat_dom;
                   8962:                 $can_cat_dom = ' ';
                   8963:             }
1.120     raeburn  8964:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   8965:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   8966:                 $toggle_catscomm_dom = ' ';
                   8967:             }
                   8968:             if ($settings->{'categorizecomm'} eq 'comm') {
                   8969:                 $can_catcomm_comm = $can_catcomm_dom;
                   8970:                 $can_catcomm_dom = ' ';
                   8971:             }
1.272     raeburn  8972:             if ($settings->{'togglecatsplace'} eq 'place') {
                   8973:                 $toggle_catsplace_place = $toggle_catsplace_dom;
                   8974:                 $toggle_catsplace_dom = ' ';
                   8975:             }
                   8976:             if ($settings->{'categorizeplace'} eq 'place') {
                   8977:                 $can_catplace_place = $can_catplace_dom;
                   8978:                 $can_catplace_dom = ' ';
                   8979:             }
1.57      raeburn  8980:         }
                   8981:         my %title = &Apache::lonlocal::texthash (
1.272     raeburn  8982:                      togglecats      => 'Show/Hide a course in catalog',
                   8983:                      togglecatscomm  => 'Show/Hide a community in catalog',
                   8984:                      togglecatsplace => 'Show/Hide a placement test in catalog',
                   8985:                      categorize      => 'Assign a category to a course',
                   8986:                      categorizecomm  => 'Assign a category to a community',
                   8987:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  8988:                     );
                   8989:         my %level = &Apache::lonlocal::texthash (
1.272     raeburn  8990:                      dom   => 'Set in Domain',
                   8991:                      crs   => 'Set in Course',
                   8992:                      comm  => 'Set in Community',
                   8993:                      place => 'Set in Placement Test',
1.57      raeburn  8994:                     );
                   8995:         $datatable = '<tr class="LC_odd_row">'.
                   8996:                   '<td>'.$title{'togglecats'}.'</td>'.
                   8997:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   8998:                   '<input type="radio" name="togglecats"'.
                   8999:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9000:                   '<label><input type="radio" name="togglecats"'.
                   9001:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   9002:                   '</tr><tr>'.
                   9003:                   '<td>'.$title{'categorize'}.'</td>'.
                   9004:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   9005:                   '<label><input type="radio" name="categorize"'.
                   9006:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9007:                   '<label><input type="radio" name="categorize"'.
                   9008:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  9009:                   '</tr><tr class="LC_odd_row">'.
                   9010:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   9011:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   9012:                   '<input type="radio" name="togglecatscomm"'.
                   9013:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9014:                   '<label><input type="radio" name="togglecatscomm"'.
                   9015:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   9016:                   '</tr><tr>'.
                   9017:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   9018:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   9019:                   '<label><input type="radio" name="categorizecomm"'.
                   9020:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9021:                   '<label><input type="radio" name="categorizecomm"'.
                   9022:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327     raeburn  9023:                   '</tr><tr class="LC_odd_row">'.
1.272     raeburn  9024:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
                   9025:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   9026:                   '<input type="radio" name="togglecatsplace"'.
                   9027:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9028:                   '<label><input type="radio" name="togglecatscomm"'.
                   9029:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
                   9030:                   '</tr><tr>'.
                   9031:                   '<td>'.$title{'categorizeplace'}.'</td>'.
                   9032:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   9033:                   '<label><input type="radio" name="categorizeplace"'.
                   9034:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9035:                   '<label><input type="radio" name="categorizeplace"'.
                   9036:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  9037:                   '</tr>';
1.272     raeburn  9038:         $$rowtotal += 6;
1.57      raeburn  9039:     } else {
                   9040:         my $css_class;
                   9041:         my $itemcount = 1;
                   9042:         my $cathash; 
                   9043:         if (ref($settings) eq 'HASH') {
                   9044:             $cathash = $settings->{'cats'};
                   9045:         }
                   9046:         if (ref($cathash) eq 'HASH') {
                   9047:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   9048:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   9049:                                                    \%allitems,\%idx,\@jsarray);
                   9050:             my $maxdepth = scalar(@cats);
                   9051:             my $colattrib = '';
                   9052:             if ($maxdepth > 2) {
                   9053:                 $colattrib = ' colspan="2" ';
                   9054:             }
                   9055:             my @path;
                   9056:             if (@cats > 0) {
                   9057:                 if (ref($cats[0]) eq 'ARRAY') {
                   9058:                     my $numtop = @{$cats[0]};
                   9059:                     my $maxnum = $numtop;
1.120     raeburn  9060:                     my %default_names = (
                   9061:                           instcode    => &mt('Official courses'),
                   9062:                           communities => &mt('Communities'),
1.272     raeburn  9063:                           placement   => &mt('Placement Tests'),
1.120     raeburn  9064:                     );
                   9065: 
                   9066:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   9067:                         ($cathash->{'instcode::0'} eq '') ||
                   9068:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272     raeburn  9069:                         ($cathash->{'communities::0'} eq '') ||
                   9070:                         (!grep(/^placement$/,@{$cats[0]})) ||
                   9071:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  9072:                         $maxnum ++;
                   9073:                     }
                   9074:                     my $lastidx;
                   9075:                     for (my $i=0; $i<$numtop; $i++) {
                   9076:                         my $parent = $cats[0][$i];
                   9077:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9078:                         my $item = &escape($parent).'::0';
                   9079:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   9080:                         $lastidx = $idx{$item};
                   9081:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   9082:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   9083:                         for (my $k=0; $k<=$maxnum; $k++) {
                   9084:                             my $vpos = $k+1;
                   9085:                             my $selstr;
                   9086:                             if ($k == $i) {
                   9087:                                 $selstr = ' selected="selected" ';
                   9088:                             }
                   9089:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9090:                         }
1.214     raeburn  9091:                         $datatable .= '</select></span></td><td>';
1.272     raeburn  9092:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  9093:                             $datatable .=  '<span class="LC_nobreak">'
                   9094:                                            .$default_names{$parent}.'</span>';
                   9095:                             if ($parent eq 'instcode') {
                   9096:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   9097:                                               .&mt('with institutional codes')
                   9098:                                               .')</span></td><td'.$colattrib.'>';
                   9099:                             } else {
                   9100:                                 $datatable .= '<table><tr><td>';
                   9101:                             }
                   9102:                             $datatable .= '<span class="LC_nobreak">'
                   9103:                                           .'<label><input type="radio" name="'
                   9104:                                           .$parent.'" value="1" checked="checked" />'
                   9105:                                           .&mt('Display').'</label>';
                   9106:                             if ($parent eq 'instcode') {
                   9107:                                 $datatable .= '&nbsp;';
                   9108:                             } else {
                   9109:                                 $datatable .= '</span></td></tr><tr><td>'
                   9110:                                               .'<span class="LC_nobreak">';
                   9111:                             }
                   9112:                             $datatable .= '<label><input type="radio" name="'
                   9113:                                           .$parent.'" value="0" />'
                   9114:                                           .&mt('Do not display').'</label></span>';
1.272     raeburn  9115:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  9116:                                 $datatable .= '</td></tr></table>';
                   9117:                             }
                   9118:                             $datatable .= '</td>';
1.57      raeburn  9119:                         } else {
                   9120:                             $datatable .= $parent
1.214     raeburn  9121:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   9122:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  9123:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   9124:                         }
                   9125:                         my $depth = 1;
                   9126:                         push(@path,$parent);
                   9127:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   9128:                         pop(@path);
                   9129:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9130:                         $itemcount ++;
                   9131:                     }
1.48      raeburn  9132:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  9133:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   9134:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  9135:                     for (my $k=0; $k<=$maxnum; $k++) {
                   9136:                         my $vpos = $k+1;
                   9137:                         my $selstr;
1.57      raeburn  9138:                         if ($k == $numtop) {
1.48      raeburn  9139:                             $selstr = ' selected="selected" ';
                   9140:                         }
                   9141:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9142:                     }
1.59      bisitz   9143:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  9144:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   9145:                                   .'</tr>'."\n";
1.48      raeburn  9146:                     $itemcount ++;
1.272     raeburn  9147:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  9148:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   9149:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9150:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   9151:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   9152:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   9153:                             for (my $k=0; $k<=$maxnum; $k++) {
                   9154:                                 my $vpos = $k+1;
                   9155:                                 my $selstr;
                   9156:                                 if ($k == $maxnum) {
                   9157:                                     $selstr = ' selected="selected" ';
                   9158:                                 }
                   9159:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  9160:                             }
1.120     raeburn  9161:                             $datatable .= '</select></span></td>'.
                   9162:                                           '<td><span class="LC_nobreak">'.
                   9163:                                           $default_names{$default}.'</span>';
                   9164:                             if ($default eq 'instcode') {
                   9165:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   9166:                                               .&mt('with institutional codes').')</span>';
                   9167:                             }
                   9168:                             $datatable .= '</td>'
                   9169:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   9170:                                           .&mt('Display').'</label>&nbsp;'
                   9171:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   9172:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  9173:                         }
                   9174:                     }
                   9175:                 }
1.57      raeburn  9176:             } else {
                   9177:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  9178:             }
                   9179:         } else {
1.327     raeburn  9180:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  9181:                           .&initialize_categories($itemcount);
1.48      raeburn  9182:         }
1.57      raeburn  9183:         $$rowtotal += $itemcount;
1.48      raeburn  9184:     }
                   9185:     return $datatable;
                   9186: }
                   9187: 
1.69      raeburn  9188: sub print_serverstatuses {
                   9189:     my ($dom,$settings,$rowtotal) = @_;
                   9190:     my $datatable;
                   9191:     my @pages = &serverstatus_pages();
                   9192:     my (%namedaccess,%machineaccess);
                   9193:     foreach my $type (@pages) {
                   9194:         $namedaccess{$type} = '';
                   9195:         $machineaccess{$type}= '';
                   9196:     }
                   9197:     if (ref($settings) eq 'HASH') {
                   9198:         foreach my $type (@pages) {
                   9199:             if (exists($settings->{$type})) {
                   9200:                 if (ref($settings->{$type}) eq 'HASH') {
                   9201:                     foreach my $key (keys(%{$settings->{$type}})) {
                   9202:                         if ($key eq 'namedusers') {
                   9203:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   9204:                         } elsif ($key eq 'machines') {
                   9205:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   9206:                         }
                   9207:                     }
                   9208:                 }
                   9209:             }
                   9210:         }
                   9211:     }
1.81      raeburn  9212:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  9213:     my $rownum = 0;
                   9214:     my $css_class;
                   9215:     foreach my $type (@pages) {
                   9216:         $rownum ++;
                   9217:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   9218:         $datatable .= '<tr'.$css_class.'>'.
                   9219:                       '<td><span class="LC_nobreak">'.
                   9220:                       $titles->{$type}.'</span></td>'.
                   9221:                       '<td class="LC_left_item">'.
                   9222:                       '<input type="text" name="'.$type.'_namedusers" '.
                   9223:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   9224:                       '<td class="LC_right_item">'.
                   9225:                       '<span class="LC_nobreak">'.
                   9226:                       '<input type="text" name="'.$type.'_machines" '.
                   9227:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.334     raeburn  9228:                       '</span></td></tr>'."\n";
1.69      raeburn  9229:     }
                   9230:     $$rowtotal += $rownum;
                   9231:     return $datatable;
                   9232: }
                   9233: 
                   9234: sub serverstatus_pages {
                   9235:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275     raeburn  9236:             'checksums','clusterstatus','certstatus','metadata_keywords',
                   9237:             'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
                   9238:             'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69      raeburn  9239: }
                   9240: 
1.236     raeburn  9241: sub defaults_javascript {
                   9242:     my ($settings) = @_;
1.354     raeburn  9243:     return unless (ref($settings) eq 'HASH');
1.236     raeburn  9244:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   9245:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   9246:         if ($maxnum eq '') {
                   9247:             $maxnum = 0;
                   9248:         }
                   9249:         $maxnum ++;
1.249     raeburn  9250:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  9251:         return <<"ENDSCRIPT";
                   9252: <script type="text/javascript">
                   9253: // <![CDATA[
                   9254: function reorderTypes(form,caller) {
                   9255:     var changedVal;
                   9256: $jstext 
                   9257:     var newpos = 'addinststatus_pos';
                   9258:     var current = new Array;
                   9259:     var maxh = $maxnum;
                   9260:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9261:     var oldVal;
                   9262:     if (caller == newpos) {
                   9263:         changedVal = newitemVal;
                   9264:     } else {
                   9265:         var curritem = 'inststatus_pos_'+caller;
                   9266:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   9267:         current[newitemVal] = newpos;
                   9268:     }
                   9269:     for (var i=0; i<inststatuses.length; i++) {
                   9270:         if (inststatuses[i] != caller) {
                   9271:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   9272:             if (form.elements[elementName]) {
                   9273:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9274:                 current[currVal] = elementName;
                   9275:             }
                   9276:         }
                   9277:     }
                   9278:     for (var j=0; j<maxh; j++) {
                   9279:         if (current[j] == undefined) {
                   9280:             oldVal = j;
                   9281:         }
                   9282:     }
                   9283:     if (oldVal < changedVal) {
                   9284:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9285:            var elementName = current[k];
                   9286:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9287:         }
                   9288:     } else {
                   9289:         for (var k=changedVal; k<oldVal; k++) {
                   9290:             var elementName = current[k];
                   9291:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9292:         }
                   9293:     }
                   9294:     return;
                   9295: }
                   9296: 
                   9297: // ]]>
                   9298: </script>
                   9299: 
                   9300: ENDSCRIPT
                   9301:     }
1.354     raeburn  9302:     return;
                   9303: }
                   9304: 
                   9305: sub passwords_javascript {
1.365     raeburn  9306:     my %intalert = &Apache::lonlocal::texthash (
                   9307:         authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
                   9308:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   9309:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   9310:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   9311:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   9312:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   9313:     );
                   9314:     &js_escape(\%intalert);
                   9315:     my $defmin = $Apache::lonnet::passwdmin;
1.354     raeburn  9316:     my $intauthjs = <<"ENDSCRIPT";
                   9317: 
                   9318: function warnIntAuth(field) {
                   9319:     if (field.name == 'intauth_check') {
                   9320:         if (field.value == '2') {
1.365     raeburn  9321:             alert('$intalert{authcheck}');
1.354     raeburn  9322:         }
                   9323:     }
                   9324:     if (field.name == 'intauth_cost') {
                   9325:         field.value.replace(/\s/g,'');
                   9326:         if (field.value != '') {
                   9327:             var regexdigit=/^\\d+\$/;
                   9328:             if (!regexdigit.test(field.value)) {
1.365     raeburn  9329:                 alert('$intalert{authcost}');
                   9330:             }
                   9331:         }
                   9332:     }
                   9333:     return;
                   9334: }
                   9335: 
                   9336: function warnIntPass(field) {
                   9337:     field.value.replace(/^\s+/,'');
                   9338:     field.value.replace(/\s+\$/,'');
                   9339:     var regexdigit=/^\\d+\$/;
                   9340:     if (field.name == 'passwords_min') {
                   9341:         if (field.value == '') {
                   9342:             alert('$intalert{passmin}');
                   9343:             field.value = '$defmin';
                   9344:         } else {
                   9345:             if (!regexdigit.test(field.value)) {
                   9346:                 alert('$intalert{passmin}');
                   9347:                 field.value = '$defmin';
                   9348:             }
1.366     raeburn  9349:             var minval = parseInt(field.value,10);
1.365     raeburn  9350:             if (minval < $defmin) {
                   9351:                 alert('$intalert{passmin}');
                   9352:                 field.value = '$defmin';
                   9353:             }
                   9354:         }
                   9355:     } else {
                   9356:         if (field.value == '0') {
                   9357:             field.value = '';
                   9358:         }
                   9359:         if (field.value != '') {
                   9360:             if (field.name == 'passwords_expire') {
                   9361:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   9362:                 if (!regexpposnum.test(field.value)) {
                   9363:                     alert('$intalert{passexp}');
                   9364:                     field.value = '';
                   9365:                 } else {
                   9366:                     var expval = parseFloat(field.value);
                   9367:                     if (expval == 0) {
                   9368:                         alert('$intalert{passexp}');
                   9369:                         field.value = '';
                   9370:                     }
                   9371:                 }
                   9372:             } else {
                   9373:                 if (!regexdigit.test(field.value)) {
                   9374:                     if (field.name == 'passwords_max') {
                   9375:                         alert('$intalert{passmax}');
                   9376:                     } else {
                   9377:                         if (field.name == 'passwords_numsaved') {
                   9378:                             alert('$intalert{passnum}');
                   9379:                         }
                   9380:                     }
                   9381:                 }
                   9382:                 field.value = '';
1.354     raeburn  9383:             }
                   9384:         }
                   9385:     }
                   9386:     return;
                   9387: }
                   9388: 
                   9389: ENDSCRIPT
                   9390:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236     raeburn  9391: }
                   9392: 
1.49      raeburn  9393: sub coursecategories_javascript {
                   9394:     my ($settings) = @_;
1.57      raeburn  9395:     my ($output,$jstext,$cathash);
1.49      raeburn  9396:     if (ref($settings) eq 'HASH') {
1.57      raeburn  9397:         $cathash = $settings->{'cats'};
                   9398:     }
                   9399:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  9400:         my (@cats,@jsarray,%idx);
1.57      raeburn  9401:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  9402:         if (@jsarray > 0) {
                   9403:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   9404:             for (my $i=0; $i<@jsarray; $i++) {
                   9405:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   9406:                     my $catstr = join('","',@{$jsarray[$i]});
                   9407:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   9408:                 }
                   9409:             }
                   9410:         }
                   9411:     } else {
                   9412:         $jstext  = '    var categories = Array(1);'."\n".
                   9413:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   9414:     }
1.237     bisitz   9415:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   9416:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272     raeburn  9417:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  9418:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   9419:     &js_escape(\$instcode_reserved);
                   9420:     &js_escape(\$communities_reserved);
1.272     raeburn  9421:     &js_escape(\$placement_reserved);
1.265     damieng  9422:     &js_escape(\$choose_again);
1.49      raeburn  9423:     $output = <<"ENDSCRIPT";
                   9424: <script type="text/javascript">
1.109     raeburn  9425: // <![CDATA[
1.49      raeburn  9426: function reorderCats(form,parent,item,idx) {
                   9427:     var changedVal;
                   9428: $jstext
                   9429:     var newpos = 'addcategory_pos';
                   9430:     if (parent == '') {
                   9431:         var has_instcode = 0;
                   9432:         var maxtop = categories[idx].length;
                   9433:         for (var j=0; j<maxtop; j++) {
                   9434:             if (categories[idx][j] == 'instcode::0') {
                   9435:                 has_instcode == 1;
                   9436:             }
                   9437:         }
                   9438:         if (has_instcode == 0) {
                   9439:             categories[idx][maxtop] = 'instcode_pos';
                   9440:         }
                   9441:     } else {
                   9442:         newpos += '_'+parent;
                   9443:     }
                   9444:     var maxh = 1 + categories[idx].length;
                   9445:     var current = new Array;
                   9446:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9447:     if (item == newpos) {
                   9448:         changedVal = newitemVal;
                   9449:     } else {
                   9450:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   9451:         current[newitemVal] = newpos;
                   9452:     }
                   9453:     for (var i=0; i<categories[idx].length; i++) {
                   9454:         var elementName = categories[idx][i];
                   9455:         if (elementName != item) {
                   9456:             if (form.elements[elementName]) {
                   9457:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9458:                 current[currVal] = elementName;
                   9459:             }
                   9460:         }
                   9461:     }
                   9462:     var oldVal;
                   9463:     for (var j=0; j<maxh; j++) {
                   9464:         if (current[j] == undefined) {
                   9465:             oldVal = j;
                   9466:         }
                   9467:     }
                   9468:     if (oldVal < changedVal) {
                   9469:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9470:            var elementName = current[k];
                   9471:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9472:         }
                   9473:     } else {
                   9474:         for (var k=changedVal; k<oldVal; k++) {
                   9475:             var elementName = current[k];
                   9476:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9477:         }
                   9478:     }
                   9479:     return;
                   9480: }
1.120     raeburn  9481: 
                   9482: function categoryCheck(form) {
                   9483:     if (form.elements['addcategory_name'].value == 'instcode') {
                   9484:         alert('$instcode_reserved\\n$choose_again');
                   9485:         return false;
                   9486:     }
                   9487:     if (form.elements['addcategory_name'].value == 'communities') {
                   9488:         alert('$communities_reserved\\n$choose_again');
                   9489:         return false;
                   9490:     }
1.272     raeburn  9491:     if (form.elements['addcategory_name'].value == 'placement') {
                   9492:         alert('$placement_reserved\\n$choose_again');
                   9493:         return false;
                   9494:     }
1.120     raeburn  9495:     return true;
                   9496: }
                   9497: 
1.109     raeburn  9498: // ]]>
1.49      raeburn  9499: </script>
                   9500: 
                   9501: ENDSCRIPT
                   9502:     return $output;
                   9503: }
                   9504: 
1.48      raeburn  9505: sub initialize_categories {
                   9506:     my ($itemcount) = @_;
1.120     raeburn  9507:     my ($datatable,$css_class,$chgstr);
                   9508:     my %default_names = (
                   9509:                       instcode    => 'Official courses (with institutional codes)',
                   9510:                       communities => 'Communities',
1.272     raeburn  9511:                       placement   => 'Placement Tests',
1.120     raeburn  9512:                         );
1.328     raeburn  9513:     my %selnum = (
                   9514:                    instcode    => '0',
                   9515:                    communities => '1',
                   9516:                    placement   => '2',
                   9517:                  );
                   9518:     my %selected;
1.272     raeburn  9519:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  9520:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327     raeburn  9521:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328     raeburn  9522:         map { $selected{$selnum{$_}} = '' } keys(%selnum);
                   9523:         $selected{$selnum{$default}} = ' selected="selected"';
1.120     raeburn  9524:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328     raeburn  9525:                      .'<select name="'.$default.'_pos"'.$chgstr.'>'
                   9526:                      .'<option value="0"'.$selected{'0'}.'>1</option>'
                   9527:                      .'<option value="1"'.$selected{'1'}.'>2</option>'
                   9528:                      .'<option value="2"'.$selected{'2'}.'>3</option>'
                   9529:                      .'<option value="3">4</option></select>&nbsp;'
1.120     raeburn  9530:                      .$default_names{$default}
                   9531:                      .'</span></td><td><span class="LC_nobreak">'
                   9532:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   9533:                      .&mt('Display').'</label>&nbsp;<label>'
                   9534:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  9535:                  .'</label></span></td></tr>';
1.120     raeburn  9536:         $itemcount ++;
                   9537:     }
1.48      raeburn  9538:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  9539:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  9540:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  9541:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   9542:                   .'<option value="0">1</option>'
                   9543:                   .'<option value="1">2</option>'
1.328     raeburn  9544:                   .'<option value="2">3</option>'
                   9545:                   .'<option value="3" selected="selected">4</option></select>&nbsp;'
1.327     raeburn  9546:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                   9547:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   9548:                   .'</td></tr>';
1.48      raeburn  9549:     return $datatable;
                   9550: }
                   9551: 
                   9552: sub build_category_rows {
1.49      raeburn  9553:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   9554:     my ($text,$name,$item,$chgstr);
1.48      raeburn  9555:     if (ref($cats) eq 'ARRAY') {
                   9556:         my $maxdepth = scalar(@{$cats});
                   9557:         if (ref($cats->[$depth]) eq 'HASH') {
                   9558:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9559:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9560:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  9561:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  9562:                 my ($idxnum,$parent_name,$parent_item);
                   9563:                 my $higher = $depth - 1;
                   9564:                 if ($higher == 0) {
                   9565:                     $parent_name = &escape($parent).'::'.$higher;
                   9566:                 } else {
                   9567:                     if (ref($path) eq 'ARRAY') {
                   9568:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9569:                     }
                   9570:                 }
                   9571:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  9572:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  9573:                     if ($j < $numchildren) {
1.48      raeburn  9574:                         $name = $cats->[$depth]{$parent}[$j];
                   9575:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  9576:                         $idxnum = $idx->{$item};
                   9577:                     } else {
                   9578:                         $name = $parent_name;
                   9579:                         $item = $parent_item;
1.48      raeburn  9580:                     }
1.49      raeburn  9581:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   9582:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  9583:                     for (my $i=0; $i<=$numchildren; $i++) {
                   9584:                         my $vpos = $i+1;
                   9585:                         my $selstr;
                   9586:                         if ($j == $i) {
                   9587:                             $selstr = ' selected="selected" ';
                   9588:                         }
                   9589:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   9590:                     }
                   9591:                     $text .= '</select>&nbsp;';
                   9592:                     if ($j < $numchildren) {
                   9593:                         my $deeper = $depth+1;
                   9594:                         $text .= $name.'&nbsp;'
                   9595:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   9596:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   9597:                         if(ref($path) eq 'ARRAY') {
                   9598:                             push(@{$path},$name);
1.49      raeburn  9599:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  9600:                             pop(@{$path});
                   9601:                         }
                   9602:                     } else {
1.330     raeburn  9603:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  9604:                         if ($j == $numchildren) {
                   9605:                             $text .= $name;
                   9606:                         } else {
                   9607:                             $text .= $item;
                   9608:                         }
                   9609:                         $text .= '" value="" />';
                   9610:                     }
                   9611:                     $text .= '</td></tr>';
                   9612:                 }
                   9613:                 $text .= '</table></td>';
                   9614:             } else {
                   9615:                 my $higher = $depth-1;
                   9616:                 if ($higher == 0) {
                   9617:                     $name = &escape($parent).'::'.$higher;
                   9618:                 } else {
                   9619:                     if (ref($path) eq 'ARRAY') {
                   9620:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9621:                     }
                   9622:                 }
                   9623:                 my $colspan;
                   9624:                 if ($parent ne 'instcode') {
                   9625:                     $colspan = $maxdepth - $depth - 1;
1.330     raeburn  9626:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  9627:                 }
                   9628:             }
                   9629:         }
                   9630:     }
                   9631:     return $text;
                   9632: }
                   9633: 
1.33      raeburn  9634: sub modifiable_userdata_row {
1.305     raeburn  9635:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357     raeburn  9636:         $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228     raeburn  9637:     my ($role,$rolename,$statustype);
                   9638:     $role = $item;
1.224     raeburn  9639:     if ($context eq 'cancreate') {
1.305     raeburn  9640:         if ($item =~ /^(emailusername)_(.+)$/) {
                   9641:             $role = $1;
                   9642:             $statustype = $2;
1.228     raeburn  9643:             if (ref($usertypes) eq 'HASH') {
                   9644:                 if ($usertypes->{$statustype}) {
                   9645:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   9646:                 } else {
                   9647:                     $rolename = &mt('Data provided by user');
                   9648:                 }
                   9649:             }
1.224     raeburn  9650:         }
                   9651:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  9652:         if (ref($usertypes) eq 'HASH') {
                   9653:             $rolename = $usertypes->{$role};
                   9654:         } else {
                   9655:             $rolename = $role;
                   9656:         }
1.325     raeburn  9657:     } elsif ($context eq 'lti') {
                   9658:         $rolename = &mt('Institutional data used (if available)');
1.357     raeburn  9659:     } elsif ($context eq 'privacy') {
                   9660:         $rolename = $itemdesc;
1.33      raeburn  9661:     } else {
1.63      raeburn  9662:         if ($role eq 'cr') {
                   9663:             $rolename = &mt('Custom role');
                   9664:         } else {
                   9665:             $rolename = &Apache::lonnet::plaintext($role);
                   9666:         }
1.33      raeburn  9667:     }
1.224     raeburn  9668:     my (@fields,%fieldtitles);
                   9669:     if (ref($fieldsref) eq 'ARRAY') {
                   9670:         @fields = @{$fieldsref};
                   9671:     } else {
                   9672:         @fields = ('lastname','firstname','middlename','generation',
                   9673:                    'permanentemail','id');
                   9674:     }
                   9675:     if ((ref($titlesref) eq 'HASH')) {
                   9676:         %fieldtitles = %{$titlesref};
                   9677:     } else {
                   9678:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9679:     }
1.33      raeburn  9680:     my $output;
1.305     raeburn  9681:     my $css_class;
                   9682:     if ($rowcount%2) {
                   9683:         $css_class = 'LC_odd_row';
                   9684:     }
                   9685:     if ($customcss) {
                   9686:         $css_class .= " $customcss";
                   9687:     }
                   9688:     $css_class =~ s/^\s+//;
                   9689:     if ($css_class) {
                   9690:         $css_class = ' class="'.$css_class.'"';
                   9691:     }
                   9692:     if ($rowstyle) {
                   9693:         $css_class .= ' style="'.$rowstyle.'"';
                   9694:     }
                   9695:     if ($rowid) {
                   9696:         $rowid = ' id="'.$rowid.'"';
                   9697:     }
                   9698:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  9699:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   9700:               '<td class="LC_left_item" colspan="2"><table>';
                   9701:     my $rem;
                   9702:     my %checks;
1.325     raeburn  9703:     my %current;
1.33      raeburn  9704:     if (ref($settings) eq 'HASH') {
1.325     raeburn  9705:         my $hashref;
                   9706:         if ($context eq 'lti') {
                   9707:             if (ref($settings) eq 'HASH') {
                   9708:                 $hashref = $settings->{'instdata'};
                   9709:             }
1.357     raeburn  9710:         } elsif ($context eq 'privacy') {
                   9711:             my ($key,$inner) = split(/_/,$role);
                   9712:             if (ref($settings) eq 'HASH') {
                   9713:                 if (ref($settings->{$key}) eq 'HASH') {
                   9714:                     $hashref = $settings->{$key}->{$inner};
                   9715:                 }
                   9716:             }
1.325     raeburn  9717:         } elsif (ref($settings->{$context}) eq 'HASH') {
1.33      raeburn  9718:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325     raeburn  9719:                 $hashref = $settings->{'lti_instdata'};
                   9720:             }
                   9721:             if ($role eq 'emailusername') {
                   9722:                 if ($statustype) {
                   9723:                     if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   9724:                         $hashref = $settings->{$context}->{$role}->{$statustype};
1.228     raeburn  9725:                     }
1.325     raeburn  9726:                 }
                   9727:             }
                   9728:         }
                   9729:         if (ref($hashref) eq 'HASH') { 
                   9730:             foreach my $field (@fields) {
                   9731:                 if ($hashref->{$field}) {
                   9732:                     if ($role eq 'emailusername') {
                   9733:                         $checks{$field} = $hashref->{$field};
                   9734:                     } else {
                   9735:                         $checks{$field} = ' checked="checked" ';
1.33      raeburn  9736:                     }
                   9737:                 }
                   9738:             }
                   9739:         }
                   9740:     }
1.305     raeburn  9741:  
                   9742:     my $total = scalar(@fields);
                   9743:     for (my $i=0; $i<$total; $i++) {
                   9744:         $rem = $i%($numinrow);
1.33      raeburn  9745:         if ($rem == 0) {
                   9746:             if ($i > 0) {
                   9747:                 $output .= '</tr>';
                   9748:             }
                   9749:             $output .= '<tr>';
                   9750:         }
                   9751:         my $check = ' ';
1.228     raeburn  9752:         unless ($role eq 'emailusername') {
                   9753:             if (exists($checks{$fields[$i]})) {
1.354     raeburn  9754:                 $check = $checks{$fields[$i]};
1.357     raeburn  9755:             } elsif ($context eq 'privacy') {
                   9756:                 if ($role =~ /^priv_(domain|course)$/) {
                   9757:                     if (ref($settings) ne 'HASH') {
                   9758:                         $check = ' checked="checked" ';
                   9759:                     }
                   9760:                 } elsif ($role =~ /^priv_(author|community)$/) {
                   9761:                     if (ref($settings) ne 'HASH') {
                   9762:                         unless ($fields[$i] eq 'id') {
                   9763:                             $check = ' checked="checked" ';
                   9764:                         }
                   9765:                     }
                   9766:                 } elsif ($role =~ /^(unpriv|othdom)_/) {
                   9767:                     if (ref($settings) ne 'HASH') {
                   9768:                         if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                   9769:                             $check = ' checked="checked" ';
                   9770:                         }
                   9771:                     }
                   9772:                 }
1.325     raeburn  9773:             } elsif ($context ne 'lti') {
1.228     raeburn  9774:                 if ($role eq 'st') {
                   9775:                     if (ref($settings) ne 'HASH') {
                   9776:                         $check = ' checked="checked" '; 
                   9777:                     }
1.33      raeburn  9778:                 }
                   9779:             }
                   9780:         }
                   9781:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  9782:                    '<span class="LC_nobreak">';
1.325     raeburn  9783:         my $prefix = 'canmodify';
1.228     raeburn  9784:         if ($role eq 'emailusername') {
                   9785:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   9786:                 $checks{$fields[$i]} = 'omit';
                   9787:             }
                   9788:             foreach my $option ('required','optional','omit') {
                   9789:                 my $checked='';
                   9790:                 if ($checks{$fields[$i]} eq $option) {
                   9791:                     $checked='checked="checked" ';
                   9792:                 }
                   9793:                 $output .= '<label>'.
1.325     raeburn  9794:                            '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228     raeburn  9795:                            &mt($option).'</label>'.('&nbsp;' x2);
                   9796:             }
                   9797:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   9798:         } else {
1.325     raeburn  9799:             if ($context eq 'lti') {
                   9800:                 $prefix = 'lti';
1.357     raeburn  9801:             } elsif ($context eq 'privacy') {
                   9802:                 $prefix = 'privacy';
1.325     raeburn  9803:             }
1.228     raeburn  9804:             $output .= '<label>'.
1.325     raeburn  9805:                        '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228     raeburn  9806:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   9807:                        '</label>';
                   9808:         }
                   9809:         $output .= '</span></td>';
1.33      raeburn  9810:     }
1.305     raeburn  9811:     $rem = $total%$numinrow;
                   9812:     my $colsleft;
                   9813:     if ($rem) {
                   9814:         $colsleft = $numinrow - $rem;
                   9815:     }
                   9816:     if ($colsleft > 1) {
1.33      raeburn  9817:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9818:                    '&nbsp;</td>';
                   9819:     } elsif ($colsleft == 1) {
                   9820:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   9821:     }
                   9822:     $output .= '</tr></table></td></tr>';
                   9823:     return $output;
                   9824: }
1.28      raeburn  9825: 
1.93      raeburn  9826: sub insttypes_row {
1.305     raeburn  9827:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   9828:         $customcss,$rowstyle) = @_;
1.93      raeburn  9829:     my %lt = &Apache::lonlocal::texthash (
                   9830:                       cansearch => 'Users allowed to search',
                   9831:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  9832:                       lockablenames => 'User preference to lock name',
1.305     raeburn  9833:                       selfassign    => 'Self-reportable affiliations',
1.315     raeburn  9834:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  9835:              );
                   9836:     my $showdom;
                   9837:     if ($context eq 'cansearch') {
                   9838:         $showdom = ' ('.$dom.')';
                   9839:     }
1.165     raeburn  9840:     my $class = 'LC_left_item';
                   9841:     if ($context eq 'statustocreate') {
                   9842:         $class = 'LC_right_item';
                   9843:     }
1.305     raeburn  9844:     my $css_class;
                   9845:     if ($$rowtotal%2) {
                   9846:         $css_class = 'LC_odd_row';
                   9847:     }
                   9848:     if ($customcss) {
                   9849:         $css_class .= ' '.$customcss;
                   9850:     }
                   9851:     $css_class =~ s/^\s+//;
                   9852:     if ($css_class) {
                   9853:         $css_class = ' class="'.$css_class.'"';
                   9854:     }
                   9855:     if ($rowstyle) {
                   9856:         $css_class .= ' style="'.$rowstyle.'"';
                   9857:     }
                   9858:     if ($onclick) {
                   9859:         $onclick = 'onclick="'.$onclick.'" ';
1.224     raeburn  9860:     }
                   9861:     my $output = '<tr'.$css_class.'>'.
                   9862:                  '<td>'.$lt{$context}.$showdom.
                   9863:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  9864:     my $rem;
                   9865:     if (ref($types) eq 'ARRAY') {
                   9866:         for (my $i=0; $i<@{$types}; $i++) {
                   9867:             if (defined($usertypes->{$types->[$i]})) {
                   9868:                 my $rem = $i%($numinrow);
                   9869:                 if ($rem == 0) {
                   9870:                     if ($i > 0) {
                   9871:                         $output .= '</tr>';
                   9872:                     }
                   9873:                     $output .= '<tr>';
1.23      raeburn  9874:                 }
1.26      raeburn  9875:                 my $check = ' ';
1.99      raeburn  9876:                 if (ref($settings) eq 'HASH') {
                   9877:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   9878:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   9879:                             $check = ' checked="checked" ';
                   9880:                         }
1.315     raeburn  9881:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   9882:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   9883:                             $check = ' checked="checked" ';
                   9884:                         }
1.99      raeburn  9885:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  9886:                         $check = ' checked="checked" ';
                   9887:                     }
1.23      raeburn  9888:                 }
1.26      raeburn  9889:                 $output .= '<td class="LC_left_item">'.
                   9890:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  9891:                            '<input type="checkbox" name="'.$context.'" '.
1.305     raeburn  9892:                            'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26      raeburn  9893:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  9894:             }
                   9895:         }
1.26      raeburn  9896:         $rem = @{$types}%($numinrow);
1.23      raeburn  9897:     }
                   9898:     my $colsleft = $numinrow - $rem;
1.315     raeburn  9899:     if ($context eq 'overrides') {
                   9900:         if ($colsleft > 1) {
                   9901:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9902:         } else {
                   9903:             $output .= '<td class="LC_left_item">';
                   9904:         }
                   9905:         $output .= '&nbsp;';  
1.23      raeburn  9906:     } else {
1.334     raeburn  9907:         if ($rem == 0) {
1.315     raeburn  9908:             $output .= '<tr>';
                   9909:         }
                   9910:         if ($colsleft > 1) {
                   9911:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9912:         } else {
                   9913:             $output .= '<td class="LC_left_item">';
                   9914:         }
                   9915:         my $defcheck = ' ';
                   9916:         if (ref($settings) eq 'HASH') {  
                   9917:             if (ref($settings->{$context}) eq 'ARRAY') {
                   9918:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   9919:                     $defcheck = ' checked="checked" ';
                   9920:                 }
                   9921:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  9922:                 $defcheck = ' checked="checked" ';
                   9923:             }
1.26      raeburn  9924:         }
1.315     raeburn  9925:         $output .= '<span class="LC_nobreak"><label>'.
                   9926:                    '<input type="checkbox" name="'.$context.'" '.
                   9927:                    'value="default"'.$defcheck.$onclick.' />'.
                   9928:                    $othertitle.'</label></span>';
1.23      raeburn  9929:     }
1.315     raeburn  9930:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  9931:     return $output;
1.23      raeburn  9932: }
                   9933: 
                   9934: sub sorted_searchtitles {
                   9935:     my %searchtitles = &Apache::lonlocal::texthash(
                   9936:                          'uname' => 'username',
                   9937:                          'lastname' => 'last name',
                   9938:                          'lastfirst' => 'last name, first name',
                   9939:                      );
                   9940:     my @titleorder = ('uname','lastname','lastfirst');
                   9941:     return (\%searchtitles,\@titleorder);
                   9942: }
                   9943: 
1.25      raeburn  9944: sub sorted_searchtypes {
                   9945:     my %srchtypes_desc = (
                   9946:                            exact    => 'is exact match',
                   9947:                            contains => 'contains ..',
                   9948:                            begins   => 'begins with ..',
                   9949:                          );
                   9950:     my @srchtypeorder = ('exact','begins','contains');
                   9951:     return (\%srchtypes_desc,\@srchtypeorder);
                   9952: }
                   9953: 
1.3       raeburn  9954: sub usertype_update_row {
                   9955:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   9956:     my $datatable;
                   9957:     my $numinrow = 4;
                   9958:     foreach my $type (@{$types}) {
                   9959:         if (defined($usertypes->{$type})) {
                   9960:             $$rownums ++;
                   9961:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   9962:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   9963:                           '</td><td class="LC_left_item"><table>';
                   9964:             for (my $i=0; $i<@{$fields}; $i++) {
                   9965:                 my $rem = $i%($numinrow);
                   9966:                 if ($rem == 0) {
                   9967:                     if ($i > 0) {
                   9968:                         $datatable .= '</tr>';
                   9969:                     }
                   9970:                     $datatable .= '<tr>';
                   9971:                 }
                   9972:                 my $check = ' ';
1.39      raeburn  9973:                 if (ref($settings) eq 'HASH') {
                   9974:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   9975:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   9976:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   9977:                                 $check = ' checked="checked" ';
                   9978:                             }
1.3       raeburn  9979:                         }
                   9980:                     }
                   9981:                 }
                   9982: 
                   9983:                 if ($i == @{$fields}-1) {
                   9984:                     my $colsleft = $numinrow - $rem;
                   9985:                     if ($colsleft > 1) {
                   9986:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   9987:                     } else {
                   9988:                         $datatable .= '<td>';
                   9989:                     }
                   9990:                 } else {
                   9991:                     $datatable .= '<td>';
                   9992:                 }
1.8       raeburn  9993:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   9994:                               '<input type="checkbox" name="updateable_'.$type.
                   9995:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   9996:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  9997:             }
                   9998:             $datatable .= '</tr></table></td></tr>';
                   9999:         }
                   10000:     }
                   10001:     return $datatable;
1.1       raeburn  10002: }
                   10003: 
                   10004: sub modify_login {
1.205     raeburn  10005:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  10006:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   10007:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   10008:     %title = ( coursecatalog => 'Display course catalog',
                   10009:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  10010:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  10011:                newuser => 'Link for visitors to create a user account',
                   10012:                loginheader => 'Log-in box header');
                   10013:     @offon = ('off','on');
1.112     raeburn  10014:     if (ref($domconfig{login}) eq 'HASH') {
                   10015:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   10016:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   10017:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   10018:             }
                   10019:         }
                   10020:     }
1.9       raeburn  10021:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   10022:                                            \%domconfig,\%loginhash);
1.188     raeburn  10023:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  10024:     foreach my $item (@toggles) {
                   10025:         $loginhash{login}{$item} = $env{'form.'.$item};
                   10026:     }
1.41      raeburn  10027:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  10028:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   10029:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   10030:                                          \%loginhash);
                   10031:     }
1.110     raeburn  10032: 
1.149     raeburn  10033:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  10034:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  10035:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  10036:     if (keys(%servers) > 1) {
                   10037:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  10038:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   10039:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   10040:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   10041:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   10042:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   10043:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10044:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   10045:                         $changes{'loginvia'}{$lonhost} = 1;
                   10046:                     } else {
                   10047:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   10048:                         $changes{'loginvia'}{$lonhost} = 1;
                   10049:                     }
                   10050:                 } else {
                   10051:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10052:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   10053:                         $changes{'loginvia'}{$lonhost} = 1;
                   10054:                     }
                   10055:                 }
                   10056:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   10057:                     foreach my $item (@loginvia_attribs) {
                   10058:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   10059:                     }
                   10060:                 } else {
                   10061:                     foreach my $item (@loginvia_attribs) {
                   10062:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   10063:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   10064:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   10065:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   10066:                                 $new = '/';
                   10067:                             }
                   10068:                         }
                   10069:                         if (($item eq 'custompath') && 
                   10070:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   10071:                             $new = '';
                   10072:                         }
                   10073:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   10074:                             $changes{'loginvia'}{$lonhost} = 1;
                   10075:                         }
                   10076:                         if ($item eq 'exempt') {
1.256     raeburn  10077:                             $new = &check_exempt_addresses($new);
1.128     raeburn  10078:                         }
                   10079:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   10080:                     }
                   10081:                 }
1.112     raeburn  10082:             } else {
1.128     raeburn  10083:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10084:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  10085:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  10086:                     foreach my $item (@loginvia_attribs) {
                   10087:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   10088:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   10089:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   10090:                                 $new = '/';
                   10091:                             }
                   10092:                         }
                   10093:                         if (($item eq 'custompath') && 
                   10094:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   10095:                             $new = '';
                   10096:                         }
                   10097:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   10098:                     }
1.110     raeburn  10099:                 }
                   10100:             }
                   10101:         }
                   10102:     }
1.119     raeburn  10103: 
1.168     raeburn  10104:     my $servadm = $r->dir_config('lonAdmEMail');
                   10105:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   10106:     if (ref($domconfig{'login'}) eq 'HASH') {
                   10107:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   10108:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   10109:                 if ($lang eq 'nolang') {
                   10110:                     push(@currlangs,$lang);
                   10111:                 } elsif (defined($langchoices{$lang})) {
                   10112:                     push(@currlangs,$lang);
                   10113:                 } else {
                   10114:                     next;
                   10115:                 }
                   10116:             }
                   10117:         }
                   10118:     }
                   10119:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   10120:     if (@currlangs > 0) {
                   10121:         foreach my $lang (@currlangs) {
                   10122:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   10123:                 $changes{'helpurl'}{$lang} = 1;
                   10124:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   10125:                 $changes{'helpurl'}{$lang} = 1;
                   10126:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   10127:                 push(@newlangs,$lang);
                   10128:             } else {
                   10129:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   10130:             }
                   10131:         }
                   10132:     }
                   10133:     unless (grep(/^nolang$/,@currlangs)) {
                   10134:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   10135:             $changes{'helpurl'}{'nolang'} = 1;
                   10136:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   10137:             push(@newlangs,'nolang');
                   10138:         }
                   10139:     }
                   10140:     if ($env{'form.loginhelpurl_add_lang'}) {
                   10141:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   10142:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   10143:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   10144:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   10145:         }
                   10146:     }
                   10147:     if ((@newlangs > 0) || ($addedfile)) {
                   10148:         my $error;
                   10149:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10150:         if ($configuserok eq 'ok') {
                   10151:             if ($switchserver) {
                   10152:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   10153:             } elsif ($author_ok eq 'ok') {
                   10154:                 my @allnew = @newlangs;
                   10155:                 if ($addedfile ne '') {
                   10156:                     push(@allnew,$addedfile);
                   10157:                 }
                   10158:                 foreach my $lang (@allnew) {
                   10159:                     my $formelem = 'loginhelpurl_'.$lang;
                   10160:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   10161:                         $formelem = 'loginhelpurl_add_file';
                   10162:                     }
                   10163:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10164:                                                                "help/$lang",'','',$newfile{$lang});
                   10165:                     if ($result eq 'ok') {
                   10166:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   10167:                         $changes{'helpurl'}{$lang} = 1;
                   10168:                     } else {
                   10169:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   10170:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  10171:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  10172:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   10173:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   10174:                         }
                   10175:                     }
                   10176:                 }
                   10177:             } else {
                   10178:                 $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);
                   10179:             }
                   10180:         } else {
                   10181:             $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);
                   10182:         }
                   10183:         if ($error) {
                   10184:             &Apache::lonnet::logthis($error);
                   10185:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10186:         }
                   10187:     }
1.256     raeburn  10188: 
                   10189:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   10190:     if (ref($domconfig{'login'}) eq 'HASH') {
                   10191:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   10192:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   10193:                 if ($domservers{$lonhost}) {
                   10194:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10195:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  10196:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  10197:                     }
                   10198:                 }
                   10199:             }
                   10200:         }
                   10201:     }
                   10202:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   10203:     foreach my $lonhost (sort(keys(%domservers))) {
                   10204:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10205:             $changes{'headtag'}{$lonhost} = 1;
                   10206:         } else {
                   10207:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   10208:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   10209:             }
                   10210:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   10211:                 push(@newhosts,$lonhost);
                   10212:             } elsif ($currheadtagurls{$lonhost}) {
                   10213:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   10214:                 if ($currexempt{$lonhost}) {
1.289     raeburn  10215:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256     raeburn  10216:                         $changes{'headtag'}{$lonhost} = 1;
                   10217:                     }
                   10218:                 } elsif ($possexempt{$lonhost}) {
                   10219:                     $changes{'headtag'}{$lonhost} = 1;
                   10220:                 }
                   10221:                 if ($possexempt{$lonhost}) {
                   10222:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10223:                 }
                   10224:             }
                   10225:         }
                   10226:     }
                   10227:     if (@newhosts) {
                   10228:         my $error;
                   10229:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10230:         if ($configuserok eq 'ok') {
                   10231:             if ($switchserver) {
                   10232:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   10233:             } elsif ($author_ok eq 'ok') {
                   10234:                 foreach my $lonhost (@newhosts) {
                   10235:                     my $formelem = 'loginheadtag_'.$lonhost;
                   10236:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10237:                                                                           "login/headtag/$lonhost",'','',
                   10238:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   10239:                     if ($result eq 'ok') {
                   10240:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   10241:                         $changes{'headtag'}{$lonhost} = 1;
                   10242:                         if ($possexempt{$lonhost}) {
                   10243:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10244:                         }
                   10245:                     } else {
                   10246:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   10247:                                            $newheadtagurls{$lonhost},$result);
                   10248:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   10249:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   10250:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   10251:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   10252:                         }
                   10253:                     }
                   10254:                 }
                   10255:             } else {
                   10256:                 $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);
                   10257:             }
                   10258:         } else {
                   10259:             $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);
                   10260:         }
                   10261:         if ($error) {
                   10262:             &Apache::lonnet::logthis($error);
                   10263:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10264:         }
                   10265:     }
1.169     raeburn  10266:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  10267: 
                   10268:     my $defaulthelpfile = '/adm/loginproblems.html';
                   10269:     my $defaulttext = &mt('Default in use');
                   10270: 
1.1       raeburn  10271:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   10272:                                              $dom);
                   10273:     if ($putresult eq 'ok') {
1.188     raeburn  10274:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  10275:         my %defaultchecked = (
                   10276:                     'coursecatalog' => 'on',
1.188     raeburn  10277:                     'helpdesk'      => 'on',
1.42      raeburn  10278:                     'adminmail'     => 'off',
1.43      raeburn  10279:                     'newuser'       => 'off',
1.42      raeburn  10280:         );
1.55      raeburn  10281:         if (ref($domconfig{'login'}) eq 'HASH') {
                   10282:             foreach my $item (@toggles) {
                   10283:                 if ($defaultchecked{$item} eq 'on') { 
                   10284:                     if (($domconfig{'login'}{$item} eq '0') &&
                   10285:                         ($env{'form.'.$item} eq '1')) {
                   10286:                         $changes{$item} = 1;
                   10287:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10288:                               $domconfig{'login'}{$item} eq '1') &&
                   10289:                              ($env{'form.'.$item} eq '0')) {
                   10290:                         $changes{$item} = 1;
                   10291:                     }
                   10292:                 } elsif ($defaultchecked{$item} eq 'off') {
                   10293:                     if (($domconfig{'login'}{$item} eq '1') &&
                   10294:                         ($env{'form.'.$item} eq '0')) {
                   10295:                         $changes{$item} = 1;
                   10296:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10297:                               $domconfig{'login'}{$item} eq '0') &&
                   10298:                              ($env{'form.'.$item} eq '1')) {
                   10299:                         $changes{$item} = 1;
                   10300:                     }
1.42      raeburn  10301:                 }
                   10302:             }
1.41      raeburn  10303:         }
1.6       raeburn  10304:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  10305:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10306:             if (ref($lastactref) eq 'HASH') {
                   10307:                 $lastactref->{'domainconfig'} = 1;
                   10308:             }
1.1       raeburn  10309:             $resulttext = &mt('Changes made:').'<ul>';
                   10310:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   10311:                 if ($item eq 'loginvia') {
1.112     raeburn  10312:                     if (ref($changes{$item}) eq 'HASH') {
                   10313:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   10314:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  10315:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   10316:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   10317:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   10318:                                     $protocol = 'http' if ($protocol ne 'https');
                   10319:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   10320: 
                   10321:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   10322:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   10323:                                     } else {
                   10324:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   10325:                                     }
                   10326:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   10327:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   10328:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   10329:                                     }
                   10330:                                     $resulttext .= '</li>';
                   10331:                                 } else {
                   10332:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   10333:                                 }
1.112     raeburn  10334:                             } else {
1.128     raeburn  10335:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  10336:                             }
                   10337:                         }
1.128     raeburn  10338:                         $resulttext .= '</ul></li>';
1.112     raeburn  10339:                     }
1.168     raeburn  10340:                 } elsif ($item eq 'helpurl') {
                   10341:                     if (ref($changes{$item}) eq 'HASH') {
                   10342:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   10343:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   10344:                                 my ($chg,$link);
                   10345:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   10346:                                 if ($lang eq 'nolang') {
                   10347:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   10348:                                 } else {
                   10349:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   10350:                                 }
                   10351:                                 $resulttext .= '<li>'.$chg.'</li>';
                   10352:                             } else {
                   10353:                                 my $chg;
                   10354:                                 if ($lang eq 'nolang') {
                   10355:                                     $chg = &mt('custom log-in help file for no preferred language');
                   10356:                                 } else {
                   10357:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   10358:                                 }
                   10359:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   10360:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   10361:                                                       '?inhibitmenu=yes',$chg,600,500).
                   10362:                                                '</li>';
                   10363:                             }
                   10364:                         }
                   10365:                     }
1.256     raeburn  10366:                 } elsif ($item eq 'headtag') {
                   10367:                     if (ref($changes{$item}) eq 'HASH') {
                   10368:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   10369:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10370:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   10371:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10372:                                 $resulttext .= '<li><a href="'.
                   10373:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   10374:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   10375:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   10376:                                 if ($possexempt{$lonhost}) {
                   10377:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   10378:                                 } else {
                   10379:                                     $resulttext .= &mt('included for any client IP');
                   10380:                                 }
                   10381:                                 $resulttext .= '</li>';
                   10382:                             }
                   10383:                         }
                   10384:                     }
1.169     raeburn  10385:                 } elsif ($item eq 'captcha') {
                   10386:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  10387:                         my $chgtxt;
1.169     raeburn  10388:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   10389:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   10390:                         } else {
                   10391:                             my %captchas = &captcha_phrases();
                   10392:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   10393:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   10394:                             } else {
                   10395:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   10396:                             }
                   10397:                         }
                   10398:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10399:                     }
                   10400:                 } elsif ($item eq 'recaptchakeys') {
                   10401:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10402:                         my ($privkey,$pubkey);
                   10403:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   10404:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   10405:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   10406:                         }
                   10407:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10408:                         if (!$pubkey) {
                   10409:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   10410:                         } else {
                   10411:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10412:                         }
                   10413:                         if (!$privkey) {
                   10414:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   10415:                         } else {
1.251     raeburn  10416:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  10417:                         }
                   10418:                         $chgtxt .= '</ul>';
                   10419:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10420:                     }
1.269     raeburn  10421:                 } elsif ($item eq 'recaptchaversion') {
                   10422:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10423:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  10424:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  10425:                                            '</li>';
                   10426:                         }
                   10427:                     }
1.41      raeburn  10428:                 } else {
                   10429:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   10430:                 }
1.1       raeburn  10431:             }
1.6       raeburn  10432:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  10433:         } else {
                   10434:             $resulttext = &mt('No changes made to log-in page settings');
                   10435:         }
                   10436:     } else {
1.11      albertel 10437:         $resulttext = '<span class="LC_error">'.
                   10438: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10439:     }
1.6       raeburn  10440:     if ($errors) {
1.9       raeburn  10441:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  10442:                        $errors.'</ul>';
                   10443:     }
                   10444:     return $resulttext;
                   10445: }
                   10446: 
1.256     raeburn  10447: sub check_exempt_addresses {
                   10448:     my ($iplist) = @_;
                   10449:     $iplist =~ s/^\s+//;
                   10450:     $iplist =~ s/\s+$//;
                   10451:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   10452:     my (@okips,$new);
                   10453:     foreach my $ip (@poss_ips) {
                   10454:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   10455:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   10456:                 push(@okips,$ip);
                   10457:             }
                   10458:         }
                   10459:     }
                   10460:     if (@okips > 0) {
                   10461:         $new = join(',',@okips);
                   10462:     } else {
                   10463:         $new = '';
                   10464:     }
                   10465:     return $new;
                   10466: }
                   10467: 
1.6       raeburn  10468: sub color_font_choices {
                   10469:     my %choices =
                   10470:         &Apache::lonlocal::texthash (
                   10471:             img => "Header",
                   10472:             bgs => "Background colors",
                   10473:             links => "Link colors",
1.55      raeburn  10474:             images => "Images",
1.6       raeburn  10475:             font => "Font color",
1.201     raeburn  10476:             fontmenu => "Font menu",
1.76      raeburn  10477:             pgbg => "Page",
1.6       raeburn  10478:             tabbg => "Header",
                   10479:             sidebg => "Border",
                   10480:             link => "Link",
                   10481:             alink => "Active link",
                   10482:             vlink => "Visited link",
                   10483:         );
                   10484:     return %choices;
                   10485: }
                   10486: 
                   10487: sub modify_rolecolors {
1.205     raeburn  10488:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  10489:     my ($resulttext,%rolehash);
                   10490:     $rolehash{'rolecolors'} = {};
1.55      raeburn  10491:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   10492:         if ($domconfig{'rolecolors'} eq '') {
                   10493:             $domconfig{'rolecolors'} = {};
                   10494:         }
                   10495:     }
1.9       raeburn  10496:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  10497:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   10498:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   10499:                                              $dom);
                   10500:     if ($putresult eq 'ok') {
                   10501:         if (keys(%changes) > 0) {
1.41      raeburn  10502:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10503:             if (ref($lastactref) eq 'HASH') {
                   10504:                 $lastactref->{'domainconfig'} = 1;
                   10505:             }
1.6       raeburn  10506:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   10507:                                              $rolehash{'rolecolors'});
                   10508:         } else {
                   10509:             $resulttext = &mt('No changes made to default color schemes');
                   10510:         }
                   10511:     } else {
1.11      albertel 10512:         $resulttext = '<span class="LC_error">'.
                   10513: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  10514:     }
                   10515:     if ($errors) {
                   10516:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10517:                        $errors.'</ul>';
                   10518:     }
                   10519:     return $resulttext;
                   10520: }
                   10521: 
                   10522: sub modify_colors {
1.9       raeburn  10523:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  10524:     my (%changes,%choices);
1.51      raeburn  10525:     my @bgs;
1.6       raeburn  10526:     my @links = ('link','alink','vlink');
1.41      raeburn  10527:     my @logintext;
1.6       raeburn  10528:     my @images;
                   10529:     my $servadm = $r->dir_config('lonAdmEMail');
                   10530:     my $errors;
1.200     raeburn  10531:     my %defaults;
1.6       raeburn  10532:     foreach my $role (@{$roles}) {
                   10533:         if ($role eq 'login') {
1.12      raeburn  10534:             %choices = &login_choices();
1.41      raeburn  10535:             @logintext = ('textcol','bgcol');
1.12      raeburn  10536:         } else {
                   10537:             %choices = &color_font_choices();
                   10538:         }
                   10539:         if ($role eq 'login') {
1.41      raeburn  10540:             @images = ('img','logo','domlogo','login');
1.51      raeburn  10541:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  10542:         } else {
                   10543:             @images = ('img');
1.200     raeburn  10544:             @bgs = ('pgbg','tabbg','sidebg');
                   10545:         }
                   10546:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   10547:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   10548:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   10549:         }
                   10550:         if ($role eq 'login') {
                   10551:             foreach my $item (@logintext) {
1.234     raeburn  10552:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10553:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10554:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10555:                 }
                   10556:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  10557:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10558:                 }
                   10559:             }
                   10560:         } else {
1.234     raeburn  10561:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   10562:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   10563:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   10564:             }
                   10565:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  10566:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   10567:             }
1.6       raeburn  10568:         }
1.200     raeburn  10569:         foreach my $item (@bgs) {
1.234     raeburn  10570:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10571:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10572:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10573:             }
                   10574:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  10575:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10576:             }
                   10577:         }
                   10578:         foreach my $item (@links) {
1.234     raeburn  10579:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   10580:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   10581:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   10582:             }
                   10583:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  10584:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   10585:             }
1.6       raeburn  10586:         }
1.46      raeburn  10587:         my ($configuserok,$author_ok,$switchserver) = 
                   10588:             &config_check($dom,$confname,$servadm);
1.9       raeburn  10589:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  10590:         if (ref($domconfig->{$role}) ne 'HASH') {
                   10591:             $domconfig->{$role} = {};
                   10592:         }
1.8       raeburn  10593:         foreach my $img (@images) {
1.70      raeburn  10594:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   10595:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   10596:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   10597:                 } else { 
                   10598:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   10599:                 }
                   10600:             } 
1.18      albertel 10601: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   10602: 		 && !defined($domconfig->{$role}{$img})
                   10603: 		 && !$env{'form.'.$role.'_del_'.$img}
                   10604: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   10605: 		# import the old configured image from the .tab setting
                   10606: 		# if they haven't provided a new one 
                   10607: 		$domconfig->{$role}{$img} = 
                   10608: 		    $env{'form.'.$role.'_import_'.$img};
                   10609: 	    }
1.6       raeburn  10610:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  10611:                 my $error;
1.6       raeburn  10612:                 if ($configuserok eq 'ok') {
1.9       raeburn  10613:                     if ($switchserver) {
1.12      raeburn  10614:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  10615:                     } else {
                   10616:                         if ($author_ok eq 'ok') {
                   10617:                             my ($result,$logourl) = 
                   10618:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   10619:                                            $dom,$confname,$img,$width,$height);
                   10620:                             if ($result eq 'ok') {
                   10621:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  10622:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  10623:                             } else {
1.12      raeburn  10624:                                 $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  10625:                             }
                   10626:                         } else {
1.46      raeburn  10627:                             $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  10628:                         }
                   10629:                     }
                   10630:                 } else {
1.46      raeburn  10631:                     $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  10632:                 }
                   10633:                 if ($error) {
1.8       raeburn  10634:                     &Apache::lonnet::logthis($error);
1.11      albertel 10635:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  10636:                 }
                   10637:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  10638:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   10639:                     my $error;
                   10640:                     if ($configuserok eq 'ok') {
                   10641: # is confname an author?
                   10642:                         if ($switchserver eq '') {
                   10643:                             if ($author_ok eq 'ok') {
                   10644:                                 my ($result,$logourl) = 
                   10645:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   10646:                                             $dom,$confname,$img,$width,$height);
                   10647:                                 if ($result eq 'ok') {
                   10648:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 10649: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  10650:                                 }
                   10651:                             }
                   10652:                         }
                   10653:                     }
1.6       raeburn  10654:                 }
                   10655:             }
                   10656:         }
                   10657:         if (ref($domconfig) eq 'HASH') {
                   10658:             if (ref($domconfig->{$role}) eq 'HASH') {
                   10659:                 foreach my $img (@images) {
                   10660:                     if ($domconfig->{$role}{$img} ne '') {
                   10661:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   10662:                             $confhash->{$role}{$img} = '';
1.12      raeburn  10663:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  10664:                         } else {
1.9       raeburn  10665:                             if ($confhash->{$role}{$img} eq '') {
                   10666:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   10667:                             }
1.6       raeburn  10668:                         }
                   10669:                     } else {
                   10670:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   10671:                             $confhash->{$role}{$img} = '';
1.12      raeburn  10672:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  10673:                         } 
                   10674:                     }
1.70      raeburn  10675:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   10676:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   10677:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   10678:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   10679:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   10680:                             }
                   10681:                         } else {
                   10682:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   10683:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   10684:                             }
                   10685:                         }
                   10686:                     }
                   10687:                 }
1.6       raeburn  10688:                 if ($domconfig->{$role}{'font'} ne '') {
                   10689:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   10690:                         $changes{$role}{'font'} = 1;
                   10691:                     }
                   10692:                 } else {
                   10693:                     if ($confhash->{$role}{'font'}) {
                   10694:                         $changes{$role}{'font'} = 1;
                   10695:                     }
                   10696:                 }
1.107     raeburn  10697:                 if ($role ne 'login') {
                   10698:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   10699:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   10700:                             $changes{$role}{'fontmenu'} = 1;
                   10701:                         }
                   10702:                     } else {
                   10703:                         if ($confhash->{$role}{'fontmenu'}) {
                   10704:                             $changes{$role}{'fontmenu'} = 1;
                   10705:                         }
1.97      tempelho 10706:                     }
                   10707:                 }
1.6       raeburn  10708:                 foreach my $item (@bgs) {
                   10709:                     if ($domconfig->{$role}{$item} ne '') {
                   10710:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10711:                             $changes{$role}{'bgs'}{$item} = 1;
                   10712:                         } 
                   10713:                     } else {
                   10714:                         if ($confhash->{$role}{$item}) {
                   10715:                             $changes{$role}{'bgs'}{$item} = 1;
                   10716:                         }
                   10717:                     }
                   10718:                 }
                   10719:                 foreach my $item (@links) {
                   10720:                     if ($domconfig->{$role}{$item} ne '') {
                   10721:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10722:                             $changes{$role}{'links'}{$item} = 1;
                   10723:                         }
                   10724:                     } else {
                   10725:                         if ($confhash->{$role}{$item}) {
                   10726:                             $changes{$role}{'links'}{$item} = 1;
                   10727:                         }
                   10728:                     }
                   10729:                 }
1.41      raeburn  10730:                 foreach my $item (@logintext) {
                   10731:                     if ($domconfig->{$role}{$item} ne '') {
                   10732:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   10733:                             $changes{$role}{'logintext'}{$item} = 1;
                   10734:                         }
                   10735:                     } else {
                   10736:                         if ($confhash->{$role}{$item}) {
                   10737:                             $changes{$role}{'logintext'}{$item} = 1;
                   10738:                         }
                   10739:                     }
                   10740:                 }
1.6       raeburn  10741:             } else {
                   10742:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  10743:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  10744:             }
                   10745:         } else {
                   10746:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  10747:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  10748:         }
                   10749:     }
                   10750:     return ($errors,%changes);
                   10751: }
                   10752: 
1.46      raeburn  10753: sub config_check {
                   10754:     my ($dom,$confname,$servadm) = @_;
                   10755:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   10756:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   10757:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   10758:                                                    $confname,$servadm);
                   10759:     if ($configuserok eq 'ok') {
                   10760:         $switchserver = &check_switchserver($dom,$confname);
                   10761:         if ($switchserver eq '') {
                   10762:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   10763:         }
                   10764:     }
                   10765:     return ($configuserok,$author_ok,$switchserver);
                   10766: }
                   10767: 
1.6       raeburn  10768: sub default_change_checker {
1.41      raeburn  10769:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  10770:     foreach my $item (@{$links}) {
                   10771:         if ($confhash->{$role}{$item}) {
                   10772:             $changes->{$role}{'links'}{$item} = 1;
                   10773:         }
                   10774:     }
                   10775:     foreach my $item (@{$bgs}) {
                   10776:         if ($confhash->{$role}{$item}) {
                   10777:             $changes->{$role}{'bgs'}{$item} = 1;
                   10778:         }
                   10779:     }
1.41      raeburn  10780:     foreach my $item (@{$logintext}) {
                   10781:         if ($confhash->{$role}{$item}) {
                   10782:             $changes->{$role}{'logintext'}{$item} = 1;
                   10783:         }
                   10784:     }
1.6       raeburn  10785:     foreach my $img (@{$images}) {
                   10786:         if ($env{'form.'.$role.'_del_'.$img}) {
                   10787:             $confhash->{$role}{$img} = '';
1.12      raeburn  10788:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  10789:         }
1.70      raeburn  10790:         if ($role eq 'login') {
                   10791:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   10792:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   10793:             }
                   10794:         }
1.6       raeburn  10795:     }
                   10796:     if ($confhash->{$role}{'font'}) {
                   10797:         $changes->{$role}{'font'} = 1;
                   10798:     }
1.48      raeburn  10799: }
1.6       raeburn  10800: 
                   10801: sub display_colorchgs {
                   10802:     my ($dom,$changes,$roles,$confhash) = @_;
                   10803:     my (%choices,$resulttext);
                   10804:     if (!grep(/^login$/,@{$roles})) {
                   10805:         $resulttext = &mt('Changes made:').'<br />';
                   10806:     }
                   10807:     foreach my $role (@{$roles}) {
                   10808:         if ($role eq 'login') {
                   10809:             %choices = &login_choices();
                   10810:         } else {
                   10811:             %choices = &color_font_choices();
                   10812:         }
                   10813:         if (ref($changes->{$role}) eq 'HASH') {
                   10814:             if ($role ne 'login') {
                   10815:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   10816:             }
                   10817:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   10818:                 if ($role ne 'login') {
                   10819:                     $resulttext .= '<ul>';
                   10820:                 }
                   10821:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   10822:                     if ($role ne 'login') {
                   10823:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   10824:                     }
                   10825:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  10826:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   10827:                             if ($confhash->{$role}{$key}{$item}) {
                   10828:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   10829:                             } else {
                   10830:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   10831:                             }
                   10832:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  10833:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   10834:                         } else {
1.12      raeburn  10835:                             my $newitem = $confhash->{$role}{$item};
                   10836:                             if ($key eq 'images') {
1.306     raeburn  10837:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12      raeburn  10838:                             }
                   10839:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  10840:                         }
                   10841:                     }
                   10842:                     if ($role ne 'login') {
                   10843:                         $resulttext .= '</ul></li>';
                   10844:                     }
                   10845:                 } else {
                   10846:                     if ($confhash->{$role}{$key} eq '') {
                   10847:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   10848:                     } else {
                   10849:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   10850:                     }
                   10851:                 }
                   10852:                 if ($role ne 'login') {
                   10853:                     $resulttext .= '</ul>';
                   10854:                 }
                   10855:             }
                   10856:         }
                   10857:     }
1.3       raeburn  10858:     return $resulttext;
1.1       raeburn  10859: }
                   10860: 
1.9       raeburn  10861: sub thumb_dimensions {
                   10862:     return ('200','50');
                   10863: }
                   10864: 
1.16      raeburn  10865: sub check_dimensions {
                   10866:     my ($inputfile) = @_;
                   10867:     my ($fullwidth,$fullheight);
                   10868:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   10869:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   10870:             my $imageinfo = <PIPE>;
                   10871:             if (!close(PIPE)) {
                   10872:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   10873:             }
                   10874:             chomp($imageinfo);
                   10875:             my ($fullsize) = 
1.21      raeburn  10876:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  10877:             if ($fullsize) {
                   10878:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   10879:             }
                   10880:         }
                   10881:     }
                   10882:     return ($fullwidth,$fullheight);
                   10883: }
                   10884: 
1.9       raeburn  10885: sub check_configuser {
                   10886:     my ($uhome,$dom,$confname,$servadm) = @_;
                   10887:     my ($configuserok,%currroles);
                   10888:     if ($uhome eq 'no_host') {
                   10889:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.361     raeburn  10890:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  10891:         $configuserok = 
                   10892:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   10893:                              $configpass,'','','','','',undef,$servadm);
                   10894:     } else {
                   10895:         $configuserok = 'ok';
                   10896:         %currroles = 
                   10897:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   10898:     }
                   10899:     return ($configuserok,%currroles);
                   10900: }
                   10901: 
                   10902: sub check_authorstatus {
                   10903:     my ($dom,$confname,%currroles) = @_;
                   10904:     my $author_ok;
1.40      raeburn  10905:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  10906:         my $start = time;
                   10907:         my $end = 0;
                   10908:         $author_ok = 
                   10909:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  10910:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  10911:     } else {
                   10912:         $author_ok = 'ok';
                   10913:     }
                   10914:     return $author_ok;
                   10915: }
                   10916: 
                   10917: sub publishlogo {
1.46      raeburn  10918:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  10919:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  10920:     if ($action eq 'upload') {
                   10921:         $fname=$env{'form.'.$formname.'.filename'};
                   10922:         chop($env{'form.'.$formname});
                   10923:     } else {
                   10924:         ($fname) = ($formname =~ /([^\/]+)$/);
                   10925:     }
1.46      raeburn  10926:     if ($savefileas ne '') {
                   10927:         $fname = $savefileas;
                   10928:     }
1.9       raeburn  10929:     $fname=&Apache::lonnet::clean_filename($fname);
                   10930: # See if there is anything left
                   10931:     unless ($fname) { return ('error: no uploaded file'); }
                   10932:     $fname="$subdir/$fname";
1.210     raeburn  10933:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  10934:     my $filepath="$docroot/priv";
                   10935:     my $relpath = "$dom/$confname";
1.9       raeburn  10936:     my ($fnamepath,$file,$fetchthumb);
                   10937:     $file=$fname;
                   10938:     if ($fname=~m|/|) {
                   10939:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   10940:     }
1.164     raeburn  10941:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  10942:     my $count;
1.164     raeburn  10943:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  10944:         $filepath.="/$parts[$count]";
                   10945:         if ((-e $filepath)!=1) {
                   10946:             mkdir($filepath,02770);
                   10947:         }
                   10948:     }
                   10949:     # Check for bad extension and disallow upload
                   10950:     if ($file=~/\.(\w+)$/ &&
                   10951:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   10952:         $output = 
1.207     bisitz   10953:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  10954:     } elsif ($file=~/\.(\w+)$/ &&
                   10955:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   10956:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   10957:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   10958:         $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  10959:     } elsif (-d "$filepath/$file") {
1.195     bisitz   10960:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  10961:     } else {
                   10962:         my $source = $filepath.'/'.$file;
                   10963:         my $logfile;
1.316     raeburn  10964:         if (!open($logfile,">>",$source.'.log')) {
1.196     raeburn  10965:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  10966:         }
                   10967:         print $logfile
                   10968: "\n================= Publish ".localtime()." ================\n".
                   10969: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   10970: # Save the file
1.316     raeburn  10971:         if (!open(FH,">",$source)) {
1.9       raeburn  10972:             &Apache::lonnet::logthis('Failed to create '.$source);
                   10973:             return (&mt('Failed to create file'));
                   10974:         }
                   10975:         if ($action eq 'upload') {
                   10976:             if (!print FH ($env{'form.'.$formname})) {
                   10977:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   10978:                 return (&mt('Failed to write file'));
                   10979:             }
                   10980:         } else {
                   10981:             my $original = &Apache::lonnet::filelocation('',$formname);
                   10982:             if(!copy($original,$source)) {
                   10983:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   10984:                 return (&mt('Failed to write file'));
                   10985:             }
                   10986:         }
                   10987:         close(FH);
                   10988:         chmod(0660, $source); # Permissions to rw-rw---.
                   10989: 
                   10990:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   10991:         my $copyfile=$targetdir.'/'.$file;
                   10992: 
                   10993:         my @parts=split(/\//,$targetdir);
                   10994:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   10995:         for (my $count=5;$count<=$#parts;$count++) {
                   10996:             $path.="/$parts[$count]";
                   10997:             if (!-e $path) {
                   10998:                 print $logfile "\nCreating directory ".$path;
                   10999:                 mkdir($path,02770);
                   11000:             }
                   11001:         }
                   11002:         my $versionresult;
                   11003:         if (-e $copyfile) {
                   11004:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   11005:         } else {
                   11006:             $versionresult = 'ok';
                   11007:         }
                   11008:         if ($versionresult eq 'ok') {
                   11009:             if (copy($source,$copyfile)) {
                   11010:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   11011:                 $output = 'ok';
                   11012:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  11013:                 push(@{$modified_urls},[$copyfile,$source]);
                   11014:                 my $metaoutput = 
                   11015:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   11016:                 unless ($registered_cleanup) {
                   11017:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   11018:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   11019:                     $registered_cleanup=1;
                   11020:                 }
1.9       raeburn  11021:             } else {
                   11022:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   11023:                 $output = &mt('Failed to copy file to RES space').", $!";
                   11024:             }
                   11025:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   11026:                 my $inputfile = $filepath.'/'.$file;
                   11027:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  11028:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   11029:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   11030:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   11031:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.316     raeburn  11032:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   11033:                         system({$args[0]} @args);
1.16      raeburn  11034:                         chmod(0660, $filepath.'/tn-'.$file);
                   11035:                         if (-e $outfile) {
                   11036:                             my $copyfile=$targetdir.'/tn-'.$file;
                   11037:                             if (copy($outfile,$copyfile)) {
                   11038:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  11039:                                 my $thumb_metaoutput = 
                   11040:                                     &write_metadata($dom,$confname,$formname,
                   11041:                                                     $targetdir,'tn-'.$file,$logfile);
                   11042:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   11043:                                 unless ($registered_cleanup) {
                   11044:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   11045:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   11046:                                     $registered_cleanup=1;
                   11047:                                 }
1.267     raeburn  11048:                                 $madethumb = 1;
1.16      raeburn  11049:                             } else {
                   11050:                                 print $logfile "\nUnable to write ".$copyfile.
                   11051:                                                ':'.$!."\n";
                   11052:                             }
                   11053:                         }
1.9       raeburn  11054:                     }
                   11055:                 }
                   11056:             }
                   11057:         } else {
                   11058:             $output = $versionresult;
                   11059:         }
                   11060:     }
1.267     raeburn  11061:     return ($output,$logourl,$madethumb);
1.9       raeburn  11062: }
                   11063: 
                   11064: sub logo_versioning {
                   11065:     my ($targetdir,$file,$logfile) = @_;
                   11066:     my $target = $targetdir.'/'.$file;
                   11067:     my ($maxversion,$fn,$extn,$output);
                   11068:     $maxversion = 0;
                   11069:     if ($file =~ /^(.+)\.(\w+)$/) {
                   11070:         $fn=$1;
                   11071:         $extn=$2;
                   11072:     }
                   11073:     opendir(DIR,$targetdir);
                   11074:     while (my $filename=readdir(DIR)) {
                   11075:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   11076:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   11077:         }
                   11078:     }
                   11079:     $maxversion++;
                   11080:     print $logfile "\nCreating old version ".$maxversion."\n";
                   11081:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   11082:     if (copy($target,$copyfile)) {
                   11083:         print $logfile "Copied old target to ".$copyfile."\n";
                   11084:         $copyfile=$copyfile.'.meta';
                   11085:         if (copy($target.'.meta',$copyfile)) {
                   11086:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   11087:             $output = 'ok';
                   11088:         } else {
                   11089:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   11090:             $output = &mt('Failed to copy old meta').", $!, ";
                   11091:         }
                   11092:     } else {
                   11093:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   11094:         $output = &mt('Failed to copy old target').", $!, ";
                   11095:     }
                   11096:     return $output;
                   11097: }
                   11098: 
                   11099: sub write_metadata {
                   11100:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   11101:     my (%metadatafields,%metadatakeys,$output);
                   11102:     $metadatafields{'title'}=$formname;
                   11103:     $metadatafields{'creationdate'}=time;
                   11104:     $metadatafields{'lastrevisiondate'}=time;
                   11105:     $metadatafields{'copyright'}='public';
                   11106:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   11107:                                          $env{'user.domain'};
                   11108:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   11109:     $metadatafields{'domain'}=$dom;
                   11110:     {
                   11111:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   11112:         my $mfh;
1.316     raeburn  11113:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  11114:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  11115:                 unless ($_=~/\./) {
                   11116:                     my $unikey=$_;
                   11117:                     $unikey=~/^([A-Za-z]+)/;
                   11118:                     my $tag=$1;
                   11119:                     $tag=~tr/A-Z/a-z/;
                   11120:                     print $mfh "\n\<$tag";
                   11121:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   11122:                         my $value=$metadatafields{$unikey.'.'.$_};
                   11123:                         $value=~s/\"/\'\'/g;
                   11124:                         print $mfh ' '.$_.'="'.$value.'"';
                   11125:                     }
                   11126:                     print $mfh '>'.
                   11127:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   11128:                             .'</'.$tag.'>';
                   11129:                 }
                   11130:             }
                   11131:             $output = 'ok';
                   11132:             print $logfile "\nWrote metadata";
                   11133:             close($mfh);
                   11134:         } else {
                   11135:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  11136:             $output = &mt('Could not write metadata');
                   11137:         }
                   11138:     }
1.155     raeburn  11139:     return $output;
                   11140: }
                   11141: 
                   11142: sub notifysubscribed {
                   11143:     foreach my $targetsource (@{$modified_urls}){
                   11144:         next unless (ref($targetsource) eq 'ARRAY');
                   11145:         my ($target,$source)=@{$targetsource};
                   11146:         if ($source ne '') {
1.316     raeburn  11147:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  11148:                 print $logfh "\nCleanup phase: Notifications\n";
                   11149:                 my @subscribed=&subscribed_hosts($target);
                   11150:                 foreach my $subhost (@subscribed) {
                   11151:                     print $logfh "\nNotifying host ".$subhost.':';
                   11152:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   11153:                     print $logfh $reply;
                   11154:                 }
                   11155:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   11156:                 foreach my $subhost (@subscribedmeta) {
                   11157:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   11158:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   11159:                                                         $subhost);
                   11160:                     print $logfh $reply;
                   11161:                 }
                   11162:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  11163:                 close($logfh);
1.155     raeburn  11164:             }
                   11165:         }
                   11166:     }
                   11167:     return OK;
                   11168: }
                   11169: 
                   11170: sub subscribed_hosts {
                   11171:     my ($target) = @_;
                   11172:     my @subscribed;
1.316     raeburn  11173:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  11174:         while (my $subline=<$fh>) {
                   11175:             if ($subline =~ /^($match_lonid):/) {
                   11176:                 my $host = $1;
                   11177:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   11178:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   11179:                         push(@subscribed,$host);
                   11180:                     }
                   11181:                 }
                   11182:             }
                   11183:         }
                   11184:     }
                   11185:     return @subscribed;
1.9       raeburn  11186: }
                   11187: 
                   11188: sub check_switchserver {
                   11189:     my ($dom,$confname) = @_;
                   11190:     my ($allowed,$switchserver);
                   11191:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   11192:     if ($home eq 'no_host') {
                   11193:         $home = &Apache::lonnet::domain($dom,'primary');
                   11194:     }
                   11195:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 11196:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   11197:     if (!$allowed) {
1.180     raeburn  11198: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  11199:     }
                   11200:     return $switchserver;
                   11201: }
                   11202: 
1.1       raeburn  11203: sub modify_quotas {
1.216     raeburn  11204:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  11205:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  11206:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  11207:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   11208:         $validationfieldsref);
1.86      raeburn  11209:     if ($action eq 'quotas') {
                   11210:         $context = 'tools'; 
1.163     raeburn  11211:     } else {
1.86      raeburn  11212:         $context = $action;
                   11213:     }
                   11214:     if ($context eq 'requestcourses') {
1.325     raeburn  11215:         @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106     raeburn  11216:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  11217:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   11218:         %titles = &courserequest_titles();
                   11219:         $toolregexp = join('|',@usertools);
                   11220:         %conditions = &courserequest_conditions();
1.216     raeburn  11221:         $confname = $dom.'-domainconfig';
                   11222:         my $servadm = $r->dir_config('lonAdmEMail');
                   11223:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  11224:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   11225:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  11226:     } elsif ($context eq 'requestauthor') {
                   11227:         @usertools = ('author');
                   11228:         %titles = &authorrequest_titles();
1.86      raeburn  11229:     } else {
1.162     raeburn  11230:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  11231:         %titles = &tool_titles();
1.86      raeburn  11232:     }
1.212     raeburn  11233:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  11234:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  11235:     foreach my $key (keys(%env)) {
1.101     raeburn  11236:         if ($context eq 'requestcourses') {
                   11237:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   11238:                 my $item = $1;
                   11239:                 my $type = $2;
                   11240:                 if ($type =~ /^limit_(.+)/) {
                   11241:                     $limithash{$item}{$1} = $env{$key};
                   11242:                 } else {
                   11243:                     $confhash{$item}{$type} = $env{$key};
                   11244:                 }
                   11245:             }
1.163     raeburn  11246:         } elsif ($context eq 'requestauthor') {
                   11247:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   11248:                 $confhash{$1} = $env{$key};
                   11249:             }
1.101     raeburn  11250:         } else {
1.86      raeburn  11251:             if ($key =~ /^form\.quota_(.+)$/) {
                   11252:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  11253:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   11254:                 $confhash{'authorquota'}{$1} = $env{$key};
                   11255:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  11256:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   11257:             }
1.72      raeburn  11258:         }
                   11259:     }
1.163     raeburn  11260:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  11261:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  11262:         @approvalnotify = sort(@approvalnotify);
                   11263:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325     raeburn  11264:         my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218     raeburn  11265:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   11266:         foreach my $type (@hasuniquecode) {
                   11267:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   11268:                 $confhash{'uniquecode'}{$type} = 1;
                   11269:             }
1.216     raeburn  11270:         }
1.242     raeburn  11271:         my (%newbook,%allpos);
1.216     raeburn  11272:         if ($context eq 'requestcourses') {
1.242     raeburn  11273:             foreach my $type ('textbooks','templates') {
                   11274:                 @{$allpos{$type}} = (); 
                   11275:                 my $invalid;
                   11276:                 if ($type eq 'textbooks') {
                   11277:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   11278:                 } else {
                   11279:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   11280:                 }
                   11281:                 if ($env{'form.'.$type.'_addbook'}) {
                   11282:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   11283:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   11284:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   11285:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   11286:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   11287:                         } else {
                   11288:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   11289:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   11290:                             $position =~ s/\D+//g;
                   11291:                             if ($position ne '') {
                   11292:                                 $allpos{$type}[$position] = $newbook{$type};
                   11293:                             }
1.216     raeburn  11294:                         }
1.242     raeburn  11295:                     } else {
                   11296:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  11297:                     }
                   11298:                 }
1.242     raeburn  11299:             } 
1.216     raeburn  11300:         }
1.102     raeburn  11301:         if (ref($domconfig{$action}) eq 'HASH') {
                   11302:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   11303:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   11304:                     $changes{'notify'}{'approval'} = 1;
                   11305:                 }
                   11306:             } else {
1.144     raeburn  11307:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11308:                     $changes{'notify'}{'approval'} = 1;
                   11309:                 }
                   11310:             }
1.218     raeburn  11311:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   11312:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11313:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   11314:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   11315:                             $changes{'uniquecode'} = 1;
                   11316:                         }
                   11317:                     }
                   11318:                     unless ($changes{'uniquecode'}) {
                   11319:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   11320:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   11321:                                 $changes{'uniquecode'} = 1;
                   11322:                             }
                   11323:                         }
                   11324:                     }
                   11325:                } else {
                   11326:                    $changes{'uniquecode'} = 1;
                   11327:                }
                   11328:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11329:                 $changes{'uniquecode'} = 1;
1.216     raeburn  11330:             }
                   11331:             if ($context eq 'requestcourses') {
1.242     raeburn  11332:                 foreach my $type ('textbooks','templates') {
                   11333:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11334:                         my %deletions;
                   11335:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   11336:                         if (@todelete) {
                   11337:                             map { $deletions{$_} = 1; } @todelete;
                   11338:                         }
                   11339:                         my %imgdeletions;
                   11340:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   11341:                         if (@todeleteimages) {
                   11342:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   11343:                         }
                   11344:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   11345:                         for (my $i=0; $i<=$maxnum; $i++) {
                   11346:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   11347:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   11348:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   11349:                                 if ($deletions{$key}) {
                   11350:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   11351:                                         #FIXME need to obsolete item in RES space
                   11352:                                     }
                   11353:                                     next;
                   11354:                                 } else {
                   11355:                                     my $newpos = $env{'form.'.$itemid};
                   11356:                                     $newpos =~ s/\D+//g;
1.243     raeburn  11357:                                     foreach my $item ('subject','title','publisher','author') {
1.289     raeburn  11358:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243     raeburn  11359:                                                  ($type eq 'templates'));
1.242     raeburn  11360:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   11361:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   11362:                                             $changes{$type}{$key} = 1;
                   11363:                                         }
                   11364:                                     }
                   11365:                                     $allpos{$type}[$newpos] = $key;
                   11366:                                 }
                   11367:                                 if ($imgdeletions{$key}) {
                   11368:                                     $changes{$type}{$key} = 1;
1.216     raeburn  11369:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  11370:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   11371:                                     my ($cdom,$cnum) = split(/_/,$key);
1.313     raeburn  11372:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11373:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11374:                                     } else {
                   11375:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   11376:                                                                                       $cdom,$cnum,$type,$configuserok,
                   11377:                                                                                       $switchserver,$author_ok);
                   11378:                                         if ($imgurl) {
                   11379:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   11380:                                             $changes{$type}{$key} = 1; 
                   11381:                                         }
                   11382:                                         if ($error) {
                   11383:                                             &Apache::lonnet::logthis($error);
                   11384:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11385:                                         }
                   11386:                                     }
1.242     raeburn  11387:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   11388:                                     $confhash{$type}{$key}{'image'} = 
                   11389:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  11390:                                 }
                   11391:                             }
                   11392:                         }
                   11393:                     }
                   11394:                 }
                   11395:             }
1.102     raeburn  11396:         } else {
1.144     raeburn  11397:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11398:                 $changes{'notify'}{'approval'} = 1;
                   11399:             }
1.218     raeburn  11400:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  11401:                 $changes{'uniquecode'} = 1;
                   11402:             }
                   11403:         }
                   11404:         if ($context eq 'requestcourses') {
1.242     raeburn  11405:             foreach my $type ('textbooks','templates') {
                   11406:                 if ($newbook{$type}) {
                   11407:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  11408:                     foreach my $item ('subject','title','publisher','author') {
                   11409:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11410:                                  ($type eq 'template'));
1.242     raeburn  11411:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   11412:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   11413:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   11414:                         }
                   11415:                     }
                   11416:                     if ($type eq 'textbooks') {
                   11417:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   11418:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313     raeburn  11419:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11420:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11421:                             } else {
                   11422:                                 my ($imageurl,$error) =
                   11423:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   11424:                                                             $configuserok,$switchserver,$author_ok);
                   11425:                                 if ($imageurl) {
                   11426:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   11427:                                 }
                   11428:                                 if ($error) {
                   11429:                                     &Apache::lonnet::logthis($error);
                   11430:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11431:                                 }
1.242     raeburn  11432:                             }
                   11433:                         }
1.216     raeburn  11434:                     }
                   11435:                 }
1.242     raeburn  11436:                 if (@{$allpos{$type}} > 0) {
                   11437:                     my $idx = 0;
                   11438:                     foreach my $item (@{$allpos{$type}}) {
                   11439:                         if ($item ne '') {
                   11440:                             $confhash{$type}{$item}{'order'} = $idx;
                   11441:                             if (ref($domconfig{$action}) eq 'HASH') {
                   11442:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11443:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   11444:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   11445:                                             $changes{$type}{$item} = 1;
                   11446:                                         }
1.216     raeburn  11447:                                     }
                   11448:                                 }
                   11449:                             }
1.242     raeburn  11450:                             $idx ++;
1.216     raeburn  11451:                         }
                   11452:                     }
                   11453:                 }
                   11454:             }
1.235     raeburn  11455:             if (ref($validationitemsref) eq 'ARRAY') {
                   11456:                 foreach my $item (@{$validationitemsref}) {
                   11457:                     if ($item eq 'fields') {
                   11458:                         my @changed;
                   11459:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   11460:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   11461:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   11462:                         }
1.266     raeburn  11463:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11464:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11465:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   11466:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   11467:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   11468:                                 } else {
                   11469:                                     @changed = @{$confhash{'validation'}{$item}};
                   11470:                                 }
1.235     raeburn  11471:                             } else {
                   11472:                                 @changed = @{$confhash{'validation'}{$item}};
                   11473:                             }
                   11474:                         } else {
                   11475:                             @changed = @{$confhash{'validation'}{$item}};
                   11476:                         }
                   11477:                         if (@changed) {
                   11478:                             if ($confhash{'validation'}{$item}) {
                   11479:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   11480:                             } else {
                   11481:                                 $changes{'validation'}{$item} = &mt('None');
                   11482:                             }
                   11483:                         }
                   11484:                     } else {
                   11485:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   11486:                         if ($item eq 'markup') {
                   11487:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   11488:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   11489:                             }
                   11490:                         }
1.266     raeburn  11491:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11492:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11493:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   11494:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11495:                                 }
                   11496:                             } else {
                   11497:                                 if ($confhash{'validation'}{$item} ne '') {
                   11498:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11499:                                 }
1.235     raeburn  11500:                             }
                   11501:                         } else {
                   11502:                             if ($confhash{'validation'}{$item} ne '') {
                   11503:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11504:                             }
                   11505:                         }
                   11506:                     }
                   11507:                 }
                   11508:             }
                   11509:             if ($env{'form.validationdc'}) {
                   11510:                 my $newval = $env{'form.validationdc'};
1.285     raeburn  11511:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235     raeburn  11512:                 if (exists($domcoords{$newval})) {
                   11513:                     $confhash{'validation'}{'dc'} = $newval;
                   11514:                 }
                   11515:             }
                   11516:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  11517:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11518:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11519:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11520:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11521:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   11522:                                     $changes{'validation'}{'dc'} = &mt('None');
                   11523:                                 } else {
                   11524:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   11525:                                 }
1.235     raeburn  11526:                             }
1.266     raeburn  11527:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11528:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  11529:                         }
                   11530:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11531:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   11532:                     }
                   11533:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   11534:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289     raeburn  11535:                 }
1.266     raeburn  11536:             } else {
                   11537:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11538:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11539:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   11540:                             $changes{'validation'}{'dc'} = &mt('None');
                   11541:                         }
                   11542:                     }
1.235     raeburn  11543:                 }
                   11544:             }
1.102     raeburn  11545:         }
                   11546:     } else {
1.86      raeburn  11547:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  11548:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  11549:     }
1.72      raeburn  11550:     foreach my $item (@usertools) {
                   11551:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  11552:             my $unset; 
1.101     raeburn  11553:             if ($context eq 'requestcourses') {
1.104     raeburn  11554:                 $unset = '0';
                   11555:                 if ($type eq '_LC_adv') {
                   11556:                     $unset = '';
                   11557:                 }
1.101     raeburn  11558:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   11559:                     $confhash{$item}{$type} .= '=';
                   11560:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   11561:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   11562:                     }
                   11563:                 }
1.163     raeburn  11564:             } elsif ($context eq 'requestauthor') {
                   11565:                 $unset = '0';
                   11566:                 if ($type eq '_LC_adv') {
                   11567:                     $unset = '';
                   11568:                 }
1.72      raeburn  11569:             } else {
1.101     raeburn  11570:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   11571:                     $confhash{$item}{$type} = 1;
                   11572:                 } else {
                   11573:                     $confhash{$item}{$type} = 0;
                   11574:                 }
1.72      raeburn  11575:             }
1.86      raeburn  11576:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  11577:                 if ($action eq 'requestauthor') {
                   11578:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   11579:                         $changes{$type} = 1;
                   11580:                     }
                   11581:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  11582:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   11583:                         $changes{$item}{$type} = 1;
                   11584:                     }
                   11585:                 } else {
                   11586:                     if ($context eq 'requestcourses') {
1.104     raeburn  11587:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  11588:                             $changes{$item}{$type} = 1;
                   11589:                         }
                   11590:                     } else {
                   11591:                         if (!$confhash{$item}{$type}) {
                   11592:                             $changes{$item}{$type} = 1;
                   11593:                         }
                   11594:                     }
                   11595:                 }
                   11596:             } else {
                   11597:                 if ($context eq 'requestcourses') {
1.104     raeburn  11598:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  11599:                         $changes{$item}{$type} = 1;
                   11600:                     }
1.163     raeburn  11601:                 } elsif ($context eq 'requestauthor') {
                   11602:                     if ($confhash{$type} ne $unset) {
                   11603:                         $changes{$type} = 1;
                   11604:                     }
1.72      raeburn  11605:                 } else {
                   11606:                     if (!$confhash{$item}{$type}) {
                   11607:                         $changes{$item}{$type} = 1;
                   11608:                     }
                   11609:                 }
                   11610:             }
1.1       raeburn  11611:         }
                   11612:     }
1.163     raeburn  11613:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  11614:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11615:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   11616:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   11617:                     if (exists($confhash{'defaultquota'}{$key})) {
                   11618:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   11619:                             $changes{'defaultquota'}{$key} = 1;
                   11620:                         }
                   11621:                     } else {
                   11622:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  11623:                     }
                   11624:                 }
1.86      raeburn  11625:             } else {
                   11626:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   11627:                     if (exists($confhash{'defaultquota'}{$key})) {
                   11628:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   11629:                             $changes{'defaultquota'}{$key} = 1;
                   11630:                         }
                   11631:                     } else {
                   11632:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  11633:                     }
1.1       raeburn  11634:                 }
                   11635:             }
1.197     raeburn  11636:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   11637:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   11638:                     if (exists($confhash{'authorquota'}{$key})) {
                   11639:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   11640:                             $changes{'authorquota'}{$key} = 1;
                   11641:                         }
                   11642:                     } else {
                   11643:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   11644:                     }
                   11645:                 }
                   11646:             }
1.1       raeburn  11647:         }
1.86      raeburn  11648:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   11649:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   11650:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11651:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   11652:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   11653:                             $changes{'defaultquota'}{$key} = 1;
                   11654:                         }
                   11655:                     } else {
                   11656:                         if (!exists($domconfig{'quotas'}{$key})) {
                   11657:                             $changes{'defaultquota'}{$key} = 1;
                   11658:                         }
1.72      raeburn  11659:                     }
                   11660:                 } else {
1.86      raeburn  11661:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  11662:                 }
1.1       raeburn  11663:             }
                   11664:         }
1.197     raeburn  11665:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   11666:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   11667:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   11668:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   11669:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   11670:                             $changes{'authorquota'}{$key} = 1;
                   11671:                         }
                   11672:                     } else {
                   11673:                         $changes{'authorquota'}{$key} = 1;
                   11674:                     }
                   11675:                 } else {
                   11676:                     $changes{'authorquota'}{$key} = 1;
                   11677:                 }
                   11678:             }
                   11679:         }
1.1       raeburn  11680:     }
1.72      raeburn  11681: 
1.163     raeburn  11682:     if ($context eq 'requestauthor') {
                   11683:         $domdefaults{'requestauthor'} = \%confhash;
                   11684:     } else {
                   11685:         foreach my $key (keys(%confhash)) {
1.242     raeburn  11686:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  11687:                 $domdefaults{$key} = $confhash{$key};
                   11688:             }
1.163     raeburn  11689:         }
1.72      raeburn  11690:     }
1.163     raeburn  11691: 
1.1       raeburn  11692:     my %quotahash = (
1.86      raeburn  11693:                       $action => { %confhash }
1.1       raeburn  11694:                     );
                   11695:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   11696:                                              $dom);
                   11697:     if ($putresult eq 'ok') {
                   11698:         if (keys(%changes) > 0) {
1.72      raeburn  11699:             my $cachetime = 24*60*60;
                   11700:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  11701:             if (ref($lastactref) eq 'HASH') {
                   11702:                 $lastactref->{'domdefaults'} = 1;
                   11703:             }
1.1       raeburn  11704:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  11705:             unless (($context eq 'requestcourses') ||
1.163     raeburn  11706:                     ($context eq 'requestauthor')) {
1.86      raeburn  11707:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   11708:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   11709:                     foreach my $type (@{$types},'default') {
                   11710:                         if (defined($changes{'defaultquota'}{$type})) {
                   11711:                             my $typetitle = $usertypes->{$type};
                   11712:                             if ($type eq 'default') {
                   11713:                                 $typetitle = $othertitle;
                   11714:                             }
1.213     raeburn  11715:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  11716:                         }
                   11717:                     }
1.86      raeburn  11718:                     $resulttext .= '</ul></li>';
1.72      raeburn  11719:                 }
1.197     raeburn  11720:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   11721:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  11722:                     foreach my $type (@{$types},'default') {
                   11723:                         if (defined($changes{'authorquota'}{$type})) {
                   11724:                             my $typetitle = $usertypes->{$type};
                   11725:                             if ($type eq 'default') {
                   11726:                                 $typetitle = $othertitle;
                   11727:                             }
1.213     raeburn  11728:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  11729:                         }
                   11730:                     }
                   11731:                     $resulttext .= '</ul></li>';
                   11732:                 }
1.72      raeburn  11733:             }
1.80      raeburn  11734:             my %newenv;
1.72      raeburn  11735:             foreach my $item (@usertools) {
1.163     raeburn  11736:                 my (%haschgs,%inconf);
                   11737:                 if ($context eq 'requestauthor') {
                   11738:                     %haschgs = %changes;
1.210     raeburn  11739:                     %inconf = %confhash;
1.163     raeburn  11740:                 } else {
                   11741:                     if (ref($changes{$item}) eq 'HASH') {
                   11742:                         %haschgs = %{$changes{$item}};
                   11743:                     }
                   11744:                     if (ref($confhash{$item}) eq 'HASH') {
                   11745:                         %inconf = %{$confhash{$item}};
                   11746:                     }
                   11747:                 }
                   11748:                 if (keys(%haschgs) > 0) {
1.80      raeburn  11749:                     my $newacc = 
                   11750:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   11751:                                                           $env{'user.domain'},
1.86      raeburn  11752:                                                           $item,'reload',$context);
1.210     raeburn  11753:                     if (($context eq 'requestcourses') ||
1.163     raeburn  11754:                         ($context eq 'requestauthor')) {
1.108     raeburn  11755:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   11756:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  11757:                         }
                   11758:                     } else {
                   11759:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   11760:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   11761:                         }
1.80      raeburn  11762:                     }
1.163     raeburn  11763:                     unless ($context eq 'requestauthor') {
                   11764:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   11765:                     }
1.72      raeburn  11766:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  11767:                         if ($haschgs{$type}) {
1.72      raeburn  11768:                             my $typetitle = $usertypes->{$type};
                   11769:                             if ($type eq 'default') {
                   11770:                                 $typetitle = $othertitle;
                   11771:                             } elsif ($type eq '_LC_adv') {
                   11772:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   11773:                             }
1.163     raeburn  11774:                             if ($inconf{$type}) {
1.101     raeburn  11775:                                 if ($context eq 'requestcourses') {
                   11776:                                     my $cond;
1.163     raeburn  11777:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  11778:                                         if ($1 eq '') {
                   11779:                                             $cond = &mt('(Automatic processing of any request).');
                   11780:                                         } else {
                   11781:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   11782:                                         }
                   11783:                                     } else { 
1.163     raeburn  11784:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  11785:                                     }
                   11786:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  11787:                                 } elsif ($context eq 'requestauthor') {
                   11788:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   11789:                                                              $titles{$inconf{$type}},$typetitle);
                   11790: 
1.101     raeburn  11791:                                 } else {
                   11792:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   11793:                                 }
1.72      raeburn  11794:                             } else {
1.104     raeburn  11795:                                 if ($type eq '_LC_adv') {
1.163     raeburn  11796:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  11797:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   11798:                                     } else { 
                   11799:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   11800:                                     }
                   11801:                                 } else {
                   11802:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   11803:                                 }
1.72      raeburn  11804:                             }
                   11805:                         }
1.26      raeburn  11806:                     }
1.163     raeburn  11807:                     unless ($context eq 'requestauthor') {
                   11808:                         $resulttext .= '</ul></li>';
                   11809:                     }
1.26      raeburn  11810:                 }
1.1       raeburn  11811:             }
1.163     raeburn  11812:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  11813:                 if (ref($changes{'notify'}) eq 'HASH') {
                   11814:                     if ($changes{'notify'}{'approval'}) {
                   11815:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   11816:                             if ($confhash{'notify'}{'approval'}) {
                   11817:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   11818:                             } else {
1.163     raeburn  11819:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  11820:                             }
                   11821:                         }
                   11822:                     }
                   11823:                 }
                   11824:             }
1.216     raeburn  11825:             if ($action eq 'requestcourses') {
                   11826:                 my @offon = ('off','on');
                   11827:                 if ($changes{'uniquecode'}) {
1.218     raeburn  11828:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11829:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   11830:                         $resulttext .= '<li>'.
                   11831:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   11832:                                        '</li>';
                   11833:                     } else {
                   11834:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   11835:                                        '</li>';
                   11836:                     }
1.216     raeburn  11837:                 }
1.242     raeburn  11838:                 foreach my $type ('textbooks','templates') {
                   11839:                     if (ref($changes{$type}) eq 'HASH') {
                   11840:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   11841:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   11842:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   11843:                             my $coursetitle = $coursehash{'description'};
                   11844:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   11845:                             $resulttext .= '<li>';
1.243     raeburn  11846:                             foreach my $item ('subject','title','publisher','author') {
                   11847:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11848:                                          ($type eq 'templates'));
1.242     raeburn  11849:                                 my $name = $item.':';
                   11850:                                 $name =~ s/^(\w)/\U$1/;
                   11851:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   11852:                             }
                   11853:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   11854:                             if ($type eq 'textbooks') {
                   11855:                                 if ($confhash{$type}{$key}{'image'}) {
                   11856:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   11857:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   11858:                                                    ' alt="Textbook cover" />').'<br />';
                   11859:                                 }
                   11860:                             }
                   11861:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  11862:                         }
1.242     raeburn  11863:                         $resulttext .= '</ul></li>';
1.216     raeburn  11864:                     }
                   11865:                 }
1.235     raeburn  11866:                 if (ref($changes{'validation'}) eq 'HASH') {
                   11867:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   11868:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   11869:                         foreach my $item (@{$validationitemsref}) {
                   11870:                             if (exists($changes{'validation'}{$item})) {
                   11871:                                 if ($item eq 'markup') {
                   11872:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   11873:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   11874:                                 } else {
                   11875:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   11876:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   11877:                                 }
                   11878:                             }
                   11879:                         }
                   11880:                         if (exists($changes{'validation'}{'dc'})) {
                   11881:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   11882:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   11883:                         }
                   11884:                     }
                   11885:                 }
1.216     raeburn  11886:             }
1.1       raeburn  11887:             $resulttext .= '</ul>';
1.80      raeburn  11888:             if (keys(%newenv)) {
                   11889:                 &Apache::lonnet::appenv(\%newenv);
                   11890:             }
1.1       raeburn  11891:         } else {
1.86      raeburn  11892:             if ($context eq 'requestcourses') {
                   11893:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  11894:             } elsif ($context eq 'requestauthor') {
                   11895:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  11896:             } else {
1.90      weissno  11897:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  11898:             }
1.1       raeburn  11899:         }
                   11900:     } else {
1.11      albertel 11901:         $resulttext = '<span class="LC_error">'.
                   11902: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  11903:     }
1.216     raeburn  11904:     if ($errors) {
                   11905:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   11906:                        '<ul>'.$errors.'</ul></p>';
                   11907:     }
1.3       raeburn  11908:     return $resulttext;
1.1       raeburn  11909: }
                   11910: 
1.216     raeburn  11911: sub process_textbook_image {
1.242     raeburn  11912:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  11913:     my $filename = $env{'form.'.$caller.'.filename'};
                   11914:     my ($error,$url);
                   11915:     my ($width,$height) = (50,50);
                   11916:     if ($configuserok eq 'ok') {
                   11917:         if ($switchserver) {
                   11918:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   11919:                          $switchserver);
                   11920:         } elsif ($author_ok eq 'ok') {
                   11921:             my ($result,$imageurl) =
                   11922:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.312     raeburn  11923:                              "$type/$cdom/$cnum/cover",$width,$height);
1.216     raeburn  11924:             if ($result eq 'ok') {
                   11925:                 $url = $imageurl;
                   11926:             } else {
                   11927:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   11928:             }
                   11929:         } else {
                   11930:             $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);
                   11931:         }
                   11932:     } else {
                   11933:         $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);
                   11934:     }
                   11935:     return ($url,$error);
                   11936: }
                   11937: 
1.267     raeburn  11938: sub modify_ltitools {
                   11939:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   11940:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.297     raeburn  11941:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
1.267     raeburn  11942:     my $confname = $dom.'-domainconfig';
                   11943:     my $servadm = $r->dir_config('lonAdmEMail');
                   11944:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   11945:     my (%posslti,%possfield);
                   11946:     my @courseroles = ('cc','in','ta','ep','st');
                   11947:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   11948:     map { $posslti{$_} = 1; } @ltiroles;
                   11949:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   11950:     map { $possfield{$_} = 1; } @allfields;
                   11951:     my %lt = &ltitools_names(); 
                   11952:     if ($env{'form.ltitools_add'}) {
                   11953:         my $title = $env{'form.ltitools_add_title'};
                   11954:         $title =~ s/(`)/'/g;
                   11955:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   11956:         if ($newid) {
                   11957:             my $position = $env{'form.ltitools_add_pos'};
                   11958:             $position =~ s/\D+//g;
                   11959:             if ($position ne '') {
                   11960:                 $allpos[$position] = $newid;
                   11961:             }
                   11962:             $changes{$newid} = 1;
1.322     raeburn  11963:             foreach my $item ('title','url','key','secret','lifetime') {
1.267     raeburn  11964:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
1.322     raeburn  11965:                 if ($item eq 'lifetime') {
                   11966:                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   11967:                 }
1.267     raeburn  11968:                 if ($env{'form.ltitools_add_'.$item}) {
1.297     raeburn  11969:                     if (($item eq 'key') || ($item eq 'secret')) {
                   11970:                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   11971:                     } else {
                   11972:                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   11973:                     }
1.267     raeburn  11974:                 }
                   11975:             }
                   11976:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   11977:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   11978:             }
                   11979:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   11980:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   11981:             }
1.323     raeburn  11982:             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   11983:                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   11984:             } else {
                   11985:                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   11986:             }
1.296     raeburn  11987:             foreach my $item ('width','height','linktext','explanation') {
1.267     raeburn  11988:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   11989:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
1.296     raeburn  11990:                 if (($item eq 'width') || ($item eq 'height')) {
                   11991:                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   11992:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   11993:                     }
                   11994:                 } else {
                   11995:                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   11996:                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item}; 
                   11997:                     }
1.267     raeburn  11998:                 }
                   11999:             }
                   12000:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   12001:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.298     raeburn  12002:             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   12003:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
1.267     raeburn  12004:             } else {
                   12005:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   12006:             }
                   12007:             foreach my $item ('passback','roster') {
1.319     raeburn  12008:                 if ($env{'form.ltitools_'.$item.'_add'}) {
1.267     raeburn  12009:                     $confhash{$newid}{$item} = 1;
1.319     raeburn  12010:                     if ($env{'form.ltitools_'.$item.'valid_add'} ne '') {
                   12011:                         my $lifetime = $env{'form.ltitools_'.$item.'valid_add'};
                   12012:                         $lifetime =~ s/^\s+|\s+$//g;
                   12013:                         if ($lifetime =~ /^\d+\.?\d*$/) {
                   12014:                             $confhash{$newid}{$item.'valid'} = $lifetime;
                   12015:                         }
                   12016:                     }
1.267     raeburn  12017:                 }
                   12018:             }
                   12019:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   12020:                 my ($imageurl,$error) =
1.307     raeburn  12021:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
1.267     raeburn  12022:                                             $configuserok,$switchserver,$author_ok);
                   12023:                 if ($imageurl) {
                   12024:                     $confhash{$newid}{'image'} = $imageurl;
                   12025:                 }
                   12026:                 if ($error) {
                   12027:                     &Apache::lonnet::logthis($error);
                   12028:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12029:                 }
                   12030:             }
                   12031:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   12032:             foreach my $field (@fields) {
                   12033:                 if ($possfield{$field}) {
                   12034:                     if ($field eq 'roles') {
                   12035:                         foreach my $role (@courseroles) {
                   12036:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   12037:                             if (($choice ne '') && ($posslti{$choice})) {
                   12038:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   12039:                                 if ($role eq 'cc') {
                   12040:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   12041:                                 }
                   12042:                             }
                   12043:                         }
                   12044:                     } else {
                   12045:                         $confhash{$newid}{'fields'}{$field} = 1;
                   12046:                     }
                   12047:                 }
                   12048:             }
1.324     raeburn  12049:             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   12050:                 if ($confhash{$newid}{'fields'}{'user'}) {
                   12051:                     if ($env{'form.ltitools_userincdom_add'}) {
                   12052:                         $confhash{$newid}{'incdom'} = 1;
                   12053:                     }
                   12054:                 }
                   12055:             }
1.273     raeburn  12056:             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   12057:             foreach my $item (@courseconfig) {
                   12058:                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   12059:             }
1.267     raeburn  12060:             if ($env{'form.ltitools_add_custom'}) {
                   12061:                 my $name = $env{'form.ltitools_add_custom_name'};
                   12062:                 my $value = $env{'form.ltitools_add_custom_value'};
                   12063:                 $value =~ s/(`)/'/g;
                   12064:                 $name =~ s/(`)/'/g;
                   12065:                 $confhash{$newid}{'custom'}{$name} = $value;
                   12066:             }
                   12067:         } else {
                   12068:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   12069:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12070:         }
                   12071:     }
                   12072:     if (ref($domconfig{$action}) eq 'HASH') {
                   12073:         my %deletions;
                   12074:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   12075:         if (@todelete) {
                   12076:             map { $deletions{$_} = 1; } @todelete;
                   12077:         }
                   12078:         my %customadds;
                   12079:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   12080:         if (@newcustom) {
                   12081:             map { $customadds{$_} = 1; } @newcustom;
                   12082:         } 
                   12083:         my %imgdeletions;
                   12084:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   12085:         if (@todeleteimages) {
                   12086:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   12087:         }
                   12088:         my $maxnum = $env{'form.ltitools_maxnum'};
                   12089:         for (my $i=0; $i<=$maxnum; $i++) {
                   12090:             my $itemid = $env{'form.ltitools_id_'.$i};
1.308     raeburn  12091:             $itemid =~ s/\D+//g;
1.267     raeburn  12092:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12093:                 if ($deletions{$itemid}) {
                   12094:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   12095:                         #FIXME need to obsolete item in RES space
                   12096:                     }
                   12097:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   12098:                     next;
                   12099:                 } else {
                   12100:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   12101:                     $newpos =~ s/\D+//g;
1.322     raeburn  12102:                     foreach my $item ('title','url','lifetime') {
1.267     raeburn  12103:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12104:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   12105:                             $changes{$itemid} = 1;
                   12106:                         }
                   12107:                     }
1.297     raeburn  12108:                     foreach my $item ('key','secret') {
                   12109:                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12110:                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   12111:                             $changes{$itemid} = 1;
                   12112:                         }
                   12113:                     }
1.267     raeburn  12114:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   12115:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   12116:                     }
                   12117:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   12118:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   12119:                     }
1.323     raeburn  12120:                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   12121:                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   12122:                     } else {
                   12123:                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1'; 
                   12124:                     }
                   12125:                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   12126:                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   12127:                             $changes{$itemid} = 1;
                   12128:                         }
                   12129:                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   12130:                         $changes{$itemid} = 1;
                   12131:                     }
1.267     raeburn  12132:                     foreach my $size ('width','height') {
                   12133:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   12134:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   12135:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   12136:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   12137:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12138:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   12139:                                     $changes{$itemid} = 1;
                   12140:                                 }
                   12141:                             } else {
                   12142:                                 $changes{$itemid} = 1;
                   12143:                             }
1.296     raeburn  12144:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12145:                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   12146:                                 $changes{$itemid} = 1;
                   12147:                             }
                   12148:                         }
                   12149:                     }
                   12150:                     foreach my $item ('linktext','explanation') {
                   12151:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   12152:                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   12153:                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   12154:                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12155:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12156:                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   12157:                                     $changes{$itemid} = 1;
                   12158:                                 }
                   12159:                             } else {
                   12160:                                 $changes{$itemid} = 1;
                   12161:                             }
                   12162:                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12163:                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   12164:                                 $changes{$itemid} = 1;
                   12165:                             }
1.267     raeburn  12166:                         }
                   12167:                     }
                   12168:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   12169:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.298     raeburn  12170:                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   12171:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
1.267     raeburn  12172:                     } else {
                   12173:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   12174:                     }
                   12175:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12176:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   12177:                             $changes{$itemid} = 1;
                   12178:                         }
                   12179:                     } else {
                   12180:                         $changes{$itemid} = 1;
                   12181:                     }
                   12182:                     foreach my $extra ('passback','roster') {
                   12183:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   12184:                             $confhash{$itemid}{$extra} = 1;
1.319     raeburn  12185:                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
1.338     raeburn  12186:                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
1.319     raeburn  12187:                                 $lifetime =~ s/^\s+|\s+$//g;
                   12188:                                 if ($lifetime =~ /^\d+\.?\d*$/) {
                   12189:                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;
                   12190:                                 }
                   12191:                             }
1.267     raeburn  12192:                         }
                   12193:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   12194:                             $changes{$itemid} = 1;
                   12195:                         }
1.319     raeburn  12196:                         if ($domconfig{$action}{$itemid}{$extra.'valid'} ne $confhash{$itemid}{$extra.'valid'}) {
                   12197:                             $changes{$itemid} = 1;
                   12198:                         }
1.267     raeburn  12199:                     }
1.273     raeburn  12200:                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
1.318     raeburn  12201:                     foreach my $item ('label','title','target','linktext','explanation','append') {
1.273     raeburn  12202:                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   12203:                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   12204:                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   12205:                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   12206:                                     $changes{$itemid} = 1;
                   12207:                                 }
                   12208:                             } else {
                   12209:                                 $changes{$itemid} = 1;
                   12210:                             }
                   12211:                         }
                   12212:                     }
1.267     raeburn  12213:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   12214:                     foreach my $field (@fields) {
                   12215:                         if ($possfield{$field}) {
                   12216:                             if ($field eq 'roles') {
                   12217:                                 foreach my $role (@courseroles) {
                   12218:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   12219:                                     if (($choice ne '') && ($posslti{$choice})) {
                   12220:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   12221:                                         if ($role eq 'cc') {
                   12222:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   12223:                                         }
                   12224:                                     }
                   12225:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   12226:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   12227:                                             $changes{$itemid} = 1;
                   12228:                                         }
                   12229:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   12230:                                         $changes{$itemid} = 1;
                   12231:                                     }
                   12232:                                 }
                   12233:                             } else {
                   12234:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   12235:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   12236:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   12237:                                         $changes{$itemid} = 1;
                   12238:                                     }
                   12239:                                 } else {
                   12240:                                     $changes{$itemid} = 1;
                   12241:                                 }
                   12242:                             }
                   12243:                         }
                   12244:                     }
1.324     raeburn  12245:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12246:                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   12247:                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   12248:                                 $confhash{$itemid}{'incdom'} = 1;
                   12249:                             }
                   12250:                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   12251:                                 $changes{$itemid} = 1;
                   12252:                             }
                   12253:                         }
                   12254:                     }
1.267     raeburn  12255:                     $allpos[$newpos] = $itemid;
                   12256:                 }
                   12257:                 if ($imgdeletions{$itemid}) {
                   12258:                     $changes{$itemid} = 1;
                   12259:                     #FIXME need to obsolete item in RES space
                   12260:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   12261:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   12262:                                                                  $itemid,$configuserok,$switchserver,
                   12263:                                                                  $author_ok);
                   12264:                     if ($imgurl) {
                   12265:                         $confhash{$itemid}{'image'} = $imgurl;
                   12266:                         $changes{$itemid} = 1;
                   12267:                     }
                   12268:                     if ($error) {
                   12269:                         &Apache::lonnet::logthis($error);
                   12270:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12271:                     }
                   12272:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   12273:                     $confhash{$itemid}{'image'} =
                   12274:                        $domconfig{$action}{$itemid}{'image'};
                   12275:                 }
                   12276:                 if ($customadds{$i}) {
                   12277:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   12278:                     $name =~ s/(`)/'/g;
                   12279:                     $name =~ s/^\s+//;
                   12280:                     $name =~ s/\s+$//;
                   12281:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   12282:                     $value =~ s/(`)/'/g;
                   12283:                     $value =~ s/^\s+//;
                   12284:                     $value =~ s/\s+$//;
                   12285:                     if ($name ne '') {
                   12286:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   12287:                         $changes{$itemid} = 1;
                   12288:                     }
                   12289:                 }
                   12290:                 my %customdels;
                   12291:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   12292:                 if (@customdeletions) {
                   12293:                     $changes{$itemid} = 1;
                   12294:                 }
                   12295:                 map { $customdels{$_} = 1; } @customdeletions;
                   12296:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   12297:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   12298:                         unless ($customdels{$key}) {
                   12299:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   12300:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   12301:                             }
                   12302:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   12303:                                 $changes{$itemid} = 1;
                   12304:                             }
                   12305:                         }
                   12306:                     }
                   12307:                 }
                   12308:                 unless ($changes{$itemid}) {
                   12309:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   12310:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   12311:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   12312:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   12313:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   12314:                                         $changes{$itemid} = 1;
                   12315:                                         last;
                   12316:                                     }
                   12317:                                 }
                   12318:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   12319:                                 $changes{$itemid} = 1;
                   12320:                             }
                   12321:                         }
                   12322:                         last if ($changes{$itemid});
                   12323:                     }
                   12324:                 }
                   12325:             }
                   12326:         }
                   12327:     }
                   12328:     if (@allpos > 0) {
                   12329:         my $idx = 0;
                   12330:         foreach my $itemid (@allpos) {
                   12331:             if ($itemid ne '') {
                   12332:                 $confhash{$itemid}{'order'} = $idx;
                   12333:                 if (ref($domconfig{$action}) eq 'HASH') {
                   12334:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12335:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   12336:                             $changes{$itemid} = 1;
                   12337:                         }
                   12338:                     }
                   12339:                 }
                   12340:                 $idx ++;
                   12341:             }
                   12342:         }
                   12343:     }
                   12344:     my %ltitoolshash = (
                   12345:                           $action => { %confhash }
                   12346:                        );
                   12347:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   12348:                                              $dom);
                   12349:     if ($putresult eq 'ok') {
1.297     raeburn  12350:         my %ltienchash = (
                   12351:                              $action => { %encconfig }
                   12352:                          );
                   12353:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
1.267     raeburn  12354:         if (keys(%changes) > 0) {
                   12355:             my $cachetime = 24*60*60;
1.297     raeburn  12356:             my %ltiall = %confhash;
                   12357:             foreach my $id (keys(%ltiall)) {
                   12358:                 if (ref($encconfig{$id}) eq 'HASH') {
                   12359:                     foreach my $item ('key','secret') {
                   12360:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   12361:                     }
                   12362:                 }
                   12363:             }
                   12364:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
1.267     raeburn  12365:             if (ref($lastactref) eq 'HASH') {
                   12366:                 $lastactref->{'ltitools'} = 1;
                   12367:             }
                   12368:             $resulttext = &mt('Changes made:').'<ul>';
                   12369:             my %bynum;
                   12370:             foreach my $itemid (sort(keys(%changes))) {
                   12371:                 my $position = $confhash{$itemid}{'order'};
                   12372:                 $bynum{$position} = $itemid;
                   12373:             }
                   12374:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12375:                 my $itemid = $bynum{$pos}; 
                   12376:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   12377:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12378:                 } else {
                   12379:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   12380:                     if ($confhash{$itemid}{'image'}) {
                   12381:                         $resulttext .= '&nbsp;'.
                   12382:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   12383:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   12384:                     }
                   12385:                     $resulttext .= '</li><ul>';
                   12386:                     my $position = $pos + 1;
                   12387:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
1.323     raeburn  12388:                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
1.267     raeburn  12389:                         if ($confhash{$itemid}{$item} ne '') {
                   12390:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   12391:                         }
                   12392:                     }
1.297     raeburn  12393:                     if ($encconfig{$itemid}{'key'} ne '') {
                   12394:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   12395:                     }
                   12396:                     if ($encconfig{$itemid}{'secret'} ne '') {
1.267     raeburn  12397:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
1.297     raeburn  12398:                         my $num = length($encconfig{$itemid}{'secret'});
1.267     raeburn  12399:                         $resulttext .= ('*'x$num).'</li>';
                   12400:                     }
1.273     raeburn  12401:                     $resulttext .= '<li>'.&mt('Configurable in course:');
1.318     raeburn  12402:                     my @possconfig = ('label','title','target','linktext','explanation','append');
1.273     raeburn  12403:                     my $numconfig = 0; 
                   12404:                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') { 
                   12405:                         foreach my $item (@possconfig) {
                   12406:                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   12407:                                 $numconfig ++;
1.296     raeburn  12408:                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
1.273     raeburn  12409:                             }
                   12410:                         }
                   12411:                     }
                   12412:                     if (!$numconfig) {
                   12413:                         $resulttext .= &mt('None');
                   12414:                     }
                   12415:                     $resulttext .= '</li>';
1.267     raeburn  12416:                     foreach my $item ('passback','roster') {
                   12417:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   12418:                         if ($confhash{$itemid}{$item}) {
                   12419:                             $resulttext .= &mt('Yes');
1.319     raeburn  12420:                             if ($confhash{$itemid}{$item.'valid'}) {
                   12421:                                 if ($item eq 'passback') {
                   12422:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,day] after launch',
                   12423:                                                            $confhash{$itemid}{$item.'valid'});
                   12424:                                 } else {
                   12425:                                     $resulttext .= ' '.&mt('valid for at least [quant,_1,second] after launch',
                   12426:                                                            $confhash{$itemid}{$item.'valid'});
                   12427:                                 }
                   12428:                             }
1.267     raeburn  12429:                         } else {
                   12430:                             $resulttext .= &mt('No');
                   12431:                         }
                   12432:                         $resulttext .= '</li>';
                   12433:                     }
                   12434:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   12435:                         my $displaylist;
                   12436:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   12437:                             $displaylist = &mt('Display target').':&nbsp;'.
                   12438:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   12439:                         }
                   12440:                         foreach my $size ('width','height') { 
                   12441:                             if ($confhash{$itemid}{'display'}{$size}) {
                   12442:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   12443:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   12444:                             }
                   12445:                         }
                   12446:                         if ($displaylist) {
                   12447:                             $displaylist =~ s/,$//;
                   12448:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   12449:                         }
1.296     raeburn  12450:                         foreach my $item ('linktext','explanation') {
                   12451:                             if ($confhash{$itemid}{'display'}{$item}) {
                   12452:                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   12453:                             }
                   12454:                         }
                   12455:                     }
1.267     raeburn  12456:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12457:                         my $fieldlist;
                   12458:                         foreach my $field (@allfields) {
                   12459:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   12460:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   12461:                             }
                   12462:                         }
                   12463:                         if ($fieldlist) {
                   12464:                             $fieldlist =~ s/,$//;
1.324     raeburn  12465:                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   12466:                                 if ($confhash{$itemid}{'incdom'}) {
                   12467:                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   12468:                                 } else {
                   12469:                                     $fieldlist .= ' ('.&mt('username').')';
                   12470:                                 }
                   12471:                             }
1.267     raeburn  12472:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   12473:                         }
                   12474:                     }
                   12475:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   12476:                         my $rolemaps;
                   12477:                         foreach my $role (@courseroles) {
                   12478:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   12479:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   12480:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   12481:                             }
                   12482:                         }
                   12483:                         if ($rolemaps) {
                   12484:                             $rolemaps =~ s/,$//; 
                   12485:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   12486:                         }
                   12487:                     }
                   12488:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   12489:                         my $customlist;
                   12490:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   12491:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   12492:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   12493:                             } 
                   12494:                         }
                   12495:                         if ($customlist) {
1.317     raeburn  12496:                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
1.267     raeburn  12497:                         }
                   12498:                     } 
                   12499:                     $resulttext .= '</ul></li>';
                   12500:                 }
                   12501:             }
                   12502:             $resulttext .= '</ul>';
                   12503:         } else {
                   12504:             $resulttext = &mt('No changes made.');
                   12505:         }
                   12506:     } else {
                   12507:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12508:     }
                   12509:     if ($errors) {
                   12510:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12511:                        $errors.'</ul>';
                   12512:     }
                   12513:     return $resulttext;
                   12514: }
                   12515: 
                   12516: sub process_ltitools_image {
                   12517:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   12518:     my $filename = $env{'form.'.$caller.'.filename'};
                   12519:     my ($error,$url);
                   12520:     my ($width,$height) = (21,21);
                   12521:     if ($configuserok eq 'ok') {
                   12522:         if ($switchserver) {
                   12523:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   12524:                          $switchserver);
                   12525:         } elsif ($author_ok eq 'ok') {
                   12526:             my ($result,$imageurl,$madethumb) =
                   12527:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   12528:                              "ltitools/$itemid/icon",$width,$height);
                   12529:             if ($result eq 'ok') {
                   12530:                 if ($madethumb) {
                   12531:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   12532:                     my $imagethumb = "$path/tn-".$imagefile;
                   12533:                     $url = $imagethumb;
                   12534:                 } else {
                   12535:                     $url = $imageurl;
                   12536:                 }
                   12537:             } else {
                   12538:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   12539:             }
                   12540:         } else {
                   12541:             $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);
                   12542:         }
                   12543:     } else {
                   12544:         $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);
                   12545:     }
                   12546:     return ($url,$error);
                   12547: }
                   12548: 
                   12549: sub get_ltitools_id {
                   12550:     my ($cdom,$title) = @_;
                   12551:     # get lock on ltitools db
                   12552:     my $lockhash = {
                   12553:                       lock => $env{'user.name'}.
                   12554:                               ':'.$env{'user.domain'},
                   12555:                    };
                   12556:     my $tries = 0;
                   12557:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   12558:     my ($id,$error);
                   12559:  
                   12560:     while (($gotlock ne 'ok') && ($tries<10)) {
                   12561:         $tries ++;
                   12562:         sleep (0.1);
                   12563:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   12564:     }
                   12565:     if ($gotlock eq 'ok') {
                   12566:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   12567:         if ($currids{'lock'}) {
                   12568:             delete($currids{'lock'});
                   12569:             if (keys(%currids)) {
                   12570:                 my @curr = sort { $a <=> $b } keys(%currids);
                   12571:                 if ($curr[-1] =~ /^\d+$/) {
                   12572:                     $id = 1 + $curr[-1];
                   12573:                 }
                   12574:             } else {
                   12575:                 $id = 1;
                   12576:             }
                   12577:             if ($id) {
                   12578:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   12579:                     $error = 'nostore';
                   12580:                 }
                   12581:             } else {
                   12582:                 $error = 'nonumber';
                   12583:             }
                   12584:         }
                   12585:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   12586:     } else {
                   12587:         $error = 'nolock';
                   12588:     }
                   12589:     return ($id,$error);
                   12590: }
                   12591: 
1.320     raeburn  12592: sub modify_lti {
                   12593:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   12594:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12595:     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   12596:     my (%posslti,%posslticrs,%posscrstype);
                   12597:     my @courseroles = ('cc','in','ta','ep','st');
                   12598:     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
                   12599:     my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
                   12600:     my @coursetypes = ('official','unofficial','community','textbook','placement');
                   12601:     my %coursetypetitles = &Apache::lonlocal::texthash (
                   12602:                                official   => 'Official',
                   12603:                                unofficial => 'Unofficial',
                   12604:                                community  => 'Community',
                   12605:                                textbook   => 'Textbook',
                   12606:                                placement  => 'Placement Test',
                   12607:     );
1.325     raeburn  12608:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320     raeburn  12609:     my %lt = &lti_names();
                   12610:     map { $posslti{$_} = 1; } @ltiroles;
                   12611:     map { $posslticrs{$_} = 1; } @lticourseroles;
                   12612:     map { $posscrstype{$_} = 1; } @coursetypes;
1.325     raeburn  12613: 
1.326     raeburn  12614:     my %menutitles = &ltimenu_titles();
                   12615: 
1.320     raeburn  12616:     my (@items,%deletions,%itemids);
                   12617:     if ($env{'form.lti_add'}) {
                   12618:         my $consumer = $env{'form.lti_consumer_add'};
                   12619:         $consumer =~ s/(`)/'/g;
                   12620:         ($newid,my $error) = &get_lti_id($dom,$consumer);
                   12621:         if ($newid) {
                   12622:             $itemids{'add'} = $newid;
                   12623:             push(@items,'add');
                   12624:             $changes{$newid} = 1;
                   12625:         } else {
                   12626:             my $error = &mt('Failed to acquire unique ID for new LTI configuration');
                   12627:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12628:         }
                   12629:     }
                   12630:     if (ref($domconfig{$action}) eq 'HASH') {
                   12631:         my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
                   12632:         if (@todelete) {
                   12633:             map { $deletions{$_} = 1; } @todelete;
                   12634:         }
                   12635:         my $maxnum = $env{'form.lti_maxnum'};
                   12636:         for (my $i=0; $i<=$maxnum; $i++) {
                   12637:             my $itemid = $env{'form.lti_id_'.$i};
                   12638:             $itemid =~ s/\D+//g;
                   12639:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12640:                 if ($deletions{$itemid}) {
                   12641:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
                   12642:                 } else {
                   12643:                    push(@items,$i);
                   12644:                    $itemids{$i} = $itemid;
                   12645:                 }
                   12646:             }
                   12647:         }
                   12648:     }
                   12649:     foreach my $idx (@items) {
                   12650:         my $itemid = $itemids{$idx};
                   12651:         next unless ($itemid);
                   12652:         my $position = $env{'form.lti_pos_'.$idx};
                   12653:         $position =~ s/\D+//g;
                   12654:         if ($position ne '') {
                   12655:             $allpos[$position] = $itemid;
                   12656:         }
1.345     raeburn  12657:         foreach my $item ('consumer','key','secret','lifetime','requser') {
1.320     raeburn  12658:             my $formitem = 'form.lti_'.$item.'_'.$idx;
                   12659:             $env{$formitem} =~ s/(`)/'/g;
                   12660:             if ($item eq 'lifetime') {
                   12661:                 $env{$formitem} =~ s/[^\d.]//g;
                   12662:             }
                   12663:             if ($env{$formitem} ne '') {
                   12664:                 if (($item eq 'key') || ($item eq 'secret')) {
                   12665:                     $encconfig{$itemid}{$item} = $env{$formitem};
                   12666:                 } else {
                   12667:                     $confhash{$itemid}{$item} = $env{$formitem};
                   12668:                     unless (($idx eq 'add') || ($changes{$itemid})) {
                   12669:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   12670:                             $changes{$itemid} = 1;
                   12671:                         }
                   12672:                     }
                   12673:                 }
                   12674:             }
                   12675:         }
                   12676:         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
                   12677:             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
                   12678:         }
1.345     raeburn  12679:         if ($confhash{$itemid}{'requser'}) {
                   12680:             if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
                   12681:                 $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
                   12682:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
                   12683:                 $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
                   12684:             } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
                   12685:                 my $mapuser = $env{'form.lti_customuser_'.$idx};
                   12686:                 $mapuser =~ s/(`)/'/g;
                   12687:                 $mapuser =~ s/^\s+|\s+$//g; 
                   12688:                 $confhash{$itemid}{'mapuser'} = $mapuser; 
                   12689:             }
                   12690:             foreach my $ltirole (@lticourseroles) {
                   12691:                 my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                   12692:                 if (grep(/^\Q$possrole\E$/,@courseroles)) {
                   12693:                     $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
                   12694:                 }
                   12695:             }
                   12696:             my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
                   12697:             my @makeuser;
                   12698:             foreach my $ltirole (sort(@possmakeuser)) {
                   12699:                 if ($posslti{$ltirole}) {
                   12700:                     push(@makeuser,$ltirole);
                   12701:                 }
                   12702:             }
                   12703:             $confhash{$itemid}{'makeuser'} = \@makeuser;
                   12704:             if (@makeuser) {
                   12705:                 my $lcauth = $env{'form.lti_lcauth_'.$idx};
                   12706:                 if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
                   12707:                     $confhash{$itemid}{'lcauth'} = $lcauth;
                   12708:                     if ($lcauth ne 'internal') {
                   12709:                         my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
                   12710:                         $lcauthparm =~ s/^(\s+|\s+)$//g;
                   12711:                         $lcauthparm =~ s/`//g;
                   12712:                         if ($lcauthparm ne '') {
                   12713:                             $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
                   12714:                         }
                   12715:                     }
                   12716:                 } else {
                   12717:                     $confhash{$itemid}{'lcauth'} = 'lti';
                   12718:                 }
1.320     raeburn  12719:             }
1.345     raeburn  12720:             my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
                   12721:             if (@possinstdata) {
                   12722:                 foreach my $field (@possinstdata) {
                   12723:                     if (exists($fieldtitles{$field})) {
                   12724:                         push(@{$confhash{$itemid}{'instdata'}});
1.325     raeburn  12725:                     }
                   12726:                 }
                   12727:             }
1.345     raeburn  12728:             if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
                   12729:                 ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
                   12730:                 $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
                   12731:             } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                   12732:                 my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
                   12733:                 $mapcrs =~ s/(`)/'/g;
                   12734:                 $mapcrs =~ s/^\s+|\s+$//g;
                   12735:                 $confhash{$itemid}{'mapcrs'} = $mapcrs;
                   12736:             }
                   12737:             my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                   12738:             my @crstypes;
                   12739:             foreach my $type (sort(@posstypes)) {
                   12740:                 if ($posscrstype{$type}) {
                   12741:                     push(@crstypes,$type);
1.325     raeburn  12742:                 }
                   12743:             }
1.345     raeburn  12744:             $confhash{$itemid}{'mapcrstype'} = \@crstypes;
                   12745:             if ($env{'form.lti_makecrs_'.$idx}) {
                   12746:                 $confhash{$itemid}{'makecrs'} = 1;
1.320     raeburn  12747:             }
1.345     raeburn  12748:             my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
                   12749:             my @selfenroll;
                   12750:             foreach my $type (sort(@possenroll)) {
                   12751:                 if ($posslticrs{$type}) {
                   12752:                     push(@selfenroll,$type);
                   12753:                 }
1.320     raeburn  12754:             }
1.345     raeburn  12755:             $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                   12756:             if ($env{'form.lti_crssec_'.$idx}) {
                   12757:                 if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                   12758:                     $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                   12759:                 } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                   12760:                     my $section = $env{'form.lti_customsection_'.$idx};
                   12761:                     $section =~ s/(`)/'/g;
                   12762:                     $section =~ s/^\s+|\s+$//g;
                   12763:                     if ($section ne '') {
                   12764:                         $confhash{$itemid}{'section'} = $section;
                   12765:                     }
1.320     raeburn  12766:                 }
                   12767:             }
1.363     raeburn  12768:             if ($env{'form.lti_callback_'.$idx}) {
                   12769:                 if ($env{'form.lti_callbackparam_'.$idx}) {
                   12770:                     my $callback = $env{'form.lti_callbackparam_'.$idx};
                   12771:                     $callback =~ s/^\s+|\s+$//g;
                   12772:                     $confhash{$itemid}{'callback'} = $callback;
                   12773:                 }
                   12774:             }
1.345     raeburn  12775:             foreach my $field ('passback','roster','topmenu','inlinemenu') {
                   12776:                 if ($env{'form.lti_'.$field.'_'.$idx}) {
                   12777:                     $confhash{$itemid}{$field} = 1;
                   12778:                 }
1.320     raeburn  12779:             }
1.345     raeburn  12780:             if ($env{'form.lti_passback_'.$idx}) {
                   12781:                 if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                   12782:                     $confhash{$itemid}{'passbackformat'} = '1.0';
                   12783:                 } else {
                   12784:                     $confhash{$itemid}{'passbackformat'} = '1.1';
                   12785:                 }
1.337     raeburn  12786:             }
1.345     raeburn  12787:             if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   12788:                 $confhash{$itemid}{lcmenu} = [];
                   12789:                 my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   12790:                 foreach my $field (@possmenu) {
                   12791:                     if (exists($menutitles{$field})) {
                   12792:                         if ($field eq 'grades') {
                   12793:                             next unless ($env{'form.lti_inlinemenu_'.$idx});
                   12794:                         }
                   12795:                         push(@{$confhash{$itemid}{lcmenu}},$field);
1.326     raeburn  12796:                     }
                   12797:                 }
                   12798:             }
1.345     raeburn  12799:             unless (($idx eq 'add') || ($changes{$itemid})) {
1.363     raeburn  12800:                 foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.345     raeburn  12801:                     if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
1.337     raeburn  12802:                         $changes{$itemid} = 1;
                   12803:                     }
                   12804:                 }
1.320     raeburn  12805:                 unless ($changes{$itemid}) {
1.345     raeburn  12806:                     if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                   12807:                         if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320     raeburn  12808:                             $changes{$itemid} = 1;
                   12809:                         }
1.345     raeburn  12810:                     }
1.320     raeburn  12811:                 }
1.345     raeburn  12812:                 foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
                   12813:                     unless ($changes{$itemid}) {
                   12814:                         if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                   12815:                             if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   12816:                                 my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                   12817:                                                                                $confhash{$itemid}{$field});
                   12818:                                 if (@diffs) {
                   12819:                                     $changes{$itemid} = 1;
                   12820:                                 }
                   12821:                             } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                   12822:                                 $changes{$itemid} = 1;
                   12823:                             }
                   12824:                         } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                   12825:                             if (@{$confhash{$itemid}{$field}} > 0) {
1.320     raeburn  12826:                                 $changes{$itemid} = 1;
                   12827:                             }
                   12828:                         }
1.345     raeburn  12829:                     }
                   12830:                 }
                   12831:                 unless ($changes{$itemid}) {
                   12832:                     if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                   12833:                         if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12834:                             foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                   12835:                                 if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                   12836:                                     $confhash{$itemid}{'maproles'}{$ltirole}) {
1.320     raeburn  12837:                                     $changes{$itemid} = 1;
                   12838:                                     last;
                   12839:                                 }
                   12840:                             }
1.345     raeburn  12841:                             unless ($changes{$itemid}) {
                   12842:                                 foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                   12843:                                     if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                   12844:                                         $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                   12845:                                         $changes{$itemid} = 1;
                   12846:                                         last;
                   12847:                                     }
                   12848:                                 }
                   12849:                             }
                   12850:                         } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                   12851:                             $changes{$itemid} = 1;
1.320     raeburn  12852:                         }
1.345     raeburn  12853:                     } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12854:                         unless ($changes{$itemid}) {
                   12855:                             if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                   12856:                                 $changes{$itemid} = 1;
                   12857:                             }
1.320     raeburn  12858:                         }
                   12859:                     }
                   12860:                 }
                   12861:             }
                   12862:         }
                   12863:     }
                   12864:     if (@allpos > 0) {
                   12865:         my $idx = 0;
                   12866:         foreach my $itemid (@allpos) {
                   12867:             if ($itemid ne '') {
                   12868:                 $confhash{$itemid}{'order'} = $idx;
                   12869:                 if (ref($domconfig{$action}) eq 'HASH') {
                   12870:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12871:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   12872:                             $changes{$itemid} = 1;
                   12873:                         }
                   12874:                     }
                   12875:                 }
                   12876:                 $idx ++;
                   12877:             }
                   12878:         }
                   12879:     }
                   12880:     my %ltihash = (
                   12881:                           $action => { %confhash }
                   12882:                        );
                   12883:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,
                   12884:                                              $dom);
                   12885:     if ($putresult eq 'ok') {
                   12886:         my %ltienchash = (
                   12887:                              $action => { %encconfig }
                   12888:                          );
                   12889:         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
                   12890:         if (keys(%changes) > 0) {
                   12891:             my $cachetime = 24*60*60;
                   12892:             my %ltiall = %confhash;
                   12893:             foreach my $id (keys(%ltiall)) {
                   12894:                 if (ref($encconfig{$id}) eq 'HASH') {
                   12895:                     foreach my $item ('key','secret') {
                   12896:                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   12897:                     }
                   12898:                 }
                   12899:             }
                   12900:             &Apache::lonnet::do_cache_new('lti',$dom,\%ltiall,$cachetime);
                   12901:             if (ref($lastactref) eq 'HASH') {
                   12902:                 $lastactref->{'lti'} = 1;
                   12903:             }
                   12904:             $resulttext = &mt('Changes made:').'<ul>';
                   12905:             my %bynum;
                   12906:             foreach my $itemid (sort(keys(%changes))) {
                   12907:                 my $position = $confhash{$itemid}{'order'};
                   12908:                 $bynum{$position} = $itemid;
                   12909:             }
                   12910:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12911:                 my $itemid = $bynum{$pos};
                   12912:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   12913:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12914:                 } else {
                   12915:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b></li><ul>';
                   12916:                     my $position = $pos + 1;
                   12917:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12918:                     foreach my $item ('version','lifetime') {
                   12919:                         if ($confhash{$itemid}{$item} ne '') {
                   12920:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   12921:                         }
                   12922:                     }
                   12923:                     if ($encconfig{$itemid}{'key'} ne '') {
                   12924:                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   12925:                     }
                   12926:                     if ($encconfig{$itemid}{'secret'} ne '') {
                   12927:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   12928:                         my $num = length($encconfig{$itemid}{'secret'});
                   12929:                         $resulttext .= ('*'x$num).'</li>';
                   12930:                     }
1.345     raeburn  12931:                     if ($confhash{$itemid}{'requser'}) {
                   12932:                         if ($confhash{$itemid}{'mapuser'}) {
                   12933:                             my $shownmapuser;
                   12934:                             if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                   12935:                                 $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                   12936:                             } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                   12937:                                 $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                   12938:                             } else {
                   12939:                                 $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320     raeburn  12940:                             }
1.345     raeburn  12941:                             $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320     raeburn  12942:                         }
1.345     raeburn  12943:                         if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                   12944:                             my $rolemaps;
                   12945:                             foreach my $role (@ltiroles) {
                   12946:                                 if ($confhash{$itemid}{'maproles'}{$role}) {
                   12947:                                     $rolemaps .= ('&nbsp;'x2).$role.'='.
                   12948:                                                  &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                   12949:                                                                             'Course').',';
                   12950:                                 }
                   12951:                             }
                   12952:                             if ($rolemaps) {
                   12953:                                 $rolemaps =~ s/,$//;
                   12954:                                 $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   12955:                             }
                   12956:                         }
                   12957:                         if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                   12958:                             if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                   12959:                                 $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                   12960:                                                           join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                   12961:                                 if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                   12962:                                     $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                   12963:                                 } else {
                   12964:                                     $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                   12965:                                                        $confhash{$itemid}{'lcauth'});
                   12966:                                     if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                   12967:                                         $resulttext .= '; '.&mt('a randomly generated password will be created');
                   12968:                                     } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                   12969:                                         if ($confhash{$itemid}{'lcauthparm'} ne '') {
                   12970:                                             $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                   12971:                                         }
                   12972:                                     } else {
                   12973:                                         $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                   12974:                                     }
                   12975:                                 }
                   12976:                                 $resulttext .= '</li>';
                   12977:                             } else {
                   12978:                                 $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                   12979:                             }
1.320     raeburn  12980:                         }
1.345     raeburn  12981:                         if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                   12982:                             if (@{$confhash{$itemid}{'instdata'}} > 0) {
                   12983:                                 $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                   12984:                                                           join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325     raeburn  12985:                             } else {
1.345     raeburn  12986:                                 $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325     raeburn  12987:                             }
1.320     raeburn  12988:                         }
1.345     raeburn  12989:                         if ($confhash{$itemid}{'mapcrs'}) {
                   12990:                             $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                   12991:                         }
                   12992:                         if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                   12993:                             if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                   12994:                                 $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                   12995:                                                join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                   12996:                                                '</li>';
                   12997:                             } else {
                   12998:                                 $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                   12999:                             }
1.325     raeburn  13000:                         }
1.345     raeburn  13001:                         if ($confhash{$itemid}{'makecrs'}) {
                   13002:                             $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
1.320     raeburn  13003:                         } else {
1.345     raeburn  13004:                             $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
1.320     raeburn  13005:                         }
1.345     raeburn  13006:                         if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                   13007:                             if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                   13008:                                 $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                   13009:                                                           join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                   13010:                                                '</li>';
                   13011:                             } else {
                   13012:                                 $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                   13013:                             }
1.320     raeburn  13014:                         }
1.345     raeburn  13015:                         if ($confhash{$itemid}{'section'}) {
                   13016:                             if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                   13017:                                 $resulttext .= '<li>'.&mt('User section from standard field:').
                   13018:                                                      ' (course_section_sourcedid)'.'</li>';  
                   13019:                             } else {
                   13020:                                 $resulttext .= '<li>'.&mt('User section from:').' '.
                   13021:                                                       $confhash{$itemid}{'section'}.'</li>';
                   13022:                             }
1.320     raeburn  13023:                         } else {
1.345     raeburn  13024:                             $resulttext .= '<li>'.&mt('No section assignment').'</li>';
1.320     raeburn  13025:                         }
1.363     raeburn  13026:                         if ($confhash{$itemid}{'callback'}) {
                   13027:                             $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                   13028:                         } else {
                   13029:                             $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
                   13030:                         }
1.345     raeburn  13031:                         foreach my $item ('passback','roster','topmenu','inlinemenu') {
                   13032:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                   13033:                             if ($confhash{$itemid}{$item}) {
                   13034:                                 $resulttext .= &mt('Yes');
                   13035:                                 if ($item eq 'passback') {
                   13036:                                     if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                   13037:                                         $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                   13038:                                     } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                   13039:                                         $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                   13040:                                     }
1.337     raeburn  13041:                                 }
1.345     raeburn  13042:                             } else {
                   13043:                                 $resulttext .= &mt('No');
1.337     raeburn  13044:                             }
1.345     raeburn  13045:                             $resulttext .= '</li>';
1.320     raeburn  13046:                         }
1.345     raeburn  13047:                         if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                   13048:                             if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                   13049:                                 $resulttext .= '<li>'.&mt('Menu items:').' '.
                   13050:                                                join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                   13051:                             } else {
                   13052:                                 $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                   13053:                             }
1.326     raeburn  13054:                         }
                   13055:                     }
1.320     raeburn  13056:                     $resulttext .= '</ul></li>';
                   13057:                 }
                   13058:             }
                   13059:             $resulttext .= '</ul>';
                   13060:         } else {
                   13061:             $resulttext = &mt('No changes made.');
                   13062:         }
                   13063:     } else {
                   13064:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   13065:     }
                   13066:     if ($errors) {
                   13067:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13068:                        $errors.'</ul>';
                   13069:     }
                   13070:     return $resulttext;
                   13071: }
                   13072: 
                   13073: sub get_lti_id {
                   13074:     my ($domain,$consumer) = @_;
                   13075:     # get lock on lti db
                   13076:     my $lockhash = {
                   13077:                       lock => $env{'user.name'}.
                   13078:                               ':'.$env{'user.domain'},
                   13079:                    };
                   13080:     my $tries = 0;
                   13081:     my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   13082:     my ($id,$error);
                   13083: 
                   13084:     while (($gotlock ne 'ok') && ($tries<10)) {
                   13085:         $tries ++;
                   13086:         sleep (0.1);
                   13087:         $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
                   13088:     }
                   13089:     if ($gotlock eq 'ok') {
                   13090:         my %currids = &Apache::lonnet::dump_dom('lti',$domain);
                   13091:         if ($currids{'lock'}) {
                   13092:             delete($currids{'lock'});
                   13093:             if (keys(%currids)) {
                   13094:                 my @curr = sort { $a <=> $b } keys(%currids);
                   13095:                 if ($curr[-1] =~ /^\d+$/) {
                   13096:                     $id = 1 + $curr[-1];
                   13097:                 }
                   13098:             } else {
                   13099:                 $id = 1;
                   13100:             }
                   13101:             if ($id) {
                   13102:                 unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
                   13103:                     $error = 'nostore';
                   13104:                 }
                   13105:             } else {
                   13106:                 $error = 'nonumber';
                   13107:             }
                   13108:         }
                   13109:         my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
                   13110:     } else {
                   13111:         $error = 'nolock';
                   13112:     }
                   13113:     return ($id,$error);
                   13114: }
                   13115: 
1.3       raeburn  13116: sub modify_autoenroll {
1.205     raeburn  13117:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  13118:     my ($resulttext,%changes);
                   13119:     my %currautoenroll;
                   13120:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   13121:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   13122:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   13123:         }
                   13124:     }
                   13125:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   13126:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  13127:                   sender => 'Sender for notification messages',
1.274     raeburn  13128:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   13129:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  13130:     my @offon = ('off','on');
1.17      raeburn  13131:     my $sender_uname = $env{'form.sender_uname'};
                   13132:     my $sender_domain = $env{'form.sender_domain'};
                   13133:     if ($sender_domain eq '') {
                   13134:         $sender_uname = '';
                   13135:     } elsif ($sender_uname eq '') {
                   13136:         $sender_domain = '';
                   13137:     }
1.129     raeburn  13138:     my $coowners = $env{'form.autoassign_coowners'};
1.274     raeburn  13139:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   13140:     $failsafe =~ s{^\s+|\s+$}{}g;
                   13141:     if ($failsafe =~ /\D/) {
                   13142:         undef($failsafe);
                   13143:     }
1.1       raeburn  13144:     my %autoenrollhash =  (
1.129     raeburn  13145:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   13146:                                        'sender_uname' => $sender_uname,
                   13147:                                        'sender_domain' => $sender_domain,
                   13148:                                        'co-owners' => $coowners,
1.274     raeburn  13149:                                        'autofailsafe' => $failsafe,
1.1       raeburn  13150:                                 }
                   13151:                      );
1.4       raeburn  13152:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   13153:                                              $dom);
1.1       raeburn  13154:     if ($putresult eq 'ok') {
                   13155:         if (exists($currautoenroll{'run'})) {
                   13156:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   13157:                  $changes{'run'} = 1;
                   13158:              }
                   13159:         } elsif ($autorun) {
                   13160:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  13161:                  $changes{'run'} = 1;
1.1       raeburn  13162:             }
                   13163:         }
1.17      raeburn  13164:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  13165:             $changes{'sender'} = 1;
                   13166:         }
1.17      raeburn  13167:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  13168:             $changes{'sender'} = 1;
                   13169:         }
1.129     raeburn  13170:         if ($currautoenroll{'co-owners'} ne '') {
                   13171:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   13172:                 $changes{'coowners'} = 1;
                   13173:             }
                   13174:         } elsif ($coowners) {
                   13175:             $changes{'coowners'} = 1;
1.274     raeburn  13176:         }
                   13177:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   13178:             $changes{'autofailsafe'} = 1;
                   13179:         }
1.1       raeburn  13180:         if (keys(%changes) > 0) {
                   13181:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  13182:             if ($changes{'run'}) {
1.1       raeburn  13183:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   13184:             }
                   13185:             if ($changes{'sender'}) {
1.17      raeburn  13186:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   13187:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   13188:                 } else {
                   13189:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   13190:                 }
1.1       raeburn  13191:             }
1.129     raeburn  13192:             if ($changes{'coowners'}) {
                   13193:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   13194:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  13195:                 if (ref($lastactref) eq 'HASH') {
                   13196:                     $lastactref->{'domainconfig'} = 1;
                   13197:                 }
1.129     raeburn  13198:             }
1.274     raeburn  13199:             if ($changes{'autofailsafe'}) {
                   13200:                 if ($failsafe ne '') {
1.299     raeburn  13201:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.274     raeburn  13202:                 } else {
1.299     raeburn  13203:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.274     raeburn  13204:                 }
                   13205:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   13206:                 if (ref($lastactref) eq 'HASH') {
                   13207:                     $lastactref->{'domdefaults'} = 1;
                   13208:                 }
                   13209:             }
1.1       raeburn  13210:             $resulttext .= '</ul>';
                   13211:         } else {
                   13212:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   13213:         }
                   13214:     } else {
1.11      albertel 13215:         $resulttext = '<span class="LC_error">'.
                   13216: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13217:     }
1.3       raeburn  13218:     return $resulttext;
1.1       raeburn  13219: }
                   13220: 
                   13221: sub modify_autoupdate {
1.3       raeburn  13222:     my ($dom,%domconfig) = @_;
1.1       raeburn  13223:     my ($resulttext,%currautoupdate,%fields,%changes);
                   13224:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   13225:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   13226:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   13227:         }
                   13228:     }
                   13229:     my @offon = ('off','on');
                   13230:     my %title = &Apache::lonlocal::texthash (
                   13231:                    run => 'Auto-update:',
                   13232:                    classlists => 'Updates to user information in classlists?'
                   13233:                 );
1.44      raeburn  13234:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13235:     my %fieldtitles = &Apache::lonlocal::texthash (
                   13236:                         id => 'Student/Employee ID',
1.20      raeburn  13237:                         permanentemail => 'E-mail address',
1.1       raeburn  13238:                         lastname => 'Last Name',
                   13239:                         firstname => 'First Name',
                   13240:                         middlename => 'Middle Name',
1.132     raeburn  13241:                         generation => 'Generation',
1.1       raeburn  13242:                       );
1.142     raeburn  13243:     $othertitle = &mt('All users');
1.1       raeburn  13244:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  13245:         $othertitle = &mt('Other users');
1.1       raeburn  13246:     }
                   13247:     foreach my $key (keys(%env)) {
                   13248:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  13249:             my ($usertype,$item) = ($1,$2);
                   13250:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   13251:                 if ($usertype eq 'default') {   
                   13252:                     push(@{$fields{$1}},$2);
                   13253:                 } elsif (ref($types) eq 'ARRAY') {
                   13254:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   13255:                         push(@{$fields{$1}},$2);
                   13256:                     }
                   13257:                 }
                   13258:             }
1.1       raeburn  13259:         }
                   13260:     }
1.131     raeburn  13261:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   13262:     @lockablenames = sort(@lockablenames);
                   13263:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   13264:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13265:         if (@changed) {
                   13266:             $changes{'lockablenames'} = 1;
                   13267:         }
                   13268:     } else {
                   13269:         if (@lockablenames) {
                   13270:             $changes{'lockablenames'} = 1;
                   13271:         }
                   13272:     }
1.1       raeburn  13273:     my %updatehash = (
                   13274:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   13275:                                       classlists => $env{'form.classlists'},
                   13276:                                       fields => {%fields},
1.131     raeburn  13277:                                       lockablenames => \@lockablenames,
1.1       raeburn  13278:                                     }
                   13279:                      );
                   13280:     foreach my $key (keys(%currautoupdate)) {
                   13281:         if (($key eq 'run') || ($key eq 'classlists')) {
                   13282:             if (exists($updatehash{autoupdate}{$key})) {
                   13283:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   13284:                     $changes{$key} = 1;
                   13285:                 }
                   13286:             }
                   13287:         } elsif ($key eq 'fields') {
                   13288:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  13289:                 foreach my $item (@{$types},'default') {
1.1       raeburn  13290:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   13291:                         my $change = 0;
                   13292:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   13293:                             if (!exists($fields{$item})) {
                   13294:                                 $change = 1;
1.132     raeburn  13295:                                 last;
1.1       raeburn  13296:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  13297:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  13298:                                     $change = 1;
1.132     raeburn  13299:                                     last;
1.1       raeburn  13300:                                 }
                   13301:                             }
                   13302:                         }
                   13303:                         if ($change) {
                   13304:                             push(@{$changes{$key}},$item);
                   13305:                         }
1.26      raeburn  13306:                     } 
1.1       raeburn  13307:                 }
                   13308:             }
1.131     raeburn  13309:         } elsif ($key eq 'lockablenames') {
                   13310:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   13311:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13312:                 if (@changed) {
                   13313:                     $changes{'lockablenames'} = 1;
                   13314:                 }
                   13315:             } else {
                   13316:                 if (@lockablenames) {
                   13317:                     $changes{'lockablenames'} = 1;
                   13318:                 }
                   13319:             }
                   13320:         }
                   13321:     }
                   13322:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   13323:         if (@lockablenames) {
                   13324:             $changes{'lockablenames'} = 1;
1.1       raeburn  13325:         }
                   13326:     }
1.26      raeburn  13327:     foreach my $item (@{$types},'default') {
                   13328:         if (defined($fields{$item})) {
                   13329:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  13330:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   13331:                     my $change = 0;
                   13332:                     if (ref($fields{$item}) eq 'ARRAY') {
                   13333:                         foreach my $type (@{$fields{$item}}) {
                   13334:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   13335:                                 $change = 1;
                   13336:                                 last;
                   13337:                             }
                   13338:                         }
                   13339:                     }
                   13340:                     if ($change) {
                   13341:                         push(@{$changes{'fields'}},$item);
                   13342:                     }
                   13343:                 } else {
1.26      raeburn  13344:                     push(@{$changes{'fields'}},$item);
                   13345:                 }
                   13346:             } else {
                   13347:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  13348:             }
                   13349:         }
                   13350:     }
                   13351:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   13352:                                              $dom);
                   13353:     if ($putresult eq 'ok') {
                   13354:         if (keys(%changes) > 0) {
                   13355:             $resulttext = &mt('Changes made:').'<ul>';
                   13356:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  13357:                 if ($key eq 'lockablenames') {
                   13358:                     $resulttext .= '<li>';
                   13359:                     if (@lockablenames) {
                   13360:                         $usertypes->{'default'} = $othertitle;
                   13361:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   13362:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   13363:                     } else {
                   13364:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   13365:                     }
                   13366:                     $resulttext .= '</li>';
                   13367:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  13368:                     foreach my $item (@{$changes{$key}}) {
                   13369:                         my @newvalues;
                   13370:                         foreach my $type (@{$fields{$item}}) {
                   13371:                             push(@newvalues,$fieldtitles{$type});
                   13372:                         }
1.3       raeburn  13373:                         my $newvaluestr;
                   13374:                         if (@newvalues > 0) {
                   13375:                             $newvaluestr = join(', ',@newvalues);
                   13376:                         } else {
                   13377:                             $newvaluestr = &mt('none');
1.6       raeburn  13378:                         }
1.1       raeburn  13379:                         if ($item eq 'default') {
1.26      raeburn  13380:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  13381:                         } else {
1.26      raeburn  13382:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  13383:                         }
                   13384:                     }
                   13385:                 } else {
                   13386:                     my $newvalue;
                   13387:                     if ($key eq 'run') {
                   13388:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   13389:                     } else {
                   13390:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  13391:                     }
1.1       raeburn  13392:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   13393:                 }
                   13394:             }
                   13395:             $resulttext .= '</ul>';
                   13396:         } else {
1.3       raeburn  13397:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  13398:         }
                   13399:     } else {
1.11      albertel 13400:         $resulttext = '<span class="LC_error">'.
                   13401: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13402:     }
1.3       raeburn  13403:     return $resulttext;
1.1       raeburn  13404: }
                   13405: 
1.125     raeburn  13406: sub modify_autocreate {
                   13407:     my ($dom,%domconfig) = @_;
                   13408:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   13409:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   13410:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   13411:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   13412:         }
                   13413:     }
                   13414:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   13415:                  req => 'Auto-creation of validated requests for official courses',
                   13416:                  xmldc => 'Identity of course creator of courses from XML files',
                   13417:                );
                   13418:     my @types = ('xml','req');
                   13419:     foreach my $item (@types) {
                   13420:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   13421:         $newvals{$item} =~ s/\D//g;
                   13422:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   13423:     }
                   13424:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285     raeburn  13425:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  13426:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   13427:         $newvals{'xmldc'} = '';
                   13428:     } 
                   13429:     %autocreatehash =  (
                   13430:                         autocreate => { xml => $newvals{'xml'},
                   13431:                                         req => $newvals{'req'},
                   13432:                                       }
                   13433:                        );
                   13434:     if ($newvals{'xmldc'} ne '') {
                   13435:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   13436:     }
                   13437:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   13438:                                              $dom);
                   13439:     if ($putresult eq 'ok') {
                   13440:         my @items = @types;
                   13441:         if ($newvals{'xml'}) {
                   13442:             push(@items,'xmldc');
                   13443:         }
                   13444:         foreach my $item (@items) {
                   13445:             if (exists($currautocreate{$item})) {
                   13446:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   13447:                     $changes{$item} = 1;
                   13448:                 }
                   13449:             } elsif ($newvals{$item}) {
                   13450:                 $changes{$item} = 1;
                   13451:             }
                   13452:         }
                   13453:         if (keys(%changes) > 0) {
                   13454:             my @offon = ('off','on'); 
                   13455:             $resulttext = &mt('Changes made:').'<ul>';
                   13456:             foreach my $item (@types) {
                   13457:                 if ($changes{$item}) {
                   13458:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  13459:                     $resulttext .= '<li>'.
                   13460:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   13461:                                        '<b>','</b>').
                   13462:                                    '</li>';
1.125     raeburn  13463:                 }
                   13464:             }
                   13465:             if ($changes{'xmldc'}) {
                   13466:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   13467:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  13468:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  13469:             }
                   13470:             $resulttext .= '</ul>';
                   13471:         } else {
                   13472:             $resulttext = &mt('No changes made to auto-creation settings');
                   13473:         }
                   13474:     } else {
                   13475:         $resulttext = '<span class="LC_error">'.
                   13476:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13477:     }
                   13478:     return $resulttext;
                   13479: }
                   13480: 
1.23      raeburn  13481: sub modify_directorysrch {
1.295     raeburn  13482:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  13483:     my ($resulttext,%changes);
                   13484:     my %currdirsrch;
                   13485:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   13486:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   13487:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   13488:         }
                   13489:     }
1.277     raeburn  13490:     my %title = ( available => 'Institutional directory search available',
                   13491:                   localonly => 'Other domains can search institution',
                   13492:                   lcavailable => 'LON-CAPA directory search available',
1.289     raeburn  13493:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  13494:                   searchby => 'Search types',
                   13495:                   searchtypes => 'Search latitude');
                   13496:     my @offon = ('off','on');
1.24      raeburn  13497:     my @otherdoms = ('Yes','No');
1.23      raeburn  13498: 
1.25      raeburn  13499:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  13500:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   13501:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   13502: 
1.44      raeburn  13503:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  13504:     if (keys(%{$usertypes}) == 0) {
                   13505:         @cansearch = ('default');
                   13506:     } else {
                   13507:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   13508:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   13509:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   13510:                     push(@{$changes{'cansearch'}},$type);
                   13511:                 }
1.23      raeburn  13512:             }
1.26      raeburn  13513:             foreach my $type (@cansearch) {
                   13514:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   13515:                     push(@{$changes{'cansearch'}},$type);
                   13516:                 }
1.23      raeburn  13517:             }
1.26      raeburn  13518:         } else {
                   13519:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  13520:         }
                   13521:     }
                   13522: 
                   13523:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   13524:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   13525:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   13526:                 push(@{$changes{'searchby'}},$by);
                   13527:             }
                   13528:         }
                   13529:         foreach my $by (@searchby) {
                   13530:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   13531:                 push(@{$changes{'searchby'}},$by);
                   13532:             }
                   13533:         }
                   13534:     } else {
                   13535:         push(@{$changes{'searchby'}},@searchby);
                   13536:     }
1.25      raeburn  13537: 
                   13538:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   13539:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   13540:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   13541:                 push(@{$changes{'searchtypes'}},$type);
                   13542:             }
                   13543:         }
                   13544:         foreach my $type (@searchtypes) {
                   13545:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   13546:                 push(@{$changes{'searchtypes'}},$type);
                   13547:             }
                   13548:         }
                   13549:     } else {
                   13550:         if (exists($currdirsrch{'searchtypes'})) {
                   13551:             foreach my $type (@searchtypes) {  
                   13552:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   13553:                     push(@{$changes{'searchtypes'}},$type);
                   13554:                 }
                   13555:             }
                   13556:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   13557:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   13558:             }   
                   13559:         } else {
                   13560:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   13561:         }
                   13562:     }
                   13563: 
1.23      raeburn  13564:     my %dirsrch_hash =  (
                   13565:             directorysrch => { available => $env{'form.dirsrch_available'},
                   13566:                                cansearch => \@cansearch,
1.277     raeburn  13567:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   13568:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   13569:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  13570:                                searchby => \@searchby,
1.25      raeburn  13571:                                searchtypes => \@searchtypes,
1.23      raeburn  13572:                              }
                   13573:             );
                   13574:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   13575:                                              $dom);
                   13576:     if ($putresult eq 'ok') {
                   13577:         if (exists($currdirsrch{'available'})) {
                   13578:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   13579:                  $changes{'available'} = 1;
                   13580:              }
                   13581:         } else {
                   13582:             if ($env{'form.dirsrch_available'} eq '1') {
                   13583:                 $changes{'available'} = 1;
                   13584:             }
                   13585:         }
1.277     raeburn  13586:         if (exists($currdirsrch{'lcavailable'})) {
1.289     raeburn  13587:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   13588:                 $changes{'lcavailable'} = 1;
                   13589:             }
1.277     raeburn  13590:         } else {
                   13591:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   13592:                 $changes{'lcavailable'} = 1;
                   13593:             }
                   13594:         }
1.24      raeburn  13595:         if (exists($currdirsrch{'localonly'})) {
1.289     raeburn  13596:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
                   13597:                 $changes{'localonly'} = 1;
                   13598:             }
1.24      raeburn  13599:         } else {
1.277     raeburn  13600:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24      raeburn  13601:                 $changes{'localonly'} = 1;
                   13602:             }
                   13603:         }
1.277     raeburn  13604:         if (exists($currdirsrch{'lclocalonly'})) {
1.289     raeburn  13605:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   13606:                 $changes{'lclocalonly'} = 1;
                   13607:             }
1.277     raeburn  13608:         } else {
                   13609:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   13610:                 $changes{'lclocalonly'} = 1;
                   13611:             }
                   13612:         }
1.23      raeburn  13613:         if (keys(%changes) > 0) {
                   13614:             $resulttext = &mt('Changes made:').'<ul>';
                   13615:             if ($changes{'available'}) {
                   13616:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   13617:             }
1.277     raeburn  13618:             if ($changes{'lcavailable'}) {
                   13619:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   13620:             }
1.24      raeburn  13621:             if ($changes{'localonly'}) {
1.277     raeburn  13622:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24      raeburn  13623:             }
1.277     raeburn  13624:             if ($changes{'lclocalonly'}) {
                   13625:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289     raeburn  13626:             }
1.23      raeburn  13627:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   13628:                 my $chgtext;
1.26      raeburn  13629:                 if (ref($usertypes) eq 'HASH') {
                   13630:                     if (keys(%{$usertypes}) > 0) {
                   13631:                         foreach my $type (@{$types}) {
                   13632:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   13633:                                 $chgtext .= $usertypes->{$type}.'; ';
                   13634:                             }
                   13635:                         }
                   13636:                         if (grep(/^default$/,@cansearch)) {
                   13637:                             $chgtext .= $othertitle;
                   13638:                         } else {
                   13639:                             $chgtext =~ s/\; $//;
                   13640:                         }
1.210     raeburn  13641:                         $resulttext .=
1.178     raeburn  13642:                             '<li>'.
                   13643:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   13644:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   13645:                             '</li>';
1.23      raeburn  13646:                     }
                   13647:                 }
                   13648:             }
                   13649:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   13650:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   13651:                 my $chgtext;
                   13652:                 foreach my $type (@{$titleorder}) {
                   13653:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   13654:                         if (defined($searchtitles->{$type})) {
                   13655:                             $chgtext .= $searchtitles->{$type}.'; ';
                   13656:                         }
                   13657:                     }
                   13658:                 }
                   13659:                 $chgtext =~ s/\; $//;
                   13660:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   13661:             }
1.25      raeburn  13662:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   13663:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   13664:                 my $chgtext;
                   13665:                 foreach my $type (@{$srchtypeorder}) {
                   13666:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   13667:                         if (defined($srchtypes_desc->{$type})) {
                   13668:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   13669:                         }
                   13670:                     }
                   13671:                 }
                   13672:                 $chgtext =~ s/\; $//;
1.178     raeburn  13673:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  13674:             }
                   13675:             $resulttext .= '</ul>';
1.295     raeburn  13676:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   13677:             if (ref($lastactref) eq 'HASH') {
                   13678:                 $lastactref->{'directorysrch'} = 1;
                   13679:             }
1.23      raeburn  13680:         } else {
1.277     raeburn  13681:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  13682:         }
                   13683:     } else {
                   13684:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  13685:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   13686:     }
                   13687:     return $resulttext;
                   13688: }
                   13689: 
1.28      raeburn  13690: sub modify_contacts {
1.205     raeburn  13691:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  13692:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   13693:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   13694:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   13695:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   13696:         }
                   13697:     }
1.286     raeburn  13698:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  13699:     my @contacts = ('supportemail','adminemail');
1.286     raeburn  13700:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350     raeburn  13701:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340     raeburn  13702:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   13703:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286     raeburn  13704:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  13705:     foreach my $type (@mailings) {
                   13706:         @{$newsetting{$type}} = 
                   13707:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   13708:         foreach my $item (@contacts) {
                   13709:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   13710:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   13711:             } else {
                   13712:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   13713:             }
1.289     raeburn  13714:         }
1.28      raeburn  13715:         $others{$type} = $env{'form.'.$type.'_others'};
                   13716:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286     raeburn  13717:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13718:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   13719:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286     raeburn  13720:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   13721:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   13722:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   13723:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   13724:             }
1.134     raeburn  13725:         }
1.28      raeburn  13726:     }
                   13727:     foreach my $item (@contacts) {
                   13728:         $to{$item} = $env{'form.'.$item};
                   13729:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   13730:     }
1.203     raeburn  13731:     foreach my $item (@toggles) {
                   13732:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   13733:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   13734:         }
                   13735:     }
1.340     raeburn  13736:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   13737:     foreach my $item (@lonstatus) {
                   13738:         if ($item eq 'excluded') {
                   13739:             my (%serverhomes,@excluded);
                   13740:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   13741:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   13742:             if (@possexcluded) {
                   13743:                 foreach my $id (sort(@possexcluded)) {
                   13744:                     if ($serverhomes{$id}) {
                   13745:                         push(@excluded,$id);
                   13746:                     }
                   13747:                 }
                   13748:             }
                   13749:             if (@excluded) {
                   13750:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   13751:             }
                   13752:         } elsif ($item eq 'weights') {
                   13753:             foreach my $type ('E','W','N') {
                   13754:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   13755:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   13756:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   13757:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   13758:                             $env{'form.error'.$item.'_'.$type};
                   13759:                     }
                   13760:                 }
                   13761:             }
                   13762:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   13763:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   13764:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   13765:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   13766:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   13767:                 }
                   13768:             }
                   13769:         }
                   13770:     }
1.286     raeburn  13771:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   13772:         foreach my $field (@{$fields}) {
                   13773:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   13774:                 my $value = $env{'form.helpform_'.$field};
                   13775:                 $value =~ s/^\s+|\s+$//g;
                   13776:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315     raeburn  13777:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286     raeburn  13778:                     if ($field eq 'screenshot') {
                   13779:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   13780:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315     raeburn  13781:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286     raeburn  13782:                         }
                   13783:                     }
                   13784:                 }
                   13785:             }
                   13786:         }
                   13787:     }
1.315     raeburn  13788:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   13789:     my (@statuses,%usertypeshash,@overrides);
                   13790:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   13791:         @statuses = @{$types};
                   13792:         if (ref($usertypes) eq 'HASH') {
                   13793:             %usertypeshash = %{$usertypes};
                   13794:         }
                   13795:     }
                   13796:     if (@statuses) {
                   13797:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   13798:         foreach my $type (@possoverrides) {
                   13799:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   13800:                 push(@overrides,$type);
                   13801:             }
                   13802:         }
                   13803:         if (@overrides) {
                   13804:             foreach my $type (@overrides) {
                   13805:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   13806:                 foreach my $item (@contacts) {
                   13807:                     if (grep(/^\Q$item\E$/,@standard)) {
                   13808:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   13809:                         $newsetting{'override_'.$type}{$item} = 1;
                   13810:                     } else {
                   13811:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   13812:                         $newsetting{'override_'.$type}{$item} = 0;
                   13813:                     }
                   13814:                 }
                   13815:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   13816:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   13817:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   13818:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   13819:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   13820:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   13821:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   13822:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   13823:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   13824:                 }
                   13825:             }     
                   13826:         }
                   13827:     }
1.28      raeburn  13828:     if (keys(%currsetting) > 0) {
                   13829:         foreach my $item (@contacts) {
                   13830:             if ($to{$item} ne $currsetting{$item}) {
                   13831:                 $changes{$item} = 1;
                   13832:             }
                   13833:         }
                   13834:         foreach my $type (@mailings) {
                   13835:             foreach my $item (@contacts) {
                   13836:                 if (ref($currsetting{$type}) eq 'HASH') {
                   13837:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   13838:                         push(@{$changes{$type}},$item);
                   13839:                     }
                   13840:                 } else {
                   13841:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   13842:                 }
                   13843:             }
                   13844:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   13845:                 push(@{$changes{$type}},'others');
                   13846:             }
1.289     raeburn  13847:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13848:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   13849:                     push(@{$changes{$type}},'bcc'); 
                   13850:                 }
1.286     raeburn  13851:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   13852:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   13853:                     push(@{$changes{$type}},'include');
                   13854:                 }
                   13855:             }
                   13856:         }
                   13857:         if (ref($fields) eq 'ARRAY') {
                   13858:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   13859:                 foreach my $field (@{$fields}) {
                   13860:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   13861:                         push(@{$changes{'helpform'}},$field);
                   13862:                     }
                   13863:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   13864:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   13865:                             push(@{$changes{'helpform'}},'maxsize');
                   13866:                         }
                   13867:                     }
                   13868:                 }
                   13869:             } else {
                   13870:                 foreach my $field (@{$fields}) {
                   13871:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   13872:                         push(@{$changes{'helpform'}},$field);
                   13873:                     }
                   13874:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   13875:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   13876:                             push(@{$changes{'helpform'}},'maxsize');
                   13877:                         }
                   13878:                     }
                   13879:                 }
1.134     raeburn  13880:             }
1.28      raeburn  13881:         }
1.315     raeburn  13882:         if (@statuses) {
                   13883:             if (ref($currsetting{'overrides'}) eq 'HASH') { 
                   13884:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   13885:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   13886:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   13887:                             foreach my $item (@contacts,'bcc','others','include') {
                   13888:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) { 
                   13889:                                     push(@{$changes{'overrides'}},$key);
                   13890:                                     last;
                   13891:                                 }
                   13892:                             }
                   13893:                         } else {
                   13894:                             push(@{$changes{'overrides'}},$key);
                   13895:                         }
                   13896:                     }
                   13897:                 }
                   13898:                 foreach my $key (@overrides) {
                   13899:                     unless (exists($currsetting{'overrides'}{$key})) {
                   13900:                         push(@{$changes{'overrides'}},$key);
                   13901:                     }
                   13902:                 }
                   13903:             } else {
                   13904:                 foreach my $key (@overrides) {
                   13905:                     push(@{$changes{'overrides'}},$key); 
                   13906:                 }
                   13907:             }
                   13908:         }
1.340     raeburn  13909:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   13910:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   13911:                 if ($key eq 'excluded') {
                   13912:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   13913:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   13914:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   13915:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   13916:                             my @diffs =
                   13917:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   13918:                                                                    $currsetting{'lonstatus'}{$key});
                   13919:                             if (@diffs) {
                   13920:                                 push(@{$changes{'lonstatus'}},$key);
                   13921:                             }
                   13922:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   13923:                             push(@{$changes{'lonstatus'}},$key);
                   13924:                         }
                   13925:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   13926:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   13927:                         push(@{$changes{'lonstatus'}},$key);
                   13928:                     }
                   13929:                 } elsif ($key eq 'weights') {
                   13930:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   13931:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   13932:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  13933:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  13934:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   13935:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   13936:                                     push(@{$changes{'lonstatus'}},$key);
                   13937:                                     last;
                   13938:                                 }
                   13939:                             }
                   13940:                         } else {
1.341     raeburn  13941:                             foreach my $type ('E','W','N','U') {
1.340     raeburn  13942:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   13943:                                     push(@{$changes{'lonstatus'}},$key);
                   13944:                                     last;
                   13945:                                 }
                   13946:                             }
                   13947:                         }
                   13948:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341     raeburn  13949:                         foreach my $type ('E','W','N','U') {
1.340     raeburn  13950:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   13951:                                 push(@{$changes{'lonstatus'}},$key);
                   13952:                                 last;
                   13953:                             }
                   13954:                         }
                   13955:                     }
                   13956:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   13957:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   13958:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   13959:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   13960:                                 push(@{$changes{'lonstatus'}},$key);
                   13961:                             }
                   13962:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   13963:                             push(@{$changes{'lonstatus'}},$key);
                   13964:                         }
                   13965:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   13966:                         push(@{$changes{'lonstatus'}},$key);
                   13967:                     }
                   13968:                 }
                   13969:             }
                   13970:         } else {
                   13971:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   13972:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   13973:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   13974:                         push(@{$changes{'lonstatus'}},$key);
                   13975:                     }
                   13976:                 }
                   13977:             }
                   13978:         }
1.28      raeburn  13979:     } else {
                   13980:         my %default;
                   13981:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   13982:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   13983:         $default{'errormail'} = 'adminemail';
                   13984:         $default{'packagesmail'} = 'adminemail';
                   13985:         $default{'helpdeskmail'} = 'supportemail';
1.286     raeburn  13986:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  13987:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  13988:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  13989:         $default{'updatesmail'} = 'adminemail';
1.350     raeburn  13990:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  13991:         foreach my $item (@contacts) {
                   13992:            if ($to{$item} ne $default{$item}) {
1.286     raeburn  13993:                $changes{$item} = 1;
1.203     raeburn  13994:            }
1.28      raeburn  13995:         }
                   13996:         foreach my $type (@mailings) {
                   13997:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   13998:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   13999:             }
                   14000:             if ($others{$type} ne '') {
                   14001:                 push(@{$changes{$type}},'others');
1.134     raeburn  14002:             }
1.286     raeburn  14003:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  14004:                 if ($bcc{$type} ne '') {
                   14005:                     push(@{$changes{$type}},'bcc');
                   14006:                 }
1.286     raeburn  14007:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   14008:                     push(@{$changes{$type}},'include');
                   14009:                 }
1.134     raeburn  14010:             }
1.28      raeburn  14011:         }
1.286     raeburn  14012:         if (ref($fields) eq 'ARRAY') {
                   14013:             foreach my $field (@{$fields}) {
                   14014:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   14015:                     push(@{$changes{'helpform'}},$field);
                   14016:                 }
                   14017:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   14018:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   14019:                         push(@{$changes{'helpform'}},'maxsize');
                   14020:                     }
                   14021:                 }
                   14022:             }
1.289     raeburn  14023:         }
1.340     raeburn  14024:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   14025:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   14026:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   14027:                     push(@{$changes{'lonstatus'}},$key);
                   14028:                 }
                   14029:             }
                   14030:         }
1.28      raeburn  14031:     }
1.203     raeburn  14032:     foreach my $item (@toggles) {
                   14033:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   14034:             $changes{$item} = 1;
                   14035:         } elsif ((!$env{'form.'.$item}) &&
                   14036:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   14037:             $changes{$item} = 1;
                   14038:         }
                   14039:     }
1.28      raeburn  14040:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   14041:                                              $dom);
                   14042:     if ($putresult eq 'ok') {
                   14043:         if (keys(%changes) > 0) {
1.205     raeburn  14044:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  14045:             if (ref($lastactref) eq 'HASH') {
                   14046:                 $lastactref->{'domainconfig'} = 1;
                   14047:             }
1.28      raeburn  14048:             my ($titles,$short_titles)  = &contact_titles();
                   14049:             $resulttext = &mt('Changes made:').'<ul>';
                   14050:             foreach my $item (@contacts) {
                   14051:                 if ($changes{$item}) {
                   14052:                     $resulttext .= '<li>'.$titles->{$item}.
                   14053:                                     &mt(' set to: ').
                   14054:                                     '<span class="LC_cusr_emph">'.
                   14055:                                     $to{$item}.'</span></li>';
                   14056:                 }
                   14057:             }
                   14058:             foreach my $type (@mailings) {
                   14059:                 if (ref($changes{$type}) eq 'ARRAY') {
1.286     raeburn  14060:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289     raeburn  14061:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286     raeburn  14062:                     } else {
                   14063:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   14064:                     }
1.28      raeburn  14065:                     my @text;
                   14066:                     foreach my $item (@{$newsetting{$type}}) {
                   14067:                         push(@text,$short_titles->{$item});
                   14068:                     }
                   14069:                     if ($others{$type} ne '') {
                   14070:                         push(@text,$others{$type});
                   14071:                     }
1.286     raeburn  14072:                     if (@text) {
                   14073:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   14074:                                        join(', ',@text).'</span>';
                   14075:                     }
                   14076:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  14077:                         if ($bcc{$type} ne '') {
1.286     raeburn  14078:                             my $bcctext;
                   14079:                             if (@text) {
1.289     raeburn  14080:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
1.286     raeburn  14081:                             } else {
                   14082:                                 $bcctext = '(Bcc)';
                   14083:                             }
                   14084:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   14085:                         } elsif (!@text) {
                   14086:                             $resulttext .= &mt('No one');
                   14087:                         }   
1.289     raeburn  14088:                         if ($includestr{$type} ne '') {
1.286     raeburn  14089:                             if ($includeloc{$type} eq 'b') {
                   14090:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   14091:                             } elsif ($includeloc{$type} eq 's') {
                   14092:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   14093:                             }
1.134     raeburn  14094:                         }
1.286     raeburn  14095:                     } elsif (!@text) {
                   14096:                         $resulttext .= &mt('No recipients');
1.134     raeburn  14097:                     }
                   14098:                     $resulttext .= '</li>';
1.28      raeburn  14099:                 }
                   14100:             }
1.315     raeburn  14101:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   14102:                 my @deletions;
                   14103:                 foreach my $type (@{$changes{'overrides'}}) {
                   14104:                     if ($usertypeshash{$type}) {
                   14105:                         if (grep(/^\Q$type\E/,@overrides)) {
                   14106:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   14107:                                                       $usertypeshash{$type}).'<ul><li>';
                   14108:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   14109:                                 my @text;
                   14110:                                 foreach my $item (@contacts) {
                   14111:                                     if ($newsetting{'override_'.$type}{$item}) { 
                   14112:                                         push(@text,$short_titles->{$item});
                   14113:                                     }
                   14114:                                 }
                   14115:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   14116:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   14117:                                 }
                   14118:   
                   14119:                                 if (@text) {
                   14120:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   14121:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   14122:                                 }
                   14123:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   14124:                                     my $bcctext;
                   14125:                                     if (@text) {
                   14126:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   14127:                                     } else {
                   14128:                                         $bcctext = '(Bcc)';
                   14129:                                     }
                   14130:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   14131:                                 } elsif (!@text) {
                   14132:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   14133:                                 }
                   14134:                                 $resulttext .= '</li>';
                   14135:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   14136:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   14137:                                     if ($loc eq 'b') {
                   14138:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   14139:                                     } elsif ($loc eq 's') {
                   14140:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   14141:                                     }
                   14142:                                 }
                   14143:                             }
                   14144:                             $resulttext .= '</li></ul></li>';
                   14145:                         } else {
                   14146:                             push(@deletions,$usertypeshash{$type});
                   14147:                         }
                   14148:                     }
                   14149:                 }
                   14150:                 if (@deletions) {
                   14151:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   14152:                                               join(', ',@deletions)).'</li>';
                   14153:                 }
                   14154:             }
1.203     raeburn  14155:             my @offon = ('off','on');
1.340     raeburn  14156:             my $corelink = &core_link_msu();
1.203     raeburn  14157:             if ($changes{'reporterrors'}) {
                   14158:                 $resulttext .= '<li>'.
                   14159:                                &mt('E-mail error reports to [_1] set to "'.
                   14160:                                    $offon[$env{'form.reporterrors'}].'".',
1.340     raeburn  14161:                                    $corelink).
1.203     raeburn  14162:                                '</li>';
                   14163:             }
                   14164:             if ($changes{'reportupdates'}) {
                   14165:                 $resulttext .= '<li>'.
                   14166:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   14167:                                     $offon[$env{'form.reportupdates'}].'".',
1.340     raeburn  14168:                                     $corelink).
1.203     raeburn  14169:                                 '</li>';
                   14170:             }
1.340     raeburn  14171:             if ($changes{'reportstatus'}) {
                   14172:                 $resulttext .= '<li>'.
                   14173:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   14174:                                     $offon[$env{'form.reportstatus'}].'".',
                   14175:                                     $corelink).
                   14176:                                 '</li>';
                   14177:             }
                   14178:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   14179:                 $resulttext .= '<li>'.
                   14180:                                &mt('Nightly status check e-mail settings').':<ul>';
                   14181:                 my (%defval,%use_def,%shown);
                   14182:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   14183:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   14184:                 $defval{'weights'} =
1.341     raeburn  14185:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340     raeburn  14186:                 $defval{'excluded'} = &mt('None');
                   14187:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   14188:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   14189:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   14190:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   14191:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   14192:                             } elsif ($item eq 'weights') {
                   14193:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341     raeburn  14194:                                     foreach my $type ('E','W','N','U') {
1.340     raeburn  14195:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   14196:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   14197:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   14198:                                         } else {
                   14199:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   14200:                                         }
                   14201:                                         $shown{$item} .= ', ';
                   14202:                                     }
                   14203:                                     $shown{$item} =~ s/, $//;
                   14204:                                 } else {
                   14205:                                     $shown{$item} = $defval{$item};
                   14206:                                 }
                   14207:                             } elsif ($item eq 'excluded') {
                   14208:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   14209:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   14210:                                 } else {
                   14211:                                     $shown{$item} = $defval{$item};
                   14212:                                 }
                   14213:                             }
                   14214:                         } else {
                   14215:                             $shown{$item} = $defval{$item};
                   14216:                         }
                   14217:                     }
                   14218:                 } else {
                   14219:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   14220:                         $shown{$item} = $defval{$item};
                   14221:                     }
                   14222:                 }
                   14223:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   14224:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   14225:                                           $shown{$item}).'</li>';
                   14226:                 }
                   14227:                 $resulttext .= '</ul></li>';
                   14228:             }
1.286     raeburn  14229:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   14230:                 my (@optional,@required,@unused,$maxsizechg);
                   14231:                 foreach my $field (@{$changes{'helpform'}}) {
                   14232:                     if ($field eq 'maxsize') {
                   14233:                         $maxsizechg = 1;
                   14234:                         next;
                   14235:                     }
                   14236:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289     raeburn  14237:                         push(@optional,$field);
1.286     raeburn  14238:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   14239:                         push(@unused,$field);
                   14240:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289     raeburn  14241:                         push(@required,$field);
1.286     raeburn  14242:                     }
                   14243:                 }
                   14244:                 if (@optional) {
                   14245:                     $resulttext .= '<li>'.
                   14246:                                    &mt('Help form fields changed to "Optional": [_1].',
                   14247:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   14248:                                    '</li>';
                   14249:                 }
                   14250:                 if (@required) {
                   14251:                     $resulttext .= '<li>'.
                   14252:                                    &mt('Help form fields changed to "Required": [_1].',
                   14253:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   14254:                                    '</li>';
                   14255:                 }
                   14256:                 if (@unused) {
                   14257:                     $resulttext .= '<li>'.
                   14258:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   14259:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   14260:                                    '</li>';
                   14261:                 }
                   14262:                 if ($maxsizechg) {
                   14263:                     $resulttext .= '<li>'.
                   14264:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   14265:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   14266:                                    '</li>';
                   14267:                 }
                   14268:             }
1.28      raeburn  14269:             $resulttext .= '</ul>';
                   14270:         } else {
1.288     raeburn  14271:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  14272:         }
                   14273:     } else {
                   14274:         $resulttext = '<span class="LC_error">'.
                   14275:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   14276:     }
                   14277:     return $resulttext;
                   14278: }
                   14279: 
1.357     raeburn  14280: sub modify_privacy {
                   14281:     my ($dom,%domconfig) = @_;
                   14282:     my ($resulttext,%current,%changes);
                   14283:     if (ref($domconfig{'privacy'}) eq 'HASH') {
                   14284:         %current = %{$domconfig{'privacy'}};
                   14285:     }
                   14286:     my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
                   14287:     my @items = ('domain','author','course','community');
                   14288:     my %names = &Apache::lonlocal::texthash (
                   14289:                    domain => 'Assigned domain role(s)',
                   14290:                    author => 'Assigned co-author role(s)',
                   14291:                    course => 'Assigned course role(s)',
                   14292:                    community => 'Assigned community role',
                   14293:                 );
                   14294:     my %roles = &Apache::lonlocal::texthash (
                   14295:                    domain => 'Domain role',
                   14296:                    author => 'Co-author role',
                   14297:                    course => 'Course role',
                   14298:                    community => 'Community role',
                   14299:                 );
                   14300:     my %titles = &Apache::lonlocal::texthash (
                   14301:                   approval => 'Approval for role in different domain',
                   14302:                   othdom   => 'User information available in other domain',
                   14303:                   priv     => 'Information viewable by privileged user in same domain',
                   14304:                   unpriv   => 'Information viewable by unprivileged user in same domain',
                   14305:                   instdom  => 'Other domain shares institution/provider',
                   14306:                   extdom   => 'Other domain has different institution/provider',
                   14307:                   none     => 'Not allowed',
                   14308:                   user     => 'User authorizes',
                   14309:                   domain   => 'Domain Coordinator authorizes',
                   14310:                   auto     => 'Unrestricted',
                   14311:     );
                   14312:     my %fieldnames = &Apache::lonlocal::texthash (
                   14313:                         id => 'Student/Employee ID',
                   14314:                         permanentemail => 'E-mail address',
                   14315:                         lastname => 'Last Name',
                   14316:                         firstname => 'First Name',
                   14317:                         middlename => 'Middle Name',
                   14318:                         generation => 'Generation',
                   14319:     );
                   14320:     my ($othertitle,$usertypes,$types) =
                   14321:         &Apache::loncommon::sorted_inst_types($dom);
                   14322:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   14323:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   14324: 
                   14325:     my %privacyhash = (
                   14326:                        'approval' => {
                   14327:                                        instdom => {},
                   14328:                                        extdom  => {},
                   14329:                                      },
                   14330:                        'othdom'   => {},
                   14331:                        'priv'     => {},
                   14332:                        'unpriv'   => {},
                   14333:                       );
                   14334:     foreach my $item (@items) {
                   14335:         if (@instdoms > 1) {
                   14336:             if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   14337:                 $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
                   14338:             }
                   14339:             if (ref($current{'approval'}) eq 'HASH') {
                   14340:                 if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                   14341:                     unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                   14342:                         $changes{'approval'} = 1;
                   14343:                     }
                   14344:                 }
                   14345:             } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   14346:                 $changes{'approval'} = 1;
                   14347:             }
                   14348:         }
                   14349:         if (keys(%by_location) > 0) {
                   14350:             if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   14351:                 $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
                   14352:             }
                   14353:             if (ref($current{'approval'}) eq 'HASH') {
                   14354:                 if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                   14355:                     unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                   14356:                         $changes{'approval'} = 1;
                   14357:                     }
                   14358:                 }
                   14359:             } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   14360:                 $changes{'approval'} = 1;
                   14361:             }
                   14362:         }
                   14363:         foreach my $status ('priv','unpriv') {
                   14364:             my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
                   14365:             my @newvalues;
                   14366:             foreach my $field (@possibles) {
                   14367:                 if (grep(/^\Q$field\E$/,@fields)) {
                   14368:                     $privacyhash{$status}{$item}{$field} = 1;
                   14369:                     push(@newvalues,$field);
                   14370:                 }
                   14371:             }
                   14372:             @newvalues = sort(@newvalues);
                   14373:             if (ref($current{$status}) eq 'HASH') {
                   14374:                 if (ref($current{$status}{$item}) eq 'HASH') {
                   14375:                     my @currvalues = sort(keys(%{$current{$status}{$item}}));
                   14376:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   14377:                     if (@diffs > 0) {
                   14378:                         $changes{$status} = 1;
                   14379:                     }
                   14380:                 }
                   14381:             } else {
                   14382:                 my @stdfields;
                   14383:                 foreach my $field (@fields) {
                   14384:                     if ($field eq 'id') {
                   14385:                         next if ($status eq 'unpriv');
                   14386:                         next if (($status eq 'priv') && ($item eq 'community'));
                   14387:                     }
                   14388:                     push(@stdfields,$field);
                   14389:                 }
                   14390:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   14391:                 if (@diffs > 0) {
                   14392:                     $changes{$status} = 1;
                   14393:                 }
                   14394:             }
                   14395:         }
                   14396:     }
                   14397:     if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   14398:         my @statuses;
                   14399:         if (ref($types) eq 'ARRAY') {
                   14400:             @statuses = @{$types};
                   14401:         }
                   14402:         foreach my $type (@statuses,'default') {
                   14403:             my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
                   14404:             my @newvalues;
                   14405:             foreach my $field (sort(@possfields)) {
                   14406:                 if (grep(/^\Q$field\E$/,@fields)) {
                   14407:                     $privacyhash{'othdom'}{$type}{$field} = 1;
                   14408:                     push(@newvalues,$field);
                   14409:                 }
                   14410:             }
                   14411:             @newvalues = sort(@newvalues);
                   14412:             if (ref($current{'othdom'}) eq 'HASH') {
                   14413:                 if (ref($current{'othdom'}{$type}) eq 'HASH') {
                   14414:                     my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                   14415:                     my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                   14416:                     if (@diffs > 0) {
                   14417:                         $changes{'othdom'} = 1;
                   14418:                     }
                   14419:                 }
                   14420:             } else {
                   14421:                 my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   14422:                 my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   14423:                 if (@diffs > 0) {
                   14424:                     $changes{'othdom'} = 1;
                   14425:                 }
                   14426:             }
                   14427:         }
                   14428:     }
                   14429:     my %confighash = (
                   14430:                         privacy => \%privacyhash,
                   14431:                      );
                   14432:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   14433:     if ($putresult eq 'ok') {
                   14434:         if (keys(%changes) > 0) {
                   14435:             $resulttext = &mt('Changes made: ').'<ul>';
                   14436:             foreach my $key ('approval','othdom','priv','unpriv') {
                   14437:                 if ($changes{$key}) {
                   14438:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   14439:                     if ($key eq 'approval') {
                   14440:                         if (keys(%{$privacyhash{$key}{instdom}})) {
                   14441:                             $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                   14442:                             foreach my $item (@items) {
                   14443:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                   14444:                             }
                   14445:                             $resulttext .= '</ul></li>';
                   14446:                         }
                   14447:                         if (keys(%{$privacyhash{$key}{extdom}})) {
                   14448:                             $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                   14449:                             foreach my $item (@items) {
                   14450:                                 $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                   14451:                             }
                   14452:                             $resulttext .= '</ul></li>';
                   14453:                         }
                   14454:                     } elsif ($key eq 'othdom') {
                   14455:                         my @statuses;
                   14456:                         if (ref($types) eq 'ARRAY') {
                   14457:                             @statuses = @{$types};
                   14458:                         }
                   14459:                         if (ref($privacyhash{$key}) eq 'HASH') {
                   14460:                             foreach my $status (@statuses,'default') {
                   14461:                                 if ($status eq 'default') {
                   14462:                                     $resulttext .= '<li>'.$othertitle.': ';
                   14463:                                 } elsif (ref($usertypes) eq 'HASH') {
                   14464:                                     $resulttext .= '<li>'.$usertypes->{$status}.': ';
                   14465:                                 } else {
                   14466:                                     next;
                   14467:                                 }
                   14468:                                 if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                   14469:                                     if (keys(%{$privacyhash{$key}{$status}})) {
                   14470:                                         $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                   14471:                                     } else {
                   14472:                                         $resulttext .= &mt('none');
                   14473:                                     }
                   14474:                                 }
                   14475:                                 $resulttext .= '</li>';
                   14476:                             }
                   14477:                         }
                   14478:                     } else {
                   14479:                         foreach my $item (@items) {
                   14480:                             if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                   14481:                                 $resulttext .= '<li>'.$names{$item}.': ';
                   14482:                                 if (keys(%{$privacyhash{$key}{$item}})) {
                   14483:                                     $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                   14484:                                 } else {
                   14485:                                     $resulttext .= &mt('none');
                   14486:                                 }
                   14487:                                 $resulttext .= '</li>';
                   14488:                             }
                   14489:                         }
                   14490:                     }
                   14491:                     $resulttext .= '</ul></li>';
                   14492:                 }
                   14493:             }
                   14494:         } else {
                   14495:             $resulttext = &mt('No changes made to user information settings');
                   14496:         }
                   14497:     } else {
                   14498:         $resulttext = '<span class="LC_error">'.
                   14499:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14500:     }
                   14501:     return $resulttext;
                   14502: }
                   14503: 
1.354     raeburn  14504: sub modify_passwords {
                   14505:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355     raeburn  14506:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   14507:         $updatedefaults,$updateconf);
1.354     raeburn  14508:     my $customfn = 'resetpw.html';
                   14509:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   14510:         %current = %{$domconfig{'passwords'}};
                   14511:     }
                   14512:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14513:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   14514:     if (ref($types) eq 'ARRAY') {
                   14515:         @oktypes = @{$types};
                   14516:     }
                   14517:     push(@oktypes,'default');
                   14518: 
                   14519:     my %titles = &Apache::lonlocal::texthash (
                   14520:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   14521:         intauth_check  => 'Check bcrypt cost if authenticated',
                   14522:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   14523:         permanent      => 'Permanent e-mail address',
                   14524:         critical       => 'Critical notification address',
                   14525:         notify         => 'Notification address',
                   14526:         min            => 'Minimum password length',
                   14527:         max            => 'Maximum password length',
                   14528:         chars          => 'Required characters',
                   14529:         expire         => 'Password expiration (days)',
1.356     raeburn  14530:         numsaved       => 'Number of previous passwords to save',
1.354     raeburn  14531:         reset          => 'Resetting Forgotten Password',
                   14532:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   14533:         rules          => 'Rules for LON-CAPA Passwords',
                   14534:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   14535:         username       => 'Username',
                   14536:         email          => 'E-mail address',
                   14537:     );
                   14538: 
                   14539: #
                   14540: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   14541: #
                   14542:     my (%curr_defaults,%save_defaults);
                   14543:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   14544:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   14545:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   14546:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   14547:             } else {
                   14548:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   14549:             }
                   14550:         }
                   14551:     }
                   14552:     my %staticdefaults = (
                   14553:         'resetlink'      => 2,
                   14554:         'resetcase'      => \@oktypes,
                   14555:         'resetprelink'   => 'both',
                   14556:         'resetemail'     => ['critical','notify','permanent'],
                   14557:         'intauth_cost'   => 10,
                   14558:         'intauth_check'  => 0,
                   14559:         'intauth_switch' => 0,
                   14560:     );
1.365     raeburn  14561:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354     raeburn  14562:     foreach my $type (@oktypes) {
                   14563:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   14564:     }
                   14565:     my $linklife = $env{'form.passwords_link'};
                   14566:     $linklife =~ s/^\s+|\s+$//g;
                   14567:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   14568:         $newvalues{'resetlink'} = $linklife;
                   14569:         if ($current{'resetlink'}) {
                   14570:             if ($current{'resetlink'} ne $linklife) {
                   14571:                 $changes{'reset'} = 1;
                   14572:             }
1.368     raeburn  14573:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  14574:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   14575:                 $changes{'reset'} = 1;
                   14576:             }
                   14577:         }
                   14578:     } elsif ($current{'resetlink'}) {
                   14579:         $changes{'reset'} = 1;
                   14580:     }
                   14581:     my @casesens;
                   14582:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   14583:     foreach my $case (sort(@posscase)) {
                   14584:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   14585:             push(@casesens,$case);
                   14586:         }
                   14587:     }
                   14588:     $newvalues{'resetcase'} = \@casesens;
                   14589:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   14590:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   14591:         if (@diffs > 0) {
                   14592:             $changes{'reset'} = 1;
                   14593:         }
1.368     raeburn  14594:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  14595:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   14596:         if (@diffs > 0) {
                   14597:             $changes{'reset'} = 1;
                   14598:         }
                   14599:     }
                   14600:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   14601:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   14602:         if (exists($current{'resetprelink'})) {
                   14603:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14604:                 $changes{'reset'} = 1;
                   14605:             }
1.368     raeburn  14606:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  14607:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14608:                 $changes{'reset'} = 1;
                   14609:             }
                   14610:         }
                   14611:     } elsif ($current{'resetprelink'}) {
                   14612:         $changes{'reset'} = 1;
                   14613:     }
                   14614:     foreach my $type (@oktypes) {
                   14615:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   14616:         my @postlink;
                   14617:         foreach my $item (sort(@possplink)) {
                   14618:             if ($item =~ /^(email|username)$/) {
                   14619:                 push(@postlink,$item);
                   14620:             }
                   14621:         }
                   14622:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   14623:         unless ($changes{'reset'}) {
                   14624:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   14625:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14626:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   14627:                     if (@diffs > 0) {
                   14628:                         $changes{'reset'} = 1;
                   14629:                     }
                   14630:                 } else {
                   14631:                     $changes{'reset'} = 1;
                   14632:                 }
1.368     raeburn  14633:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  14634:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   14635:                 if (@diffs > 0) {
                   14636:                     $changes{'reset'} = 1;
                   14637:                 }
                   14638:             }
                   14639:         }
                   14640:     }
                   14641:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   14642:     my @resetemail;
                   14643:     foreach my $item (sort(@possemailsrc)) {
                   14644:         if ($item =~ /^(permanent|critical|notify)$/) {
                   14645:             push(@resetemail,$item);
                   14646:         }
                   14647:     }
                   14648:     $newvalues{'resetemail'} = \@resetemail;
                   14649:     unless ($changes{'reset'}) {
                   14650:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   14651:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   14652:             if (@diffs > 0) {
                   14653:                 $changes{'reset'} = 1;
                   14654:             }
1.368     raeburn  14655:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354     raeburn  14656:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   14657:             if (@diffs > 0) {
                   14658:                 $changes{'reset'} = 1;
                   14659:             }
                   14660:         }
                   14661:     }
                   14662:     if ($env{'form.passwords_stdtext'} == 0) {
                   14663:         $newvalues{'resetremove'} = 1;
                   14664:         unless ($current{'resetremove'}) {
                   14665:             $changes{'reset'} = 1;
                   14666:         }
                   14667:     } elsif ($current{'resetremove'}) {
                   14668:         $changes{'reset'} = 1;
                   14669:     }
                   14670:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   14671:         my $servadm = $r->dir_config('lonAdmEMail');
                   14672:         my ($configuserok,$author_ok,$switchserver) =
                   14673:             &config_check($dom,$confname,$servadm);
                   14674:         my $error;
                   14675:         if ($configuserok eq 'ok') {
                   14676:             if ($switchserver) {
                   14677:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   14678:             } else {
                   14679:                 if ($author_ok eq 'ok') {
                   14680:                     my ($result,$customurl) =
                   14681:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   14682:                                      $confname,'customtext/resetpw','','',$customfn);
                   14683:                     if ($result eq 'ok') {
                   14684:                         $newvalues{'resetcustom'} = $customurl;
                   14685:                         $changes{'reset'} = 1;
                   14686:                     } else {
                   14687:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   14688:                     }
                   14689:                 } else {
                   14690:                     $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);
                   14691:                 }
                   14692:             }
                   14693:         } else {
                   14694:             $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);
                   14695:         }
                   14696:         if ($error) {
                   14697:             &Apache::lonnet::logthis($error);
                   14698:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14699:         }
                   14700:     } elsif ($current{'resetcustom'}) {
                   14701:         if ($env{'form.passwords_custom_del'}) {
                   14702:             $changes{'reset'} = 1;
                   14703:         } else {
                   14704:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   14705:         }
                   14706:     }
                   14707:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   14708:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   14709:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   14710:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   14711:             $changes{'intauth'} = 1;
                   14712:         }
                   14713:     } else {
                   14714:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   14715:     }
                   14716:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   14717:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   14718:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   14719:             $changes{'intauth'} = 1;
                   14720:         }
                   14721:     } else {
                   14722:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14723:     }
                   14724:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   14725:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   14726:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   14727:             $changes{'intauth'} = 1;
                   14728:         }
                   14729:     } else {
                   14730:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14731:     }
                   14732:     foreach my $item ('cost','check','switch') {
                   14733:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   14734:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   14735:             $updatedefaults = 1;
                   14736:         }
                   14737:     }
1.356     raeburn  14738:     foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  14739:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.356     raeburn  14740:         my $ruleok;
                   14741:         if ($rule eq 'expire') {
1.365     raeburn  14742:             if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   14743:                 ($env{'form.passwords_'.$rule} ne '0')) {
1.359     raeburn  14744:                 $ruleok = 1;
1.356     raeburn  14745:             }
1.365     raeburn  14746:         } elsif ($rule eq 'min') {
                   14747:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   14748:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   14749:                     $ruleok = 1;
                   14750:                 }
                   14751:             }
                   14752:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   14753:                  ($env{'form.passwords_'.$rule} ne '0')) {
1.356     raeburn  14754:             $ruleok = 1;
                   14755:         }
                   14756:         if ($ruleok) {
1.354     raeburn  14757:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   14758:             if (exists($current{$rule})) {
                   14759:                 if ($newvalues{$rule} ne $current{$rule}) {
                   14760:                     $changes{'rules'} = 1;
                   14761:                 }
                   14762:             } elsif ($rule eq 'min') {
                   14763:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   14764:                     $changes{'rules'} = 1;
                   14765:                 }
                   14766:             }
                   14767:         } elsif (exists($current{$rule})) {
                   14768:             $changes{'rules'} = 1;
                   14769:         }
                   14770:     }
                   14771:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   14772:     my @chars;
                   14773:     foreach my $item (sort(@posschars)) {
                   14774:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   14775:             push(@chars,$item);
                   14776:         }
                   14777:     }
                   14778:     $newvalues{'chars'} = \@chars;
                   14779:     unless ($changes{'rules'}) {
                   14780:         if (ref($current{'chars'}) eq 'ARRAY') {
                   14781:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   14782:             if (@diffs > 0) {
                   14783:                 $changes{'rules'} = 1;
                   14784:             }
                   14785:         } else {
                   14786:             if (@chars > 0) {
                   14787:                 $changes{'rules'} = 1;
                   14788:             }
                   14789:         }
                   14790:     }
1.359     raeburn  14791:     my %crsownerchg = (
                   14792:                         by => [],
                   14793:                         for => [],
                   14794:                       );
                   14795:     foreach my $item ('by','for') {
                   14796:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   14797:         foreach my $type (sort(@posstypes)) {
                   14798:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   14799:                 push(@{$crsownerchg{$item}},$type);
                   14800:             }
                   14801:         }
                   14802:     }
                   14803:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   14804:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   14805:         foreach my $item ('by','for') {
                   14806:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   14807:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   14808:                 if (@diffs > 0) {
                   14809:                     $changes{'crsownerchg'} = 1;
                   14810:                     last;
                   14811:                 }
                   14812:             }
                   14813:         }
1.368     raeburn  14814:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359     raeburn  14815:         foreach my $item ('by','for') {
                   14816:             if (@{$crsownerchg{$item}} > 0) {
                   14817:                 $changes{'crsownerchg'} = 1;
                   14818:                 last;
                   14819:             }
1.354     raeburn  14820:         }
                   14821:     }
                   14822: 
                   14823:     my %confighash = (
                   14824:                         defaults  => \%save_defaults,
                   14825:                         passwords => \%newvalues,
                   14826:                      );
                   14827:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   14828: 
                   14829:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   14830:     if ($putresult eq 'ok') {
                   14831:         if (keys(%changes) > 0) {
                   14832:             $resulttext = &mt('Changes made: ').'<ul>';
                   14833:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   14834:                 if ($changes{$key}) {
1.355     raeburn  14835:                     unless ($key eq 'intauth') {
                   14836:                         $updateconf = 1;
                   14837:                     }
1.354     raeburn  14838:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   14839:                     if ($key eq 'reset') {
                   14840:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   14841:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   14842:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   14843:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369   ! raeburn  14844:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
        !          14845:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
        !          14846:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
        !          14847:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
        !          14848:                             }
1.354     raeburn  14849:                         } else {
                   14850:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   14851:                         }
                   14852:                         if ($confighash{'passwords'}{'resetlink'}) {
                   14853:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   14854:                         } else {
                   14855:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   14856:                                                   &mt('Will default to 2 hours').'</li>';
                   14857:                         }
                   14858:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   14859:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   14860:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   14861:                             } else {
                   14862:                                 my $casesens;
                   14863:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   14864:                                     if ($type eq 'default') {
                   14865:                                         $casesens .= $othertitle.', ';
                   14866:                                     } elsif ($usertypes->{$type} ne '') {
                   14867:                                         $casesens .= $usertypes->{$type}.', ';
                   14868:                                     }
                   14869:                                 }
                   14870:                                 $casesens =~ s/\Q, \E$//;
                   14871:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   14872:                             }
                   14873:                         } else {
                   14874:                             $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>';
                   14875:                         }
                   14876:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   14877:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   14878:                         } else {
                   14879:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   14880:                         }
                   14881:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   14882:                             my $output;
                   14883:                             if (ref($types) eq 'ARRAY') {
                   14884:                                 foreach my $type (@{$types}) {
                   14885:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14886:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   14887:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   14888:                                         } else {
                   14889:                                             $output .= $usertypes->{$type}.' -- '.
                   14890:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   14891:                                         }
                   14892:                                     }
                   14893:                                 }
                   14894:                             }
                   14895:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   14896:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   14897:                                     $output .= $othertitle.' -- '.&mt('none');
                   14898:                                 } else {
                   14899:                                     $output .= $othertitle.' -- '.
                   14900:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   14901:                                 }
                   14902:                             }
                   14903:                             if ($output) {
                   14904:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   14905:                             } else {
                   14906:                                 $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>';
                   14907:                             }
                   14908:                         } else {
                   14909:                             $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>';
                   14910:                         }
                   14911:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   14912:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   14913:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   14914:                             } else {
                   14915:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   14916:                             }
                   14917:                         } else {
                   14918:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   14919:                         }
                   14920:                         if ($confighash{'passwords'}{'resetremove'}) {
                   14921:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   14922:                         } else {
                   14923:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   14924:                         }
                   14925:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   14926:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369   ! raeburn  14927:                                                                             &mt('custom text'),600,500,undef,undef,
        !          14928:                                                                             undef,undef,'background-color:#ffffff');
        !          14929:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354     raeburn  14930:                         } else {
                   14931:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   14932:                         }
                   14933:                     } elsif ($key eq 'intauth') {
                   14934:                         foreach my $item ('cost','switch','check') {
                   14935:                             my $value = $save_defaults{$key.'_'.$item};
                   14936:                             if ($item eq 'switch') {
                   14937:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14938:                                                      0 => 'No',
                   14939:                                                      1 => 'Yes',
                   14940:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   14941:                                                  );
                   14942:                                 if ($value =~ /^(0|1|2)$/) {
                   14943:                                     $value = $optiondesc{$value};
                   14944:                                 } else {
                   14945:                                     $value = &mt('none -- defaults to No');
                   14946:                                 }
                   14947:                             } elsif ($item eq 'check') {
                   14948:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14949:                                                      0 => 'No',
                   14950:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   14951:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   14952:                                                  );
                   14953:                                 if ($value =~ /^(0|1|2)$/) {
                   14954:                                     $value = $optiondesc{$value};
                   14955:                                 } else {
                   14956:                                     $value = &mt('none -- defaults to No');
                   14957:                                 }
                   14958:                             }
                   14959:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   14960:                         }
                   14961:                     } elsif ($key eq 'rules') {
1.356     raeburn  14962:                         foreach my $rule ('min','max','expire','numsaved') {
1.354     raeburn  14963:                             if ($confighash{'passwords'}{$rule} eq '') {
                   14964:                                 if ($rule eq 'min') {
1.356     raeburn  14965:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365     raeburn  14966:                                                    ' '.&mt('Default of [_1] will be used',
                   14967:                                                            $Apache::lonnet::passwdmin).'</li>';
1.356     raeburn  14968:                                 } else {
                   14969:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354     raeburn  14970:                                 }
                   14971:                             } else {
                   14972:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   14973:                             }
                   14974:                         }
                   14975:                     } elsif ($key eq 'crsownerchg') {
1.359     raeburn  14976:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   14977:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   14978:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   14979:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   14980:                             } else {
                   14981:                                 my %crsownerstr;
                   14982:                                 foreach my $item ('by','for') {
                   14983:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   14984:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   14985:                                             if ($type eq 'default') {
                   14986:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   14987:                                             } elsif ($usertypes->{$type} ne '') {
                   14988:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   14989:                                             }
                   14990:                                         }
                   14991:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   14992:                                     }
                   14993:                                 }
                   14994:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   14995:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   14996:                             }
1.354     raeburn  14997:                         } else {
1.359     raeburn  14998:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354     raeburn  14999:                         }
                   15000:                     }
                   15001:                     $resulttext .= '</ul></li>';
                   15002:                 }
                   15003:             }
                   15004:             $resulttext .= '</ul>';
                   15005:         } else {
                   15006:             $resulttext = &mt('No changes made to password settings');
                   15007:         }
1.355     raeburn  15008:         my $cachetime = 24*60*60;
1.354     raeburn  15009:         if ($updatedefaults) {
                   15010:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15011:             if (ref($lastactref) eq 'HASH') {
                   15012:                 $lastactref->{'domdefaults'} = 1;
                   15013:             }
                   15014:         }
1.355     raeburn  15015:         if ($updateconf) {
                   15016:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   15017:             if (ref($lastactref) eq 'HASH') {
                   15018:                 $lastactref->{'passwdconf'} = 1;
                   15019:             }
                   15020:         }
1.354     raeburn  15021:     } else {
                   15022:         $resulttext = '<span class="LC_error">'.
                   15023:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15024:     }
                   15025:     if ($errors) {
                   15026:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   15027:                        $errors.'</ul></p>';
                   15028:     }
                   15029:     return $resulttext;
                   15030: }
                   15031: 
1.28      raeburn  15032: sub modify_usercreation {
1.27      raeburn  15033:     my ($dom,%domconfig) = @_;
1.224     raeburn  15034:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  15035:     my $warningmsg;
1.27      raeburn  15036:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   15037:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  15038:             if ($key eq 'cancreate') {
                   15039:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   15040:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303     raeburn  15041:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
                   15042:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15043:                         } else {
1.224     raeburn  15044:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15045:                         }
                   15046:                     }
                   15047:                 }
                   15048:             } elsif ($key eq 'email_rule') {
                   15049:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   15050:             } else {
                   15051:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   15052:             }
1.27      raeburn  15053:         }
                   15054:     }
                   15055:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  15056:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  15057:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  15058:     foreach my $item(@contexts) {
1.224     raeburn  15059:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  15060:     }
1.34      raeburn  15061:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15062:         foreach my $item (@contexts) {
1.224     raeburn  15063:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   15064:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  15065:             }
1.27      raeburn  15066:         }
1.34      raeburn  15067:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   15068:         foreach my $item (@contexts) {
1.43      raeburn  15069:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  15070:                 if ($cancreate{$item} ne 'any') {
                   15071:                     push(@{$changes{'cancreate'}},$item);
                   15072:                 }
                   15073:             } else {
                   15074:                 if ($cancreate{$item} ne 'none') {
                   15075:                     push(@{$changes{'cancreate'}},$item);
                   15076:                 }
1.27      raeburn  15077:             }
                   15078:         }
                   15079:     } else {
1.43      raeburn  15080:         foreach my $item (@contexts)  {
1.34      raeburn  15081:             push(@{$changes{'cancreate'}},$item);
                   15082:         }
1.27      raeburn  15083:     }
1.34      raeburn  15084: 
1.27      raeburn  15085:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   15086:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   15087:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   15088:                 push(@{$changes{'username_rule'}},$type);
                   15089:             }
                   15090:         }
                   15091:         foreach my $type (@username_rule) {
                   15092:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   15093:                 push(@{$changes{'username_rule'}},$type);
                   15094:             }
                   15095:         }
                   15096:     } else {
                   15097:         push(@{$changes{'username_rule'}},@username_rule);
                   15098:     }
                   15099: 
1.32      raeburn  15100:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   15101:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   15102:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   15103:                 push(@{$changes{'id_rule'}},$type);
                   15104:             }
                   15105:         }
                   15106:         foreach my $type (@id_rule) {
                   15107:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   15108:                 push(@{$changes{'id_rule'}},$type);
                   15109:             }
                   15110:         }
                   15111:     } else {
                   15112:         push(@{$changes{'id_rule'}},@id_rule);
                   15113:     }
                   15114: 
1.43      raeburn  15115:     my @authen_contexts = ('author','course','domain');
1.325     raeburn  15116:     my @authtypes = ('int','krb4','krb5','loc','lti');
1.28      raeburn  15117:     my %authhash;
1.43      raeburn  15118:     foreach my $item (@authen_contexts) {
1.28      raeburn  15119:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   15120:         foreach my $auth (@authtypes) {
                   15121:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   15122:                 $authhash{$item}{$auth} = 1;
                   15123:             } else {
                   15124:                 $authhash{$item}{$auth} = 0;
                   15125:             }
                   15126:         }
                   15127:     }
                   15128:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  15129:         foreach my $item (@authen_contexts) {
1.28      raeburn  15130:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   15131:                 foreach my $auth (@authtypes) {
                   15132:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   15133:                         push(@{$changes{'authtypes'}},$item);
                   15134:                         last;
                   15135:                     }
                   15136:                 }
                   15137:             }
                   15138:         }
                   15139:     } else {
1.43      raeburn  15140:         foreach my $item (@authen_contexts) {
1.28      raeburn  15141:             push(@{$changes{'authtypes'}},$item);
                   15142:         }
                   15143:     }
                   15144: 
1.224     raeburn  15145:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   15146:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   15147:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   15148:     $save_usercreate{'id_rule'} = \@id_rule;
                   15149:     $save_usercreate{'username_rule'} = \@username_rule,
                   15150:     $save_usercreate{'authtypes'} = \%authhash;
                   15151: 
1.27      raeburn  15152:     my %usercreation_hash =  (
1.224     raeburn  15153:         usercreation     => \%save_usercreate,
                   15154:     );
1.27      raeburn  15155: 
                   15156:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   15157:                                              $dom);
1.50      raeburn  15158: 
1.224     raeburn  15159:     if ($putresult eq 'ok') {
                   15160:         if (keys(%changes) > 0) {
                   15161:             $resulttext = &mt('Changes made:').'<ul>';
                   15162:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   15163:                 my %lt = &usercreation_types();
                   15164:                 foreach my $type (@{$changes{'cancreate'}}) {
                   15165:                     my $chgtext = $lt{$type}.', ';
                   15166:                     if ($cancreate{$type} eq 'none') {
                   15167:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   15168:                     } elsif ($cancreate{$type} eq 'any') {
                   15169:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   15170:                     } elsif ($cancreate{$type} eq 'official') {
                   15171:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   15172:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   15173:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   15174:                     }
                   15175:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   15176:                 }
                   15177:             }
                   15178:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   15179:                 my ($rules,$ruleorder) = 
                   15180:                     &Apache::lonnet::inst_userrules($dom,'username');
                   15181:                 my $chgtext = '<ul>';
                   15182:                 foreach my $type (@username_rule) {
                   15183:                     if (ref($rules->{$type}) eq 'HASH') {
                   15184:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   15185:                     }
                   15186:                 }
                   15187:                 $chgtext .= '</ul>';
                   15188:                 if (@username_rule > 0) {
                   15189:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   15190:                 } else {
                   15191:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   15192:                 }
                   15193:             }
                   15194:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   15195:                 my ($idrules,$idruleorder) = 
                   15196:                     &Apache::lonnet::inst_userrules($dom,'id');
                   15197:                 my $chgtext = '<ul>';
                   15198:                 foreach my $type (@id_rule) {
                   15199:                     if (ref($idrules->{$type}) eq 'HASH') {
                   15200:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   15201:                     }
                   15202:                 }
                   15203:                 $chgtext .= '</ul>';
                   15204:                 if (@id_rule > 0) {
                   15205:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   15206:                 } else {
                   15207:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   15208:                 }
                   15209:             }
                   15210:             my %authname = &authtype_names();
                   15211:             my %context_title = &context_names();
                   15212:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   15213:                 my $chgtext = '<ul>';
                   15214:                 foreach my $type (@{$changes{'authtypes'}}) {
                   15215:                     my @allowed;
                   15216:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   15217:                     foreach my $auth (@authtypes) {
                   15218:                         if ($authhash{$type}{$auth}) {
                   15219:                             push(@allowed,$authname{$auth});
                   15220:                         }
                   15221:                     }
                   15222:                     if (@allowed > 0) {
                   15223:                         $chgtext .= join(', ',@allowed).'</li>';
                   15224:                     } else {
                   15225:                         $chgtext .= &mt('none').'</li>';
                   15226:                     }
                   15227:                 }
                   15228:                 $chgtext .= '</ul>';
                   15229:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   15230:                 $resulttext .= '</li>';
                   15231:             }
                   15232:             $resulttext .= '</ul>';
                   15233:         } else {
                   15234:             $resulttext = &mt('No changes made to user creation settings');
                   15235:         }
                   15236:     } else {
                   15237:         $resulttext = '<span class="LC_error">'.
                   15238:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15239:     }
                   15240:     if ($warningmsg ne '') {
                   15241:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   15242:     }
                   15243:     return $resulttext;
                   15244: }
                   15245: 
                   15246: sub modify_selfcreation {
1.305     raeburn  15247:     my ($dom,$lastactref,%domconfig) = @_;
                   15248:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   15249:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   15250:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303     raeburn  15251:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   15252:     if (ref($typesref) eq 'ARRAY') {
                   15253:         @types = @{$typesref};
                   15254:     }
                   15255:     if (ref($usertypesref) eq 'HASH') {
                   15256:         %usertypes = %{$usertypesref};
1.228     raeburn  15257:     }
1.303     raeburn  15258:     $usertypes{'default'} = $othertitle;
1.224     raeburn  15259: #
                   15260: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   15261: #
                   15262:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   15263:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   15264:             if ($key eq 'cancreate') {
                   15265:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   15266:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   15267:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303     raeburn  15268:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   15269:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   15270:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   15271:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305     raeburn  15272:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224     raeburn  15273:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15274:                         } else {
                   15275:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15276:                         }
                   15277:                     }
                   15278:                 }
                   15279:             } elsif ($key eq 'email_rule') {
                   15280:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   15281:             } else {
                   15282:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   15283:             }
                   15284:         }
                   15285:     }
                   15286: #
                   15287: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   15288: #
                   15289:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   15290:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   15291:             if ($key eq 'selfcreate') {
                   15292:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15293:             } else {
                   15294:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15295:             }
                   15296:         }
                   15297:     }
1.305     raeburn  15298: #
                   15299: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   15300: #
                   15301:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   15302:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   15303:             if ($key eq 'inststatusguest') {
                   15304:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15305:             } else {
                   15306:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15307:             }
                   15308:         }
                   15309:     }
1.224     raeburn  15310: 
                   15311:     my @contexts = ('selfcreate');
                   15312:     @{$cancreate{'selfcreate'}} = ();
                   15313:     %{$cancreate{'emailusername'}} = ();
1.305     raeburn  15314:     if (@types) {
                   15315:         @{$cancreate{'statustocreate'}} = ();
                   15316:     }
1.236     raeburn  15317:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  15318:     %{$cancreate{'shibenv'}} = ();
1.303     raeburn  15319:     %{$cancreate{'emailverified'}} = ();
1.305     raeburn  15320:     %{$cancreate{'emailoptions'}} = ();
1.303     raeburn  15321:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  15322:     my %selfcreatetypes = (
                   15323:                              sso   => 'users authenticated by institutional single sign on',
                   15324:                              login => 'users authenticated by institutional log-in',
1.303     raeburn  15325:                              email => 'users verified by e-mail',
1.50      raeburn  15326:                           );
1.224     raeburn  15327: #
                   15328: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   15329: # is permitted.
                   15330: #
1.305     raeburn  15331:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236     raeburn  15332: 
1.305     raeburn  15333:     my (@statuses,%email_rule);
1.228     raeburn  15334:     foreach my $item ('login','sso','email') {
1.224     raeburn  15335:         if ($item eq 'email') {
1.236     raeburn  15336:             if ($env{'form.cancreate_email'}) {
1.305     raeburn  15337:                 if (@types) {
                   15338:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   15339:                     foreach my $status (@poss_statuses) {
                   15340:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   15341:                             push(@statuses,$status);
                   15342:                         }
                   15343:                     }
                   15344:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   15345:                 } else {
                   15346:                     push(@statuses,'default');
                   15347:                 }
                   15348:                 if (@statuses) {
                   15349:                     my %curr_rule;
                   15350:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   15351:                         foreach my $type (@statuses) {
                   15352:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303     raeburn  15353:                         }
1.305     raeburn  15354:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   15355:                         foreach my $type (@statuses) {
                   15356:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   15357:                         }
                   15358:                     }
                   15359:                     push(@{$cancreate{'selfcreate'}},'email');
                   15360:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   15361:                     my %curremaildom;
                   15362:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   15363:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   15364:                     }
                   15365:                     foreach my $type (@statuses) {
                   15366:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   15367:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   15368:                         }
                   15369:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   15370:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   15371:                         }
                   15372:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   15373: #
                   15374: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   15375: #
                   15376:                             my $chosen = $1;
                   15377:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   15378:                                 my $emaildom;
                   15379:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   15380:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type}; 
                   15381:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   15382:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   15383:                                         if (exists($curremaildom{$type}{$chosen})) {
                   15384:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   15385:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   15386:                                             }
                   15387:                                         } elsif ($emaildom ne '') {
                   15388:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   15389:                                         }
                   15390:                                     } elsif ($emaildom ne '') {
                   15391:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   15392:                                     } 
                   15393:                                 }
                   15394:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15395:                             } elsif ($chosen eq 'custom') {
                   15396:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   15397:                                 $email_rule{$type} = [];
                   15398:                                 if (ref($emailrules) eq 'HASH') {
                   15399:                                     foreach my $rule (@possemail_rules) {
                   15400:                                         if (exists($emailrules->{$rule})) {
                   15401:                                             push(@{$email_rule{$type}},$rule);
                   15402:                                         }
                   15403:                                     }
                   15404:                                 }
                   15405:                                 if (@{$email_rule{$type}}) {
                   15406:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   15407:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   15408:                                         if (@{$curr_rule{$type}} > 0) {
                   15409:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   15410:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   15411:                                                     push(@{$changes{'email_rule'}},$type);
                   15412:                                                 }
                   15413:                                             }
                   15414:                                         }
                   15415:                                         foreach my $type (@{$email_rule{$type}}) {
                   15416:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   15417:                                                 push(@{$changes{'email_rule'}},$type);
                   15418:                                             }
                   15419:                                         }
                   15420:                                     } else {
                   15421:                                         push(@{$changes{'email_rule'}},$type);
                   15422:                                     }
                   15423:                                 }
                   15424:                             } else {
                   15425:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15426:                             }
                   15427:                         }
                   15428:                     }
                   15429:                     if (@types) {
                   15430:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15431:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   15432:                             if (@changed) {
                   15433:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   15434:                             }
                   15435:                         } else {
                   15436:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15437:                         }
                   15438:                     }
                   15439:                 } else {
                   15440:                     delete($env{'form.cancreate_email'});
                   15441:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15442:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15443:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15444:                         }
                   15445:                     }
                   15446:                 }
                   15447:             } else {
                   15448:                 $save_inststatus{'inststatusguest'} = [];
                   15449:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15450:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15451:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.236     raeburn  15452:                     }
                   15453:                 }
1.224     raeburn  15454:             }
                   15455:         } else {
                   15456:             if ($env{'form.cancreate_'.$item}) {
                   15457:                 push(@{$cancreate{'selfcreate'}},$item);
                   15458:             }
                   15459:         }
                   15460:     }
1.305     raeburn  15461:     my (%userinfo,%savecaptcha);
1.224     raeburn  15462:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   15463: #
1.228     raeburn  15464: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   15465: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  15466: #
1.236     raeburn  15467: 
1.244     raeburn  15468:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  15469:         push(@contexts,'emailusername');
1.305     raeburn  15470:         if (@statuses) {
                   15471:             foreach my $type (@statuses) {
1.228     raeburn  15472:                 if (ref($infofields) eq 'ARRAY') {
                   15473:                     foreach my $field (@{$infofields}) {
                   15474:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   15475:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   15476:                         }
                   15477:                     }
1.224     raeburn  15478:                 }
                   15479:             }
                   15480:         }
                   15481: #
                   15482: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303     raeburn  15483: # queued requests for self-creation of account verified by e-mail.
1.224     raeburn  15484: #
                   15485: 
                   15486:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   15487:         @approvalnotify = sort(@approvalnotify);
                   15488:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   15489:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15490:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   15491:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   15492:                     push(@{$changes{'cancreate'}},'notify');
                   15493:                 }
                   15494:             } else {
                   15495:                 if ($cancreate{'notify'}{'approval'}) {
                   15496:                     push(@{$changes{'cancreate'}},'notify');
                   15497:                 }
                   15498:             }
                   15499:         } elsif ($cancreate{'notify'}{'approval'}) {
                   15500:             push(@{$changes{'cancreate'}},'notify');
                   15501:         }
                   15502: 
                   15503:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   15504:     }
                   15505: #  
1.236     raeburn  15506: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  15507: # institutional log-in.
                   15508: #
                   15509:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   15510:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   15511:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   15512:             $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.').' '.
                   15513:                           &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.');
                   15514:         }
                   15515:     }
                   15516:     my @fields = ('lastname','firstname','middlename','generation',
                   15517:                   'permanentemail','id');
1.240     raeburn  15518:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  15519:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   15520: #
                   15521: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   15522: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   15523: # may self-create accounts 
                   15524: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   15525: # which the user may supply, if institutional data is unavailable.
                   15526: #
                   15527:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303     raeburn  15528:         if (@types) {
1.305     raeburn  15529:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   15530:             push(@contexts,'statustocreate');
1.303     raeburn  15531:             foreach my $type (@types) {
1.224     raeburn  15532:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   15533:                 foreach my $field (@fields) {
                   15534:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   15535:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   15536:                     } else {
                   15537:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   15538:                     }
                   15539:                 }
                   15540:             }
                   15541:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303     raeburn  15542:                 foreach my $type (@types) {
1.224     raeburn  15543:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   15544:                         foreach my $field (@fields) {
                   15545:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   15546:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   15547:                                 push(@{$changes{'selfcreate'}},$type);
                   15548:                                 last;
                   15549:                             }
                   15550:                         }
                   15551:                     }
                   15552:                 }
                   15553:             } else {
1.303     raeburn  15554:                 foreach my $type (@types) {
1.224     raeburn  15555:                     push(@{$changes{'selfcreate'}},$type);
                   15556:                 }
                   15557:             }
                   15558:         }
1.240     raeburn  15559:         foreach my $field (@shibfields) {
                   15560:             if ($env{'form.shibenv_'.$field} ne '') {
                   15561:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   15562:             }
                   15563:         }
                   15564:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15565:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   15566:                 foreach my $field (@shibfields) {
                   15567:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   15568:                         push(@{$changes{'cancreate'}},'shibenv');
                   15569:                     }
                   15570:                 }
                   15571:             } else {
                   15572:                 foreach my $field (@shibfields) {
                   15573:                     if ($env{'form.shibenv_'.$field}) {
                   15574:                         push(@{$changes{'cancreate'}},'shibenv');
                   15575:                         last;
                   15576:                     }
                   15577:                 }
                   15578:             }
                   15579:         }
1.224     raeburn  15580:     }
                   15581:     foreach my $item (@contexts) {
                   15582:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   15583:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   15584:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   15585:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   15586:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15587:                             push(@{$changes{'cancreate'}},$item);
                   15588:                         }
                   15589:                     }
                   15590:                 }
                   15591:             }
                   15592:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15593:                 foreach my $type (@{$cancreate{$item}}) {
                   15594:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   15595:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15596:                             push(@{$changes{'cancreate'}},$item);
                   15597:                         }
                   15598:                     }
                   15599:                 }
                   15600:             }
                   15601:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   15602:             if (ref($cancreate{$item}) eq 'HASH') {
1.305     raeburn  15603:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   15604:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15605:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   15606:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  15607:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15608:                                     push(@{$changes{'cancreate'}},$item);
                   15609:                                 }
                   15610:                             }
                   15611:                         }
1.305     raeburn  15612:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15613:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  15614:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15615:                                 push(@{$changes{'cancreate'}},$item);
                   15616:                             }
1.224     raeburn  15617:                         }
                   15618:                     }
                   15619:                 }
1.305     raeburn  15620:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15621:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15622:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15623:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15624:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228     raeburn  15625:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15626:                                         push(@{$changes{'cancreate'}},$item);
                   15627:                                     }
                   15628:                                 }
                   15629:                             } else {
                   15630:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15631:                                     push(@{$changes{'cancreate'}},$item);
                   15632:                                 }
                   15633:                             }
                   15634:                         }
1.305     raeburn  15635:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15636:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228     raeburn  15637:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15638:                                 push(@{$changes{'cancreate'}},$item);
                   15639:                             }
1.224     raeburn  15640:                         }
                   15641:                     }
                   15642:                 }
                   15643:             }
                   15644:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   15645:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15646:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   15647:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15648:                         push(@{$changes{'cancreate'}},$item);
                   15649:                     }
                   15650:                 }
1.305     raeburn  15651:             }
                   15652:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15653:             if (ref($cancreate{$item}) eq 'HASH') {
                   15654:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15655:                     push(@{$changes{'cancreate'}},$item);
1.224     raeburn  15656:                 }
                   15657:             }
                   15658:         } elsif ($item eq 'emailusername') {
1.228     raeburn  15659:             if (ref($cancreate{$item}) eq 'HASH') {
                   15660:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15661:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15662:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15663:                             if ($cancreate{$item}{$type}{$field}) {
                   15664:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15665:                                     push(@{$changes{'cancreate'}},$item);
                   15666:                                 }
                   15667:                                 last;
                   15668:                             }
                   15669:                         }
                   15670:                     }
                   15671:                 }
1.224     raeburn  15672:             }
                   15673:         }
                   15674:     }
                   15675: #
                   15676: # Populate %save_usercreate hash with updates to self-creation configuration.
                   15677: #
                   15678:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   15679:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  15680:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  15681:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   15682:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   15683:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   15684:     }
1.236     raeburn  15685:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   15686:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   15687:     }
1.303     raeburn  15688:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   15689:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   15690:     }
1.305     raeburn  15691:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   15692:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   15693:     }
1.303     raeburn  15694:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   15695:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   15696:     }
1.224     raeburn  15697:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15698:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   15699:     }
1.240     raeburn  15700:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   15701:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   15702:     }
1.224     raeburn  15703:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305     raeburn  15704:     $save_usercreate{'email_rule'} = \%email_rule;
1.224     raeburn  15705: 
                   15706:     my %userconfig_hash = (
                   15707:             usercreation     => \%save_usercreate,
                   15708:             usermodification => \%save_usermodify,
1.305     raeburn  15709:             inststatus       => \%save_inststatus,
1.224     raeburn  15710:     );
1.305     raeburn  15711: 
1.224     raeburn  15712:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   15713:                                              $dom);
                   15714: #
1.305     raeburn  15715: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224     raeburn  15716: #
1.27      raeburn  15717:     if ($putresult eq 'ok') {
                   15718:         if (keys(%changes) > 0) {
                   15719:             $resulttext = &mt('Changes made:').'<ul>';
                   15720:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  15721:                 my %lt = &selfcreation_types();
1.34      raeburn  15722:                 foreach my $type (@{$changes{'cancreate'}}) {
1.303     raeburn  15723:                     my $chgtext = '';
1.45      raeburn  15724:                     if ($type eq 'selfcreate') {
1.50      raeburn  15725:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  15726:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  15727:                         } else {
1.224     raeburn  15728:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   15729:                                         '<ul>';
1.50      raeburn  15730:                             foreach my $case (@{$cancreate{$type}}) {
                   15731:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   15732:                             }
                   15733:                             $chgtext .= '</ul>';
1.100     raeburn  15734:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   15735:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   15736:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15737:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.303     raeburn  15738:                                             $chgtext .= '<span class="LC_warning">'.
                   15739:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   15740:                                                         '</span><br />';
                   15741:                                         }
                   15742:                                     }
                   15743:                                 }
                   15744:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
1.305     raeburn  15745:                                     if (!@statuses) {
                   15746:                                         $chgtext .= '<span class="LC_warning">'.
                   15747:                                                     &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.").
                   15748:                                                     '</span><br />';
1.303     raeburn  15749: 
1.100     raeburn  15750:                                     }
                   15751:                                 }
                   15752:                             }
1.43      raeburn  15753:                         }
1.240     raeburn  15754:                     } elsif ($type eq 'shibenv') {
                   15755:                         if (keys(%{$cancreate{$type}}) == 0) {
1.303     raeburn  15756:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.240     raeburn  15757:                         } else {
                   15758:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   15759:                                         '<ul>';
                   15760:                             foreach my $field (@shibfields) {
                   15761:                                 next if ($cancreate{$type}{$field} eq '');
                   15762:                                 if ($field eq 'inststatus') {
                   15763:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   15764:                                 } else {
                   15765:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   15766:                                 }
                   15767:                             }
                   15768:                             $chgtext .= '</ul>';
1.303     raeburn  15769:                         }
1.93      raeburn  15770:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  15771:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   15772:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   15773:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   15774:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  15775:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  15776:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  15777:                                         $chgtext .= '<br />'.
                   15778:                                                     '<span class="LC_warning">'.
                   15779:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   15780:                                                     '</span>';
                   15781:                                     }
1.303     raeburn  15782:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  15783:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  15784:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   15785:                                     } else {
                   15786:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   15787:                                     }
                   15788:                                     $chgtext .= '<ul>';
                   15789:                                     foreach my $case (@{$cancreate{$type}}) {
                   15790:                                         if ($case eq 'default') {
                   15791:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   15792:                                         } else {
1.303     raeburn  15793:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  15794:                                         }
                   15795:                                     }
1.100     raeburn  15796:                                     $chgtext .= '</ul>';
                   15797:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303     raeburn  15798:                                         $chgtext .= '<span class="LC_warning">'.
1.224     raeburn  15799:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   15800:                                                     '</span>';
1.100     raeburn  15801:                                     }
                   15802:                                 }
                   15803:                             } else {
                   15804:                                 if (@{$cancreate{$type}} == 0) {
                   15805:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   15806:                                 } else {
                   15807:                                     $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  15808:                                 }
                   15809:                             }
1.303     raeburn  15810:                             $chgtext .= '<br />';
1.93      raeburn  15811:                         }
1.236     raeburn  15812:                     } elsif ($type eq 'selfcreateprocessing') {
                   15813:                         my %choices = &Apache::lonlocal::texthash (
                   15814:                                                                     automatic => 'Automatic approval',
                   15815:                                                                     approval  => 'Queued for approval',
                   15816:                                                                   );
1.305     raeburn  15817:                         if (@types) {
                   15818:                             if (@statuses) {
1.303     raeburn  15819:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:'). 
1.309     raeburn  15820:                                             '<ul>';
1.305     raeburn  15821:                                 foreach my $status (@statuses) {
                   15822:                                     if ($status eq 'default') {
                   15823:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  15824:                                     } else {
1.305     raeburn  15825:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303     raeburn  15826:                                     }
                   15827:                                 }
                   15828:                                 $chgtext .= '</ul>';
                   15829:                             }
                   15830:                         } else {
                   15831:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   15832:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   15833:                         }
                   15834:                     } elsif ($type eq 'emailverified') {
                   15835:                         my %options = &Apache::lonlocal::texthash (
1.305     raeburn  15836:                                                                     all   => 'Same as e-mail',
                   15837:                                                                     first => 'Omit @domain',
                   15838:                                                                     free  => 'Free to choose',
1.303     raeburn  15839:                                                                   );
1.305     raeburn  15840:                         if (@types) {
                   15841:                             if (@statuses) {
1.303     raeburn  15842:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   15843:                                             '<ul>';
1.305     raeburn  15844:                                 foreach my $status (@statuses) {
1.362     raeburn  15845:                                     if ($status eq 'default') {
1.305     raeburn  15846:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  15847:                                     } else {
1.305     raeburn  15848:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303     raeburn  15849:                                     }
                   15850:                                 }
                   15851:                                 $chgtext .= '</ul>';
                   15852:                             }
                   15853:                         } else {
1.305     raeburn  15854:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304     raeburn  15855:                                             $options{$cancreate{'emailverified'}{'default'}});
1.303     raeburn  15856:                         }
1.305     raeburn  15857:                     } elsif ($type eq 'emailoptions') {
                   15858:                         my %options = &Apache::lonlocal::texthash (
                   15859:                                                                     any     => 'Any e-mail',
                   15860:                                                                     inst    => 'Institutional only',
                   15861:                                                                     noninst => 'Non-institutional only',
                   15862:                                                                     custom  => 'Custom restrictions',
                   15863:                                                                   );
                   15864:                         if (@types) {
                   15865:                             if (@statuses) {
                   15866:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   15867:                                             '<ul>';
                   15868:                                 foreach my $status (@statuses) {
                   15869:                                     if ($type eq 'default') {
                   15870:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   15871:                                     } else {
                   15872:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303     raeburn  15873:                                     }
                   15874:                                 }
1.305     raeburn  15875:                                 $chgtext .= '</ul>';
                   15876:                             }
                   15877:                         } else {
                   15878:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   15879:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   15880:                             } else {
                   15881:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   15882:                                                 $options{$cancreate{'emailoptions'}{'default'}});
1.303     raeburn  15883:                             }
1.305     raeburn  15884:                         }
                   15885:                     } elsif ($type eq 'emaildomain') {
                   15886:                         my $output;
                   15887:                         if (@statuses) {
                   15888:                             foreach my $type (@statuses) {
                   15889:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   15890:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   15891:                                         if ($type eq 'default') {
                   15892:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15893:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15894:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15895:                                             } else {
                   15896:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15897:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   15898:                                             }
1.303     raeburn  15899:                                         } else {
1.305     raeburn  15900:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15901:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15902:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15903:                                             } else {
                   15904:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15905:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>'; 
                   15906:                                             }
1.303     raeburn  15907:                                         }
1.305     raeburn  15908:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   15909:                                         if ($type eq 'default') {
                   15910:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15911:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15912:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15913:                                             } else {
                   15914:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15915:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   15916:                                             }
1.303     raeburn  15917:                                         } else {
1.305     raeburn  15918:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15919:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15920:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15921:                                             } else {
                   15922:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15923:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';   
                   15924:                                             }
1.303     raeburn  15925:                                         }
                   15926:                                     }
                   15927:                                 }
                   15928:                             }
1.305     raeburn  15929:                         }
                   15930:                         if ($output ne '') {
                   15931:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   15932:                                         '<ul>'.$output.'</ul>';
1.236     raeburn  15933:                         }
1.165     raeburn  15934:                     } elsif ($type eq 'captcha') {
1.224     raeburn  15935:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  15936:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   15937:                         } else {
                   15938:                             my %captchas = &captcha_phrases();
1.224     raeburn  15939:                             if ($captchas{$savecaptcha{$type}}) {
                   15940:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  15941:                             } else {
1.210     raeburn  15942:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  15943:                             }
                   15944:                         }
                   15945:                     } elsif ($type eq 'recaptchakeys') {
                   15946:                         my ($privkey,$pubkey);
1.224     raeburn  15947:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   15948:                             $pubkey = $savecaptcha{$type}{'public'};
                   15949:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  15950:                         }
                   15951:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   15952:                         if (!$pubkey) {
                   15953:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   15954:                         } else {
                   15955:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   15956:                         }
                   15957:                         if (!$privkey) {
                   15958:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   15959:                         } else {
                   15960:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   15961:                         }
                   15962:                         $chgtext .= '</ul>';
1.269     raeburn  15963:                     } elsif ($type eq 'recaptchaversion') {
                   15964:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  15965:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  15966:                         }
1.224     raeburn  15967:                     } elsif ($type eq 'emailusername') {
                   15968:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305     raeburn  15969:                             if (@statuses) {
                   15970:                                 foreach my $type (@statuses) {
1.228     raeburn  15971:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   15972:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303     raeburn  15973:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228     raeburn  15974:                                                     '<ul>';
                   15975:                                             foreach my $field (@{$infofields}) {
                   15976:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   15977:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   15978:                                                 }
                   15979:                                             }
1.245     raeburn  15980:                                             $chgtext .= '</ul>';
                   15981:                                         } else {
1.303     raeburn  15982:                                             $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  15983:                                         }
                   15984:                                     } else {
1.303     raeburn  15985:                                         $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  15986:                                     }
                   15987:                                 }
                   15988:                             }
                   15989:                         }
                   15990:                     } elsif ($type eq 'notify') {
1.303     raeburn  15991:                         my $numapprove = 0;
1.224     raeburn  15992:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   15993:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   15994:                                 if ($cancreate{'notify'}{'approval'}) {
1.303     raeburn  15995:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   15996:                                     $numapprove ++;
1.224     raeburn  15997:                                 }
                   15998:                             }
1.43      raeburn  15999:                         }
1.303     raeburn  16000:                         unless ($numapprove) {
                   16001:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   16002:                         }
1.34      raeburn  16003:                     }
1.224     raeburn  16004:                     if ($chgtext) {
                   16005:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  16006:                     }
                   16007:                 }
                   16008:             }
1.305     raeburn  16009:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  16010:                 my ($emailrules,$emailruleorder) =
                   16011:                     &Apache::lonnet::inst_userrules($dom,'email');
1.305     raeburn  16012:                 foreach my $type (@{$changes{'email_rule'}}) {
                   16013:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   16014:                         my $chgtext = '<ul>';
                   16015:                         foreach my $rule (@{$email_rule{$type}}) {
                   16016:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   16017:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   16018:                             }
                   16019:                         }
                   16020:                         $chgtext .= '</ul>';
1.310     raeburn  16021:                         my $typename;
1.305     raeburn  16022:                         if (@types) {
                   16023:                             if ($type eq 'default') {
                   16024:                                 $typename = $othertitle;
                   16025:                             } else {
                   16026:                                 $typename = $usertypes{$type};
                   16027:                             } 
                   16028:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   16029:                         }
                   16030:                         if (@{$email_rule{$type}} > 0) {
                   16031:                             $resulttext .= '<li>'.
                   16032:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   16033:                                                $usertypes{$type}).
                   16034:                                            $chgtext.
                   16035:                                            '</li>';
                   16036:                         } else {
                   16037:                             $resulttext .= '<li>'.
1.310     raeburn  16038:                                            &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  16039:                                            '</li>'.
1.310     raeburn  16040:                                            &mt('(Affiliation: [_1])',$typename);
1.305     raeburn  16041:                         }
1.43      raeburn  16042:                     }
                   16043:                 }
1.305     raeburn  16044:             }
                   16045:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   16046:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   16047:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   16048:                         my $chgtext = '<ul>';
                   16049:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   16050:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   16051:                         }
                   16052:                         $chgtext .= '</ul>';
                   16053:                         $resulttext .= '<li>'.
                   16054:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   16055:                                           $chgtext.
                   16056:                                        '</li>';
                   16057:                     } else {
                   16058:                         $resulttext .= '<li>'.
                   16059:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   16060:                                        '</li>';
                   16061:                     }
1.43      raeburn  16062:                 }
                   16063:             }
1.224     raeburn  16064:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   16065:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   16066:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   16067:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   16068:                     my $typename = $type;
1.303     raeburn  16069:                     if (keys(%usertypes) > 0) {
                   16070:                         if ($usertypes{$type} ne '') {
                   16071:                             $typename = $usertypes{$type};
1.224     raeburn  16072:                         }
                   16073:                     }
                   16074:                     my @modifiable;
                   16075:                     $resulttext .= '<li>'.
                   16076:                                     &mt('Self-creation of account by users with status: [_1]',
                   16077:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   16078:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   16079:                     foreach my $field (@fields) {
                   16080:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   16081:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  16082:                         }
                   16083:                     }
1.224     raeburn  16084:                     if (@modifiable > 0) {
                   16085:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  16086:                     } else {
1.224     raeburn  16087:                         $resulttext .= &mt('none');
1.43      raeburn  16088:                     }
1.224     raeburn  16089:                     $resulttext .= '</li>';
1.28      raeburn  16090:                 }
1.224     raeburn  16091:                 $resulttext .= '</ul></li>';
1.28      raeburn  16092:             }
1.27      raeburn  16093:             $resulttext .= '</ul>';
1.305     raeburn  16094:             my $cachetime = 24*60*60;
                   16095:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   16096:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   16097:             if (ref($lastactref) eq 'HASH') {
                   16098:                 $lastactref->{'domdefaults'} = 1;
                   16099:             }
1.27      raeburn  16100:         } else {
1.224     raeburn  16101:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  16102:         }
                   16103:     } else {
                   16104:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  16105:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16106:     }
1.43      raeburn  16107:     if ($warningmsg ne '') {
                   16108:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   16109:     }
1.23      raeburn  16110:     return $resulttext;
                   16111: }
                   16112: 
1.165     raeburn  16113: sub process_captcha {
1.369   ! raeburn  16114:     my ($container,$changes,$newsettings,$currsettings) = @_;
        !          16115:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165     raeburn  16116:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   16117:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   16118:         $newsettings->{'captcha'} = 'original';
                   16119:     }
1.369   ! raeburn  16120:     my %current;
        !          16121:     if (ref($currsettings) eq 'HASH') {
        !          16122:         %current = %{$currsettings};
        !          16123:     }
        !          16124:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  16125:         if ($container eq 'cancreate') {
1.169     raeburn  16126:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16127:                 push(@{$changes->{'cancreate'}},'captcha');
                   16128:             } elsif (!defined($changes->{'cancreate'})) {
                   16129:                 $changes->{'cancreate'} = ['captcha'];
                   16130:             }
1.368     raeburn  16131:         } elsif ($container eq 'passwords') {
                   16132:             $changes->{'reset'} = 1;
1.169     raeburn  16133:         } else {
                   16134:             $changes->{'captcha'} = 1;
1.165     raeburn  16135:         }
                   16136:     }
1.269     raeburn  16137:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  16138:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   16139:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   16140:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  16141:         $newpub =~ s/[^\w\-]//g;
                   16142:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  16143:         $newsettings->{'recaptchakeys'} = {
                   16144:                                              public  => $newpub,
                   16145:                                              private => $newpriv,
                   16146:                                           };
1.269     raeburn  16147:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   16148:         $newversion =~ s/\D//g;
                   16149:         if ($newversion ne '2') {
                   16150:             $newversion = 1;
                   16151:         }
                   16152:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  16153:     }
1.369   ! raeburn  16154:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
        !          16155:         $currpub = $current{'recaptchakeys'}{'public'};
        !          16156:         $currpriv = $current{'recaptchakeys'}{'private'};
1.179     raeburn  16157:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   16158:             $newsettings->{'recaptchakeys'} = {
                   16159:                                                  public  => '',
                   16160:                                                  private => '',
                   16161:                                               }
                   16162:         }
1.165     raeburn  16163:     }
1.369   ! raeburn  16164:     if ($current{'captcha'} eq 'recaptcha') {
        !          16165:         $currversion = $current{'recaptchaversion'};
1.269     raeburn  16166:         if ($currversion ne '2') {
                   16167:             $currversion = 1;
                   16168:         }
                   16169:     }
                   16170:     if ($currversion ne $newversion) {
                   16171:         if ($container eq 'cancreate') {
                   16172:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16173:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   16174:             } elsif (!defined($changes->{'cancreate'})) {
                   16175:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   16176:             }
1.368     raeburn  16177:         } elsif ($container eq 'passwords') {
                   16178:             $changes->{'reset'} = 1;
1.269     raeburn  16179:         } else {
                   16180:             $changes->{'recaptchaversion'} = 1;
                   16181:         }
                   16182:     }
1.165     raeburn  16183:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  16184:         if ($container eq 'cancreate') {
                   16185:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16186:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   16187:             } elsif (!defined($changes->{'cancreate'})) {
                   16188:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   16189:             }
1.368     raeburn  16190:         } elsif ($container eq 'passwords') {
                   16191:             $changes->{'reset'} = 1;
1.169     raeburn  16192:         } else {
1.210     raeburn  16193:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  16194:         }
                   16195:     }
                   16196:     return;
                   16197: }
                   16198: 
1.33      raeburn  16199: sub modify_usermodification {
                   16200:     my ($dom,%domconfig) = @_;
1.224     raeburn  16201:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  16202:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   16203:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  16204:             if ($key eq 'selfcreate') {
                   16205:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   16206:             } else {  
                   16207:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   16208:             }
1.33      raeburn  16209:         }
                   16210:     }
1.224     raeburn  16211:     my @contexts = ('author','course');
1.33      raeburn  16212:     my %context_title = (
                   16213:                            author => 'In author context',
                   16214:                            course => 'In course context',
                   16215:                         );
                   16216:     my @fields = ('lastname','firstname','middlename','generation',
                   16217:                   'permanentemail','id');
                   16218:     my %roles = (
                   16219:                   author => ['ca','aa'],
                   16220:                   course => ['st','ep','ta','in','cr'],
                   16221:                 );
                   16222:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   16223:     foreach my $context (@contexts) {
                   16224:         foreach my $role (@{$roles{$context}}) {
                   16225:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   16226:             foreach my $item (@fields) {
                   16227:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   16228:                     $modifyhash{$context}{$role}{$item} = 1;
                   16229:                 } else {
                   16230:                     $modifyhash{$context}{$role}{$item} = 0;
                   16231:                 }
                   16232:             }
                   16233:         }
                   16234:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   16235:             foreach my $role (@{$roles{$context}}) {
                   16236:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   16237:                     foreach my $field (@fields) {
                   16238:                         if ($modifyhash{$context}{$role}{$field} ne 
                   16239:                                 $curr_usermodification{$context}{$role}{$field}) {
                   16240:                             push(@{$changes{$context}},$role);
                   16241:                             last;
                   16242:                         }
                   16243:                     }
                   16244:                 }
                   16245:             }
                   16246:         } else {
                   16247:             foreach my $context (@contexts) {
                   16248:                 foreach my $role (@{$roles{$context}}) {
                   16249:                     push(@{$changes{$context}},$role);
                   16250:                 }
                   16251:             }
                   16252:         }
                   16253:     }
                   16254:     my %usermodification_hash =  (
                   16255:                                    usermodification => \%modifyhash,
                   16256:                                  );
                   16257:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   16258:                                              \%usermodification_hash,$dom);
                   16259:     if ($putresult eq 'ok') {
                   16260:         if (keys(%changes) > 0) {
                   16261:             $resulttext = &mt('Changes made: ').'<ul>';
                   16262:             foreach my $context (@contexts) {
                   16263:                 if (ref($changes{$context}) eq 'ARRAY') {
                   16264:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   16265:                     if (ref($changes{$context}) eq 'ARRAY') {
                   16266:                         foreach my $role (@{$changes{$context}}) {
                   16267:                             my $rolename;
1.224     raeburn  16268:                             if ($role eq 'cr') {
                   16269:                                 $rolename = &mt('Custom');
1.33      raeburn  16270:                             } else {
1.224     raeburn  16271:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  16272:                             }
                   16273:                             my @modifiable;
1.224     raeburn  16274:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  16275:                             foreach my $field (@fields) {
                   16276:                                 if ($modifyhash{$context}{$role}{$field}) {
                   16277:                                     push(@modifiable,$fieldtitles{$field});
                   16278:                                 }
                   16279:                             }
                   16280:                             if (@modifiable > 0) {
                   16281:                                 $resulttext .= join(', ',@modifiable);
                   16282:                             } else {
                   16283:                                 $resulttext .= &mt('none'); 
                   16284:                             }
                   16285:                             $resulttext .= '</li>';
                   16286:                         }
                   16287:                         $resulttext .= '</ul></li>';
                   16288:                     }
                   16289:                 }
                   16290:             }
                   16291:             $resulttext .= '</ul>';
                   16292:         } else {
                   16293:             $resulttext = &mt('No changes made to user modification settings');
                   16294:         }
                   16295:     } else {
                   16296:         $resulttext = '<span class="LC_error">'.
                   16297:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16298:     }
                   16299:     return $resulttext;
                   16300: }
                   16301: 
1.43      raeburn  16302: sub modify_defaults {
1.212     raeburn  16303:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  16304:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  16305:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294     raeburn  16306:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354     raeburn  16307:                  'portal_def');
1.325     raeburn  16308:     my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43      raeburn  16309:     foreach my $item (@items) {
                   16310:         $newvalues{$item} = $env{'form.'.$item};
                   16311:         if ($item eq 'auth_def') {
                   16312:             if ($newvalues{$item} ne '') {
                   16313:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   16314:                     push(@errors,$item);
                   16315:                 }
                   16316:             }
                   16317:         } elsif ($item eq 'lang_def') {
                   16318:             if ($newvalues{$item} ne '') {
                   16319:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   16320:                     my $langcode = $1;
1.103     raeburn  16321:                     if ($langcode ne 'x_chef') {
                   16322:                         if (code2language($langcode) eq '') {
                   16323:                             push(@errors,$item);
                   16324:                         }
1.43      raeburn  16325:                     }
                   16326:                 } else {
                   16327:                     push(@errors,$item);
                   16328:                 }
                   16329:             }
1.54      raeburn  16330:         } elsif ($item eq 'timezone_def') {
                   16331:             if ($newvalues{$item} ne '') {
1.62      raeburn  16332:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  16333:                     push(@errors,$item);   
                   16334:                 }
                   16335:             }
1.68      raeburn  16336:         } elsif ($item eq 'datelocale_def') {
                   16337:             if ($newvalues{$item} ne '') {
                   16338:                 my @datelocale_ids = DateTime::Locale->ids();
                   16339:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   16340:                     push(@errors,$item);
                   16341:                 }
                   16342:             }
1.141     raeburn  16343:         } elsif ($item eq 'portal_def') {
                   16344:             if ($newvalues{$item} ne '') {
                   16345:                 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])\/?$/) {
                   16346:                     push(@errors,$item);
                   16347:                 }
                   16348:             }
1.43      raeburn  16349:         }
                   16350:         if (grep(/^\Q$item\E$/,@errors)) {
                   16351:             $newvalues{$item} = $domdefaults{$item};
                   16352:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   16353:             $changes{$item} = 1;
                   16354:         }
1.72      raeburn  16355:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  16356:     }
1.354     raeburn  16357:     my %staticdefaults = (
                   16358:                            'intauth_cost'   => 10,
                   16359:                            'intauth_check'  => 0,
                   16360:                            'intauth_switch' => 0,
                   16361:                          );
                   16362:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   16363:         if (exists($domdefaults{$item})) {
                   16364:             $newvalues{$item} = $domdefaults{$item};
                   16365:         } else {
                   16366:             $newvalues{$item} = $staticdefaults{$item};
                   16367:         }
                   16368:     }
1.43      raeburn  16369:     my %defaults_hash = (
1.72      raeburn  16370:                          defaults => \%newvalues,
                   16371:                         );
1.43      raeburn  16372:     my $title = &defaults_titles();
1.236     raeburn  16373: 
                   16374:     my $currinststatus;
                   16375:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   16376:         $currinststatus = $domconfig{'inststatus'};
                   16377:     } else {
                   16378:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16379:         $currinststatus = {
                   16380:                              inststatustypes => $usertypes,
                   16381:                              inststatusorder => $types,
                   16382:                              inststatusguest => [],
                   16383:                           };
                   16384:     }
                   16385:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   16386:     my @allpos;
                   16387:     my %alltypes;
1.305     raeburn  16388:     my @inststatusguest;
                   16389:     if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   16390:         foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   16391:             unless (grep(/^\Q$type\E$/,@todelete)) {
                   16392:                 push(@inststatusguest,$type);
                   16393:             }
                   16394:         }
                   16395:     }
                   16396:     my ($currtitles,$currorder);
1.236     raeburn  16397:     if (ref($currinststatus) eq 'HASH') {
                   16398:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   16399:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   16400:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   16401:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   16402:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   16403:                     }
                   16404:                 }
                   16405:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   16406:                     my $position = $env{'form.inststatus_pos_'.$type};
                   16407:                     $position =~ s/\D+//g;
                   16408:                     $allpos[$position] = $type;
                   16409:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   16410:                     $alltypes{$type} =~ s/`//g;
                   16411:                 }
                   16412:             }
                   16413:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   16414:             $currtitles =~ s/,$//;
                   16415:         }
                   16416:     }
                   16417:     if ($env{'form.addinststatus'}) {
                   16418:         my $newtype = $env{'form.addinststatus'};
                   16419:         $newtype =~ s/\W//g;
                   16420:         unless (exists($alltypes{$newtype})) {
                   16421:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   16422:             $alltypes{$newtype} =~ s/`//g; 
                   16423:             my $position = $env{'form.addinststatus_pos'};
                   16424:             $position =~ s/\D+//g;
                   16425:             if ($position ne '') {
                   16426:                 $allpos[$position] = $newtype;
                   16427:             }
                   16428:         }
                   16429:     }
1.305     raeburn  16430:     my @orderedstatus;
1.236     raeburn  16431:     foreach my $type (@allpos) {
                   16432:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   16433:             push(@orderedstatus,$type);
                   16434:         }
                   16435:     }
                   16436:     foreach my $type (keys(%alltypes)) {
                   16437:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   16438:             delete($alltypes{$type});
                   16439:         }
                   16440:     }
                   16441:     $defaults_hash{'inststatus'} = {
                   16442:                                      inststatustypes => \%alltypes,
                   16443:                                      inststatusorder => \@orderedstatus,
1.305     raeburn  16444:                                      inststatusguest => \@inststatusguest,
1.236     raeburn  16445:                                    };
                   16446:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   16447:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   16448:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   16449:         }
                   16450:     }
                   16451:     if ($currorder ne join(',',@orderedstatus)) {
                   16452:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   16453:     }
                   16454:     my $newtitles;
                   16455:     foreach my $item (@orderedstatus) {
                   16456:         $newtitles .= $alltypes{$item}.',';
                   16457:     }
                   16458:     $newtitles =~ s/,$//;
                   16459:     if ($currtitles ne $newtitles) {
                   16460:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   16461:     }
1.43      raeburn  16462:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   16463:                                              $dom);
                   16464:     if ($putresult eq 'ok') {
                   16465:         if (keys(%changes) > 0) {
                   16466:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  16467:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  16468:             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";
                   16469:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  16470:                 if ($item eq 'inststatus') {
                   16471:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.305     raeburn  16472:                         if (@orderedstatus) {
1.236     raeburn  16473:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   16474:                             foreach my $type (@orderedstatus) { 
                   16475:                                 $resulttext .= $alltypes{$type}.', ';
                   16476:                             }
                   16477:                             $resulttext =~ s/, $//;
                   16478:                             $resulttext .= '</li>';
1.305     raeburn  16479:                         } else {
                   16480:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>'; 
1.236     raeburn  16481:                         }
                   16482:                     }
                   16483:                 } else {
                   16484:                     my $value = $env{'form.'.$item};
                   16485:                     if ($value eq '') {
                   16486:                         $value = &mt('none');
                   16487:                     } elsif ($item eq 'auth_def') {
                   16488:                         my %authnames = &authtype_names();
                   16489:                         my %shortauth = (
                   16490:                                           internal   => 'int',
                   16491:                                           krb4       => 'krb4',
                   16492:                                           krb5       => 'krb5',
                   16493:                                           localauth  => 'loc',
1.325     raeburn  16494:                                           lti        => 'lti',
1.236     raeburn  16495:                         );
                   16496:                         $value = $authnames{$shortauth{$value}};
                   16497:                     }
                   16498:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   16499:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  16500:                 }
                   16501:             }
                   16502:             $resulttext .= '</ul>';
                   16503:             $mailmsgtext .= "\n";
                   16504:             my $cachetime = 24*60*60;
1.72      raeburn  16505:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  16506:             if (ref($lastactref) eq 'HASH') {
                   16507:                 $lastactref->{'domdefaults'} = 1;
                   16508:             }
1.68      raeburn  16509:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  16510:                 my $notify = 1;
                   16511:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16512:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   16513:                         $notify = 0;
                   16514:                     }
                   16515:                 }
                   16516:                 if ($notify) {
                   16517:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   16518:                                                "LON-CAPA Domain Settings Change - $dom",
                   16519:                                                $mailmsgtext);
                   16520:                 }
1.54      raeburn  16521:             }
1.43      raeburn  16522:         } else {
1.54      raeburn  16523:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  16524:         }
                   16525:     } else {
                   16526:         $resulttext = '<span class="LC_error">'.
                   16527:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16528:     }
                   16529:     if (@errors > 0) {
                   16530:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   16531:         foreach my $item (@errors) {
                   16532:             $resulttext .= ' "'.$title->{$item}.'",';
                   16533:         }
                   16534:         $resulttext =~ s/,$//;
                   16535:     }
                   16536:     return $resulttext;
                   16537: }
                   16538: 
1.46      raeburn  16539: sub modify_scantron {
1.205     raeburn  16540:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  16541:     my ($resulttext,%confhash,%changes,$errors);
                   16542:     my $custom = 'custom.tab';
                   16543:     my $default = 'default.tab';
                   16544:     my $servadm = $r->dir_config('lonAdmEMail');
1.346     raeburn  16545:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  16546:         &config_check($dom,$confname,$servadm);
                   16547:     if ($env{'form.scantronformat.filename'} ne '') {
                   16548:         my $error;
                   16549:         if ($configuserok eq 'ok') {
                   16550:             if ($switchserver) {
1.130     raeburn  16551:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  16552:             } else {
                   16553:                 if ($author_ok eq 'ok') {
                   16554:                     my ($result,$scantronurl) =
                   16555:                         &publishlogo($r,'upload','scantronformat',$dom,
                   16556:                                      $confname,'scantron','','',$custom);
                   16557:                     if ($result eq 'ok') {
                   16558:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  16559:                         $changes{'scantronformat'} = 1;
1.46      raeburn  16560:                     } else {
                   16561:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   16562:                     }
                   16563:                 } else {
                   16564:                     $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);
                   16565:                 }
                   16566:             }
                   16567:         } else {
                   16568:             $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);
                   16569:         }
                   16570:         if ($error) {
                   16571:             &Apache::lonnet::logthis($error);
                   16572:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   16573:         }
                   16574:     }
1.48      raeburn  16575:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16576:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   16577:             if ($env{'form.scantronformat_del'}) {
                   16578:                 $confhash{'scantron'}{'scantronformat'} = '';
                   16579:                 $changes{'scantronformat'} = 1;
1.347     raeburn  16580:             } else {
                   16581:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46      raeburn  16582:             }
                   16583:         }
                   16584:     }
1.347     raeburn  16585:     my @options = ('hdr','pad','rem');
1.346     raeburn  16586:     my @fields = &scantroncsv_fields();
                   16587:     my %titles = &scantronconfig_titles();
1.347     raeburn  16588:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346     raeburn  16589:     my ($newdat,$currdat,%newcol,%currcol);
                   16590:     if (grep(/^dat$/,@formats)) {
                   16591:         $confhash{'scantron'}{config}{dat} = 1;
                   16592:         $newdat = 1;
                   16593:     } else {
                   16594:         $newdat = 0;
                   16595:     }
                   16596:     if (grep(/^csv$/,@formats)) {
                   16597:         my %bynum;
                   16598:         foreach my $field (@fields) {
                   16599:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   16600:                 my $posscol = $1;
                   16601:                 if (($posscol < 20) && (!$bynum{$posscol})) {
1.347     raeburn  16602:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346     raeburn  16603:                     $bynum{$posscol} = $field;
                   16604:                     $newcol{$field} = $posscol;
                   16605:                 }
                   16606:             }
                   16607:         }
1.347     raeburn  16608:         if (keys(%newcol)) {
                   16609:             foreach my $option (@options) {
                   16610:                 if ($env{'form.scantroncsv_'.$option}) {
                   16611:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   16612:                 }
                   16613:             }
                   16614:         }
1.346     raeburn  16615:     }
                   16616:     $currdat = 1;
                   16617:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16618:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347     raeburn  16619:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346     raeburn  16620:                 $currdat = 0;
                   16621:             }
                   16622:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  16623:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16624:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   16625:                 }
1.346     raeburn  16626:             }
                   16627:         }
                   16628:     }
                   16629:     if ($currdat != $newdat) {
                   16630:         $changes{'config'} = 1;
                   16631:     } else {
                   16632:         foreach my $field (@fields) {
                   16633:             if ($currcol{$field} ne '') {
                   16634:                 if ($currcol{$field} ne $newcol{$field}) {
                   16635:                     $changes{'config'} = 1;
                   16636:                     last;
1.347     raeburn  16637:                 }
1.346     raeburn  16638:             } elsif ($newcol{$field} ne '') {
                   16639:                 $changes{'config'} = 1;
                   16640:                 last;
                   16641:             }
                   16642:         }
                   16643:     }
1.46      raeburn  16644:     if (keys(%confhash) > 0) {
                   16645:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   16646:                                                  $dom);
                   16647:         if ($putresult eq 'ok') {
                   16648:             if (keys(%changes) > 0) {
1.48      raeburn  16649:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   16650:                     $resulttext = &mt('Changes made:').'<ul>';
1.346     raeburn  16651:                     if ($changes{'scantronformat'}) {
                   16652:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   16653:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   16654:                         } else {
                   16655:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   16656:                         }
                   16657:                     }
1.347     raeburn  16658:                     if ($changes{'config'}) {
1.346     raeburn  16659:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   16660:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   16661:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   16662:                             }
                   16663:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347     raeburn  16664:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16665:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   16666:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   16667:                                         foreach my $field (@fields) {
                   16668:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   16669:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   16670:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   16671:                                             }
                   16672:                                         }
                   16673:                                         $resulttext .= '</ul></li>';
                   16674:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   16675:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   16676:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   16677:                                                 foreach my $option (@options) {
                   16678:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   16679:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   16680:                                                     }
                   16681:                                                 }
                   16682:                                                 $resulttext .= '</ul></li>';
                   16683:                                             }
1.346     raeburn  16684:                                         }
                   16685:                                     }
                   16686:                                 }
                   16687:                             }
                   16688:                         } else {
                   16689:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   16690:                         }
1.46      raeburn  16691:                     }
1.48      raeburn  16692:                     $resulttext .= '</ul>';
                   16693:                 } else {
1.130     raeburn  16694:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  16695:                 }
                   16696:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  16697:                 if (ref($lastactref) eq 'HASH') {
                   16698:                     $lastactref->{'domainconfig'} = 1;
                   16699:                 }
1.46      raeburn  16700:             } else {
1.346     raeburn  16701:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  16702:             }
                   16703:         } else {
                   16704:             $resulttext = '<span class="LC_error">'.
                   16705:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   16706:         }
                   16707:     } else {
1.130     raeburn  16708:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  16709:     }
                   16710:     if ($errors) {
1.353     raeburn  16711:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   16712:                        $errors.'</ul></p>';
1.46      raeburn  16713:     }
                   16714:     return $resulttext;
                   16715: }
                   16716: 
1.48      raeburn  16717: sub modify_coursecategories {
1.239     raeburn  16718:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  16719:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   16720:         $cathash);
1.48      raeburn  16721:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  16722:     my @catitems = ('unauth','auth');
                   16723:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  16724:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  16725:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   16726:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   16727:             $changes{'togglecats'} = 1;
                   16728:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   16729:         }
                   16730:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   16731:             $changes{'categorize'} = 1;
                   16732:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   16733:         }
1.120     raeburn  16734:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   16735:             $changes{'togglecatscomm'} = 1;
                   16736:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   16737:         }
                   16738:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   16739:             $changes{'categorizecomm'} = 1;
                   16740:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272     raeburn  16741: 
                   16742:         }
                   16743:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
                   16744:             $changes{'togglecatsplace'} = 1;
                   16745:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
                   16746:         }
                   16747:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
                   16748:             $changes{'categorizeplace'} = 1;
                   16749:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  16750:         }
1.238     raeburn  16751:         foreach my $item (@catitems) {
                   16752:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16753:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   16754:                     $changes{$item} = 1;
                   16755:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16756:                 }
                   16757:             }
                   16758:         }
1.57      raeburn  16759:     } else {
                   16760:         $changes{'togglecats'} = 1;
                   16761:         $changes{'categorize'} = 1;
1.124     raeburn  16762:         $changes{'togglecatscomm'} = 1;
                   16763:         $changes{'categorizecomm'} = 1;
1.272     raeburn  16764:         $changes{'togglecatsplace'} = 1;
                   16765:         $changes{'categorizeplace'} = 1;
1.87      raeburn  16766:         $domconfig{'coursecategories'} = {
                   16767:                                              togglecats => $env{'form.togglecats'},
                   16768:                                              categorize => $env{'form.categorize'},
1.124     raeburn  16769:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   16770:                                              categorizecomm => $env{'form.categorizecomm'},
1.272     raeburn  16771:                                              togglecatsplace => $env{'form.togglecatsplace'},
                   16772:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  16773:                                          };
1.238     raeburn  16774:         foreach my $item (@catitems) {
                   16775:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   16776:                 $changes{$item} = 1;
                   16777:             }
                   16778:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16779:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16780:             }
                   16781:         }
1.57      raeburn  16782:     }
                   16783:     if (ref($cathash) eq 'HASH') {
                   16784:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  16785:             push (@deletecategory,'instcode::0');
                   16786:         }
1.120     raeburn  16787:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   16788:             push(@deletecategory,'communities::0');
                   16789:         }
1.272     raeburn  16790:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
                   16791:             push(@deletecategory,'placement::0');
                   16792:         }
1.48      raeburn  16793:     }
1.57      raeburn  16794:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   16795:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  16796:         if (@deletecategory > 0) {
                   16797:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  16798:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  16799:             foreach my $item (@deletecategory) {
1.57      raeburn  16800:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   16801:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  16802:                     $deletions{$item} = 1;
1.57      raeburn  16803:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  16804:                 }
                   16805:             }
                   16806:         }
1.57      raeburn  16807:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  16808:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  16809:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  16810:                 $reorderings{$item} = 1;
1.57      raeburn  16811:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  16812:             }
                   16813:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   16814:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   16815:                 my $newdepth = $depth+1;
                   16816:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16817:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  16818:                 $adds{$newitem} = 1; 
                   16819:             }
                   16820:             if ($env{'form.subcat_'.$item} ne '') {
                   16821:                 my $newcat = $env{'form.subcat_'.$item};
                   16822:                 my $newdepth = $depth+1;
                   16823:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16824:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  16825:                 $adds{$newitem} = 1;
                   16826:             }
                   16827:         }
                   16828:     }
                   16829:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  16830:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  16831:             my $newitem = 'instcode::0';
1.57      raeburn  16832:             if ($cathash->{$newitem} eq '') {  
                   16833:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16834:                 $adds{$newitem} = 1;
                   16835:             }
                   16836:         } else {
                   16837:             my $newitem = 'instcode::0';
1.57      raeburn  16838:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16839:             $adds{$newitem} = 1;
                   16840:         }
                   16841:     }
1.120     raeburn  16842:     if ($env{'form.communities'} eq '1') {
                   16843:         if (ref($cathash) eq 'HASH') {
                   16844:             my $newitem = 'communities::0';
                   16845:             if ($cathash->{$newitem} eq '') {
                   16846:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16847:                 $adds{$newitem} = 1;
                   16848:             }
                   16849:         } else {
                   16850:             my $newitem = 'communities::0';
                   16851:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16852:             $adds{$newitem} = 1;
                   16853:         }
                   16854:     }
1.272     raeburn  16855:     if ($env{'form.placement'} eq '1') {
                   16856:         if (ref($cathash) eq 'HASH') {
                   16857:             my $newitem = 'placement::0';
                   16858:             if ($cathash->{$newitem} eq '') {
                   16859:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   16860:                 $adds{$newitem} = 1;
                   16861:             }
                   16862:         } else {
                   16863:             my $newitem = 'placement::0';
                   16864:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
                   16865:             $adds{$newitem} = 1;
                   16866:         }
                   16867:     }
1.48      raeburn  16868:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  16869:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272     raeburn  16870:             ($env{'form.addcategory_name'} ne 'communities') &&
                   16871:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  16872:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   16873:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   16874:             $adds{$newitem} = 1;
                   16875:         }
1.48      raeburn  16876:     }
1.57      raeburn  16877:     my $putresult;
1.48      raeburn  16878:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16879:         if (keys(%deletions) > 0) {
                   16880:             foreach my $key (keys(%deletions)) {
                   16881:                 if ($predelallitems{$key} ne '') {
                   16882:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   16883:                 }
                   16884:             }
                   16885:         }
                   16886:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  16887:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  16888:         if (ref($chkcats[0]) eq 'ARRAY') {
                   16889:             my $depth = 0;
                   16890:             my $chg = 0;
                   16891:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   16892:                 my $name = $chkcats[0][$i];
                   16893:                 my $item;
                   16894:                 if ($name eq '') {
                   16895:                     $chg ++;
                   16896:                 } else {
                   16897:                     $item = &escape($name).'::0';
                   16898:                     if ($chg) {
1.57      raeburn  16899:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  16900:                     }
                   16901:                     $depth ++; 
1.57      raeburn  16902:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  16903:                     $depth --;
                   16904:                 }
                   16905:             }
                   16906:         }
1.57      raeburn  16907:     }
                   16908:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16909:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  16910:         if ($putresult eq 'ok') {
1.57      raeburn  16911:             my %title = (
1.120     raeburn  16912:                          togglecats     => 'Show/Hide a course in catalog',
                   16913:                          categorize     => 'Assign a category to a course',
                   16914:                          togglecatscomm => 'Show/Hide a community in catalog',
                   16915:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  16916:                         );
                   16917:             my %level = (
1.120     raeburn  16918:                          dom  => 'set in Domain ("Modify Course/Community")',
                   16919:                          crs  => 'set in Course ("Course Configuration")',
                   16920:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  16921:                          none     => 'No catalog',
                   16922:                          std      => 'Standard catalog',
                   16923:                          domonly  => 'Domain-only catalog',
                   16924:                          codesrch => 'Code search form',
1.57      raeburn  16925:                         );
1.48      raeburn  16926:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  16927:             if ($changes{'togglecats'}) {
                   16928:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   16929:             }
                   16930:             if ($changes{'categorize'}) {
                   16931:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  16932:             }
1.120     raeburn  16933:             if ($changes{'togglecatscomm'}) {
                   16934:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   16935:             }
                   16936:             if ($changes{'categorizecomm'}) {
                   16937:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   16938:             }
1.238     raeburn  16939:             if ($changes{'unauth'}) {
                   16940:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   16941:             }
                   16942:             if ($changes{'auth'}) {
                   16943:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   16944:             }
1.57      raeburn  16945:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16946:                 my $cathash;
                   16947:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   16948:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   16949:                 } else {
                   16950:                     $cathash = {};
                   16951:                 } 
                   16952:                 my (@cats,@trails,%allitems);
                   16953:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   16954:                 if (keys(%deletions) > 0) {
                   16955:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   16956:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   16957:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   16958:                     }
                   16959:                     $resulttext .= '</ul></li>';
                   16960:                 }
                   16961:                 if (keys(%reorderings) > 0) {
                   16962:                     my %sort_by_trail;
                   16963:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   16964:                     foreach my $key (keys(%reorderings)) {
                   16965:                         if ($allitems{$key} ne '') {
                   16966:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   16967:                         }
1.48      raeburn  16968:                     }
1.57      raeburn  16969:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   16970:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   16971:                     }
                   16972:                     $resulttext .= '</ul></li>';
1.48      raeburn  16973:                 }
1.57      raeburn  16974:                 if (keys(%adds) > 0) {
                   16975:                     my %sort_by_trail;
                   16976:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   16977:                     foreach my $key (keys(%adds)) {
                   16978:                         if ($allitems{$key} ne '') {
                   16979:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   16980:                         }
                   16981:                     }
                   16982:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   16983:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  16984:                     }
1.57      raeburn  16985:                     $resulttext .= '</ul></li>';
1.48      raeburn  16986:                 }
1.364     raeburn  16987:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   16988:                 if (ref($lastactref) eq 'HASH') {
                   16989:                     $lastactref->{'cats'} = 1;
                   16990:                 }
1.48      raeburn  16991:             }
                   16992:             $resulttext .= '</ul>';
1.239     raeburn  16993:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  16994:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   16995:                 if ($changes{'auth'}) {
                   16996:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   16997:                 }
                   16998:                 if ($changes{'unauth'}) {
                   16999:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   17000:                 }
                   17001:                 my $cachetime = 24*60*60;
                   17002:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  17003:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  17004:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  17005:                 }
                   17006:             }
1.48      raeburn  17007:         } else {
                   17008:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  17009:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  17010:         }
                   17011:     } else {
1.120     raeburn  17012:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  17013:     }
                   17014:     return $resulttext;
                   17015: }
                   17016: 
1.69      raeburn  17017: sub modify_serverstatuses {
                   17018:     my ($dom,%domconfig) = @_;
                   17019:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   17020:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   17021:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   17022:     }
                   17023:     my @pages = &serverstatus_pages();
                   17024:     foreach my $type (@pages) {
                   17025:         $newserverstatus{$type}{'namedusers'} = '';
                   17026:         $newserverstatus{$type}{'machines'} = '';
                   17027:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   17028:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   17029:             my @okusers;
                   17030:             foreach my $user (@users) {
                   17031:                 my ($uname,$udom) = split(/:/,$user);
                   17032:                 if (($udom =~ /^$match_domain$/) &&   
                   17033:                     (&Apache::lonnet::domain($udom)) &&
                   17034:                     ($uname =~ /^$match_username$/)) {
                   17035:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   17036:                         push(@okusers,$user);
                   17037:                     }
                   17038:                 }
                   17039:             }
                   17040:             if (@okusers > 0) {
                   17041:                  @okusers = sort(@okusers);
                   17042:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   17043:             }
                   17044:         }
                   17045:         if (defined($env{'form.'.$type.'_machines'})) {
                   17046:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   17047:             my @okmachines;
                   17048:             foreach my $ip (@machines) {
                   17049:                 my @parts = split(/\./,$ip);
                   17050:                 next if (@parts < 4);
                   17051:                 my $badip = 0;
                   17052:                 for (my $i=0; $i<4; $i++) {
                   17053:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   17054:                         $badip = 1;
                   17055:                         last;
                   17056:                     }
                   17057:                 }
                   17058:                 if (!$badip) {
                   17059:                     push(@okmachines,$ip);     
                   17060:                 }
                   17061:             }
                   17062:             @okmachines = sort(@okmachines);
                   17063:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   17064:         }
                   17065:     }
                   17066:     my %serverstatushash =  (
                   17067:                                 serverstatuses => \%newserverstatus,
                   17068:                             );
                   17069:     foreach my $type (@pages) {
1.83      raeburn  17070:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  17071:             my (@current,@new);
1.83      raeburn  17072:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  17073:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   17074:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   17075:                 }
                   17076:             }
                   17077:             if ($newserverstatus{$type}{$setting} ne '') {
                   17078:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  17079:             }
                   17080:             if (@current > 0) {
                   17081:                 if (@new > 0) {
                   17082:                     foreach my $item (@current) {
                   17083:                         if (!grep(/^\Q$item\E$/,@new)) {
                   17084:                             $changes{$type}{$setting} = 1;
1.82      raeburn  17085:                             last;
                   17086:                         }
                   17087:                     }
1.84      raeburn  17088:                     foreach my $item (@new) {
                   17089:                         if (!grep(/^\Q$item\E$/,@current)) {
                   17090:                             $changes{$type}{$setting} = 1;
                   17091:                             last;
1.82      raeburn  17092:                         }
                   17093:                     }
                   17094:                 } else {
1.83      raeburn  17095:                     $changes{$type}{$setting} = 1;
1.69      raeburn  17096:                 }
1.83      raeburn  17097:             } elsif (@new > 0) {
                   17098:                 $changes{$type}{$setting} = 1;
1.69      raeburn  17099:             }
                   17100:         }
                   17101:     }
                   17102:     if (keys(%changes) > 0) {
1.81      raeburn  17103:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  17104:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   17105:                                                  \%serverstatushash,$dom);
                   17106:         if ($putresult eq 'ok') {
                   17107:             $resulttext .= &mt('Changes made:').'<ul>';
                   17108:             foreach my $type (@pages) {
1.84      raeburn  17109:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  17110:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  17111:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  17112:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   17113:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   17114:                         } else {
                   17115:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   17116:                         }
1.84      raeburn  17117:                     }
                   17118:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  17119:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   17120:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   17121:                         } else {
                   17122:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   17123:                         }
                   17124: 
                   17125:                     }
                   17126:                     $resulttext .= '</ul></li>';
                   17127:                 }
                   17128:             }
                   17129:             $resulttext .= '</ul>';
                   17130:         } else {
                   17131:             $resulttext = '<span class="LC_error">'.
                   17132:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   17133: 
                   17134:         }
                   17135:     } else {
                   17136:         $resulttext = &mt('No changes made to access to server status pages');
                   17137:     }
                   17138:     return $resulttext;
                   17139: }
                   17140: 
1.118     jms      17141: sub modify_helpsettings {
1.285     raeburn  17142:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166     raeburn  17143:     my ($resulttext,$errors,%changes,%helphash);
                   17144:     my %defaultchecked = ('submitbugs' => 'on');
                   17145:     my @offon = ('off','on');
1.118     jms      17146:     my @toggles = ('submitbugs');
1.285     raeburn  17147:     my %current = ('submitbugs' => '',
                   17148:                    'adhoc'      => {},
                   17149:                   );
1.118     jms      17150:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282     raeburn  17151:         %current = %{$domconfig{'helpsettings'}};
                   17152:     }
1.285     raeburn  17153:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282     raeburn  17154:     foreach my $item (@toggles) {
                   17155:         if ($defaultchecked{$item} eq 'on') { 
                   17156:             if ($current{$item} eq '') {
                   17157:                 if ($env{'form.'.$item} eq '0') {
                   17158:                     $changes{$item} = 1;
                   17159:                 }
                   17160:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   17161:                 $changes{$item} = 1;
                   17162:             }
                   17163:         } elsif ($defaultchecked{$item} eq 'off') {
                   17164:             if ($current{$item} eq '') {
                   17165:                 if ($env{'form.'.$item} eq '1') {
1.166     raeburn  17166:                     $changes{$item} = 1;
                   17167:                 }
1.282     raeburn  17168:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   17169:                 $changes{$item} = 1;
                   17170:             }
                   17171:         }
                   17172:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   17173:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   17174:         }
                   17175:     }
1.285     raeburn  17176:     my $maxnum = $env{'form.helproles_maxnum'};
1.282     raeburn  17177:     my $confname = $dom.'-domainconfig';
                   17178:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285     raeburn  17179:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   17180:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292     raeburn  17181:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290     raeburn  17182:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285     raeburn  17183:     my %lt = &Apache::lonlocal::texthash(
                   17184:                     s      => 'system',
                   17185:                     d      => 'domain',
                   17186:                     order  => 'Display order',
                   17187:                     access => 'Role usage',
1.291     raeburn  17188:                     all    => 'All with domain helpdesk or helpdesk assistant role',
1.292     raeburn  17189:                     dh     => 'All with domain helpdesk role',
                   17190:                     da     => 'All with domain helpdesk assistant role',
1.285     raeburn  17191:                     none   => 'None',
                   17192:                     status => 'Determined based on institutional status',
                   17193:                     inc    => 'Include all, but exclude specific personnel',
                   17194:                     exc    => 'Exclude all, but include specific personnel',
                   17195:     );
                   17196:     for (my $num=0; $num<=$maxnum; $num++) {
                   17197:         my ($prefix,$identifier,$rolename,%curr);
                   17198:         if ($num == $maxnum) {
                   17199:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   17200:             $identifier = 'custhelp'.$num;
                   17201:             $prefix = 'helproles_'.$num;
                   17202:             $rolename = $env{'form.custhelpname'.$num};
                   17203:             $rolename=~s/[^A-Za-z0-9]//gs;
                   17204:             next if ($rolename eq '');
                   17205:             next if (exists($existing{'rolesdef_'.$rolename}));
                   17206:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   17207:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   17208:                                                      $newprivs{'c'},$confname,$dom);
                   17209:             if ($result ne 'ok') {
                   17210:                 $errors .= '<li><span class="LC_error">'.
                   17211:                            &mt('An error occurred storing the new custom role: [_1]',
                   17212:                            $result).'</span></li>';
                   17213:                 next;
                   17214:             } else {
                   17215:                 $changedprivs{$rolename} = \%newprivs;
                   17216:                 $newrole = $rolename;
                   17217:             }
                   17218:         } else {
                   17219:             $prefix = 'helproles_'.$num;
                   17220:             $rolename = $env{'form.'.$prefix};
                   17221:             next if ($rolename eq '');
                   17222:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   17223:             $identifier = 'custhelp'.$num;
                   17224:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   17225:             my %currprivs;
1.289     raeburn  17226:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285     raeburn  17227:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   17228:             foreach my $level ('c','d','s') {
                   17229:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   17230:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   17231:                                                              $newprivs{'c'},$confname,$dom);
                   17232:                     if ($result ne 'ok') {
                   17233:                         $errors .= '<li><span class="LC_error">'.
                   17234:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   17235:                                        $rolename,$result).'</span></li>';
                   17236:                     } else {
                   17237:                         $changedprivs{$rolename} = \%newprivs;
                   17238:                     }
                   17239:                     last;
                   17240:                 }
                   17241:             }
                   17242:             if (ref($current{'adhoc'}) eq 'HASH') {
                   17243:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17244:                     %curr = %{$current{'adhoc'}{$rolename}};
                   17245:                 }
                   17246:             }
                   17247:         }
                   17248:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   17249:         $newpos =~ s/\D+//g;
                   17250:         $allpos[$newpos] = $rolename;
                   17251:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   17252:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   17253:         if ($curr{'desc'}) {
                   17254:             if ($curr{'desc'} ne $newdesc) {
                   17255:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17256:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   17257:             }
                   17258:         } elsif ($newdesc ne '') {
                   17259:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17260:             $newsettings{$rolename}{'desc'} = $newdesc;
                   17261:         }
                   17262:         my $access = $env{'form.'.$prefix.'_access'};
                   17263:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   17264:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   17265:             if ($access eq 'status') {
                   17266:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   17267:                 if (scalar(@statuses) == 0) {
1.289     raeburn  17268:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285     raeburn  17269:                 } else {
                   17270:                     my (@shownstatus,$numtypes);
                   17271:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17272:                     if (ref($types) eq 'ARRAY') {
                   17273:                         $numtypes = scalar(@{$types});
                   17274:                         foreach my $type (sort(@statuses)) {
                   17275:                             if ($type eq 'default') {
                   17276:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17277:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   17278:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17279:                                 push(@shownstatus,$usertypes->{$type});
                   17280:                             }
                   17281:                         }
                   17282:                     }
                   17283:                     if (grep(/^default$/,@statuses)) {
                   17284:                         push(@shownstatus,$othertitle);
                   17285:                     }
                   17286:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   17287:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   17288:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   17289:                     } else {
                   17290:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   17291:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   17292:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17293:                             if (@diffs) {
                   17294:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   17295:                             }
                   17296:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17297:                             $changes{'customrole'}{$rolename}{$access} = 1;
1.282     raeburn  17298:                         }
1.166     raeburn  17299:                     }
                   17300:                 }
1.285     raeburn  17301:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   17302:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   17303:                 my @newspecstaff;
                   17304:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17305:                 foreach my $person (sort(@personnel)) {
                   17306:                     if ($domhelpdesk{$person}) {
                   17307:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   17308:                     }
                   17309:                 }
                   17310:                 if (ref($curr{$access}) eq 'ARRAY') {
                   17311:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17312:                     if (@diffs) {
                   17313:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   17314:                     }
                   17315:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17316:                     $changes{'customrole'}{$rolename}{$access} = 1;
                   17317:                 }
                   17318:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17319:                     my ($uname,$udom) = split(/:/,$person);
                   17320:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   17321:                 }
                   17322:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166     raeburn  17323:             }
1.285     raeburn  17324:         } else {
                   17325:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   17326:         }
                   17327:         unless ($curr{'access'} eq $access) {
                   17328:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   17329:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282     raeburn  17330:         }
                   17331:     }
1.285     raeburn  17332:     if (@allpos > 0) {
                   17333:         my $idx = 0;
                   17334:         foreach my $rolename (@allpos) {
                   17335:             if ($rolename ne '') {
                   17336:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   17337:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   17338:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17339:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   17340:                             $changes{'customrole'}{$rolename}{'order'} = 1;
1.289     raeburn  17341:                             $newsettings{$rolename}{'order'} = $idx+1;
1.285     raeburn  17342:                         }
                   17343:                     }
1.282     raeburn  17344:                 }
1.285     raeburn  17345:                 $idx ++;
1.166     raeburn  17346:             }
                   17347:         }
1.118     jms      17348:     }
1.123     jms      17349:     my $putresult;
                   17350:     if (keys(%changes) > 0) {
1.166     raeburn  17351:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  17352:         if ($putresult eq 'ok') {
1.285     raeburn  17353:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   17354:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   17355:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   17356:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   17357:                 }
                   17358:             }
                   17359:             my $cachetime = 24*60*60;
                   17360:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17361:             if (ref($lastactref) eq 'HASH') {
                   17362:                 $lastactref->{'domdefaults'} = 1;
                   17363:             }
                   17364:         } else {
                   17365:             $errors .= '<li><span class="LC_error">'.
                   17366:                        &mt('An error occurred storing the settings: [_1]',
                   17367:                            $putresult).'</span></li>';
                   17368:         }
                   17369:     }
                   17370:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   17371:         $resulttext = &mt('Changes made:').'<ul>';
                   17372:         my (%shownprivs,@levelorder);
                   17373:         @levelorder = ('c','d','s');
                   17374:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166     raeburn  17375:             foreach my $item (sort(keys(%changes))) {
                   17376:                 if ($item eq 'submitbugs') {
                   17377:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   17378:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   17379:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282     raeburn  17380:                 } elsif ($item eq 'customrole') {
                   17381:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.285     raeburn  17382:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   17383:                         my %keytext = &Apache::lonlocal::texthash(
                   17384:                                                                    order  => 'Order',
                   17385:                                                                    desc   => 'Role description',
                   17386:                                                                    access => 'Role usage',
1.300     droeschl 17387:                                                                    status => 'Allowed institutional types',
1.285     raeburn  17388:                                                                    exc    => 'Allowed personnel',
                   17389:                                                                    inc    => 'Disallowed personnel',
                   17390:                         );
1.282     raeburn  17391:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285     raeburn  17392:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   17393:                                 if ($role eq $newrole) {
                   17394:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   17395:                                                               $role).'<ul>';
                   17396:                                 } else {
                   17397:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17398:                                                               $role).'<ul>';
                   17399:                                 }
                   17400:                                 foreach my $key (@keyorder) {
                   17401:                                     if ($changes{'customrole'}{$role}{$key}) {
                   17402:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   17403:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   17404:                                                        '</li>';
                   17405:                                     }
                   17406:                                 }
                   17407:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   17408:                                     $shownprivs{$role} = 1;
                   17409:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   17410:                                     foreach my $level (@levelorder) {
                   17411:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17412:                                             next if ($item eq '');
                   17413:                                             my ($priv) = split(/\&/,$item,2);
                   17414:                                             if (&Apache::lonnet::plaintext($priv)) {
                   17415:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17416:                                                 unless ($level eq 'c') {
                   17417:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   17418:                                                 }
                   17419:                                                 $resulttext .= '</li>';
                   17420:                                             }
                   17421:                                         }
                   17422:                                     }
                   17423:                                     $resulttext .= '</ul>';
                   17424:                                 }
                   17425:                                 $resulttext .= '</ul></li>';
                   17426:                             }
                   17427:                         }
                   17428:                     }
                   17429:                 }
                   17430:             }
                   17431:         }
                   17432:         if (keys(%changedprivs)) {
                   17433:             foreach my $role (sort(keys(%changedprivs))) {
                   17434:                 unless ($shownprivs{$role}) {
                   17435:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17436:                                               $role).'<ul>'.
                   17437:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   17438:                     foreach my $level (@levelorder) {
                   17439:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17440:                             next if ($item eq '');
                   17441:                             my ($priv) = split(/\&/,$item,2);
                   17442:                             if (&Apache::lonnet::plaintext($priv)) {
                   17443:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17444:                                 unless ($level eq 'c') {
                   17445:                                     $resulttext .= ' ('.$lt{$level}.')';
                   17446:                                 }
                   17447:                                 $resulttext .= '</li>';
                   17448:                             }
1.282     raeburn  17449:                         }
                   17450:                     }
1.285     raeburn  17451:                     $resulttext .= '</ul></li></ul></li>';
1.166     raeburn  17452:                 }
                   17453:             }
                   17454:         }
1.285     raeburn  17455:         $resulttext .= '</ul>';
                   17456:     } else {
                   17457:         $resulttext = &mt('No changes made to help settings');
1.118     jms      17458:     }
                   17459:     if ($errors) {
1.168     raeburn  17460:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285     raeburn  17461:                                     $errors.'</ul>';
1.118     jms      17462:     }
                   17463:     return $resulttext;
                   17464: }
                   17465: 
1.121     raeburn  17466: sub modify_coursedefaults {
1.212     raeburn  17467:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  17468:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  17469:     my %defaultchecked = (
                   17470:                            'canuse_pdfforms' => 'off',
                   17471:                            'uselcmath'       => 'on',
                   17472:                            'usejsme'         => 'on'
                   17473:                          );
                   17474:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  17475:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276     raeburn  17476:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement',
                   17477:                    'mysqltables_official','mysqltables_unofficial','mysqltables_community',
                   17478:                    'mysqltables_textbook','mysqltables_placement');
1.271     raeburn  17479:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  17480:     my %staticdefaults = (
                   17481:                            anonsurvey_threshold => 10,
                   17482:                            uploadquota          => 500,
1.257     raeburn  17483:                            postsubmit           => 60,
1.276     raeburn  17484:                            mysqltables          => 172800,
1.198     raeburn  17485:                          );
1.314     raeburn  17486:     my %texoptions = (
                   17487:                         MathJax  => 'MathJax',
                   17488:                         mimetex  => &mt('Convert to Images'),
                   17489:                         tth      => &mt('TeX to HTML'),
                   17490:                      );
1.121     raeburn  17491:     $defaultshash{'coursedefaults'} = {};
                   17492: 
                   17493:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   17494:         if ($domconfig{'coursedefaults'} eq '') {
                   17495:             $domconfig{'coursedefaults'} = {};
                   17496:         }
                   17497:     }
                   17498: 
                   17499:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   17500:         foreach my $item (@toggles) {
                   17501:             if ($defaultchecked{$item} eq 'on') {
                   17502:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17503:                     ($env{'form.'.$item} eq '0')) {
                   17504:                     $changes{$item} = 1;
1.192     raeburn  17505:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  17506:                     $changes{$item} = 1;
                   17507:                 }
                   17508:             } elsif ($defaultchecked{$item} eq 'off') {
                   17509:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17510:                     ($env{'form.'.$item} eq '1')) {
                   17511:                     $changes{$item} = 1;
                   17512:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   17513:                     $changes{$item} = 1;
                   17514:                 }
                   17515:             }
                   17516:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   17517:         }
1.198     raeburn  17518:         foreach my $item (@numbers) {
                   17519:             my ($currdef,$newdef);
1.208     raeburn  17520:             $newdef = $env{'form.'.$item};
1.198     raeburn  17521:             if ($item eq 'anonsurvey_threshold') {
                   17522:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   17523:                 $newdef =~ s/\D//g;
                   17524:                 if ($newdef eq '' || $newdef < 1) {
                   17525:                     $newdef = 1;
                   17526:                 }
                   17527:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   17528:             } else {
1.276     raeburn  17529:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   17530:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   17531:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198     raeburn  17532:                 }
                   17533:                 $newdef =~ s/[^\w.\-]//g;
1.276     raeburn  17534:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198     raeburn  17535:             }
                   17536:             if ($currdef ne $newdef) {
                   17537:                 if ($item eq 'anonsurvey_threshold') {
                   17538:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   17539:                         $changes{$item} = 1;
                   17540:                     }
1.276     raeburn  17541:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289     raeburn  17542:                     my $setting = $1;
1.276     raeburn  17543:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   17544:                         $changes{$setting} = 1;
1.198     raeburn  17545:                     }
                   17546:                 }
1.139     raeburn  17547:             }
                   17548:         }
1.314     raeburn  17549:         my $texengine;
                   17550:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   17551:             $texengine = $env{'form.texengine'};
1.349     raeburn  17552:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   17553:             if ($currdef eq '') {
                   17554:                 unless ($texengine eq $Apache::lonnet::deftex) {
1.314     raeburn  17555:                     $changes{'texengine'} = 1;
                   17556:                 }
1.349     raeburn  17557:             } elsif ($currdef ne $texengine) {
1.314     raeburn  17558:                 $changes{'texengine'} = 1;
                   17559:             }
                   17560:         }
                   17561:         if ($texengine ne '') {
                   17562:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   17563:         }
1.264     raeburn  17564:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   17565:         my @currclonecode;
                   17566:         if (ref($currclone) eq 'HASH') {
                   17567:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   17568:                 @currclonecode = @{$currclone->{'instcode'}};
                   17569:             }
                   17570:         }
                   17571:         my $newclone;
1.289     raeburn  17572:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264     raeburn  17573:             $newclone = $env{'form.canclone'};
                   17574:         }
                   17575:         if ($newclone eq 'instcode') {
                   17576:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   17577:             my (%codedefaults,@code_order,@clonecode);
                   17578:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   17579:                                                     \@code_order);
                   17580:             foreach my $item (@code_order) {
                   17581:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   17582:                     push(@clonecode,$item);
                   17583:                 }
                   17584:             }
                   17585:             if (@clonecode) {
                   17586:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   17587:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   17588:                 if (@diffs) {
                   17589:                     $changes{'canclone'} = 1;
                   17590:                 }
                   17591:             } else {
                   17592:                 $newclone eq '';
                   17593:             }
                   17594:         } elsif ($newclone ne '') {
1.289     raeburn  17595:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   17596:         }
1.264     raeburn  17597:         if ($newclone ne $currclone) {
                   17598:             $changes{'canclone'} = 1;
                   17599:         }
1.257     raeburn  17600:         my %credits;
                   17601:         foreach my $type (@types) {
                   17602:             unless ($type eq 'community') {
                   17603:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   17604:                 $credits{$type} =~ s/[^\d.]+//g;
                   17605:             }
                   17606:         }
                   17607:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   17608:             ($env{'form.coursecredits'} eq '1')) {
                   17609:             $changes{'coursecredits'} = 1;
                   17610:             foreach my $type (keys(%credits)) {
                   17611:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17612:             }
                   17613:         } else {
1.289     raeburn  17614:             if ($env{'form.coursecredits'} eq '1') {
1.257     raeburn  17615:                 foreach my $type (@types) {
                   17616:                     unless ($type eq 'community') {
1.289     raeburn  17617:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257     raeburn  17618:                             $changes{'coursecredits'} = 1;
                   17619:                         }
                   17620:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17621:                     }
                   17622:                 }
                   17623:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17624:                 foreach my $type (@types) {
                   17625:                     unless ($type eq 'community') {
                   17626:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   17627:                             $changes{'coursecredits'} = 1;
                   17628:                             last;
                   17629:                         }
                   17630:                     }
                   17631:                 }
                   17632:             }
                   17633:         }
                   17634:         if ($env{'form.postsubmit'} eq '1') {
                   17635:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   17636:             my %currtimeout;
                   17637:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17638:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   17639:                     $changes{'postsubmit'} = 1;
                   17640:                 }
                   17641:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17642:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   17643:                 }
                   17644:             } else {
                   17645:                 $changes{'postsubmit'} = 1;
                   17646:             }
                   17647:             foreach my $type (@types) {
                   17648:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   17649:                 $timeout =~ s/\D//g;
                   17650:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   17651:                     $timeout = '';
                   17652:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   17653:                     $timeout = '0';
                   17654:                 }
                   17655:                 unless ($timeout eq '') {
                   17656:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   17657:                 }
                   17658:                 if (exists($currtimeout{$type})) {
                   17659:                     if ($timeout ne $currtimeout{$type}) {
1.289     raeburn  17660:                         $changes{'postsubmit'} = 1;
1.257     raeburn  17661:                     }
                   17662:                 } elsif ($timeout ne '') {
                   17663:                     $changes{'postsubmit'} = 1;
                   17664:                 }
                   17665:             }
                   17666:         } else {
                   17667:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   17668:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17669:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   17670:                     $changes{'postsubmit'} = 1;
                   17671:                 }
                   17672:             } else {
                   17673:                 $changes{'postsubmit'} = 1;
                   17674:             }
1.192     raeburn  17675:         }
1.121     raeburn  17676:     }
                   17677:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   17678:                                              $dom);
                   17679:     if ($putresult eq 'ok') {
                   17680:         if (keys(%changes) > 0) {
1.213     raeburn  17681:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  17682:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  17683:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.314     raeburn  17684:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   17685:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme','texengine') {
1.257     raeburn  17686:                     if ($changes{$item}) {
                   17687:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   17688:                     }
1.289     raeburn  17689:                 }
1.192     raeburn  17690:                 if ($changes{'coursecredits'}) {
                   17691:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  17692:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   17693:                             $domdefaults{$type.'credits'} =
                   17694:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   17695:                         }
                   17696:                     }
                   17697:                 }
                   17698:                 if ($changes{'postsubmit'}) {
                   17699:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17700:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   17701:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17702:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   17703:                                 $domdefaults{$type.'postsubtimeout'} =
                   17704:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17705:                             }
                   17706:                         }
1.192     raeburn  17707:                     }
                   17708:                 }
1.198     raeburn  17709:                 if ($changes{'uploadquota'}) {
                   17710:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17711:                         foreach my $type (@types) {
                   17712:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   17713:                         }
                   17714:                     }
                   17715:                 }
1.264     raeburn  17716:                 if ($changes{'canclone'}) {
                   17717:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17718:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17719:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   17720:                             if (@clonecodes) {
                   17721:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   17722:                             }
                   17723:                         }
                   17724:                     } else {
                   17725:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   17726:                     }
                   17727:                 }
1.121     raeburn  17728:                 my $cachetime = 24*60*60;
                   17729:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  17730:                 if (ref($lastactref) eq 'HASH') {
                   17731:                     $lastactref->{'domdefaults'} = 1;
                   17732:                 }
1.121     raeburn  17733:             }
                   17734:             $resulttext = &mt('Changes made:').'<ul>';
                   17735:             foreach my $item (sort(keys(%changes))) {
                   17736:                 if ($item eq 'canuse_pdfforms') {
                   17737:                     if ($env{'form.'.$item} eq '1') {
                   17738:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   17739:                     } else {
                   17740:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   17741:                     }
1.257     raeburn  17742:                 } elsif ($item eq 'uselcmath') {
                   17743:                     if ($env{'form.'.$item} eq '1') {
                   17744:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   17745:                     } else {
                   17746:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   17747:                     }
                   17748:                 } elsif ($item eq 'usejsme') {
                   17749:                     if ($env{'form.'.$item} eq '1') {
                   17750:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   17751:                     } else {
1.289     raeburn  17752:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257     raeburn  17753:                     }
1.314     raeburn  17754:                 } elsif ($item eq 'texengine') {
                   17755:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   17756:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   17757:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   17758:                     }
1.139     raeburn  17759:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  17760:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  17761:                 } elsif ($item eq 'uploadquota') {
                   17762:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17763:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   17764:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   17765:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  17766:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  17767:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  17768:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   17769:                                        '</ul>'.
                   17770:                                        '</li>';
                   17771:                     } else {
                   17772:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   17773:                     }
1.276     raeburn  17774:                 } elsif ($item eq 'mysqltables') {
                   17775:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   17776:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   17777:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   17778:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   17779:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   17780:                                        '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
                   17781:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   17782:                                        '</ul>'.
                   17783:                                        '</li>';
                   17784:                     } else {
                   17785:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   17786:                     }
1.257     raeburn  17787:                 } elsif ($item eq 'postsubmit') {
                   17788:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   17789:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   17790:                     } else {
                   17791:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289     raeburn  17792:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257     raeburn  17793:                             $resulttext .= &mt('durations:').'<ul>';
                   17794:                             foreach my $type (@types) {
                   17795:                                 $resulttext .= '<li>';
                   17796:                                 my $timeout;
                   17797:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17798:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17799:                                 }
                   17800:                                 my $display;
                   17801:                                 if ($timeout eq '0') {
                   17802:                                     $display = &mt('unlimited');
                   17803:                                 } elsif ($timeout eq '') {
                   17804:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   17805:                                 } else {
                   17806:                                     $display = &mt('[quant,_1,second]',$timeout);
                   17807:                                 }
                   17808:                                 if ($type eq 'community') {
                   17809:                                     $resulttext .= &mt('Communities');
                   17810:                                 } elsif ($type eq 'official') {
                   17811:                                     $resulttext .= &mt('Official courses');
                   17812:                                 } elsif ($type eq 'unofficial') {
                   17813:                                     $resulttext .= &mt('Unofficial courses');
                   17814:                                 } elsif ($type eq 'textbook') {
                   17815:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  17816:                                 } elsif ($type eq 'placement') {
                   17817:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  17818:                                 }
                   17819:                                 $resulttext .= ' -- '.$display.'</li>';
                   17820:                             }
                   17821:                             $resulttext .= '</ul>';
                   17822:                         }
1.289     raeburn  17823:                         $resulttext .= '</li>';
1.257     raeburn  17824:                     }
1.192     raeburn  17825:                 } elsif ($item eq 'coursecredits') {
                   17826:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17827:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  17828:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   17829:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  17830:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17831:                         } else {
                   17832:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   17833:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   17834:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  17835:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  17836:                                            '</ul>'.
                   17837:                                            '</li>';
                   17838:                         }
                   17839:                     } else {
                   17840:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17841:                     }
1.264     raeburn  17842:                 } elsif ($item eq 'canclone') {
                   17843:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17844:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17845:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   17846:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   17847:                         }
                   17848:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   17849:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   17850:                     } else {
1.289     raeburn  17851:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264     raeburn  17852:                     }
1.140     raeburn  17853:                 }
1.121     raeburn  17854:             }
                   17855:             $resulttext .= '</ul>';
                   17856:         } else {
                   17857:             $resulttext = &mt('No changes made to course defaults');
                   17858:         }
                   17859:     } else {
                   17860:         $resulttext = '<span class="LC_error">'.
                   17861:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17862:     }
                   17863:     return $resulttext;
                   17864: }
                   17865: 
1.231     raeburn  17866: sub modify_selfenrollment {
                   17867:     my ($dom,$lastactref,%domconfig) = @_;
                   17868:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  17869:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  17870:     my %titles = &tool_titles();
1.232     raeburn  17871:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   17872:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  17873:     $ordered{'default'} = ['types','registered','approval','limit'];
                   17874: 
                   17875:     my (%roles,%shown,%toplevel);
                   17876:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   17877: 
                   17878:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   17879:         if ($domconfig{'selfenrollment'} eq '') {
                   17880:             $domconfig{'selfenrollment'} = {};
                   17881:         }
                   17882:     }
                   17883:     %toplevel = (
                   17884:                   admin      => 'Configuration Rights',
                   17885:                   default    => 'Default settings',
                   17886:                   validation => 'Validation of self-enrollment requests',
                   17887:                 );
1.233     raeburn  17888:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  17889: 
                   17890:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   17891:         foreach my $item (@{$ordered{'admin'}}) {
                   17892:             foreach my $type (@types) {
                   17893:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   17894:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   17895:                 } else {
                   17896:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   17897:                 }
                   17898:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   17899:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   17900:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   17901:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   17902:                             push(@{$changes{'admin'}{$type}},$item);
                   17903:                         }
                   17904:                     } else {
                   17905:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17906:                             push(@{$changes{'admin'}{$type}},$item);
                   17907:                         }
                   17908:                     }
                   17909:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17910:                     push(@{$changes{'admin'}{$type}},$item);
                   17911:                 }
                   17912:             }
                   17913:         }
                   17914:     }
                   17915: 
                   17916:     foreach my $item (@{$ordered{'default'}}) {
                   17917:         foreach my $type (@types) {
                   17918:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   17919:             if ($item eq 'types') {
                   17920:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   17921:                     $value = '';
                   17922:                 }
                   17923:             } elsif ($item eq 'registered') {
                   17924:                 unless ($value eq '1') {
                   17925:                     $value = 0;
                   17926:                 }
                   17927:             } elsif ($item eq 'approval') {
                   17928:                 unless ($value =~ /^[012]$/) {
                   17929:                     $value = 0;
                   17930:                 }
                   17931:             } else {
                   17932:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   17933:                     $value = 'none';
                   17934:                 }
                   17935:             }
                   17936:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   17937:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   17938:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   17939:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   17940:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   17941:                          push(@{$changes{'default'}{$type}},$item);
                   17942:                     }
                   17943:                 } else {
                   17944:                     push(@{$changes{'default'}{$type}},$item);
                   17945:                 }
                   17946:             } else {
                   17947:                 push(@{$changes{'default'}{$type}},$item);
                   17948:             }
                   17949:             if ($item eq 'limit') {
                   17950:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   17951:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   17952:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   17953:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   17954:                     }
                   17955:                 } else {
                   17956:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   17957:                 }
                   17958:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   17959:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   17960:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   17961:                          push(@{$changes{'default'}{$type}},'cap');
                   17962:                     }
                   17963:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   17964:                     push(@{$changes{'default'}{$type}},'cap');
                   17965:                 }
                   17966:             }
                   17967:         }
                   17968:     }
                   17969: 
                   17970:     foreach my $item (@{$itemsref}) {
                   17971:         if ($item eq 'fields') {
                   17972:             my @changed;
                   17973:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   17974:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   17975:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   17976:             }
                   17977:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   17978:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   17979:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   17980:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   17981:                 } else {
                   17982:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   17983:                 }
                   17984:             } else {
                   17985:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   17986:             }
                   17987:             if (@changed) {
                   17988:                 if ($selfenrollhash{'validation'}{$item}) { 
                   17989:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   17990:                 } else {
                   17991:                     $changes{'validation'}{$item} = &mt('None');
                   17992:                 }
                   17993:             }
                   17994:         } else {
                   17995:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   17996:             if ($item eq 'markup') {
                   17997:                if ($env{'form.selfenroll_validation_'.$item}) {
                   17998:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   17999:                }
                   18000:             }
                   18001:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   18002:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   18003:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   18004:                 }
                   18005:             }
                   18006:         }
                   18007:     }
                   18008: 
                   18009:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   18010:                                              $dom);
                   18011:     if ($putresult eq 'ok') {
                   18012:         if (keys(%changes) > 0) {
                   18013:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18014:             $resulttext = &mt('Changes made:').'<ul>';
                   18015:             foreach my $key ('admin','default','validation') {
                   18016:                 if (ref($changes{$key}) eq 'HASH') {
                   18017:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   18018:                     if ($key eq 'validation') {
                   18019:                         foreach my $item (@{$itemsref}) {
                   18020:                             if (exists($changes{$key}{$item})) {
                   18021:                                 if ($item eq 'markup') {
                   18022:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   18023:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   18024:                                 } else {  
                   18025:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   18026:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   18027:                                 }
                   18028:                             }
                   18029:                         }
                   18030:                     } else {
                   18031:                         foreach my $type (@types) {
                   18032:                             if ($type eq 'community') {
                   18033:                                 $roles{'1'} = &mt('Community personnel');
                   18034:                             } else {
                   18035:                                 $roles{'1'} = &mt('Course personnel');
                   18036:                             }
                   18037:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  18038:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   18039:                                     if ($key eq 'admin') {
                   18040:                                         my @mgrdc = ();
                   18041:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   18042:                                             foreach my $item (@{$ordered{'admin'}}) {
                   18043:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   18044:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   18045:                                                         push(@mgrdc,$item);
                   18046:                                                     }
                   18047:                                                 }
                   18048:                                             }
                   18049:                                             if (@mgrdc) {
                   18050:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   18051:                                             } else {
                   18052:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   18053:                                             }
                   18054:                                         }
                   18055:                                     } else {
                   18056:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   18057:                                             foreach my $item (@{$ordered{$key}}) {
                   18058:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   18059:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   18060:                                                         $selfenrollhash{$key}{$type}{$item};
                   18061:                                                 }
                   18062:                                             }
                   18063:                                         }
                   18064:                                     }
                   18065:                                 }
1.231     raeburn  18066:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   18067:                                 foreach my $item (@{$ordered{$key}}) {
                   18068:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   18069:                                         $resulttext .= '<li>';
                   18070:                                         if ($key eq 'admin') {
                   18071:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   18072:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   18073:                                         } else {
                   18074:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   18075:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   18076:                                         }
                   18077:                                         $resulttext .= '</li>';
                   18078:                                     }
                   18079:                                 }
                   18080:                                 $resulttext .= '</ul></li>';
                   18081:                             }
                   18082:                         }
                   18083:                         $resulttext .= '</ul></li>'; 
                   18084:                     }
                   18085:                 }
1.305     raeburn  18086:             }
                   18087:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   18088:                 my $cachetime = 24*60*60;
                   18089:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18090:                 if (ref($lastactref) eq 'HASH') {
                   18091:                     $lastactref->{'domdefaults'} = 1;
1.232     raeburn  18092:                 }
1.231     raeburn  18093:             }
                   18094:             $resulttext .= '</ul>';
                   18095:         } else {
                   18096:             $resulttext = &mt('No changes made to self-enrollment settings');
                   18097:         }
                   18098:     } else {
                   18099:         $resulttext = '<span class="LC_error">'.
                   18100:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18101:     }
                   18102:     return $resulttext;
                   18103: }
                   18104: 
1.137     raeburn  18105: sub modify_usersessions {
1.212     raeburn  18106:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  18107:     my @hostingtypes = ('version','excludedomain','includedomain');
                   18108:     my @offloadtypes = ('primary','default');
                   18109:     my %types = (
                   18110:                   remote => \@hostingtypes,
                   18111:                   hosted => \@hostingtypes,
                   18112:                   spares => \@offloadtypes,
                   18113:                 );
                   18114:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  18115:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275     raeburn  18116:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18117:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138     raeburn  18118:     my @locations = sort(keys(%by_location));
1.137     raeburn  18119:     my (%defaultshash,%changes);
                   18120:     foreach my $prefix (@prefixes) {
                   18121:         $defaultshash{'usersessions'}{$prefix} = {};
                   18122:     }
1.212     raeburn  18123:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  18124:     my $resulttext;
1.138     raeburn  18125:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  18126:     foreach my $prefix (@prefixes) {
1.145     raeburn  18127:         next if ($prefix eq 'spares');
                   18128:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  18129:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18130:             if ($type eq 'version') {
                   18131:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   18132:                 my $okvalue;
                   18133:                 if ($value ne '') {
                   18134:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   18135:                         $okvalue = $value;
                   18136:                     }
                   18137:                 }
                   18138:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18139:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   18140:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   18141:                             if ($inuse == 0) {
                   18142:                                 $changes{$prefix}{$type} = 1;
                   18143:                             } else {
                   18144:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   18145:                                     $changes{$prefix}{$type} = 1;
                   18146:                                 }
                   18147:                                 if ($okvalue ne '') {
                   18148:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18149:                                 } 
                   18150:                             }
                   18151:                         } else {
                   18152:                             if (($inuse == 1) && ($okvalue ne '')) {
                   18153:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18154:                                 $changes{$prefix}{$type} = 1;
                   18155:                             }
                   18156:                         }
                   18157:                     } else {
                   18158:                         if (($inuse == 1) && ($okvalue ne '')) {
                   18159:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18160:                             $changes{$prefix}{$type} = 1;
                   18161:                         }
                   18162:                     }
                   18163:                 } else {
                   18164:                     if (($inuse == 1) && ($okvalue ne '')) {
                   18165:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18166:                         $changes{$prefix}{$type} = 1;
                   18167:                     }
                   18168:                 }
                   18169:             } else {
                   18170:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18171:                 my @okvals;
                   18172:                 foreach my $val (@vals) {
1.138     raeburn  18173:                     if ($val =~ /:/) {
                   18174:                         my @items = split(/:/,$val);
                   18175:                         foreach my $item (@items) {
                   18176:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   18177:                                 push(@okvals,$item);
                   18178:                             }
                   18179:                         }
                   18180:                     } else {
                   18181:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   18182:                             push(@okvals,$val);
                   18183:                         }
1.137     raeburn  18184:                     }
                   18185:                 }
                   18186:                 @okvals = sort(@okvals);
                   18187:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18188:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   18189:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   18190:                             if ($inuse == 0) {
                   18191:                                 $changes{$prefix}{$type} = 1; 
                   18192:                             } else {
                   18193:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18194:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   18195:                                 if (@changed > 0) {
                   18196:                                     $changes{$prefix}{$type} = 1;
                   18197:                                 }
                   18198:                             }
                   18199:                         } else {
                   18200:                             if ($inuse == 1) {
                   18201:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18202:                                 $changes{$prefix}{$type} = 1;
                   18203:                             }
                   18204:                         } 
                   18205:                     } else {
                   18206:                         if ($inuse == 1) {
                   18207:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18208:                             $changes{$prefix}{$type} = 1;
                   18209:                         }
                   18210:                     }
                   18211:                 } else {
                   18212:                     if ($inuse == 1) {
                   18213:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18214:                         $changes{$prefix}{$type} = 1;
                   18215:                     }
                   18216:                 }
                   18217:             }
                   18218:         }
                   18219:     }
1.145     raeburn  18220: 
                   18221:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  18222:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  18223:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   18224:     my $savespares;
                   18225: 
                   18226:     foreach my $lonhost (sort(keys(%servers))) {
                   18227:         my $serverhomeID =
                   18228:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  18229:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  18230:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   18231:         my %spareschg;
                   18232:         foreach my $type (@{$types{'spares'}}) {
                   18233:             my @okspares;
                   18234:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   18235:             foreach my $server (@checked) {
1.152     raeburn  18236:                 if (&Apache::lonnet::hostname($server) ne '') {
                   18237:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   18238:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   18239:                             push(@okspares,$server);
                   18240:                         }
1.145     raeburn  18241:                     }
                   18242:                 }
                   18243:             }
                   18244:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   18245:             my $newspare;
1.152     raeburn  18246:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   18247:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  18248:                     $newspare = $new;
                   18249:                 }
                   18250:             }
1.152     raeburn  18251:             my @spares;
                   18252:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   18253:                 @spares = sort(@okspares,$newspare);
                   18254:             } else {
                   18255:                 @spares = sort(@okspares);
                   18256:             }
                   18257:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  18258:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   18259:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  18260:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  18261:                     if (@diffs > 0) {
                   18262:                         $spareschg{$type} = 1;
                   18263:                     }
                   18264:                 }
                   18265:             }
                   18266:         }
                   18267:         if (keys(%spareschg) > 0) {
                   18268:             $changes{'spares'}{$lonhost} = \%spareschg;
                   18269:         }
                   18270:     }
1.261     raeburn  18271:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   18272:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   18273:     my @okoffload;
                   18274:     if (@offloadnow) {
                   18275:         foreach my $server (@offloadnow) {
                   18276:             if (&Apache::lonnet::hostname($server) ne '') {
                   18277:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   18278:                     push(@okoffload,$server);
                   18279:                 }
                   18280:             }
                   18281:         }
                   18282:         if (@okoffload) {
                   18283:             foreach my $lonhost (@okoffload) {
                   18284:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   18285:             }
                   18286:         }
                   18287:     }
1.145     raeburn  18288:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18289:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   18290:             if (ref($changes{'spares'}) eq 'HASH') {
                   18291:                 if (keys(%{$changes{'spares'}}) > 0) {
                   18292:                     $savespares = 1;
                   18293:                 }
                   18294:             }
                   18295:         } else {
                   18296:             $savespares = 1;
                   18297:         }
1.261     raeburn  18298:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18299:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   18300:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   18301:                     $changes{'offloadnow'} = 1;
                   18302:                     last;
                   18303:                 }
                   18304:             }
                   18305:             unless ($changes{'offloadnow'}) {
1.289     raeburn  18306:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
1.261     raeburn  18307:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   18308:                         $changes{'offloadnow'} = 1;
                   18309:                         last;
                   18310:                     }
                   18311:                 }
                   18312:             }
                   18313:         } elsif (@okoffload) {
                   18314:             $changes{'offloadnow'} = 1;
                   18315:         }
                   18316:     } elsif (@okoffload) {
                   18317:         $changes{'offloadnow'} = 1;
1.145     raeburn  18318:     }
1.147     raeburn  18319:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   18320:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  18321:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18322:                                                  $dom);
                   18323:         if ($putresult eq 'ok') {
                   18324:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18325:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   18326:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   18327:                 }
                   18328:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   18329:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   18330:                 }
1.261     raeburn  18331:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18332:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   18333:                 }
1.137     raeburn  18334:             }
                   18335:             my $cachetime = 24*60*60;
                   18336:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295     raeburn  18337:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212     raeburn  18338:             if (ref($lastactref) eq 'HASH') {
                   18339:                 $lastactref->{'domdefaults'} = 1;
1.295     raeburn  18340:                 $lastactref->{'usersessions'} = 1;
1.212     raeburn  18341:             }
1.147     raeburn  18342:             if (keys(%changes) > 0) {
                   18343:                 my %lt = &usersession_titles();
                   18344:                 $resulttext = &mt('Changes made:').'<ul>';
                   18345:                 foreach my $prefix (@prefixes) {
                   18346:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18347:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   18348:                         if ($prefix eq 'spares') {
                   18349:                             if (ref($changes{$prefix}) eq 'HASH') {
                   18350:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   18351:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  18352:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  18353:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   18354:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  18355:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   18356:                                         foreach my $type (@{$types{$prefix}}) {
                   18357:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   18358:                                                 my $offloadto = &mt('None');
                   18359:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   18360:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   18361:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   18362:                                                     }
1.145     raeburn  18363:                                                 }
1.147     raeburn  18364:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  18365:                                             }
1.137     raeburn  18366:                                         }
                   18367:                                     }
1.147     raeburn  18368:                                     $resulttext .= '</li>';
1.137     raeburn  18369:                                 }
                   18370:                             }
1.147     raeburn  18371:                         } else {
                   18372:                             foreach my $type (@{$types{$prefix}}) {
                   18373:                                 if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18374:                                     my ($newvalue,$notinuse);
1.147     raeburn  18375:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18376:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   18377:                                             if ($type eq 'version') {
                   18378:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344     raeburn  18379:                                             } else {
                   18380:                                                 if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   18381:                                                     if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   18382:                                                         $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   18383:                                                     }
                   18384:                                                 } else {
                   18385:                                                     $notinuse = 1;
1.147     raeburn  18386:                                                 }
1.145     raeburn  18387:                                             }
                   18388:                                         }
                   18389:                                     }
1.147     raeburn  18390:                                     if ($newvalue eq '') {
                   18391:                                         if ($type eq 'version') {
                   18392:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344     raeburn  18393:                                         } elsif ($notinuse) {
                   18394:                                             $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147     raeburn  18395:                                         } else {
                   18396:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   18397:                                         }
1.145     raeburn  18398:                                     } else {
1.147     raeburn  18399:                                         if ($type eq 'version') {
1.344     raeburn  18400:                                             $newvalue .= ' '.&mt('(or later)');
1.147     raeburn  18401:                                         }
                   18402:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  18403:                                     }
1.137     raeburn  18404:                                 }
                   18405:                             }
                   18406:                         }
1.147     raeburn  18407:                         $resulttext .= '</ul>';
1.137     raeburn  18408:                     }
                   18409:                 }
1.261     raeburn  18410:                 if ($changes{'offloadnow'}) {
                   18411:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18412:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   18413:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   18414:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   18415:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   18416:                             }
                   18417:                             $resulttext .= '</ul>';
                   18418:                         } else {
                   18419:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   18420:                         }
                   18421:                     } else {
                   18422:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   18423:                     }
                   18424:                 }
1.147     raeburn  18425:                 $resulttext .= '</ul>';
                   18426:             } else {
                   18427:                 $resulttext = $nochgmsg;
1.137     raeburn  18428:             }
                   18429:         } else {
                   18430:             $resulttext = '<span class="LC_error">'.
                   18431:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18432:         }
                   18433:     } else {
1.147     raeburn  18434:         $resulttext = $nochgmsg;
1.137     raeburn  18435:     }
                   18436:     return $resulttext;
                   18437: }
                   18438: 
1.275     raeburn  18439: sub modify_ssl {
                   18440:     my ($dom,$lastactref,%domconfig) = @_;
                   18441:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18442:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   18443:     my @locations = sort(keys(%by_location));
                   18444:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   18445:     my (%defaultshash,%changes);
                   18446:     my $action = 'ssl';
1.293     raeburn  18447:     my @prefixes = ('connto','connfrom','replication');
1.275     raeburn  18448:     foreach my $prefix (@prefixes) {
                   18449:         $defaultshash{$action}{$prefix} = {};
                   18450:     }
                   18451:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18452:     my $resulttext;
                   18453:     my %iphost = &Apache::lonnet::get_iphost();
                   18454:     my @reptypes = ('certreq','nocertreq');
                   18455:     my @connecttypes = ('dom','intdom','other');
                   18456:     my %types = (
1.293     raeburn  18457:                   connto      => \@connecttypes,
                   18458:                   connfrom    => \@connecttypes,
                   18459:                   replication => \@reptypes,
1.275     raeburn  18460:                 );
                   18461:     foreach my $prefix (sort(keys(%types))) {
                   18462:         foreach my $type (@{$types{$prefix}}) {
1.293     raeburn  18463:             if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  18464:                 my $value = 'yes';
                   18465:                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                   18466:                     $value = $env{'form.'.$prefix.'_'.$type};
                   18467:                 }
1.335     raeburn  18468:                 if (ref($domconfig{$action}) eq 'HASH') {
                   18469:                     if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   18470:                         if ($domconfig{$action}{$prefix}{$type} ne '') {
                   18471:                             if ($value ne $domconfig{$action}{$prefix}{$type}) {
                   18472:                                 $changes{$prefix}{$type} = 1;
                   18473:                             }
                   18474:                             $defaultshash{$action}{$prefix}{$type} = $value;
                   18475:                         } else {
                   18476:                             $defaultshash{$action}{$prefix}{$type} = $value;
1.275     raeburn  18477:                             $changes{$prefix}{$type} = 1;
                   18478:                         }
                   18479:                     } else {
                   18480:                         $defaultshash{$action}{$prefix}{$type} = $value;
                   18481:                         $changes{$prefix}{$type} = 1;
                   18482:                     }
                   18483:                 } else {
                   18484:                     $defaultshash{$action}{$prefix}{$type} = $value;
                   18485:                     $changes{$prefix}{$type} = 1;
                   18486:                 }
                   18487:                 if (($type eq 'dom') && (keys(%servers) == 1)) {
                   18488:                     delete($changes{$prefix}{$type});
                   18489:                 } elsif (($type eq 'intdom') && (@instdoms == 1)) {
                   18490:                     delete($changes{$prefix}{$type});
                   18491:                 } elsif (($type eq 'other') && (keys(%by_location) == 0)) { 
                   18492:                     delete($changes{$prefix}{$type});
                   18493:                 }
                   18494:             } elsif ($prefix eq 'replication') {
                   18495:                 if (@locations > 0) {
                   18496:                     my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18497:                     my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18498:                     my @okvals;
                   18499:                     foreach my $val (@vals) {
                   18500:                         if ($val =~ /:/) {
                   18501:                             my @items = split(/:/,$val);
                   18502:                             foreach my $item (@items) {
                   18503:                                 if (ref($by_location{$item}) eq 'ARRAY') {
                   18504:                                     push(@okvals,$item);
                   18505:                                 }
                   18506:                             }
                   18507:                         } else {
                   18508:                             if (ref($by_location{$val}) eq 'ARRAY') {
                   18509:                                 push(@okvals,$val);
                   18510:                             }
                   18511:                         }
                   18512:                     }
                   18513:                     @okvals = sort(@okvals);
                   18514:                     if (ref($domconfig{$action}) eq 'HASH') {
                   18515:                         if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                   18516:                             if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
                   18517:                                 if ($inuse == 0) {
                   18518:                                     $changes{$prefix}{$type} = 1;
                   18519:                                 } else {
                   18520:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18521:                                     my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
                   18522:                                     if (@changed > 0) {
                   18523:                                         $changes{$prefix}{$type} = 1;
                   18524:                                     }
                   18525:                                 }
                   18526:                             } else {
                   18527:                                 if ($inuse == 1) {
                   18528:                                     $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18529:                                     $changes{$prefix}{$type} = 1;
                   18530:                                 }
                   18531:                             }
                   18532:                         } else {
                   18533:                             if ($inuse == 1) {
                   18534:                                 $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18535:                                 $changes{$prefix}{$type} = 1;
                   18536:                             }
                   18537:                         }
                   18538:                     } else {
                   18539:                         if ($inuse == 1) {
                   18540:                             $defaultshash{$action}{$prefix}{$type} = \@okvals;
                   18541:                             $changes{$prefix}{$type} = 1;
                   18542:                         }
                   18543:                     }
                   18544:                 }
                   18545:             }
                   18546:         }
                   18547:     }
1.336     raeburn  18548:     if (keys(%changes)) {
                   18549:         foreach my $prefix (keys(%changes)) {
                   18550:             if (ref($changes{$prefix}) eq 'HASH') {
                   18551:                 if (scalar(keys(%{$changes{$prefix}})) == 0) {
                   18552:                     delete($changes{$prefix});
                   18553:                 }
                   18554:             } else {
                   18555:                 delete($changes{$prefix});
                   18556:             }
                   18557:         }
                   18558:     }
1.275     raeburn  18559:     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
                   18560:     if (keys(%changes) > 0) {
                   18561:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18562:                                                  $dom);
                   18563:         if ($putresult eq 'ok') {
                   18564:             if (ref($defaultshash{$action}) eq 'HASH') {
                   18565:                 if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
                   18566:                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                   18567:                 }
1.293     raeburn  18568:                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335     raeburn  18569:                     $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293     raeburn  18570:                 }
                   18571:                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335     raeburn  18572:                     $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275     raeburn  18573:                 }
                   18574:             }
                   18575:             my $cachetime = 24*60*60;
                   18576:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18577:             if (ref($lastactref) eq 'HASH') {
                   18578:                 $lastactref->{'domdefaults'} = 1;
                   18579:             }
                   18580:             if (keys(%changes) > 0) {
                   18581:                 my %titles = &ssl_titles();
                   18582:                 $resulttext = &mt('Changes made:').'<ul>';
                   18583:                 foreach my $prefix (@prefixes) {
                   18584:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18585:                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                   18586:                         foreach my $type (@{$types{$prefix}}) {
                   18587:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18588:                                 my ($newvalue,$notinuse);
1.275     raeburn  18589:                                 if (ref($defaultshash{$action}) eq 'HASH') {
                   18590:                                     if (ref($defaultshash{$action}{$prefix})) {
1.293     raeburn  18591:                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275     raeburn  18592:                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344     raeburn  18593:                                         } else {
                   18594:                                             if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                   18595:                                                 if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                   18596:                                                     $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                   18597:                                                 }
                   18598:                                             } else {
                   18599:                                                 $notinuse = 1;
1.275     raeburn  18600:                                             }
                   18601:                                         }
                   18602:                                     }
1.344     raeburn  18603:                                     if ($notinuse) {
                   18604:                                         $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                   18605:                                     } elsif ($newvalue eq '') {
1.275     raeburn  18606:                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                   18607:                                     } else {
                   18608:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
                   18609:                                     }
                   18610:                                 }
                   18611:                             }
                   18612:                         }
                   18613:                         $resulttext .= '</ul>';
                   18614:                     }
                   18615:                 }
                   18616:             } else {
                   18617:                 $resulttext = $nochgmsg;
                   18618:             }
                   18619:         } else {
                   18620:             $resulttext = '<span class="LC_error">'.
                   18621:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18622:         }
                   18623:     } else {
                   18624:         $resulttext = $nochgmsg;
                   18625:     }
                   18626:     return $resulttext;
                   18627: }
                   18628: 
1.279     raeburn  18629: sub modify_trust {
                   18630:     my ($dom,$lastactref,%domconfig) = @_;
                   18631:     my (%by_ip,%by_location,@intdoms,@instdoms);
                   18632:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
                   18633:     my @locations = sort(keys(%by_location));
                   18634:     my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
                   18635:     my @types = ('exc','inc');
                   18636:     my (%defaultshash,%changes);
                   18637:     foreach my $prefix (@prefixes) {
                   18638:         $defaultshash{'trust'}{$prefix} = {};
                   18639:     }
                   18640:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18641:     my $resulttext;
                   18642:     foreach my $prefix (@prefixes) {
                   18643:         foreach my $type (@types) {
                   18644:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18645:             my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18646:             my @okvals;
                   18647:             foreach my $val (@vals) {
                   18648:                 if ($val =~ /:/) {
                   18649:                     my @items = split(/:/,$val);
                   18650:                     foreach my $item (@items) {
                   18651:                         if (ref($by_location{$item}) eq 'ARRAY') {
                   18652:                             push(@okvals,$item);
                   18653:                         }
                   18654:                     }
                   18655:                 } else {
                   18656:                     if (ref($by_location{$val}) eq 'ARRAY') {
                   18657:                         push(@okvals,$val);
                   18658:                     }
                   18659:                 }
                   18660:             }
                   18661:             @okvals = sort(@okvals);
                   18662:             if (ref($domconfig{'trust'}) eq 'HASH') {
                   18663:                 if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
                   18664:                     if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   18665:                         if ($inuse == 0) {
                   18666:                             $changes{$prefix}{$type} = 1;
                   18667:                         } else {
                   18668:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18669:                             my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
                   18670:                             if (@changed > 0) {
                   18671:                                 $changes{$prefix}{$type} = 1;
                   18672:                             }
                   18673:                         }
                   18674:                     } else {
                   18675:                         if ($inuse == 1) {
                   18676:                             $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18677:                             $changes{$prefix}{$type} = 1;
                   18678:                         }
                   18679:                     }
                   18680:                 } else {
                   18681:                     if ($inuse == 1) {
                   18682:                         $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18683:                         $changes{$prefix}{$type} = 1;
                   18684:                     }
                   18685:                 }
                   18686:             } else {
                   18687:                 if ($inuse == 1) {
                   18688:                     $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
                   18689:                     $changes{$prefix}{$type} = 1;
                   18690:                 }
                   18691:             }
                   18692:         }
                   18693:     }
                   18694:     my $nochgmsg = &mt('No changes made to trust settings.');
                   18695:     if (keys(%changes) > 0) {
                   18696:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18697:                                                  $dom);
                   18698:         if ($putresult eq 'ok') {
                   18699:             if (ref($defaultshash{'trust'}) eq 'HASH') {
                   18700:                 foreach my $prefix (@prefixes) {
                   18701:                     if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
                   18702:                         $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
                   18703:                     }
                   18704:                 }
                   18705:             }
                   18706:             my $cachetime = 24*60*60;
                   18707:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18708:             if (ref($lastactref) eq 'HASH') {
                   18709:                 $lastactref->{'domdefaults'} = 1;
                   18710:             }
                   18711:             if (keys(%changes) > 0) {
                   18712:                 my %lt = &trust_titles();
                   18713:                 $resulttext = &mt('Changes made:').'<ul>';
                   18714:                 foreach my $prefix (@prefixes) {
                   18715:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18716:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   18717:                         foreach my $type (@types) {
                   18718:                             if (defined($changes{$prefix}{$type})) {
1.344     raeburn  18719:                                 my ($newvalue,$notinuse);
1.279     raeburn  18720:                                 if (ref($defaultshash{'trust'}) eq 'HASH') {
                   18721:                                     if (ref($defaultshash{'trust'}{$prefix})) {
                   18722:                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                   18723:                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                   18724:                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                   18725:                                             }
1.344     raeburn  18726:                                         } else {
                   18727:                                             $notinuse = 1;
1.279     raeburn  18728:                                         }
                   18729:                                     }
                   18730:                                 }
1.344     raeburn  18731:                                 if ($notinuse) {
                   18732:                                     $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                   18733:                                 } elsif ($newvalue eq '') {
1.279     raeburn  18734:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   18735:                                 } else {
                   18736:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                   18737:                                 }
                   18738:                             }
                   18739:                         }
                   18740:                         $resulttext .= '</ul>';
                   18741:                     }
                   18742:                 }
                   18743:                 $resulttext .= '</ul>';
                   18744:             } else {
                   18745:                 $resulttext = $nochgmsg;
                   18746:             }
                   18747:         } else {
                   18748:             $resulttext = '<span class="LC_error">'.
                   18749:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18750:         }
                   18751:     } else {
                   18752:         $resulttext = $nochgmsg;
                   18753:     }
                   18754:     return $resulttext;
                   18755: }
                   18756: 
1.150     raeburn  18757: sub modify_loadbalancing {
                   18758:     my ($dom,%domconfig) = @_;
                   18759:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   18760:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   18761:     my ($othertitle,$usertypes,$types) =
                   18762:         &Apache::loncommon::sorted_inst_types($dom);
                   18763:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  18764:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  18765:     my @sparestypes = ('primary','default');
                   18766:     my %typetitles = &sparestype_titles();
                   18767:     my $resulttext;
1.342     raeburn  18768:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  18769:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18770:         %existing = %{$domconfig{'loadbalancing'}};
                   18771:     }
                   18772:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342     raeburn  18773:                               \%currtargets,\%currrules,\%currcookies);
1.171     raeburn  18774:     my ($saveloadbalancing,%defaultshash,%changes);
                   18775:     my ($alltypes,$othertypes,$titles) =
                   18776:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   18777:     my %ruletitles = &offloadtype_text();
                   18778:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   18779:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   18780:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   18781:         if ($balancer eq '') {
                   18782:             next;
                   18783:         }
1.210     raeburn  18784:         if (!exists($servers{$balancer})) {
1.171     raeburn  18785:             if (exists($currbalancer{$balancer})) {
                   18786:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  18787:             }
1.171     raeburn  18788:             next;
                   18789:         }
                   18790:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   18791:             push(@{$changes{'delete'}},$balancer);
                   18792:             next;
                   18793:         }
                   18794:         if (!exists($currbalancer{$balancer})) {
                   18795:             push(@{$changes{'add'}},$balancer);
                   18796:         }
                   18797:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   18798:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   18799:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   18800:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18801:             $saveloadbalancing = 1;
                   18802:         }
                   18803:         foreach my $sparetype (@sparestypes) {
                   18804:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   18805:             my @offloadto;
                   18806:             foreach my $target (@targets) {
                   18807:                 if (($servers{$target}) && ($target ne $balancer)) {
                   18808:                     if ($sparetype eq 'default') {
                   18809:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   18810:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  18811:                         }
                   18812:                     }
1.171     raeburn  18813:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   18814:                         push(@offloadto,$target);
                   18815:                     }
1.150     raeburn  18816:                 }
                   18817:             }
1.284     raeburn  18818:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   18819:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   18820:                     push(@offloadto,$balancer);
                   18821:                 }
                   18822:             }
                   18823:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  18824:         }
1.342     raeburn  18825:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   18826:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   18827:             if (exists($currbalancer{$balancer})) { 
                   18828:                 unless ($currcookies{$balancer}) {
                   18829:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18830:                 }
                   18831:             }
                   18832:         } elsif (exists($currbalancer{$balancer})) {
                   18833:             if ($currcookies{$balancer}) {
                   18834:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18835:             }
                   18836:         }
1.171     raeburn  18837:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  18838:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  18839:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   18840:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  18841:                     if (@targetdiffs > 0) {
1.171     raeburn  18842:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18843:                     }
1.171     raeburn  18844:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18845:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18846:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18847:                     }
                   18848:                 }
                   18849:             }
                   18850:         } else {
1.171     raeburn  18851:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  18852:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  18853:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18854:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18855:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   18856:                         }
1.150     raeburn  18857:                     }
                   18858:                 }
1.210     raeburn  18859:             }
1.150     raeburn  18860:         }
                   18861:         my $ishomedom;
1.171     raeburn  18862:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   18863:             $ishomedom = 1;
1.150     raeburn  18864:         }
                   18865:         if (ref($alltypes) eq 'ARRAY') {
                   18866:             foreach my $type (@{$alltypes}) {
                   18867:                 my $rule;
1.210     raeburn  18868:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  18869:                          (!$ishomedom)) {
1.171     raeburn  18870:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   18871:                 }
                   18872:                 if ($rule eq 'specific') {
1.255     raeburn  18873:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289     raeburn  18874:                     if (exists($servers{$specifiedhost})) {
1.255     raeburn  18875:                         $rule = $specifiedhost;
                   18876:                     }
1.150     raeburn  18877:                 }
1.171     raeburn  18878:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   18879:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   18880:                     if ($rule ne $currrules{$balancer}{$type}) {
                   18881:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18882:                     }
                   18883:                 } elsif ($rule ne '') {
1.171     raeburn  18884:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18885:                 }
                   18886:             }
                   18887:         }
1.171     raeburn  18888:     }
                   18889:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   18890:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   18891:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   18892:             $defaultshash{'loadbalancing'} = {};
                   18893:         }
                   18894:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   18895:                                                  \%defaultshash,$dom);
                   18896:         if ($putresult eq 'ok') {
                   18897:             if (keys(%changes) > 0) {
1.252     raeburn  18898:                 my %toupdate;
1.171     raeburn  18899:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   18900:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   18901:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  18902:                         $toupdate{$balancer} = 1;
1.150     raeburn  18903:                     }
1.171     raeburn  18904:                 }
                   18905:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  18906:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  18907:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  18908:                         $toupdate{$balancer} = 1;
1.171     raeburn  18909:                     }
                   18910:                 }
                   18911:                 if (ref($changes{'curr'}) eq 'HASH') {
                   18912:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  18913:                         $toupdate{$balancer} = 1;
1.171     raeburn  18914:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   18915:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   18916:                                 my %offloadstr;
                   18917:                                 foreach my $sparetype (@sparestypes) {
                   18918:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18919:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18920:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   18921:                                         }
                   18922:                                     }
1.150     raeburn  18923:                                 }
1.171     raeburn  18924:                                 if (keys(%offloadstr) == 0) {
                   18925:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  18926:                                 } else {
1.171     raeburn  18927:                                     my $showoffload;
                   18928:                                     foreach my $sparetype (@sparestypes) {
                   18929:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   18930:                                         if (defined($offloadstr{$sparetype})) {
                   18931:                                             $showoffload .= $offloadstr{$sparetype};
                   18932:                                         } else {
                   18933:                                             $showoffload .= &mt('None');
                   18934:                                         }
                   18935:                                         $showoffload .= ('&nbsp;'x3);
                   18936:                                     }
                   18937:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  18938:                                 }
                   18939:                             }
                   18940:                         }
1.171     raeburn  18941:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   18942:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   18943:                                 foreach my $type (@{$alltypes}) {
                   18944:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   18945:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   18946:                                         my $balancetext;
                   18947:                                         if ($rule eq '') {
                   18948:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  18949:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289     raeburn  18950:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254     raeburn  18951:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  18952:                                                 foreach my $sparetype (@sparestypes) {
                   18953:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18954:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   18955:                                                     }
                   18956:                                                 }
1.253     raeburn  18957:                                                 foreach my $item (@{$alltypes}) {
                   18958:                                                     next if ($item =~  /^_LC_ipchange/);
                   18959:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   18960:                                                     if ($hasrule eq 'homeserver') {
                   18961:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   18962:                                                     } else {
                   18963:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   18964:                                                             if ($servers{$hasrule}) {
                   18965:                                                                 $toupdate{$hasrule} = 1;
                   18966:                                                             }
                   18967:                                                         }
                   18968:                                                     }
                   18969:                                                 }
1.254     raeburn  18970:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   18971:                                                     $balancetext =  $ruletitles{$rule};
                   18972:                                                 } else {
                   18973:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   18974:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   18975:                                                     if ($receiver) {
                   18976:                                                         $toupdate{$receiver};
                   18977:                                                     }
                   18978:                                                 }
                   18979:                                             } else {
                   18980:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  18981:                                             }
1.171     raeburn  18982:                                         } else {
                   18983:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   18984:                                         }
1.210     raeburn  18985:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  18986:                                     }
                   18987:                                 }
                   18988:                             }
                   18989:                         }
1.342     raeburn  18990:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
                   18991:                             $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   18992:                                                       $balancer).'</li>'; 
                   18993:                         }
1.252     raeburn  18994:                         if (keys(%toupdate)) {
                   18995:                             my %thismachine;
                   18996:                             my $updatedhere;
                   18997:                             my $cachetime = 60*60*24;
                   18998:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   18999:                             foreach my $lonhost (keys(%toupdate)) {
                   19000:                                 if ($thismachine{$lonhost}) {
                   19001:                                     unless ($updatedhere) {
                   19002:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   19003:                                                                       $defaultshash{'loadbalancing'},
                   19004:                                                                       $cachetime);
                   19005:                                         $updatedhere = 1;
                   19006:                                     }
                   19007:                                 } else {
                   19008:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   19009:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   19010:                                 }
                   19011:                             }
                   19012:                         }
1.150     raeburn  19013:                     }
1.171     raeburn  19014:                 }
                   19015:                 if ($resulttext ne '') {
                   19016:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  19017:                 } else {
                   19018:                     $resulttext = $nochgmsg;
                   19019:                 }
                   19020:             } else {
1.171     raeburn  19021:                 $resulttext = $nochgmsg;
1.150     raeburn  19022:             }
                   19023:         } else {
1.171     raeburn  19024:             $resulttext = '<span class="LC_error">'.
                   19025:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  19026:         }
                   19027:     } else {
1.171     raeburn  19028:         $resulttext = $nochgmsg;
1.150     raeburn  19029:     }
                   19030:     return $resulttext;
                   19031: }
                   19032: 
1.48      raeburn  19033: sub recurse_check {
                   19034:     my ($chkcats,$categories,$depth,$name) = @_;
                   19035:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   19036:         my $chg = 0;
                   19037:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   19038:             my $category = $chkcats->[$depth]{$name}[$j];
                   19039:             my $item;
                   19040:             if ($category eq '') {
                   19041:                 $chg ++;
                   19042:             } else {
                   19043:                 my $deeper = $depth + 1;
                   19044:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   19045:                 if ($chg) {
                   19046:                     $categories->{$item} -= $chg;
                   19047:                 }
                   19048:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   19049:                 $deeper --;
                   19050:             }
                   19051:         }
                   19052:     }
                   19053:     return;
                   19054: }
                   19055: 
                   19056: sub recurse_cat_deletes {
                   19057:     my ($item,$coursecategories,$deletions) = @_;
                   19058:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   19059:     my $subdepth = $depth + 1;
                   19060:     if (ref($coursecategories) eq 'HASH') {
                   19061:         foreach my $subitem (keys(%{$coursecategories})) {
                   19062:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   19063:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   19064:                 delete($coursecategories->{$subitem});
                   19065:                 $deletions->{$subitem} = 1;
                   19066:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  19067:             }
1.48      raeburn  19068:         }
                   19069:     }
                   19070:     return;
                   19071: }
                   19072: 
1.125     raeburn  19073: sub active_dc_picker {
1.191     raeburn  19074:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287     raeburn  19075:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191     raeburn  19076:     my @domcoord = keys(%domcoords);
                   19077:     if (keys(%currhash)) {
                   19078:         foreach my $dc (keys(%currhash)) {
                   19079:             unless (exists($domcoords{$dc})) {
                   19080:                 push(@domcoord,$dc);
                   19081:             }
                   19082:         }
                   19083:     }
                   19084:     @domcoord = sort(@domcoord);
1.210     raeburn  19085:     my $numdcs = scalar(@domcoord);
1.191     raeburn  19086:     my $rows = 0;
                   19087:     my $table;
1.125     raeburn  19088:     if ($numdcs > 1) {
1.191     raeburn  19089:         $table = '<table>';
                   19090:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  19091:             my $rem = $i%($numinrow);
                   19092:             if ($rem == 0) {
                   19093:                 if ($i > 0) {
1.191     raeburn  19094:                     $table .= '</tr>';
1.125     raeburn  19095:                 }
1.191     raeburn  19096:                 $table .= '<tr>';
                   19097:                 $rows ++;
1.125     raeburn  19098:             }
1.191     raeburn  19099:             my $check = '';
                   19100:             if ($inputtype eq 'radio') {
                   19101:                 if (keys(%currhash) == 0) {
                   19102:                     if (!$i) {
                   19103:                         $check = ' checked="checked"';
                   19104:                     }
                   19105:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   19106:                     $check = ' checked="checked"';
                   19107:                 }
                   19108:             } else {
                   19109:                 if (exists($currhash{$domcoord[$i]})) {
                   19110:                     $check = ' checked="checked"';
1.125     raeburn  19111:                 }
                   19112:             }
1.191     raeburn  19113:             if ($i == @domcoord - 1) {
1.125     raeburn  19114:                 my $colsleft = $numinrow - $rem;
                   19115:                 if ($colsleft > 1) {
1.191     raeburn  19116:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  19117:                 } else {
1.191     raeburn  19118:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  19119:                 }
                   19120:             } else {
1.191     raeburn  19121:                 $table .= '<td class="LC_left_item">';
                   19122:             }
                   19123:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   19124:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   19125:             $table .= '<span class="LC_nobreak"><label>'.
                   19126:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   19127:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   19128:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  19129:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  19130:             }
1.219     raeburn  19131:             $table .= '</label></span></td>';
1.191     raeburn  19132:         }
                   19133:         $table .= '</tr></table>';
                   19134:     } elsif ($numdcs == 1) {
1.219     raeburn  19135:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   19136:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  19137:         if ($inputtype eq 'radio') {
1.247     raeburn  19138:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  19139:             if ($user ne $dcname.':'.$dcdom) {
                   19140:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   19141:             }
1.191     raeburn  19142:         } else {
                   19143:             my $check;
                   19144:             if (exists($currhash{$domcoord[0]})) {
                   19145:                 $check = ' checked="checked"';
1.125     raeburn  19146:             }
1.247     raeburn  19147:             $table = '<span class="LC_nobreak"><label>'.
                   19148:                      '<input type="checkbox" name="'.$name.'" '.
                   19149:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  19150:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  19151:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  19152:             }
1.220     raeburn  19153:             $table .= '</label></span>';
1.191     raeburn  19154:             $rows ++;
1.125     raeburn  19155:         }
                   19156:     }
1.191     raeburn  19157:     return ($numdcs,$table,$rows);
1.125     raeburn  19158: }
                   19159: 
1.137     raeburn  19160: sub usersession_titles {
                   19161:     return &Apache::lonlocal::texthash(
                   19162:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   19163:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  19164:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  19165:                version => 'LON-CAPA version requirement',
1.138     raeburn  19166:                excludedomain => 'Allow all, but exclude specific domains',
                   19167:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  19168:                primary => 'Primary (checked first)',
1.154     raeburn  19169:                default => 'Default',
1.137     raeburn  19170:            );
                   19171: }
                   19172: 
1.152     raeburn  19173: sub id_for_thisdom {
                   19174:     my (%servers) = @_;
                   19175:     my %altids;
                   19176:     foreach my $server (keys(%servers)) {
                   19177:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   19178:         if ($serverhome ne $server) {
                   19179:             $altids{$serverhome} = $server;
                   19180:         }
                   19181:     }
                   19182:     return %altids;
                   19183: }
                   19184: 
1.150     raeburn  19185: sub count_servers {
                   19186:     my ($currbalancer,%servers) = @_;
                   19187:     my (@spares,$numspares);
                   19188:     foreach my $lonhost (sort(keys(%servers))) {
                   19189:         next if ($currbalancer eq $lonhost);
                   19190:         push(@spares,$lonhost);
                   19191:     }
                   19192:     if ($currbalancer) {
                   19193:         $numspares = scalar(@spares);
                   19194:     } else {
                   19195:         $numspares = scalar(@spares) - 1;
                   19196:     }
                   19197:     return ($numspares,@spares);
                   19198: }
                   19199: 
                   19200: sub lonbalance_targets_js {
1.171     raeburn  19201:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  19202:     my $select = &mt('Select');
                   19203:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   19204:     if (ref($servers) eq 'HASH') {
                   19205:         $alltargets = join("','",sort(keys(%{$servers})));
                   19206:         my @homedoms;
                   19207:         foreach my $server (sort(keys(%{$servers}))) {
                   19208:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   19209:                 push(@homedoms,'1');
                   19210:             } else {
                   19211:                 push(@homedoms,'0');
                   19212:             }
                   19213:         }
                   19214:         $allishome = join("','",@homedoms);
                   19215:     }
                   19216:     if (ref($types) eq 'ARRAY') {
                   19217:         if (@{$types} > 0) {
                   19218:             @alltypes = @{$types};
                   19219:         }
                   19220:     }
                   19221:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   19222:     $allinsttypes = join("','",@alltypes);
1.342     raeburn  19223:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171     raeburn  19224:     if (ref($settings) eq 'HASH') {
                   19225:         %existing = %{$settings};
                   19226:     }
                   19227:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342     raeburn  19228:                               \%currtargets,\%currrules,\%currcookies);
1.210     raeburn  19229:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  19230:     return <<"END";
                   19231: 
                   19232: <script type="text/javascript">
                   19233: // <![CDATA[
                   19234: 
1.171     raeburn  19235: currBalancers = new Array('$balancers');
                   19236: 
                   19237: function toggleTargets(balnum) {
                   19238:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19239:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   19240:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   19241:     var prevbalancer = prevhostitem.value;
                   19242:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19243:     prevhostitem.value = balancer;
                   19244:     if (prevbalancer != '') {
                   19245:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   19246:         if (prevIdx != -1) {
                   19247:             currBalancers.splice(prevIdx,1);
                   19248:         }
                   19249:     }
1.150     raeburn  19250:     if (balancer == '') {
1.171     raeburn  19251:         hideSpares(balnum);
1.150     raeburn  19252:     } else {
1.171     raeburn  19253:         var currIdx = currBalancers.indexOf(balancer);
                   19254:         if (currIdx == -1) {
                   19255:             currBalancers.push(balancer);
                   19256:         }
1.150     raeburn  19257:         var homedoms = new Array('$allishome');
1.171     raeburn  19258:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   19259:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  19260:     }
1.171     raeburn  19261:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  19262:     return;
                   19263: }
                   19264: 
1.171     raeburn  19265: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  19266:     var alltargets = new Array('$alltargets');
                   19267:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  19268:     var offloadtypes = new Array('primary','default');
                   19269: 
1.171     raeburn  19270:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   19271:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  19272:  
1.151     raeburn  19273:     for (var i=0; i<offloadtypes.length; i++) {
                   19274:         var count = 0;
                   19275:         for (var j=0; j<alltargets.length; j++) {
                   19276:             if (alltargets[j] != balancer) {
1.171     raeburn  19277:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   19278:                 item.value = alltargets[j];
                   19279:                 item.style.textAlign='left';
                   19280:                 item.style.textFace='normal';
                   19281:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   19282:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   19283:                     item.disabled = '';
                   19284:                 } else {
                   19285:                     item.disabled = 'disabled';
                   19286:                     item.checked = false;
                   19287:                 }
1.151     raeburn  19288:                 count ++;
                   19289:             }
1.150     raeburn  19290:         }
                   19291:     }
1.151     raeburn  19292:     for (var k=0; k<insttypes.length; k++) {
                   19293:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  19294:             if (ishomedom == 1) {
1.171     raeburn  19295:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19296:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19297:             } else {
1.171     raeburn  19298:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19299:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  19300:             }
                   19301:         } else {
1.171     raeburn  19302:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19303:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19304:         }
1.151     raeburn  19305:         if ((insttypes[k] != '_LC_external') && 
                   19306:             ((insttypes[k] != '_LC_internetdom') ||
                   19307:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  19308:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   19309:             item.options.length = 0;
                   19310:             item.options[0] = new Option("","",true,true);
1.210     raeburn  19311:             var idx = 0;
1.151     raeburn  19312:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  19313:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   19314:                     idx ++;
                   19315:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  19316:                 }
                   19317:             }
                   19318:         }
                   19319:     }
                   19320:     return;
                   19321: }
                   19322: 
1.171     raeburn  19323: function hideSpares(balnum) {
1.150     raeburn  19324:     var alltargets = new Array('$alltargets');
                   19325:     var insttypes = new Array('$allinsttypes');
                   19326:     var offloadtypes = new Array('primary','default');
                   19327: 
1.171     raeburn  19328:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   19329:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  19330: 
                   19331:     var total = alltargets.length - 1;
                   19332:     for (var i=0; i<offloadtypes; i++) {
                   19333:         for (var j=0; j<total; j++) {
1.171     raeburn  19334:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   19335:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   19336:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  19337:         }
1.150     raeburn  19338:     }
                   19339:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  19340:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19341:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  19342:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  19343:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   19344:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  19345:         }
                   19346:     }
                   19347:     return;
                   19348: }
                   19349: 
1.171     raeburn  19350: function checkOffloads(item,balnum,type) {
1.150     raeburn  19351:     var alltargets = new Array('$alltargets');
                   19352:     var offloadtypes = new Array('primary','default');
                   19353:     if (item.checked) {
                   19354:         var total = alltargets.length - 1;
                   19355:         var other;
                   19356:         if (type == offloadtypes[0]) {
1.151     raeburn  19357:             other = offloadtypes[1];
1.150     raeburn  19358:         } else {
1.151     raeburn  19359:             other = offloadtypes[0];
1.150     raeburn  19360:         }
                   19361:         for (var i=0; i<total; i++) {
1.171     raeburn  19362:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  19363:             if (server == item.value) {
1.171     raeburn  19364:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   19365:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  19366:                 }
                   19367:             }
                   19368:         }
                   19369:     }
                   19370:     return;
                   19371: }
                   19372: 
1.171     raeburn  19373: function singleServerToggle(balnum,type) {
                   19374:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  19375:     if (offloadtoSelIdx == 0) {
1.171     raeburn  19376:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   19377:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19378: 
                   19379:     } else {
1.171     raeburn  19380:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   19381:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  19382:     }
                   19383:     return;
                   19384: }
                   19385: 
1.171     raeburn  19386: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  19387:     if (type == '_LC_external') {
1.171     raeburn  19388:         return;
1.150     raeburn  19389:     }
1.171     raeburn  19390:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  19391:     for (var i=0; i<typesRules.length; i++) {
                   19392:         if (formname.elements[typesRules[i]].checked) {
                   19393:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  19394:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   19395:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19396:             } else {
1.171     raeburn  19397:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   19398:             }
                   19399:         }
                   19400:     }
                   19401:     return;
                   19402: }
                   19403: 
                   19404: function balancerDeleteChange(balnum) {
                   19405:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19406:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19407:     var addtarget;
                   19408:     var removetarget;
                   19409:     var action = 'delete';
                   19410:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   19411:         var lonhost = hostitem.value;
                   19412:         var currIdx = currBalancers.indexOf(lonhost);
                   19413:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   19414:             if (currIdx != -1) {
                   19415:                 currBalancers.splice(currIdx,1);
                   19416:             }
                   19417:             addtarget = lonhost;
                   19418:         } else {
                   19419:             if (currIdx == -1) {
                   19420:                 currBalancers.push(lonhost);
                   19421:             }
                   19422:             removetarget = lonhost;
                   19423:             action = 'undelete';
                   19424:         }
                   19425:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   19426:     }
                   19427:     return;
                   19428: }
                   19429: 
                   19430: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   19431:     if (baltotal > 1) {
                   19432:         var offloadtypes = new Array('primary','default');
                   19433:         var alltargets = new Array('$alltargets');
                   19434:         var insttypes = new Array('$allinsttypes');
                   19435:         for (var i=0; i<baltotal; i++) {
                   19436:             if (i != balnum) {
                   19437:                 for (var j=0; j<offloadtypes.length; j++) {
                   19438:                     var total = alltargets.length - 1;
                   19439:                     for (var k=0; k<total; k++) {
                   19440:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   19441:                         var server = serveritem.value;
                   19442:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   19443:                             if (server == addtarget) {
                   19444:                                 serveritem.disabled = '';
                   19445:                             }
                   19446:                         }
                   19447:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19448:                             if (server == removetarget) {
                   19449:                                 serveritem.disabled = 'disabled';
                   19450:                                 serveritem.checked = false;
                   19451:                             }
                   19452:                         }
                   19453:                     }
                   19454:                 }
                   19455:                 for (var j=0; j<insttypes.length; j++) {
                   19456:                     if (insttypes[j] != '_LC_external') {
                   19457:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   19458:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   19459:                             var currSel = singleserver.selectedIndex;
                   19460:                             var currVal = singleserver.options[currSel].value;
                   19461:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   19462:                                 var numoptions = singleserver.options.length;
                   19463:                                 var needsnew = 1;
                   19464:                                 for (var k=0; k<numoptions; k++) {
                   19465:                                     if (singleserver.options[k] == addtarget) {
                   19466:                                         needsnew = 0;
                   19467:                                         break;
                   19468:                                     }
                   19469:                                 }
                   19470:                                 if (needsnew == 1) {
                   19471:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   19472:                                 }
                   19473:                             }
                   19474:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19475:                                 singleserver.options.length = 0;
                   19476:                                 if ((currVal) && (currVal != removetarget)) {
                   19477:                                     singleserver.options[0] = new Option("","",false,false);
                   19478:                                 } else {
                   19479:                                     singleserver.options[0] = new Option("","",true,true);
                   19480:                                 }
                   19481:                                 var idx = 0;
                   19482:                                 for (var m=0; m<alltargets.length; m++) {
                   19483:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   19484:                                         idx ++;
                   19485:                                         if (currVal == alltargets[m]) {
                   19486:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   19487:                                         } else {
                   19488:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   19489:                                         }
                   19490:                                     }
                   19491:                                 }
                   19492:                             }
                   19493:                         }
                   19494:                     }
                   19495:                 }
1.150     raeburn  19496:             }
                   19497:         }
                   19498:     }
                   19499:     return;
                   19500: }
                   19501: 
1.152     raeburn  19502: // ]]>
                   19503: </script>
                   19504: 
                   19505: END
                   19506: }
                   19507: 
                   19508: sub new_spares_js {
                   19509:     my @sparestypes = ('primary','default');
                   19510:     my $types = join("','",@sparestypes);
                   19511:     my $select = &mt('Select');
                   19512:     return <<"END";
                   19513: 
                   19514: <script type="text/javascript">
                   19515: // <![CDATA[
                   19516: 
                   19517: function updateNewSpares(formname,lonhost) {
                   19518:     var types = new Array('$types');
                   19519:     var include = new Array();
                   19520:     var exclude = new Array();
                   19521:     for (var i=0; i<types.length; i++) {
                   19522:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   19523:         for (var j=0; j<spareboxes.length; j++) {
                   19524:             if (formname.elements[spareboxes[j]].checked) {
                   19525:                 exclude.push(formname.elements[spareboxes[j]].value);
                   19526:             } else {
                   19527:                 include.push(formname.elements[spareboxes[j]].value);
                   19528:             }
                   19529:         }
                   19530:     }
                   19531:     for (var i=0; i<types.length; i++) {
                   19532:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   19533:         var selIdx = newSpare.selectedIndex;
                   19534:         var currnew = newSpare.options[selIdx].value;
                   19535:         var okSpares = new Array();
                   19536:         for (var j=0; j<newSpare.options.length; j++) {
                   19537:             var possible = newSpare.options[j].value;
                   19538:             if (possible != '') {
                   19539:                 if (exclude.indexOf(possible) == -1) {
                   19540:                     okSpares.push(possible);
                   19541:                 } else {
                   19542:                     if (currnew == possible) {
                   19543:                         selIdx = 0;
                   19544:                     }
                   19545:                 }
                   19546:             }
                   19547:         }
                   19548:         for (var k=0; k<include.length; k++) {
                   19549:             if (okSpares.indexOf(include[k]) == -1) {
                   19550:                 okSpares.push(include[k]);
                   19551:             }
                   19552:         }
                   19553:         okSpares.sort();
                   19554:         newSpare.options.length = 0;
                   19555:         if (selIdx == 0) {
                   19556:             newSpare.options[0] = new Option("$select","",true,true);
                   19557:         } else {
                   19558:             newSpare.options[0] = new Option("$select","",false,false);
                   19559:         }
                   19560:         for (var m=0; m<okSpares.length; m++) {
                   19561:             var idx = m+1;
                   19562:             var selThis = 0;
                   19563:             if (selIdx != 0) {
                   19564:                 if (okSpares[m] == currnew) {
                   19565:                     selThis = 1;
                   19566:                 }
                   19567:             }
                   19568:             if (selThis == 1) {
                   19569:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   19570:             } else {
                   19571:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   19572:             }
                   19573:         }
                   19574:     }
                   19575:     return;
                   19576: }
                   19577: 
                   19578: function checkNewSpares(lonhost,type) {
                   19579:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   19580:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   19581:     if (chosen != '') { 
                   19582:         var othertype;
                   19583:         var othernewSpare;
                   19584:         if (type == 'primary') {
                   19585:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   19586:         }
                   19587:         if (type == 'default') {
                   19588:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   19589:         }
                   19590:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   19591:             othernewSpare.selectedIndex = 0;
                   19592:         }
                   19593:     }
                   19594:     return;
                   19595: }
                   19596: 
                   19597: // ]]>
                   19598: </script>
                   19599: 
                   19600: END
                   19601: 
                   19602: }
                   19603: 
                   19604: sub common_domprefs_js {
                   19605:     return <<"END";
                   19606: 
                   19607: <script type="text/javascript">
                   19608: // <![CDATA[
                   19609: 
1.150     raeburn  19610: function getIndicesByName(formname,item) {
1.152     raeburn  19611:     var group = new Array();
1.150     raeburn  19612:     for (var i=0;i<formname.elements.length;i++) {
                   19613:         if (formname.elements[i].name == item) {
1.152     raeburn  19614:             group.push(formname.elements[i].id);
1.150     raeburn  19615:         }
                   19616:     }
1.152     raeburn  19617:     return group;
1.150     raeburn  19618: }
                   19619: 
                   19620: // ]]>
                   19621: </script>
                   19622: 
                   19623: END
1.152     raeburn  19624: 
1.150     raeburn  19625: }
                   19626: 
1.165     raeburn  19627: sub recaptcha_js {
                   19628:     my %lt = &captcha_phrases();
                   19629:     return <<"END";
                   19630: 
                   19631: <script type="text/javascript">
                   19632: // <![CDATA[
                   19633: 
                   19634: function updateCaptcha(caller,context) {
                   19635:     var privitem;
                   19636:     var pubitem;
                   19637:     var privtext;
                   19638:     var pubtext;
1.269     raeburn  19639:     var versionitem;
                   19640:     var versiontext;
1.165     raeburn  19641:     if (document.getElementById(context+'_recaptchapub')) {
                   19642:         pubitem = document.getElementById(context+'_recaptchapub');
                   19643:     } else {
                   19644:         return;
                   19645:     }
                   19646:     if (document.getElementById(context+'_recaptchapriv')) {
                   19647:         privitem = document.getElementById(context+'_recaptchapriv');
                   19648:     } else {
                   19649:         return;
                   19650:     }
                   19651:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   19652:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   19653:     } else {
                   19654:         return;
                   19655:     }
                   19656:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   19657:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   19658:     } else {
                   19659:         return;
                   19660:     }
1.269     raeburn  19661:     if (document.getElementById(context+'_recaptchaversion')) {
                   19662:         versionitem = document.getElementById(context+'_recaptchaversion');
                   19663:     } else {
                   19664:         return;
                   19665:     }
                   19666:     if (document.getElementById(context+'_recaptchavertxt')) {
                   19667:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   19668:     } else {
                   19669:         return;
                   19670:     }
1.165     raeburn  19671:     if (caller.checked) {
                   19672:         if (caller.value == 'recaptcha') {
                   19673:             pubitem.type = 'text';
                   19674:             privitem.type = 'text';
                   19675:             pubitem.size = '40';
                   19676:             privitem.size = '40';
                   19677:             pubtext.innerHTML = "$lt{'pub'}";
                   19678:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  19679:             versionitem.type = 'text';
                   19680:             versionitem.size = '3';
1.289     raeburn  19681:             versiontext.innerHTML = "$lt{'ver'}";
1.165     raeburn  19682:         } else {
                   19683:             pubitem.type = 'hidden';
                   19684:             privitem.type = 'hidden';
1.269     raeburn  19685:             versionitem.type = 'hidden';
1.165     raeburn  19686:             pubtext.innerHTML = '';
                   19687:             privtext.innerHTML = '';
1.269     raeburn  19688:             versiontext.innerHTML = '';
1.165     raeburn  19689:         }
                   19690:     }
                   19691:     return;
                   19692: }
                   19693: 
                   19694: // ]]>
                   19695: </script>
                   19696: 
                   19697: END
                   19698: 
                   19699: }
                   19700: 
1.236     raeburn  19701: sub toggle_display_js {
1.192     raeburn  19702:     return <<"END";
                   19703: 
                   19704: <script type="text/javascript">
                   19705: // <![CDATA[
                   19706: 
1.236     raeburn  19707: function toggleDisplay(domForm,caller) {
                   19708:     if (document.getElementById(caller)) {
                   19709:         var divitem = document.getElementById(caller);
                   19710:         var optionsElement = domForm.coursecredits;
1.264     raeburn  19711:         var checkval = 1;
                   19712:         var dispval = 'block';
1.303     raeburn  19713:         var selfcreateRegExp = /^cancreate_emailverified/;
1.236     raeburn  19714:         if (caller == 'emailoptions') {
                   19715:             optionsElement = domForm.cancreate_email; 
                   19716:         }
1.257     raeburn  19717:         if (caller == 'studentsubmission') {
                   19718:             optionsElement = domForm.postsubmit;
                   19719:         }
1.264     raeburn  19720:         if (caller == 'cloneinstcode') {
                   19721:             optionsElement = domForm.canclone;
                   19722:             checkval = 'instcode';
                   19723:         }
1.303     raeburn  19724:         if (selfcreateRegExp.test(caller)) {
                   19725:             optionsElement = domForm.elements[caller];
                   19726:             checkval = 'other';
                   19727:             dispval = 'inline'
                   19728:         }
1.236     raeburn  19729:         if (optionsElement.length) {
1.192     raeburn  19730:             var currval;
1.236     raeburn  19731:             for (var i=0; i<optionsElement.length; i++) {
                   19732:                 if (optionsElement[i].checked) {
                   19733:                    currval = optionsElement[i].value;
1.192     raeburn  19734:                 }
                   19735:             }
1.264     raeburn  19736:             if (currval == checkval) {
                   19737:                 divitem.style.display = dispval;
1.192     raeburn  19738:             } else {
1.236     raeburn  19739:                 divitem.style.display = 'none';
1.192     raeburn  19740:             }
                   19741:         }
                   19742:     }
                   19743:     return;
                   19744: }
                   19745: 
                   19746: // ]]>
                   19747: </script>
                   19748: 
                   19749: END
                   19750: 
                   19751: }
                   19752: 
1.165     raeburn  19753: sub captcha_phrases {
                   19754:     return &Apache::lonlocal::texthash (
                   19755:                  priv => 'Private key',
                   19756:                  pub  => 'Public key',
                   19757:                  original  => 'original (CAPTCHA)',
                   19758:                  recaptcha => 'successor (ReCAPTCHA)',
                   19759:                  notused   => 'unused',
1.289     raeburn  19760:                  ver => 'ReCAPTCHA version (1 or 2)',
1.165     raeburn  19761:     );
                   19762: }
                   19763: 
1.205     raeburn  19764: sub devalidate_remote_domconfs {
1.212     raeburn  19765:     my ($dom,$cachekeys) = @_;
                   19766:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  19767:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   19768:     my %thismachine;
                   19769:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355     raeburn  19770:     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.364     raeburn  19771:                       'directorysrch','passwdconf','cats');
1.260     raeburn  19772:     if (keys(%servers)) {
1.205     raeburn  19773:         foreach my $server (keys(%servers)) {
                   19774:             next if ($thismachine{$server});
1.212     raeburn  19775:             my @cached;
                   19776:             foreach my $name (@posscached) {
                   19777:                 if ($cachekeys->{$name}) {
                   19778:                     push(@cached,&escape($name).':'.&escape($dom));
                   19779:                 }
                   19780:             }
                   19781:             if (@cached) {
                   19782:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   19783:             }
1.205     raeburn  19784:         }
                   19785:     }
                   19786:     return;
                   19787: }
                   19788: 
1.3       raeburn  19789: 1;

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