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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.160.6.112! raeburn     4: # $Id: domainprefs.pm,v 1.160.6.111 2021/03/06 19:55:58 raeburn Exp $
1.160.6.40  raeburn     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.160.6.78  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: ###############################################################
                     30: ##############################################################
                     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.160.6.13  raeburn    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.160.6.27  raeburn    90: number of rows displayed on the page, and $action is the context (quotas, 
1.160.6.5  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.160.6.20  raeburn    98: used by course owners to request creation of a course, and to display/store
1.160.6.34  raeburn    99: default quota sizes for Authoring Spaces.
1.160.6.20  raeburn   100: 
1.101     raeburn   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.160.6.30  raeburn   107: (official, unofficial, community, and textbook).  In each case the radio buttons 
                    108: 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.160.6.37  raeburn   168: use Apache::lonuserutils();
1.160.6.39  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.9       raeburn   173: use File::Copy;
1.43      raeburn   174: use Locale::Language;
1.62      raeburn   175: use DateTime::TimeZone;
1.68      raeburn   176: use DateTime::Locale;
1.1       raeburn   177: 
1.155     raeburn   178: my $registered_cleanup;
                    179: my $modified_urls;
                    180: 
1.1       raeburn   181: sub handler {
                    182:     my $r=shift;
                    183:     if ($r->header_only) {
                    184:         &Apache::loncommon::content_type($r,'text/html');
                    185:         $r->send_http_header;
                    186:         return OK;
                    187:     }
                    188: 
1.91      raeburn   189:     my $context = 'domain';
1.1       raeburn   190:     my $dom = $env{'request.role.domain'};
1.5       albertel  191:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   192:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    193:         &Apache::loncommon::content_type($r,'text/html');
                    194:         $r->send_http_header;
                    195:     } else {
                    196:         $env{'user.error.msg'}=
                    197:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    198:         return HTTP_NOT_ACCEPTABLE;
                    199:     }
1.155     raeburn   200: 
                    201:     $registered_cleanup=0;
                    202:     @{$modified_urls}=();
                    203: 
1.1       raeburn   204:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    205:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   206:                                             ['phase','actions']);
1.30      raeburn   207:     my $phase = 'pickactions';
1.3       raeburn   208:     if ( exists($env{'form.phase'}) ) {
                    209:         $phase = $env{'form.phase'};
                    210:     }
1.150     raeburn   211:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   212:     my %domconfig =
1.6       raeburn   213:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   214:                 'quotas','autoenroll','autoupdate','autocreate',
                    215:                 'directorysrch','usercreation','usermodification',
                    216:                 'contacts','defaults','scantron','coursecategories',
1.160.6.73  raeburn   217:                 'serverstatuses','requestcourses','helpsettings',
                    218:                 'coursedefaults','usersessions','loadbalancing',
1.160.6.98  raeburn   219:                 'requestauthor','selfenrollment','inststatus','passwords'],$dom);
                    220:     my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125     raeburn   221:                        'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34  raeburn   222:                        'usercreation','selfcreation','usermodification','scantron',
1.160.6.5  raeburn   223:                        'requestcourses','requestauthor','coursecategories',
1.160.6.73  raeburn   224:                        'serverstatuses','helpsettings','coursedefaults',
                    225:                        'selfenrollment','usersessions');
1.160.6.7  raeburn   226:     my %existing;
                    227:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    228:         %existing = %{$domconfig{'loadbalancing'}};
                    229:     }
                    230:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   231:         push(@prefs_order,'loadbalancing');
                    232:     }
1.30      raeburn   233:     my %prefs = (
                    234:         'rolecolors' =>
                    235:                    { text => 'Default color schemes',
1.67      raeburn   236:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   237:                      header => [{col1 => 'Student Settings',
                    238:                                  col2 => '',},
                    239:                                 {col1 => 'Coordinator Settings',
                    240:                                  col2 => '',},
                    241:                                 {col1 => 'Author Settings',
                    242:                                  col2 => '',},
                    243:                                 {col1 => 'Administrator Settings',
                    244:                                  col2 => '',}],
1.160.6.37  raeburn   245:                       print => \&print_rolecolors,
                    246:                       modify => \&modify_rolecolors,
1.30      raeburn   247:                     },
1.110     raeburn   248:         'login' =>
1.30      raeburn   249:                     { text => 'Log-in page options',
1.67      raeburn   250:                       help => 'Domain_Configuration_Login_Page',
1.160.6.5  raeburn   251:                       header => [{col1 => 'Log-in Page Items',
                    252:                                   col2 => '',},
                    253:                                  {col1 => 'Log-in Help',
1.160.6.56  raeburn   254:                                   col2 => 'Value'},
                    255:                                  {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   256:                                   col2 => 'Value'}],
1.160.6.37  raeburn   257:                       print => \&print_login,
                    258:                       modify => \&modify_login,
1.30      raeburn   259:                     },
1.43      raeburn   260:         'defaults' => 
1.160.6.40  raeburn   261:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   262:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   263:                       header => [{col1 => 'Setting',
1.160.6.40  raeburn   264:                                   col2 => 'Value'},
                    265:                                  {col1 => 'Institutional user types',
1.160.6.93  raeburn   266:                                   col2 => 'Name displayed'}],
1.160.6.37  raeburn   267:                       print => \&print_defaults,
                    268:                       modify => \&modify_defaults,
1.43      raeburn   269:                     },
1.160.6.98  raeburn   270:         'passwords' =>
                    271:                     { text => 'Passwords (Internal authentication)',
                    272:                       help => 'Domain_Configuration_Passwords',
                    273:                       header => [{col1 => 'Resetting Forgotten Password',
                    274:                                   col2 => 'Settings'},
                    275:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    276:                                   col2 => 'Settings'},
                    277:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    278:                                   col2 => 'Settings'},
                    279:                                  {col1 => 'Course Owner Changing Student Passwords',
                    280:                                   col2 => 'Settings'}],
                    281:                       print => \&print_passwords,
                    282:                       modify => \&modify_passwords,
                    283:                     },
1.30      raeburn   284:         'quotas' => 
1.160.6.20  raeburn   285:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   286:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   287:                       header => [{col1 => 'User affiliation',
1.72      raeburn   288:                                   col2 => 'Available tools',
1.160.6.28  raeburn   289:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37  raeburn   290:                       print => \&print_quotas,
                    291:                       modify => \&modify_quotas,
1.30      raeburn   292:                     },
                    293:         'autoenroll' =>
                    294:                    { text => 'Auto-enrollment settings',
1.67      raeburn   295:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   296:                      header => [{col1 => 'Configuration setting',
                    297:                                  col2 => 'Value(s)'}],
1.160.6.37  raeburn   298:                      print => \&print_autoenroll,
                    299:                      modify => \&modify_autoenroll,
1.30      raeburn   300:                    },
                    301:         'autoupdate' => 
                    302:                    { text => 'Auto-update settings',
1.67      raeburn   303:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   304:                      header => [{col1 => 'Setting',
                    305:                                  col2 => 'Value',},
1.131     raeburn   306:                                 {col1 => 'Setting',
                    307:                                  col2 => 'Affiliation'},
1.43      raeburn   308:                                 {col1 => 'User population',
1.160.6.35  raeburn   309:                                  col2 => 'Updatable user data'}],
1.160.6.37  raeburn   310:                      print => \&print_autoupdate,
                    311:                      modify => \&modify_autoupdate,
1.30      raeburn   312:                   },
1.125     raeburn   313:         'autocreate' => 
                    314:                   { text => 'Auto-course creation settings',
                    315:                      help => 'Domain_Configuration_Auto_Creation',
                    316:                      header => [{col1 => 'Configuration Setting',
                    317:                                  col2 => 'Value',}],
1.160.6.37  raeburn   318:                      print => \&print_autocreate,
                    319:                      modify => \&modify_autocreate,
1.125     raeburn   320:                   },
1.30      raeburn   321:         'directorysrch' => 
1.160.6.72  raeburn   322:                   { text => 'Directory searches',
1.67      raeburn   323:                     help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72  raeburn   324:                     header => [{col1 => 'Institutional Directory Setting',
                    325:                                 col2 => 'Value',},
                    326:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   327:                                 col2 => 'Value',}],
1.160.6.37  raeburn   328:                     print => \&print_directorysrch,
                    329:                     modify => \&modify_directorysrch,
1.30      raeburn   330:                   },
                    331:         'contacts' =>
1.160.6.78  raeburn   332:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   333:                     help => 'Domain_Configuration_Contact_Info',
1.160.6.78  raeburn   334:                     header => [{col1 => 'Default e-mail addresses',
                    335:                                 col2 => 'Value',},
                    336:                                {col1 => 'Recipient(s) for notifications',
                    337:                                 col2 => 'Value',},
1.160.6.107  raeburn   338:                                {col1 => 'Nightly status check e-mail',
                    339:                                 col2 => 'Settings',},
1.160.6.78  raeburn   340:                                {col1 => 'Ask helpdesk form settings',
                    341:                                 col2 => 'Value',},],
1.160.6.37  raeburn   342:                     print => \&print_contacts,
                    343:                     modify => \&modify_contacts,
1.30      raeburn   344:                   },
                    345:         'usercreation' => 
                    346:                   { text => 'User creation',
1.67      raeburn   347:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   348:                     header => [{col1 => 'Format rule type',
                    349:                                 col2 => 'Format rules in force'},
1.34      raeburn   350:                                {col1 => 'User account creation',
                    351:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   352:                                {col1 => 'Context',
1.43      raeburn   353:                                 col2 => 'Assignable authentication types'}],
1.160.6.37  raeburn   354:                     print => \&print_usercreation,
                    355:                     modify => \&modify_usercreation,
1.30      raeburn   356:                   },
1.160.6.34  raeburn   357:         'selfcreation' => 
                    358:                   { text => 'Users self-creating accounts',
                    359:                     help => 'Domain_Configuration_Self_Creation', 
                    360:                     header => [{col1 => 'Self-creation with institutional username',
                    361:                                 col2 => 'Enabled?'},
                    362:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    363:                                 col2 => 'Information user can enter'},
1.160.6.93  raeburn   364:                                {col1 => 'Self-creation with e-mail verification',
1.160.6.34  raeburn   365:                                 col2 => 'Settings'}],
1.160.6.37  raeburn   366:                     print => \&print_selfcreation,
                    367:                     modify => \&modify_selfcreation,
1.160.6.34  raeburn   368:                   },
1.69      raeburn   369:         'usermodification' =>
1.33      raeburn   370:                   { text => 'User modification',
1.67      raeburn   371:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   372:                     header => [{col1 => 'Target user has role',
1.160.6.35  raeburn   373:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   374:                                {col1 => 'Target user has role',
1.160.6.35  raeburn   375:                                 col2 => 'User information updatable in course context'}],
1.160.6.37  raeburn   376:                     print => \&print_usermodification,
                    377:                     modify => \&modify_usermodification,
1.33      raeburn   378:                   },
1.69      raeburn   379:         'scantron' =>
1.160.6.97  raeburn   380:                   { text => 'Bubblesheet format',
1.67      raeburn   381:                     help => 'Domain_Configuration_Scantron_Format',
1.160.6.97  raeburn   382:                     header => [ {col1 => 'Bubblesheet format file',
                    383:                                  col2 => ''},
                    384:                                 {col1 => 'Bubblesheet data upload formats',
                    385:                                  col2 => 'Settings'}],
1.160.6.37  raeburn   386:                     print => \&print_scantron,
                    387:                     modify => \&modify_scantron,
1.46      raeburn   388:                   },
1.86      raeburn   389:         'requestcourses' => 
                    390:                  {text => 'Request creation of courses',
                    391:                   help => 'Domain_Configuration_Request_Courses',
                    392:                   header => [{col1 => 'User affiliation',
1.102     raeburn   393:                               col2 => 'Availability/Processing of requests',},
                    394:                              {col1 => 'Setting',
1.160.6.30  raeburn   395:                               col2 => 'Value'},
                    396:                              {col1 => 'Available textbooks',
1.160.6.39  raeburn   397:                               col2 => ''},
1.160.6.46  raeburn   398:                              {col1 => 'Available templates',
                    399:                               col2 => ''},
1.160.6.39  raeburn   400:                              {col1 => 'Validation (not official courses)',
                    401:                               col2 => 'Value'},],
1.160.6.37  raeburn   402:                   print => \&print_quotas,
                    403:                   modify => \&modify_quotas,
1.86      raeburn   404:                  },
1.160.6.5  raeburn   405:         'requestauthor' =>
1.160.6.34  raeburn   406:                  {text => 'Request Authoring Space',
1.160.6.5  raeburn   407:                   help => 'Domain_Configuration_Request_Author',
                    408:                   header => [{col1 => 'User affiliation',
                    409:                               col2 => 'Availability/Processing of requests',},
                    410:                              {col1 => 'Setting',
                    411:                               col2 => 'Value'}],
1.160.6.37  raeburn   412:                   print => \&print_quotas,
                    413:                   modify => \&modify_quotas,
1.160.6.5  raeburn   414:                  },
1.69      raeburn   415:         'coursecategories' =>
1.120     raeburn   416:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   417:                     help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42  raeburn   418:                     header => [{col1 => 'Catalog type/availability',
                    419:                                 col2 => '',},
                    420:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   421:                                 col2 => '',},
                    422:                                {col1 => 'Categories',
                    423:                                 col2 => '',
                    424:                                }],
1.160.6.37  raeburn   425:                     print => \&print_coursecategories,
                    426:                     modify => \&modify_coursecategories,
1.69      raeburn   427:                   },
                    428:         'serverstatuses' =>
1.77      raeburn   429:                  {text   => 'Access to server status pages',
1.69      raeburn   430:                   help   => 'Domain_Configuration_Server_Status',
                    431:                   header => [{col1 => 'Status Page',
                    432:                               col2 => 'Other named users',
                    433:                               col3 => 'Specific IPs',
                    434:                             }],
1.160.6.37  raeburn   435:                   print => \&print_serverstatuses,
                    436:                   modify => \&modify_serverstatuses,
1.69      raeburn   437:                  },
1.160.6.73  raeburn   438:         'helpsettings' =>
                    439:                  {text   => 'Support settings',
                    440:                   help   => 'Domain_Configuration_Help_Settings',
                    441:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    442:                               col2 => 'Value'},
                    443:                              {col1 => 'Helpdesk Roles',
                    444:                               col2 => 'Settings'},],
                    445:                   print  => \&print_helpsettings,
                    446:                   modify => \&modify_helpsettings,
                    447:                  },
1.160.6.39  raeburn   448:         'coursedefaults' => 
1.160.6.16  raeburn   449:                  {text => 'Course/Community defaults',
                    450:                   help => 'Domain_Configuration_Course_Defaults',
1.160.6.57  raeburn   451:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    452:                               col2 => 'Value',},
                    453:                              {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16  raeburn   454:                               col2 => 'Value',},],
1.160.6.37  raeburn   455:                   print => \&print_coursedefaults,
                    456:                   modify => \&modify_coursedefaults,
                    457:                  },
1.160.6.39  raeburn   458:         'selfenrollment' => 
1.160.6.37  raeburn   459:                  {text   => 'Self-enrollment in Course/Community',
                    460:                   help   => 'Domain_Configuration_Selfenrollment',
                    461:                   header => [{col1 => 'Configuration Rights',
                    462:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    463:                              {col1 => 'Defaults',
                    464:                               col2 => 'Value'},
                    465:                              {col1 => 'Self-enrollment validation (optional)',
                    466:                               col2 => 'Value'},],
                    467:                   print => \&print_selfenrollment,
                    468:                   modify => \&modify_selfenrollment,
1.160.6.16  raeburn   469:                  },
1.141     raeburn   470:         'usersessions' =>
1.145     raeburn   471:                  {text  => 'User session hosting/offloading',
1.137     raeburn   472:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   473:                   header => [{col1 => 'Domain server',
                    474:                               col2 => 'Servers to offload sessions to when busy'},
                    475:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   476:                               col2 => 'Rules'},
                    477:                              {col1 => "Hosting domain's own users elsewhere",
                    478:                               col2 => 'Rules'}],
1.160.6.37  raeburn   479:                   print => \&print_usersessions,
                    480:                   modify => \&modify_usersessions,
1.137     raeburn   481:                  },
1.160.6.78  raeburn   482:         'loadbalancing' =>
1.160.6.7  raeburn   483:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   484:                   help  => 'Domain_Configuration_Load_Balancing',
1.160.6.7  raeburn   485:                   header => [{col1 => 'Balancers',
1.150     raeburn   486:                               col2 => 'Default destinations',
1.160.6.13  raeburn   487:                               col3 => 'User affiliation',
1.150     raeburn   488:                               col4 => 'Overrides'},
                    489:                             ],
1.160.6.37  raeburn   490:                   print => \&print_loadbalancing,
                    491:                   modify => \&modify_loadbalancing,
1.150     raeburn   492:                  },
1.3       raeburn   493:     );
1.110     raeburn   494:     if (keys(%servers) > 1) {
                    495:         $prefs{'login'}  = { text   => 'Log-in page options',
                    496:                              help   => 'Domain_Configuration_Login_Page',
                    497:                             header => [{col1 => 'Log-in Service',
                    498:                                         col2 => 'Server Setting',},
                    499:                                        {col1 => 'Log-in Page Items',
1.160.6.5  raeburn   500:                                         col2 => ''},
                    501:                                        {col1 => 'Log-in Help',
1.160.6.56  raeburn   502:                                         col2 => 'Value'},
                    503:                                        {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   504:                                         col2 => 'Value'}],
1.160.6.37  raeburn   505:                             print => \&print_login,
                    506:                             modify => \&modify_login,
1.110     raeburn   507:                            };
                    508:     }
1.160.6.13  raeburn   509: 
1.6       raeburn   510:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   511:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   512:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   513:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   514:       text=>"Settings to display/modify"});
1.9       raeburn   515:     my $confname = $dom.'-domainconfig';
1.160.6.13  raeburn   516: 
1.3       raeburn   517:     if ($phase eq 'process') {
1.160.6.27  raeburn   518:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    519:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33  raeburn   520:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24  raeburn   521:             $r->rflush();
1.160.6.27  raeburn   522:             &devalidate_remote_domconfs($dom,$result);
1.160.6.24  raeburn   523:         }
1.30      raeburn   524:     } elsif ($phase eq 'display') {
1.160.6.16  raeburn   525:         my $js = &recaptcha_js().
1.160.6.40  raeburn   526:                  &toggle_display_js();
1.160.6.7  raeburn   527:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   528:             my ($othertitle,$usertypes,$types) =
                    529:                 &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7  raeburn   530:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    531:                                           $domconfig{'loadbalancing'}).
1.160.6.6  raeburn   532:                    &new_spares_js().
                    533:                    &common_domprefs_js().
                    534:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   535:         }
1.160.6.30  raeburn   536:         if (grep(/^requestcourses$/,@actions)) {
                    537:             my $javascript_validations;
                    538:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    539:             $js .= <<END;
                    540: <script type="text/javascript">
                    541: $javascript_validations
                    542: </script>
                    543: $coursebrowserjs
                    544: END
                    545:         }
1.160.6.93  raeburn   546:         if (grep(/^selfcreation$/,@actions)) {
                    547:             $js .= &selfcreate_javascript();
                    548:         }
1.160.6.78  raeburn   549:         if (grep(/^contacts$/,@actions)) {
                    550:             $js .= &contacts_javascript();
                    551:         }
1.160.6.97  raeburn   552:         if (grep(/^scantron$/,@actions)) {
                    553:             $js .= &scantron_javascript();
                    554:         }
1.150     raeburn   555:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   556:     } else {
1.160.6.11  raeburn   557: # check if domconfig user exists for the domain.
                    558:         my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26  raeburn   559:         my ($configuserok,$author_ok,$switchserver) =
1.160.6.11  raeburn   560:             &config_check($dom,$confname,$servadm);
                    561:         unless ($configuserok eq 'ok') {
                    562:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    563:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    564:                           $confname).
                    565:                       '<br />'
                    566:             );
                    567:             if ($switchserver) {
                    568:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    569:                           '<br />'.
                    570:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    571:                           '<br />'.
                    572:                           &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).
                    573:                           '<br />'.
                    574:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    575:                 );
                    576:             } else {
                    577:                 $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.').
                    578:                           '<br />'.
                    579:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    580:                 );
                    581:             }
                    582:             $r->print(&Apache::loncommon::end_page());
                    583:             return OK;
                    584:         }
1.21      raeburn   585:         if (keys(%domconfig) == 0) {
                    586:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   587:             my @ids=&Apache::lonnet::current_machine_ids();
                    588:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   589:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   590:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   591:                 my $custom_img_count = 0;
                    592:                 foreach my $img (@loginimages) {
                    593:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    594:                         $custom_img_count ++;
                    595:                     }
                    596:                 }
                    597:                 foreach my $role (@roles) {
                    598:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    599:                         $custom_img_count ++;
                    600:                     }
                    601:                 }
                    602:                 if ($custom_img_count > 0) {
1.94      raeburn   603:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   604:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   605:                     $r->print(
                    606:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    607:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    608:     &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 />'.
                    609:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    610:                     if ($switch_server) {
1.30      raeburn   611:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   612:                     }
1.91      raeburn   613:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   614:                     return OK;
                    615:                 }
                    616:             }
                    617:         }
1.91      raeburn   618:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   619:     }
                    620:     return OK;
                    621: }
                    622: 
                    623: sub process_changes {
1.160.6.24  raeburn   624:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   625:     my %domconfig;
                    626:     if (ref($values) eq 'HASH') {
                    627:         %domconfig = %{$values};
                    628:     }
1.3       raeburn   629:     my $output;
                    630:     if ($action eq 'login') {
1.160.6.24  raeburn   631:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   632:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   633:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24  raeburn   634:                                      $lastactref,%domconfig);
1.3       raeburn   635:     } elsif ($action eq 'quotas') {
1.160.6.30  raeburn   636:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   637:     } elsif ($action eq 'autoenroll') {
1.160.6.24  raeburn   638:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   639:     } elsif ($action eq 'autoupdate') {
                    640:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   641:     } elsif ($action eq 'autocreate') {
                    642:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   643:     } elsif ($action eq 'directorysrch') {
1.160.6.81  raeburn   644:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   645:     } elsif ($action eq 'usercreation') {
1.28      raeburn   646:         $output = &modify_usercreation($dom,%domconfig);
1.160.6.34  raeburn   647:     } elsif ($action eq 'selfcreation') {
1.160.6.93  raeburn   648:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   649:     } elsif ($action eq 'usermodification') {
                    650:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   651:     } elsif ($action eq 'contacts') {
1.160.6.24  raeburn   652:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   653:     } elsif ($action eq 'defaults') {
1.160.6.27  raeburn   654:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   655:     } elsif ($action eq 'scantron') {
1.160.6.24  raeburn   656:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   657:     } elsif ($action eq 'coursecategories') {
1.160.6.43  raeburn   658:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   659:     } elsif ($action eq 'serverstatuses') {
                    660:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   661:     } elsif ($action eq 'requestcourses') {
1.160.6.30  raeburn   662:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5  raeburn   663:     } elsif ($action eq 'requestauthor') {
1.160.6.30  raeburn   664:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73  raeburn   665:     } elsif ($action eq 'helpsettings') {
1.160.6.77  raeburn   666:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16  raeburn   667:     } elsif ($action eq 'coursedefaults') {
1.160.6.27  raeburn   668:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37  raeburn   669:     } elsif ($action eq 'selfenrollment') {
                    670:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   671:     } elsif ($action eq 'usersessions') {
1.160.6.27  raeburn   672:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   673:     } elsif ($action eq 'loadbalancing') {
                    674:         $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98  raeburn   675:     } elsif ($action eq 'passwords') {
                    676:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.3       raeburn   677:     }
                    678:     return $output;
                    679: }
                    680: 
                    681: sub print_config_box {
1.9       raeburn   682:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   683:     my $rowtotal = 0;
1.49      raeburn   684:     my $output;
                    685:     if ($action eq 'coursecategories') {
                    686:         $output = &coursecategories_javascript($settings);
1.160.6.40  raeburn   687:     } elsif ($action eq 'defaults') {
                    688:         $output = &defaults_javascript($settings); 
1.160.6.98  raeburn   689:     } elsif ($action eq 'passwords') {
                    690:         $output = &passwords_javascript();
1.160.6.73  raeburn   691:     } elsif ($action eq 'helpsettings') {
                    692:         my (%privs,%levelscurrent);
                    693:         my %full=();
                    694:         my %levels=(
                    695:                      course => {},
                    696:                      domain => {},
                    697:                      system => {},
                    698:                    );
                    699:         my $context = 'domain';
                    700:         my $crstype = 'Course';
                    701:         my $formname = 'display';
                    702:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    703:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    704:         $output =
                    705:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
                    706:                                                       \@templateroles);
1.91      raeburn   707:     }
1.160.6.40  raeburn   708:     $output .=
1.30      raeburn   709:          '<table class="LC_nested_outer">
1.3       raeburn   710:           <tr>
1.66      raeburn   711:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    712:            &mt($item->{text}).'&nbsp;'.
                    713:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    714:           '</tr>';
1.30      raeburn   715:     $rowtotal ++;
1.110     raeburn   716:     my $numheaders = 1;
                    717:     if (ref($item->{'header'}) eq 'ARRAY') {
                    718:         $numheaders = scalar(@{$item->{'header'}});
                    719:     }
                    720:     if ($numheaders > 1) {
1.64      raeburn   721:         my $colspan = '';
1.145     raeburn   722:         my $rightcolspan = '';
1.160.6.104  raeburn   723:         my $leftnobr = '';  
1.160.6.42  raeburn   724:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72  raeburn   725:             ($action eq 'directorysrch') ||
1.160.6.56  raeburn   726:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   727:             $colspan = ' colspan="2"';
                    728:         }
1.145     raeburn   729:         if ($action eq 'usersessions') {
                    730:             $rightcolspan = ' colspan="3"'; 
                    731:         }
1.160.6.104  raeburn   732:         if ($action eq 'passwords') {
                    733:             $leftnobr = ' LC_nobreak';
                    734:         }
1.30      raeburn   735:         $output .= '
1.3       raeburn   736:           <tr>
                    737:            <td>
                    738:             <table class="LC_nested">
                    739:              <tr class="LC_info_row">
1.160.6.104  raeburn   740:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   741:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   742:              </tr>';
1.69      raeburn   743:         $rowtotal ++;
1.160.6.37  raeburn   744:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57  raeburn   745:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   746:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78  raeburn   747:             ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37  raeburn   748:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98  raeburn   749:         } elsif ($action eq 'passwords') {
                    750:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   751:         } elsif ($action eq 'coursecategories') {
1.160.6.37  raeburn   752:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97  raeburn   753:         } elsif ($action eq 'scantron') {
                    754:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   755:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   756:             if ($numheaders == 4) {
1.160.6.5  raeburn   757:                 $colspan = ' colspan="2"';
                    758:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    759:             } else {
                    760:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    761:             }
1.160.6.37  raeburn   762:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn   763:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       764:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   765:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2  raeburn   766:         }
1.30      raeburn   767:         $output .= '
1.6       raeburn   768:            </table>
                    769:           </td>
                    770:          </tr>
                    771:          <tr>
                    772:            <td>
                    773:             <table class="LC_nested">
                    774:              <tr class="LC_info_row">
1.160.6.37  raeburn   775:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    776:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   777:              </tr>';
                    778:             $rowtotal ++;
1.160.6.37  raeburn   779:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    780:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78  raeburn   781:             ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98  raeburn   782:             ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42  raeburn   783:             if ($action eq 'coursecategories') {
                    784:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    785:                 $colspan = ' colspan="2"';
1.160.6.98  raeburn   786:             } elsif ($action eq 'passwords') {
                    787:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42  raeburn   788:             } else {
                    789:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    790:             }
                    791:             $output .= '
1.63      raeburn   792:            </table>
                    793:           </td>
                    794:          </tr>
                    795:          <tr>
                    796:            <td>
                    797:             <table class="LC_nested">
                    798:              <tr class="LC_info_row">
1.160.6.104  raeburn   799:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34  raeburn   800:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42  raeburn   801:              </tr>'."\n";
                    802:             if ($action eq 'coursecategories') {
                    803:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108  raeburn   804:             } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107  raeburn   805:                 if ($action eq 'passwords') {
                    806:                     $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                    807:                 } else {
                    808:                     $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                    809:                 }
                    810:                 $output .= '
1.160.6.98  raeburn   811:              </tr>
                    812:             </table>
                    813:            </td>
                    814:           </tr>
                    815:           <tr>
                    816:            <td>
                    817:             <table class="LC_nested">
                    818:              <tr class="LC_info_row">
                    819:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107  raeburn   820:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108  raeburn   821:                 if ($action eq 'passwords') {
                    822:                     $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                    823:                 } else {
                    824:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    825:                 }
                    826:                 $output .= '
1.160.6.98  raeburn   827:             </table>
                    828:           </td>
                    829:          </tr>
                    830:          <tr>';
1.160.6.42  raeburn   831:             } else {
                    832:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    833:             }
1.63      raeburn   834:             $rowtotal ++;
1.160.6.57  raeburn   835:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   836:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    837:                  ($action eq 'helpsettings')) {
1.160.6.37  raeburn   838:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97  raeburn   839:         } elsif ($action eq 'scantron') {
                    840:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   841:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   842:             if ($numheaders == 4) {
1.160.6.5  raeburn   843:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    844:            </table>
                    845:           </td>
                    846:          </tr>
                    847:          <tr>
                    848:            <td>
                    849:             <table class="LC_nested">
                    850:              <tr class="LC_info_row">
                    851:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30  raeburn   852:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5  raeburn   853:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    854:                 $rowtotal ++;
                    855:             } else {
                    856:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    857:             }
1.160.6.56  raeburn   858:             $output .= '
                    859:            </table>
                    860:           </td>
                    861:          </tr>
                    862:          <tr>
                    863:            <td>
                    864:             <table class="LC_nested">
                    865:              <tr class="LC_info_row">';
                    866:             if ($numheaders == 4) {
                    867:                 $output .= '
                    868:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    869:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    870:              </tr>';
                    871:             } else {
                    872:                 $output .= '
                    873:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    874:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    875:              </tr>';
                    876:             }
                    877:             $rowtotal ++;
                    878:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   879:         } elsif ($action eq 'requestcourses') {
1.160.6.50  raeburn   880:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    881:             $rowtotal ++;
                    882:             $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30  raeburn   883:            </table>
                    884:           </td>
                    885:          </tr>
                    886:          <tr>
                    887:            <td>
                    888:             <table class="LC_nested">
                    889:              <tr class="LC_info_row">
                    890:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    891:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46  raeburn   892:                        &textbookcourses_javascript($settings).
                    893:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    894:             </table>
                    895:            </td>
                    896:           </tr>
                    897:          <tr>
                    898:            <td>
                    899:             <table class="LC_nested">
                    900:              <tr class="LC_info_row">
                    901:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    902:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    903:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39  raeburn   904:             </table>
                    905:            </td>
                    906:           </tr>
                    907:           <tr>
                    908:            <td>
                    909:             <table class="LC_nested">
                    910:              <tr class="LC_info_row">
1.160.6.46  raeburn   911:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    912:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39  raeburn   913:              </tr>'.
                    914:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5  raeburn   915:         } elsif ($action eq 'requestauthor') {
                    916:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50  raeburn   917:             $rowtotal ++;
1.122     jms       918:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   919:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   920:            </table>
                    921:           </td>
                    922:          </tr>
                    923:          <tr>
                    924:            <td>
                    925:             <table class="LC_nested">
                    926:              <tr class="LC_info_row">
1.69      raeburn   927:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    928:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    929:               <td class="LC_right_item" valign="top">'.
                    930:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   931:              </tr>'.
1.30      raeburn   932:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   933:            </table>
                    934:           </td>
                    935:          </tr>
                    936:          <tr>
                    937:            <td>
                    938:             <table class="LC_nested">
                    939:              <tr class="LC_info_row">
1.59      bisitz    940:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    941:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   942:              </tr>'.
1.30      raeburn   943:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    944:             $rowtotal += 2;
1.6       raeburn   945:         }
1.3       raeburn   946:     } else {
1.30      raeburn   947:         $output .= '
1.3       raeburn   948:           <tr>
                    949:            <td>
                    950:             <table class="LC_nested">
1.30      raeburn   951:              <tr class="LC_info_row">';
1.160.6.72  raeburn   952:         if ($action eq 'login') {
1.30      raeburn   953:             $output .= '  
1.59      bisitz    954:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   955:         } elsif ($action eq 'serverstatuses') {
                    956:             $output .= '
                    957:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    958:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    959: 
1.6       raeburn   960:         } else {
1.30      raeburn   961:             $output .= '
1.69      raeburn   962:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    963:         }
1.72      raeburn   964:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    965:             $output .= '<td class="LC_left_item" valign="top">'.
                    966:                        &mt($item->{'header'}->[0]->{'col2'});
                    967:             if ($action eq 'serverstatuses') {
                    968:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    969:             } 
1.69      raeburn   970:         } else {
                    971:             $output .= '<td class="LC_right_item" valign="top">'.
                    972:                        &mt($item->{'header'}->[0]->{'col2'});
                    973:         }
                    974:         $output .= '</td>';
                    975:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   976:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    977:                 $output .= '<td class="LC_left_item" valign="top">'.
                    978:                             &mt($item->{'header'}->[0]->{'col3'});
                    979:             } else {
                    980:                 $output .= '<td class="LC_right_item" valign="top">'.
                    981:                            &mt($item->{'header'}->[0]->{'col3'});
                    982:             }
1.69      raeburn   983:             if ($action eq 'serverstatuses') {
                    984:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    985:             }
                    986:             $output .= '</td>';
1.6       raeburn   987:         }
1.150     raeburn   988:         if ($item->{'header'}->[0]->{'col4'}) {
                    989:             $output .= '<td class="LC_right_item" valign="top">'.
                    990:                        &mt($item->{'header'}->[0]->{'col4'});
                    991:         }
1.69      raeburn   992:         $output .= '</tr>';
1.48      raeburn   993:         $rowtotal ++;
1.160.6.5  raeburn   994:         if ($action eq 'quotas') {
1.86      raeburn   995:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72  raeburn   996:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.160.6.78  raeburn   997:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing')) {
1.160.6.37  raeburn   998:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn   999:         }
1.3       raeburn  1000:     }
1.30      raeburn  1001:     $output .= '
1.3       raeburn  1002:    </table>
                   1003:   </td>
                   1004:  </tr>
1.30      raeburn  1005: </table><br />';
                   1006:     return ($output,$rowtotal);
1.1       raeburn  1007: }
                   1008: 
1.3       raeburn  1009: sub print_login {
1.160.6.5  raeburn  1010:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1011:     my ($css_class,$datatable);
1.6       raeburn  1012:     my %choices = &login_choices();
1.110     raeburn  1013: 
1.160.6.5  raeburn  1014:     if ($caller eq 'service') {
1.149     raeburn  1015:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1016:         my $choice = $choices{'disallowlogin'};
                   1017:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1018:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn  1019:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1020:                       '<th>'.$choices{'server'}.'</th>'.
                   1021:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1022:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1023:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1024:         my %disallowed;
                   1025:         if (ref($settings) eq 'HASH') {
                   1026:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1027:                %disallowed = %{$settings->{'loginvia'}};
                   1028:             }
                   1029:         }
                   1030:         foreach my $lonhost (sort(keys(%servers))) {
                   1031:             my $direct = 'selected="selected"';
1.128     raeburn  1032:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1033:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1034:                     $direct = '';
                   1035:                 }
1.110     raeburn  1036:             }
1.115     raeburn  1037:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1038:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1039:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1040:                           '</option>';
1.160.6.13  raeburn  1041:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1042:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1043:                 my $selected = '';
1.128     raeburn  1044:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1045:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1046:                         $selected = 'selected="selected"';
                   1047:                     }
1.110     raeburn  1048:                 }
                   1049:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1050:                               $servers{$hostid}.'</option>';
                   1051:             }
1.128     raeburn  1052:             $datatable .= '</select></td>'.
                   1053:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1054:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1055:                 my $pathname = $path;
                   1056:                 if ($path eq 'custom') {
                   1057:                     $pathname = &mt('Custom Path').' ->';
                   1058:                 }
                   1059:                 my $selected = '';
                   1060:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1061:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1062:                         $selected = 'selected="selected"';
                   1063:                     }
                   1064:                 } elsif ($path eq '') {
                   1065:                     $selected = 'selected="selected"';
                   1066:                 }
                   1067:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1068:             }
                   1069:             $datatable .= '</select></td>';
                   1070:             my ($custom,$exempt);
                   1071:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1072:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1073:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1074:             }
                   1075:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1076:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1077:                           '</tr>';
1.110     raeburn  1078:         }
                   1079:         $datatable .= '</table></td></tr>';
                   1080:         return $datatable;
1.160.6.5  raeburn  1081:     } elsif ($caller eq 'page') {
                   1082:         my %defaultchecked = ( 
                   1083:                                'coursecatalog' => 'on',
1.160.6.14  raeburn  1084:                                'helpdesk'      => 'on',
1.160.6.5  raeburn  1085:                                'adminmail'     => 'off',
                   1086:                                'newuser'       => 'off',
                   1087:                              );
1.160.6.14  raeburn  1088:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5  raeburn  1089:         my (%checkedon,%checkedoff);
1.42      raeburn  1090:         foreach my $item (@toggles) {
1.160.6.5  raeburn  1091:             if ($defaultchecked{$item} eq 'on') { 
                   1092:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1093:                 $checkedoff{$item} = ' ';
1.160.6.5  raeburn  1094:             } elsif ($defaultchecked{$item} eq 'off') {
                   1095:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1096:                 $checkedon{$item} = ' ';
                   1097:             }
1.1       raeburn  1098:         }
1.160.6.5  raeburn  1099:         my @images = ('img','logo','domlogo','login');
                   1100:         my @logintext = ('textcol','bgcol');
                   1101:         my @bgs = ('pgbg','mainbg','sidebg');
                   1102:         my @links = ('link','alink','vlink');
                   1103:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1104:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1105:         my (%is_custom,%designs);
                   1106:         my %defaults = (
                   1107:                        font => $defaultdesign{'login.font'},
                   1108:                        );
1.6       raeburn  1109:         foreach my $item (@images) {
1.160.6.5  raeburn  1110:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1111:             $defaults{'showlogo'}{$item} = 1;
                   1112:         }
                   1113:         foreach my $item (@bgs) {
                   1114:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1115:         }
1.41      raeburn  1116:         foreach my $item (@logintext) {
1.160.6.5  raeburn  1117:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1118:         }
1.160.6.5  raeburn  1119:         foreach my $item (@links) {
                   1120:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1121:         }
1.160.6.5  raeburn  1122:         if (ref($settings) eq 'HASH') {
                   1123:             foreach my $item (@toggles) {
                   1124:                 if ($settings->{$item} eq '1') {
                   1125:                     $checkedon{$item} =  ' checked="checked" ';
                   1126:                     $checkedoff{$item} = ' ';
                   1127:                 } elsif ($settings->{$item} eq '0') {
                   1128:                     $checkedoff{$item} =  ' checked="checked" ';
                   1129:                     $checkedon{$item} = ' ';
                   1130:                 }
1.6       raeburn  1131:             }
1.160.6.5  raeburn  1132:             foreach my $item (@images) {
                   1133:                 if (defined($settings->{$item})) {
                   1134:                     $designs{$item} = $settings->{$item};
                   1135:                     $is_custom{$item} = 1;
                   1136:                 }
                   1137:                 if (defined($settings->{'showlogo'}{$item})) {
                   1138:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1139:                 }
                   1140:             }
                   1141:             foreach my $item (@logintext) {
                   1142:                 if ($settings->{$item} ne '') {
                   1143:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1144:                     $is_custom{$item} = 1;
                   1145:                 }
                   1146:             }
                   1147:             if ($settings->{'font'} ne '') {
                   1148:                 $designs{'font'} = $settings->{'font'};
                   1149:                 $is_custom{'font'} = 1;
                   1150:             }
                   1151:             foreach my $item (@bgs) {
                   1152:                 if ($settings->{$item} ne '') {
                   1153:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1154:                     $is_custom{$item} = 1;
                   1155:                 }
                   1156:             }
                   1157:             foreach my $item (@links) {
                   1158:                 if ($settings->{$item} ne '') {
                   1159:                     $designs{'links'}{$item} = $settings->{$item};
                   1160:                     $is_custom{$item} = 1;
                   1161:                 }
                   1162:             }
                   1163:         } else {
                   1164:             if ($designhash{$dom.'.login.font'} ne '') {
                   1165:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1166:                 $is_custom{'font'} = 1;
                   1167:             }
                   1168:             foreach my $item (@images) {
                   1169:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1170:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1171:                     $is_custom{$item} = 1;
                   1172:                 }
                   1173:             }
                   1174:             foreach my $item (@bgs) {
                   1175:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1176:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1177:                     $is_custom{$item} = 1;
                   1178:                 }
                   1179:             }
                   1180:             foreach my $item (@links) {
                   1181:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1182:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1183:                     $is_custom{$item} = 1;
                   1184:                 }
1.6       raeburn  1185:             }
                   1186:         }
1.160.6.5  raeburn  1187:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1188:                                                       logo => 'Institution Logo',
                   1189:                                                       domlogo => 'Domain Logo',
                   1190:                                                       login => 'Login box');
                   1191:         my $itemcount = 1;
                   1192:         foreach my $item (@toggles) {
                   1193:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1194:             $datatable .=  
                   1195:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1196:                 '</td><td>'.
                   1197:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1198:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1199:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1200:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1201:                 '</tr>';
                   1202:             $itemcount ++;
1.6       raeburn  1203:         }
1.160.6.5  raeburn  1204:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1205:         $datatable .= '</tr></table></td></tr>';
                   1206:     } elsif ($caller eq 'help') {
                   1207:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1208:         my $switchserver = &check_switchserver($dom,$confname);
                   1209:         my $itemcount = 1;
                   1210:         $defaulturl = '/adm/loginproblems.html';
                   1211:         $defaulttype = 'default';
                   1212:         %lt = &Apache::lonlocal::texthash (
                   1213:                      del     => 'Delete?',
                   1214:                      rep     => 'Replace:',
                   1215:                      upl     => 'Upload:',
                   1216:                      default => 'Default',
                   1217:                      custom  => 'Custom',
                   1218:                                              );
                   1219:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1220:         my @currlangs;
                   1221:         if (ref($settings) eq 'HASH') {
                   1222:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1223:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1224:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1225:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1226:                     $type{$key} = 'custom';
                   1227:                     unless ($key eq 'nolang') {
                   1228:                         push(@currlangs,$key);
                   1229:                     }
                   1230:                 }
                   1231:             } elsif ($settings->{'helpurl'} ne '') {
                   1232:                 $type{'nolang'} = 'custom';
                   1233:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1234:             }
                   1235:         }
1.160.6.5  raeburn  1236:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1237:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1238:             $datatable .= '<tr'.$css_class.'>';
                   1239:             if ($url{$lang} eq '') {
                   1240:                 $url{$lang} = $defaulturl;
                   1241:             }
                   1242:             if ($type{$lang} eq '') {
                   1243:                 $type{$lang} = $defaulttype;
                   1244:             }
                   1245:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1246:             if ($lang eq 'nolang') {
                   1247:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1248:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1249:             } else {
                   1250:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1251:                                   $langchoices{$lang},
                   1252:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1253:             }
                   1254:             $datatable .= '</span></td>'."\n".
                   1255:                           '<td class="LC_left_item">';
                   1256:             if ($type{$lang} eq 'custom') {
                   1257:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1258:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1259:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1260:             } else {
                   1261:                 $datatable .= $lt{'upl'};
                   1262:             }
                   1263:             $datatable .='<br />';
                   1264:             if ($switchserver) {
                   1265:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1266:             } else {
                   1267:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1268:             }
1.160.6.5  raeburn  1269:             $datatable .= '</td></tr>';
                   1270:             $itemcount ++;
1.6       raeburn  1271:         }
1.160.6.5  raeburn  1272:         my @addlangs;
                   1273:         foreach my $lang (sort(keys(%langchoices))) {
                   1274:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1275:             push(@addlangs,$lang);
                   1276:         }
                   1277:         if (@addlangs > 0) {
                   1278:             my %toadd;
                   1279:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1280:             $toadd{''} = &mt('Select');
                   1281:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1282:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1283:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1284:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1285:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1286:             if ($switchserver) {
                   1287:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1288:             } else {
                   1289:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1290:             }
1.160.6.5  raeburn  1291:             $datatable .= '</td></tr>';
                   1292:             $itemcount ++;
1.6       raeburn  1293:         }
1.160.6.5  raeburn  1294:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56  raeburn  1295:     } elsif ($caller eq 'headtag') {
                   1296:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1297:         my $choice = $choices{'headtag'};
                   1298:         $css_class = ' class="LC_odd_row"';
                   1299:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1300:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1301:                       '<th>'.$choices{'current'}.'</th>'.
                   1302:                       '<th>'.$choices{'action'}.'</th>'.
                   1303:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1304:         my (%currurls,%currexempt);
                   1305:         if (ref($settings) eq 'HASH') {
                   1306:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1307:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1308:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1309:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1310:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1311:                     }
                   1312:                 }
                   1313:             }
                   1314:         }
                   1315:         my %lt = &Apache::lonlocal::texthash(
                   1316:                                                del  => 'Delete?',
                   1317:                                                rep  => 'Replace:',
                   1318:                                                upl  => 'Upload:',
                   1319:                                                curr => 'View contents',
                   1320:                                                none => 'None',
                   1321:         );
                   1322:         my $switchserver = &check_switchserver($dom,$confname);
                   1323:         foreach my $lonhost (sort(keys(%domservers))) {
                   1324:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1325:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1326:             if ($currurls{$lonhost}) {
                   1327:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1328:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1329:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1330:                               '">'.$lt{'curr'}.'</a></td>'.
                   1331:                               '<td><span class="LC_nobreak"><label>'.
                   1332:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1333:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1334:             } else {
                   1335:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1336:             }
                   1337:             $datatable .='<br />';
                   1338:             if ($switchserver) {
                   1339:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1340:             } else {
                   1341:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1342:             }
1.160.6.87  raeburn  1343:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56  raeburn  1344:         }
                   1345:         $datatable .= '</table></td></tr>';
1.1       raeburn  1346:     }
1.6       raeburn  1347:     return $datatable;
                   1348: }
                   1349: 
                   1350: sub login_choices {
                   1351:     my %choices =
                   1352:         &Apache::lonlocal::texthash (
1.116     bisitz   1353:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1354:             adminmail     => "Display Administrator's E-mail Address?",
1.160.6.14  raeburn  1355:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1356:             disallowlogin => "Login page requests redirected",
                   1357:             hostid        => "Server",
1.128     raeburn  1358:             server        => "Redirect to:",
                   1359:             serverpath    => "Path",
                   1360:             custompath    => "Custom", 
                   1361:             exempt        => "Exempt IP(s)",
1.110     raeburn  1362:             directlogin   => "No redirect",
                   1363:             newuser       => "Link to create a user account",
                   1364:             img           => "Header",
                   1365:             logo          => "Main Logo",
                   1366:             domlogo       => "Domain Logo",
                   1367:             login         => "Log-in Header", 
                   1368:             textcol       => "Text color",
                   1369:             bgcol         => "Box color",
                   1370:             bgs           => "Background colors",
                   1371:             links         => "Link colors",
                   1372:             font          => "Font color",
                   1373:             pgbg          => "Header",
                   1374:             mainbg        => "Page",
                   1375:             sidebg        => "Login box",
                   1376:             link          => "Link",
                   1377:             alink         => "Active link",
                   1378:             vlink         => "Visited link",
1.160.6.56  raeburn  1379:             headtag       => "Custom markup",
                   1380:             action        => "Action",
                   1381:             current       => "Current",
1.6       raeburn  1382:         );
                   1383:     return %choices;
                   1384: }
                   1385: 
                   1386: sub print_rolecolors {
1.30      raeburn  1387:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1388:     my %choices = &color_font_choices();
                   1389:     my @bgs = ('pgbg','tabbg','sidebg');
                   1390:     my @links = ('link','alink','vlink');
                   1391:     my @images = ('img');
                   1392:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1393:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1394:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1395:     my (%is_custom,%designs);
1.160.6.22  raeburn  1396:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1397:     if (ref($settings) eq 'HASH') {
                   1398:         if (ref($settings->{$role}) eq 'HASH') {
                   1399:             if ($settings->{$role}->{'img'} ne '') {
                   1400:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1401:                 $is_custom{'img'} = 1;
                   1402:             }
                   1403:             if ($settings->{$role}->{'font'} ne '') {
                   1404:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1405:                 $is_custom{'font'} = 1;
                   1406:             }
1.97      tempelho 1407:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1408:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1409:                 $is_custom{'fontmenu'} = 1;
                   1410:             }
1.6       raeburn  1411:             foreach my $item (@bgs) {
                   1412:                 if ($settings->{$role}->{$item} ne '') {
                   1413:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1414:                     $is_custom{$item} = 1;
                   1415:                 }
                   1416:             }
                   1417:             foreach my $item (@links) {
                   1418:                 if ($settings->{$role}->{$item} ne '') {
                   1419:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1420:                     $is_custom{$item} = 1;
                   1421:                 }
                   1422:             }
                   1423:         }
                   1424:     } else {
                   1425:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1426:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1427:             $is_custom{'img'} = 1;
                   1428:         }
1.97      tempelho 1429:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1430:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1431:             $is_custom{'fontmenu'} = 1; 
                   1432:         }
1.6       raeburn  1433:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1434:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1435:             $is_custom{'font'} = 1;
                   1436:         }
                   1437:         foreach my $item (@bgs) {
                   1438:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1439:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1440:                 $is_custom{$item} = 1;
                   1441:             
                   1442:             }
                   1443:         }
                   1444:         foreach my $item (@links) {
                   1445:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1446:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1447:                 $is_custom{$item} = 1;
                   1448:             }
                   1449:         }
                   1450:     }
                   1451:     my $itemcount = 1;
1.30      raeburn  1452:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1453:     $datatable .= '</tr></table></td></tr>';
                   1454:     return $datatable;
                   1455: }
                   1456: 
1.160.6.22  raeburn  1457: sub role_defaults {
                   1458:     my ($role,$bgs,$links,$images,$logintext) = @_;
                   1459:     my %defaults;
                   1460:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
                   1461:         return %defaults;
                   1462:     }
                   1463:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1464:     if ($role eq 'login') {
                   1465:         %defaults = (
                   1466:                        font => $defaultdesign{$role.'.font'},
                   1467:                     );
                   1468:         if (ref($logintext) eq 'ARRAY') {
                   1469:             foreach my $item (@{$logintext}) {
                   1470:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1471:             }
                   1472:         }
                   1473:         foreach my $item (@{$images}) {
                   1474:             $defaults{'showlogo'}{$item} = 1;
                   1475:         }
                   1476:     } else {
                   1477:         %defaults = (
                   1478:                        img => $defaultdesign{$role.'.img'},
                   1479:                        font => $defaultdesign{$role.'.font'},
                   1480:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1481:                     );
                   1482:     }
                   1483:     foreach my $item (@{$bgs}) {
                   1484:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1485:     }
                   1486:     foreach my $item (@{$links}) {
                   1487:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1488:     }
                   1489:     foreach my $item (@{$images}) {
                   1490:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1491:     }
                   1492:     return %defaults;
                   1493: }
                   1494: 
1.6       raeburn  1495: sub display_color_options {
1.9       raeburn  1496:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1497:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1498:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1499:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1500:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1501:         '<td>'.$choices->{'font'}.'</td>';
                   1502:     if (!$is_custom->{'font'}) {
1.160.6.87  raeburn  1503:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1504:     } else {
                   1505:         $datatable .= '<td>&nbsp;</td>';
                   1506:     }
1.160.6.9  raeburn  1507:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1508: 
1.8       raeburn  1509:     $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1510:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1511:                   ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1512:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1513:     unless ($role eq 'login') { 
                   1514:         $datatable .= '<tr'.$css_class.'>'.
                   1515:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1516:         if (!$is_custom->{'fontmenu'}) {
1.160.6.87  raeburn  1517:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1518:         } else {
                   1519:             $datatable .= '<td>&nbsp;</td>';
                   1520:         }
1.160.6.22  raeburn  1521: 	$current_color = $designs->{'fontmenu'} ?
                   1522: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1523:         $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1524:                       '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22  raeburn  1525: 		      .$role.'_fontmenu"'.
1.160.6.9  raeburn  1526:                       ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1527:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1528:     }
1.9       raeburn  1529:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1530:     foreach my $img (@{$images}) {
1.18      albertel 1531: 	$itemcount ++;
1.6       raeburn  1532:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1533:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1534:                       '<td>'.$choices->{$img};
1.41      raeburn  1535:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1536:         if ($role eq 'login') {
                   1537:             if ($img eq 'login') {
                   1538:                 $login_hdr_pick =
1.135     bisitz   1539:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1540:                 $logincolors =
                   1541:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22  raeburn  1542:                                        $designs,$defaults);
1.70      raeburn  1543:             } elsif ($img ne 'domlogo') {
                   1544:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1545:             }
                   1546:         }
                   1547:         $datatable .= '</td>';
1.6       raeburn  1548:         if ($designs->{$img} ne '') {
                   1549:             $imgfile = $designs->{$img};
1.18      albertel 1550: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1551:         } else {
                   1552:             $imgfile = $defaults->{$img};
                   1553:         }
                   1554:         if ($imgfile) {
1.9       raeburn  1555:             my ($showfile,$fullsize);
                   1556:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1557:                 my $urldir = $1;
                   1558:                 my $filename = $2;
                   1559:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1560:                 if (@info) {
                   1561:                     my $thumbfile = 'tn-'.$filename;
                   1562:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1563:                     if (@thumb) {
                   1564:                         $showfile = $urldir.'/'.$thumbfile;
                   1565:                     } else {
                   1566:                         $showfile = $imgfile;
                   1567:                     }
                   1568:                 } else {
                   1569:                     $showfile = '';
                   1570:                 }
                   1571:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1572:                 $showfile = $imgfile;
1.6       raeburn  1573:                 my $imgdir = $1;
                   1574:                 my $filename = $2;
1.159     raeburn  1575:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1576:                     $showfile = "/$imgdir/tn-".$filename;
                   1577:                 } else {
1.159     raeburn  1578:                     my $input = $londocroot.$imgfile;
                   1579:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1580:                     if (!-e $output) {
1.9       raeburn  1581:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1582:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1583:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1584:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1585:                                 my $size = $width.'x'.$height;
1.160.6.88  raeburn  1586:                                 my @args = ('convert','-sample',$size,$input,$output);
                   1587:                                 system({$args[0]} @args);
1.159     raeburn  1588:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1589:                             }
                   1590:                         }
1.6       raeburn  1591:                     }
                   1592:                 }
1.16      raeburn  1593:             }
1.6       raeburn  1594:             if ($showfile) {
1.40      raeburn  1595:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1596:                     if ($showfile =~ m{^/res/}) {
                   1597:                         my $local_showfile =
                   1598:                             &Apache::lonnet::filelocation('',$showfile);
                   1599:                         &Apache::lonnet::repcopy($local_showfile);
                   1600:                     }
                   1601:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1602:                 }
                   1603:                 if ($imgfile) {
                   1604:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1605:                         if ($imgfile =~ m{^/res/}) {
                   1606:                             my $local_imgfile =
                   1607:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1608:                             &Apache::lonnet::repcopy($local_imgfile);
                   1609:                         }
                   1610:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1611:                     } else {
                   1612:                         $fullsize = $imgfile;
                   1613:                     }
                   1614:                 }
1.41      raeburn  1615:                 $datatable .= '<td>';
                   1616:                 if ($img eq 'login') {
1.135     bisitz   1617:                     $datatable .= $login_hdr_pick;
                   1618:                 } 
1.41      raeburn  1619:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1620:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1621:             } else {
1.160.6.22  raeburn  1622:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1623:                               &mt('Upload:').'<br />';
1.6       raeburn  1624:             }
                   1625:         } else {
1.160.6.22  raeburn  1626:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1627:                           &mt('Upload:').'<br />';
1.6       raeburn  1628:         }
1.9       raeburn  1629:         if ($switchserver) {
                   1630:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1631:         } else {
1.135     bisitz   1632:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1633:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1634:             }
1.9       raeburn  1635:         }
                   1636:         $datatable .= '</td></tr>';
1.6       raeburn  1637:     }
                   1638:     $itemcount ++;
                   1639:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1640:     $datatable .= '<tr'.$css_class.'>'.
                   1641:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1642:     my $bgs_def;
                   1643:     foreach my $item (@{$bgs}) {
                   1644:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1645:             $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  1646:         }
                   1647:     }
                   1648:     if ($bgs_def) {
1.8       raeburn  1649:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1650:     } else {
                   1651:         $datatable .= '<td>&nbsp;</td>';
                   1652:     }
                   1653:     $datatable .= '<td class="LC_right_item">'.
                   1654:                   '<table border="0"><tr>';
1.160.6.13  raeburn  1655: 
1.6       raeburn  1656:     foreach my $item (@{$bgs}) {
1.160.6.22  raeburn  1657:         $datatable .= '<td align="center">'.$choices->{$item};
                   1658: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1659:         if ($designs->{'bgs'}{$item}) {
1.160.6.9  raeburn  1660:             $datatable .= '&nbsp;';
1.6       raeburn  1661:         }
1.160.6.9  raeburn  1662:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1663:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1664:     }
                   1665:     $datatable .= '</tr></table></td></tr>';
                   1666:     $itemcount ++;
                   1667:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1668:     $datatable .= '<tr'.$css_class.'>'.
                   1669:                   '<td>'.$choices->{'links'}.'</td>';
                   1670:     my $links_def;
                   1671:     foreach my $item (@{$links}) {
                   1672:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1673:             $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  1674:         }
                   1675:     }
                   1676:     if ($links_def) {
1.8       raeburn  1677:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1678:     } else {
                   1679:         $datatable .= '<td>&nbsp;</td>';
                   1680:     }
                   1681:     $datatable .= '<td class="LC_right_item">'.
                   1682:                   '<table border="0"><tr>';
                   1683:     foreach my $item (@{$links}) {
1.160.6.39  raeburn  1684: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22  raeburn  1685:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1686:         if ($designs->{'links'}{$item}) {
1.160.6.9  raeburn  1687:             $datatable.='&nbsp;';
1.6       raeburn  1688:         }
1.160.6.9  raeburn  1689:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1690:                       '" /></td>';
                   1691:     }
1.30      raeburn  1692:     $$rowtotal += $itemcount;
1.3       raeburn  1693:     return $datatable;
                   1694: }
                   1695: 
1.70      raeburn  1696: sub logo_display_options {
                   1697:     my ($img,$defaults,$designs) = @_;
                   1698:     my $checkedon;
                   1699:     if (ref($defaults) eq 'HASH') {
                   1700:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1701:             if ($defaults->{'showlogo'}{$img}) {
                   1702:                 $checkedon = 'checked="checked" ';     
                   1703:             }
                   1704:         } 
                   1705:     }
                   1706:     if (ref($designs) eq 'HASH') {
                   1707:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1708:             if (defined($designs->{'showlogo'}{$img})) {
                   1709:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1710:                     $checkedon = '';
                   1711:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1712:                     $checkedon = 'checked="checked" ';
                   1713:                 }
                   1714:             }
                   1715:         }
                   1716:     }
                   1717:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1718:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1719:            &mt('show').'</label>'."\n";
                   1720: }
                   1721: 
1.41      raeburn  1722: sub login_header_options  {
1.135     bisitz   1723:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1724:     my $output = '';
1.41      raeburn  1725:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1726:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1727:         if (!$is_custom->{'textcol'}) {
                   1728:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1729:                        '&nbsp;&nbsp;&nbsp;';
                   1730:         }
                   1731:         if (!$is_custom->{'bgcol'}) {
                   1732:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1733:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1734:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1735:         }
                   1736:         $output .= '<br />';
                   1737:     }
                   1738:     $output .='<br />';
                   1739:     return $output;
                   1740: }
                   1741: 
                   1742: sub login_text_colors {
1.160.6.22  raeburn  1743:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1744:     my $color_menu = '<table border="0"><tr>';
                   1745:     foreach my $item (@{$logintext}) {
1.160.6.22  raeburn  1746:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1747:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1748:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1749:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1750:     }
                   1751:     $color_menu .= '</tr></table><br />';
                   1752:     return $color_menu;
                   1753: }
                   1754: 
                   1755: sub image_changes {
                   1756:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1757:     my $output;
1.135     bisitz   1758:     if ($img eq 'login') {
1.160.6.87  raeburn  1759:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   1760:     } elsif (!$is_custom) {
1.70      raeburn  1761:         if ($img ne 'domlogo') {
1.160.6.87  raeburn  1762:             $output = &mt('Default image:').'<br />';
1.41      raeburn  1763:         } else {
1.160.6.87  raeburn  1764:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  1765:         }
                   1766:     }
1.160.6.87  raeburn  1767:     if ($img ne 'login') {
1.135     bisitz   1768:         if ($img_import) {
                   1769:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1770:         }
                   1771:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1772:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1773:         if ($is_custom) {
                   1774:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1775:                        '<input type="checkbox" name="'.
                   1776:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1777:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1778:         } else {
1.160.6.22  raeburn  1779:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1780:         }
1.41      raeburn  1781:     }
                   1782:     return $output;
                   1783: }
                   1784: 
1.3       raeburn  1785: sub print_quotas {
1.86      raeburn  1786:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1787:     my $context;
                   1788:     if ($action eq 'quotas') {
                   1789:         $context = 'tools';
                   1790:     } else {
                   1791:         $context = $action;
                   1792:     }
1.160.6.20  raeburn  1793:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1794:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1795:     my $typecount = 0;
1.101     raeburn  1796:     my ($css_class,%titles);
1.86      raeburn  1797:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  1798:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  1799:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1800:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1801:         %titles = &courserequest_titles();
1.160.6.5  raeburn  1802:     } elsif ($context eq 'requestauthor') {
                   1803:         @usertools = ('author');
                   1804:         @options = ('norequest','approval','automatic');
                   1805:         %titles = &authorrequest_titles();
1.86      raeburn  1806:     } else {
1.160.6.4  raeburn  1807:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1808:         %titles = &tool_titles();
1.86      raeburn  1809:     }
1.26      raeburn  1810:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1811:         foreach my $type (@{$types}) {
1.160.6.20  raeburn  1812:             my ($currdefquota,$currauthorquota);
1.160.6.5  raeburn  1813:             unless (($context eq 'requestcourses') ||
                   1814:                     ($context eq 'requestauthor')) {
1.86      raeburn  1815:                 if (ref($settings) eq 'HASH') {
                   1816:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20  raeburn  1817:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1818:                     } else {
                   1819:                         $currdefquota = $settings->{$type};
                   1820:                     }
1.160.6.20  raeburn  1821:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1822:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1823:                     }
1.78      raeburn  1824:                 }
1.72      raeburn  1825:             }
1.3       raeburn  1826:             if (defined($usertypes->{$type})) {
                   1827:                 $typecount ++;
                   1828:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1829:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1830:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1831:                               '<td class="LC_left_item">';
1.101     raeburn  1832:                 if ($context eq 'requestcourses') {
                   1833:                     $datatable .= '<table><tr>';
                   1834:                 }
                   1835:                 my %cell;  
1.72      raeburn  1836:                 foreach my $item (@usertools) {
1.101     raeburn  1837:                     if ($context eq 'requestcourses') {
                   1838:                         my ($curroption,$currlimit);
                   1839:                         if (ref($settings) eq 'HASH') {
                   1840:                             if (ref($settings->{$item}) eq 'HASH') {
                   1841:                                 $curroption = $settings->{$item}->{$type};
                   1842:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1843:                                     $currlimit = $1; 
                   1844:                                 }
                   1845:                             }
                   1846:                         }
                   1847:                         if (!$curroption) {
                   1848:                             $curroption = 'norequest';
                   1849:                         }
                   1850:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1851:                         foreach my $option (@options) {
                   1852:                             my $val = $option;
                   1853:                             if ($option eq 'norequest') {
                   1854:                                 $val = 0;  
                   1855:                             }
                   1856:                             if ($option eq 'validate') {
                   1857:                                 my $canvalidate = 0;
                   1858:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1859:                                     if ($validations{$item}{$type}) {
                   1860:                                         $canvalidate = 1;
                   1861:                                     }
                   1862:                                 }
                   1863:                                 next if (!$canvalidate);
                   1864:                             }
                   1865:                             my $checked = '';
                   1866:                             if ($option eq $curroption) {
                   1867:                                 $checked = ' checked="checked"';
                   1868:                             } elsif ($option eq 'autolimit') {
                   1869:                                 if ($curroption =~ /^autolimit/) {
                   1870:                                     $checked = ' checked="checked"';
                   1871:                                 }                       
                   1872:                             } 
                   1873:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1874:                                   '<input type="radio" name="crsreq_'.$item.
                   1875:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1876:                                   $titles{$option}.'</label>';
1.101     raeburn  1877:                             if ($option eq 'autolimit') {
1.127     raeburn  1878:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1879:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1880:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1881:                             }
1.127     raeburn  1882:                             $cell{$item} .= '</span> ';
1.103     raeburn  1883:                             if ($option eq 'autolimit') {
1.127     raeburn  1884:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1885:                             }
1.101     raeburn  1886:                         }
1.160.6.5  raeburn  1887:                     } elsif ($context eq 'requestauthor') {
                   1888:                         my $curroption;
                   1889:                         if (ref($settings) eq 'HASH') {
                   1890:                             $curroption = $settings->{$type};
                   1891:                         }
                   1892:                         if (!$curroption) {
                   1893:                             $curroption = 'norequest';
                   1894:                         }
                   1895:                         foreach my $option (@options) {
                   1896:                             my $val = $option;
                   1897:                             if ($option eq 'norequest') {
                   1898:                                 $val = 0;
                   1899:                             }
                   1900:                             my $checked = '';
                   1901:                             if ($option eq $curroption) {
                   1902:                                 $checked = ' checked="checked"';
                   1903:                             }
                   1904:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1905:                                   '<input type="radio" name="authorreq_'.$type.
                   1906:                                   '" value="'.$val.'"'.$checked.' />'.
                   1907:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1908:                         }
1.101     raeburn  1909:                     } else {
                   1910:                         my $checked = 'checked="checked" ';
                   1911:                         if (ref($settings) eq 'HASH') {
                   1912:                             if (ref($settings->{$item}) eq 'HASH') {
                   1913:                                 if ($settings->{$item}->{$type} == 0) {
                   1914:                                     $checked = '';
                   1915:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1916:                                     $checked =  'checked="checked" ';
                   1917:                                 }
1.78      raeburn  1918:                             }
1.72      raeburn  1919:                         }
1.101     raeburn  1920:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1921:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1922:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1923:                                       '</label></span>&nbsp; ';
1.72      raeburn  1924:                     }
1.101     raeburn  1925:                 }
                   1926:                 if ($context eq 'requestcourses') {
                   1927:                     $datatable .= '</tr><tr>';
                   1928:                     foreach my $item (@usertools) {
1.106     raeburn  1929:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1930:                     }
                   1931:                     $datatable .= '</tr></table>';
1.72      raeburn  1932:                 }
1.86      raeburn  1933:                 $datatable .= '</td>';
1.160.6.5  raeburn  1934:                 unless (($context eq 'requestcourses') ||
                   1935:                         ($context eq 'requestauthor')) {
1.86      raeburn  1936:                     $datatable .= 
1.160.6.20  raeburn  1937:                               '<td class="LC_right_item">'.
                   1938:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1939:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1940:                               '" value="'.$currdefquota.
1.160.6.20  raeburn  1941:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1942:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1943:                               '<input type="text" name="authorquota_'.$type.
                   1944:                               '" value="'.$currauthorquota.
                   1945:                               '" size="5" /></span></td>';
1.86      raeburn  1946:                 }
                   1947:                 $datatable .= '</tr>';
1.3       raeburn  1948:             }
                   1949:         }
                   1950:     }
1.160.6.5  raeburn  1951:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1952:         $defaultquota = '20';
1.160.6.20  raeburn  1953:         $authorquota = '500';
1.86      raeburn  1954:         if (ref($settings) eq 'HASH') {
                   1955:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1956:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1957:             } elsif (defined($settings->{'default'})) {
                   1958:                 $defaultquota = $settings->{'default'};
                   1959:             }
1.160.6.20  raeburn  1960:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1961:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1962:             }
1.3       raeburn  1963:         }
                   1964:     }
                   1965:     $typecount ++;
                   1966:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1967:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1968:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1969:                   '<td class="LC_left_item">';
1.101     raeburn  1970:     if ($context eq 'requestcourses') {
                   1971:         $datatable .= '<table><tr>';
                   1972:     }
                   1973:     my %defcell;
1.72      raeburn  1974:     foreach my $item (@usertools) {
1.101     raeburn  1975:         if ($context eq 'requestcourses') {
                   1976:             my ($curroption,$currlimit);
                   1977:             if (ref($settings) eq 'HASH') {
                   1978:                 if (ref($settings->{$item}) eq 'HASH') {
                   1979:                     $curroption = $settings->{$item}->{'default'};
                   1980:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1981:                         $currlimit = $1;
                   1982:                     }
                   1983:                 }
                   1984:             }
                   1985:             if (!$curroption) {
                   1986:                 $curroption = 'norequest';
                   1987:             }
                   1988:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1989:             foreach my $option (@options) {
                   1990:                 my $val = $option;
                   1991:                 if ($option eq 'norequest') {
                   1992:                     $val = 0;
                   1993:                 }
                   1994:                 if ($option eq 'validate') {
                   1995:                     my $canvalidate = 0;
                   1996:                     if (ref($validations{$item}) eq 'HASH') {
                   1997:                         if ($validations{$item}{'default'}) {
                   1998:                             $canvalidate = 1;
                   1999:                         }
                   2000:                     }
                   2001:                     next if (!$canvalidate);
                   2002:                 }
                   2003:                 my $checked = '';
                   2004:                 if ($option eq $curroption) {
                   2005:                     $checked = ' checked="checked"';
                   2006:                 } elsif ($option eq 'autolimit') {
                   2007:                     if ($curroption =~ /^autolimit/) {
                   2008:                         $checked = ' checked="checked"';
                   2009:                     }
                   2010:                 }
                   2011:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2012:                                   '<input type="radio" name="crsreq_'.$item.
                   2013:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2014:                                   $titles{$option}.'</label>';
                   2015:                 if ($option eq 'autolimit') {
1.127     raeburn  2016:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2017:                                        $item.'_limit_default" size="1" '.
                   2018:                                        'value="'.$currlimit.'" />';
                   2019:                 }
1.127     raeburn  2020:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2021:                 if ($option eq 'autolimit') {
1.127     raeburn  2022:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2023:                 }
1.101     raeburn  2024:             }
1.160.6.5  raeburn  2025:         } elsif ($context eq 'requestauthor') {
                   2026:             my $curroption;
                   2027:             if (ref($settings) eq 'HASH') {
1.160.6.8  raeburn  2028:                 $curroption = $settings->{'default'};
1.160.6.5  raeburn  2029:             }
                   2030:             if (!$curroption) {
                   2031:                 $curroption = 'norequest';
                   2032:             }
                   2033:             foreach my $option (@options) {
                   2034:                 my $val = $option;
                   2035:                 if ($option eq 'norequest') {
                   2036:                     $val = 0;
                   2037:                 }
                   2038:                 my $checked = '';
                   2039:                 if ($option eq $curroption) {
                   2040:                     $checked = ' checked="checked"';
                   2041:                 }
                   2042:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2043:                               '<input type="radio" name="authorreq_default"'.
                   2044:                               ' value="'.$val.'"'.$checked.' />'.
                   2045:                               $titles{$option}.'</label></span>&nbsp; ';
                   2046:             }
1.101     raeburn  2047:         } else {
                   2048:             my $checked = 'checked="checked" ';
                   2049:             if (ref($settings) eq 'HASH') {
                   2050:                 if (ref($settings->{$item}) eq 'HASH') {
                   2051:                     if ($settings->{$item}->{'default'} == 0) {
                   2052:                         $checked = '';
                   2053:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2054:                         $checked = 'checked="checked" ';
                   2055:                     }
1.78      raeburn  2056:                 }
1.72      raeburn  2057:             }
1.101     raeburn  2058:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2059:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2060:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2061:                           '</label></span>&nbsp; ';
                   2062:         }
                   2063:     }
                   2064:     if ($context eq 'requestcourses') {
                   2065:         $datatable .= '</tr><tr>';
                   2066:         foreach my $item (@usertools) {
1.106     raeburn  2067:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2068:         }
1.101     raeburn  2069:         $datatable .= '</tr></table>';
1.72      raeburn  2070:     }
1.86      raeburn  2071:     $datatable .= '</td>';
1.160.6.5  raeburn  2072:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20  raeburn  2073:         $datatable .= '<td class="LC_right_item">'.
                   2074:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2075:                       '<input type="text" name="defaultquota" value="'.
1.160.6.20  raeburn  2076:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2077:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2078:                       '<input type="text" name="authorquota" value="'.
                   2079:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2080:     }
                   2081:     $datatable .= '</tr>';
1.72      raeburn  2082:     $typecount ++;
                   2083:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2084:     $datatable .= '<tr'.$css_class.'>'.
1.160.6.20  raeburn  2085:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2086:     if ($context eq 'requestcourses') {
1.109     raeburn  2087:         $datatable .= &mt('(overrides affiliation, if set)').
                   2088:                       '</td>'.
                   2089:                       '<td class="LC_left_item">'.
                   2090:                       '<table><tr>';
1.101     raeburn  2091:     } else {
1.109     raeburn  2092:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2093:                       '</td>'.
                   2094:                       '<td class="LC_left_item" colspan="2">'.
                   2095:                       '<br />';
1.101     raeburn  2096:     }
                   2097:     my %advcell;
1.72      raeburn  2098:     foreach my $item (@usertools) {
1.101     raeburn  2099:         if ($context eq 'requestcourses') {
                   2100:             my ($curroption,$currlimit);
                   2101:             if (ref($settings) eq 'HASH') {
                   2102:                 if (ref($settings->{$item}) eq 'HASH') {
                   2103:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2104:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2105:                         $currlimit = $1;
                   2106:                     }
                   2107:                 }
                   2108:             }
                   2109:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2110:             my $checked = '';
                   2111:             if ($curroption eq '') {
                   2112:                 $checked = ' checked="checked"';
                   2113:             }
                   2114:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2115:                                '<input type="radio" name="crsreq_'.$item.
                   2116:                                '__LC_adv" value=""'.$checked.' />'.
                   2117:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2118:             foreach my $option (@options) {
                   2119:                 my $val = $option;
                   2120:                 if ($option eq 'norequest') {
                   2121:                     $val = 0;
                   2122:                 }
                   2123:                 if ($option eq 'validate') {
                   2124:                     my $canvalidate = 0;
                   2125:                     if (ref($validations{$item}) eq 'HASH') {
                   2126:                         if ($validations{$item}{'_LC_adv'}) {
                   2127:                             $canvalidate = 1;
                   2128:                         }
                   2129:                     }
                   2130:                     next if (!$canvalidate);
                   2131:                 }
                   2132:                 my $checked = '';
1.104     raeburn  2133:                 if ($val eq $curroption) {
1.101     raeburn  2134:                     $checked = ' checked="checked"';
                   2135:                 } elsif ($option eq 'autolimit') {
                   2136:                     if ($curroption =~ /^autolimit/) {
                   2137:                         $checked = ' checked="checked"';
                   2138:                     }
                   2139:                 }
                   2140:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2141:                                   '<input type="radio" name="crsreq_'.$item.
                   2142:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2143:                                   $titles{$option}.'</label>';
                   2144:                 if ($option eq 'autolimit') {
1.127     raeburn  2145:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2146:                                        $item.'_limit__LC_adv" size="1" '.
                   2147:                                        'value="'.$currlimit.'" />';
                   2148:                 }
1.127     raeburn  2149:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2150:                 if ($option eq 'autolimit') {
1.127     raeburn  2151:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2152:                 }
1.101     raeburn  2153:             }
1.160.6.5  raeburn  2154:         } elsif ($context eq 'requestauthor') {
                   2155:             my $curroption;
                   2156:             if (ref($settings) eq 'HASH') {
                   2157:                 $curroption = $settings->{'_LC_adv'};
                   2158:             }
                   2159:             my $checked = '';
                   2160:             if ($curroption eq '') {
                   2161:                 $checked = ' checked="checked"';
                   2162:             }
                   2163:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2164:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2165:                           ' value=""'.$checked.' />'.
                   2166:                           &mt('No override set').'</label></span>&nbsp; ';
                   2167:             foreach my $option (@options) {
                   2168:                 my $val = $option;
                   2169:                 if ($option eq 'norequest') {
                   2170:                     $val = 0;
                   2171:                 }
                   2172:                 my $checked = '';
                   2173:                 if ($val eq $curroption) {
                   2174:                     $checked = ' checked="checked"';
                   2175:                 }
                   2176:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8  raeburn  2177:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2178:                               ' value="'.$val.'"'.$checked.' />'.
1.160.6.5  raeburn  2179:                               $titles{$option}.'</label></span>&nbsp; ';
                   2180:             }
1.101     raeburn  2181:         } else {
                   2182:             my $checked = 'checked="checked" ';
                   2183:             if (ref($settings) eq 'HASH') {
                   2184:                 if (ref($settings->{$item}) eq 'HASH') {
                   2185:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2186:                         $checked = '';
                   2187:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2188:                         $checked = 'checked="checked" ';
                   2189:                     }
1.79      raeburn  2190:                 }
1.72      raeburn  2191:             }
1.101     raeburn  2192:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2193:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2194:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2195:                           '</label></span>&nbsp; ';
                   2196:         }
                   2197:     }
                   2198:     if ($context eq 'requestcourses') {
                   2199:         $datatable .= '</tr><tr>';
                   2200:         foreach my $item (@usertools) {
1.106     raeburn  2201:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2202:         }
1.101     raeburn  2203:         $datatable .= '</tr></table>';
1.72      raeburn  2204:     }
1.98      raeburn  2205:     $datatable .= '</td></tr>';
1.30      raeburn  2206:     $$rowtotal += $typecount;
1.3       raeburn  2207:     return $datatable;
                   2208: }
                   2209: 
1.160.6.5  raeburn  2210: sub print_requestmail {
1.160.6.93  raeburn  2211:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25  raeburn  2212:     my ($now,$datatable,%currapp);
1.102     raeburn  2213:     $now = time;
                   2214:     if (ref($settings) eq 'HASH') {
                   2215:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2216:             if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34  raeburn  2217:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2218:             }
                   2219:         }
                   2220:     }
1.160.6.16  raeburn  2221:     my $numinrow = 2;
1.160.6.34  raeburn  2222:     my $css_class;
1.160.6.93  raeburn  2223:     if ($$rowtotal%2) {
                   2224:         $css_class = 'LC_odd_row';
                   2225:     }
                   2226:     if ($customcss) {
                   2227:         $css_class .= " $customcss";
                   2228:     }
                   2229:     $css_class =~ s/^\s+//;
                   2230:     if ($css_class) {
                   2231:         $css_class = ' class="'.$css_class.'"';
                   2232:     }
                   2233:     if ($rowstyle) {
                   2234:         $css_class .= ' style="'.$rowstyle.'"';
                   2235:     }
1.160.6.5  raeburn  2236:     my $text;
                   2237:     if ($action eq 'requestcourses') {
                   2238:         $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34  raeburn  2239:     } elsif ($action eq 'requestauthor') {
                   2240:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5  raeburn  2241:     } else {
1.160.6.34  raeburn  2242:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5  raeburn  2243:     }
1.160.6.34  raeburn  2244:     $datatable = '<tr'.$css_class.'>'.
1.160.6.5  raeburn  2245:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2246:                  ' <td class="LC_left_item">';
1.160.6.16  raeburn  2247:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34  raeburn  2248:                                                  $action.'notifyapproval',%currapp);
1.160.6.16  raeburn  2249:     if ($numdc > 0) {
                   2250:         $datatable .= $table;
1.102     raeburn  2251:     } else {
                   2252:         $datatable .= &mt('There are no active Domain Coordinators');
                   2253:     }
                   2254:     $datatable .='</td></tr>';
                   2255:     return $datatable;
                   2256: }
                   2257: 
1.160.6.30  raeburn  2258: sub print_studentcode {
                   2259:     my ($settings,$rowtotal) = @_;
                   2260:     my $rownum = 0; 
                   2261:     my ($output,%current);
                   2262:     my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51  raeburn  2263:     if (ref($settings) eq 'HASH') {
                   2264:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2265:             foreach my $type (@crstypes) {
                   2266:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2267:             }
1.160.6.30  raeburn  2268:         }
                   2269:     }
                   2270:     $output .= '<tr>'.
                   2271:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2272:                '<td class="LC_left_item">';
                   2273:     foreach my $type (@crstypes) {
                   2274:         my $check = ' ';
                   2275:         if ($current{$type}) {
                   2276:             $check = ' checked="checked" ';
                   2277:         }
                   2278:         $output .= '<span class="LC_nobreak"><label>'.
                   2279:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2280:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2281:     }
                   2282:     $output .= '</td></tr>';
                   2283:     $$rowtotal ++;
                   2284:     return $output;
                   2285: }
                   2286: 
                   2287: sub print_textbookcourses {
1.160.6.46  raeburn  2288:     my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30  raeburn  2289:     my $rownum = 0;
                   2290:     my $css_class;
                   2291:     my $itemcount = 1;
                   2292:     my $maxnum = 0;
                   2293:     my $bookshash;
                   2294:     if (ref($settings) eq 'HASH') {
1.160.6.46  raeburn  2295:         $bookshash = $settings->{$type};
1.160.6.30  raeburn  2296:     }
                   2297:     my %ordered;
                   2298:     if (ref($bookshash) eq 'HASH') {
                   2299:         foreach my $item (keys(%{$bookshash})) {
                   2300:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2301:                 my $num = $bookshash->{$item}{'order'};
                   2302:                 $ordered{$num} = $item;
                   2303:             }
                   2304:         }
                   2305:     }
                   2306:     my $confname = $dom.'-domainconfig';
                   2307:     my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46  raeburn  2308:     my $maxnum = scalar(keys(%ordered));
                   2309:     my $datatable;
1.160.6.30  raeburn  2310:     if (keys(%ordered)) {
                   2311:         my @items = sort { $a <=> $b } keys(%ordered);
                   2312:         for (my $i=0; $i<@items; $i++) {
                   2313:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2314:             my $key = $ordered{$items[$i]};
                   2315:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2316:             my $coursetitle = $coursehash{'description'};
1.160.6.47  raeburn  2317:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30  raeburn  2318:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2319:                 $subject = $bookshash->{$key}->{'subject'};
                   2320:                 $title = $bookshash->{$key}->{'title'};
1.160.6.46  raeburn  2321:                 if ($type eq 'textbooks') {
1.160.6.47  raeburn  2322:                     $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46  raeburn  2323:                     $author = $bookshash->{$key}->{'author'};
                   2324:                     $image = $bookshash->{$key}->{'image'};
                   2325:                     if ($image ne '') {
                   2326:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2327:                         my $imagethumb = "$path/tn-".$imagefile;
                   2328:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2329:                     }
1.160.6.30  raeburn  2330:                 }
                   2331:             }
1.160.6.46  raeburn  2332:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30  raeburn  2333:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46  raeburn  2334:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30  raeburn  2335:             for (my $k=0; $k<=$maxnum; $k++) {
                   2336:                 my $vpos = $k+1;
                   2337:                 my $selstr;
                   2338:                 if ($k == $i) {
                   2339:                     $selstr = ' selected="selected" ';
                   2340:                 }
                   2341:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2342:             }
                   2343:             $datatable .= '</select>'.('&nbsp;'x2).
1.160.6.46  raeburn  2344:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30  raeburn  2345:                 &mt('Delete?').'</label></span></td>'.
                   2346:                 '<td colspan="2">'.
1.160.6.46  raeburn  2347:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30  raeburn  2348:                 ('&nbsp;'x2).
1.160.6.46  raeburn  2349:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2350:             if ($type eq 'textbooks') {
                   2351:                 $datatable .= ('&nbsp;'x2).
1.160.6.47  raeburn  2352:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2353:                               ('&nbsp;'x2).
1.160.6.46  raeburn  2354:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2355:                               ('&nbsp;'x2).
                   2356:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2357:                 if ($image) {
                   2358:                     $datatable .= '<span class="LC_nobreak">'.
                   2359:                                   $imgsrc.
                   2360:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2361:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2362:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2363:                 }
                   2364:                 if ($switchserver) {
                   2365:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2366:                 } else {
                   2367:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2368:                 }
1.160.6.30  raeburn  2369:             }
1.160.6.46  raeburn  2370:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30  raeburn  2371:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2372:                           $coursetitle.'</span></td></tr>'."\n";
                   2373:             $itemcount ++;
                   2374:         }
                   2375:     }
                   2376:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46  raeburn  2377:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30  raeburn  2378:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46  raeburn  2379:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2380:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30  raeburn  2381:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2382:         my $vpos = $k+1;
                   2383:         my $selstr;
                   2384:         if ($k == $maxnum) {
                   2385:             $selstr = ' selected="selected" ';
                   2386:         }
                   2387:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2388:     }
                   2389:     $datatable .= '</select>&nbsp;'."\n".
1.160.6.87  raeburn  2390:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30  raeburn  2391:                   '<td colspan="2">'.
1.160.6.46  raeburn  2392:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30  raeburn  2393:                   ('&nbsp;'x2).
1.160.6.46  raeburn  2394:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2395:                   ('&nbsp;'x2);
                   2396:     if ($type eq 'textbooks') {
1.160.6.47  raeburn  2397:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2398:                       ('&nbsp;'x2).
                   2399:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46  raeburn  2400:                       ('&nbsp;'x2).
                   2401:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2402:         if ($switchserver) {
                   2403:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2404:         } else {
                   2405:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2406:         }
1.160.6.87  raeburn  2407:         $datatable .= '</span>'."\n";
1.160.6.30  raeburn  2408:     }
1.160.6.87  raeburn  2409:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.160.6.46  raeburn  2410:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2411:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30  raeburn  2412:                   &Apache::loncommon::selectcourse_link
1.160.6.87  raeburn  2413:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30  raeburn  2414:                   '</span></td>'."\n".
                   2415:                   '</tr>'."\n";
                   2416:     $itemcount ++;
                   2417:     return $datatable;
                   2418: }
                   2419: 
                   2420: sub textbookcourses_javascript {
1.160.6.46  raeburn  2421:     my ($settings) = @_;
                   2422:     return unless(ref($settings) eq 'HASH');
                   2423:     my (%ordered,%total,%jstext);
                   2424:     foreach my $type ('textbooks','templates') {
                   2425:         $total{$type} = 0;
                   2426:         if (ref($settings->{$type}) eq 'HASH') {
                   2427:             foreach my $item (keys(%{$settings->{$type}})) {
                   2428:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2429:                     my $num = $settings->{$type}->{$item}{'order'};
                   2430:                     $ordered{$type}{$num} = $item;
                   2431:                 }
                   2432:             }
                   2433:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2434:         }
                   2435:         my @jsarray = ();
                   2436:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2437:             push(@jsarray,$ordered{$type}{$item});
                   2438:         }
                   2439:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30  raeburn  2440:     }
                   2441:     return <<"ENDSCRIPT";
                   2442: <script type="text/javascript">
                   2443: // <![CDATA[
1.160.6.46  raeburn  2444: function reorderBooks(form,item,caller) {
1.160.6.30  raeburn  2445:     var changedVal;
1.160.6.46  raeburn  2446: $jstext{'textbooks'};
                   2447: $jstext{'templates'};
                   2448:     var newpos;
                   2449:     var maxh;
                   2450:     if (caller == 'textbooks') {  
                   2451:         newpos = 'textbooks_addbook_pos';
                   2452:         maxh = 1 + $total{'textbooks'};
                   2453:     } else {
                   2454:         newpos = 'templates_addbook_pos';
                   2455:         maxh = 1 + $total{'templates'};
                   2456:     }
1.160.6.30  raeburn  2457:     var current = new Array;
                   2458:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2459:     if (item == newpos) {
                   2460:         changedVal = newitemVal;
                   2461:     } else {
                   2462:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2463:         current[newitemVal] = newpos;
                   2464:     }
1.160.6.46  raeburn  2465:     if (caller == 'textbooks') {
                   2466:         for (var i=0; i<textbooks.length; i++) {
                   2467:             var elementName = 'textbooks_'+textbooks[i];
                   2468:             if (elementName != item) {
                   2469:                 if (form.elements[elementName]) {
                   2470:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2471:                     current[currVal] = elementName;
                   2472:                 }
                   2473:             }
                   2474:         }
                   2475:     }
                   2476:     if (caller == 'templates') {
                   2477:         for (var i=0; i<templates.length; i++) {
                   2478:             var elementName = 'templates_'+templates[i];
                   2479:             if (elementName != item) {
                   2480:                 if (form.elements[elementName]) {
                   2481:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2482:                     current[currVal] = elementName;
                   2483:                 }
1.160.6.30  raeburn  2484:             }
                   2485:         }
                   2486:     }
                   2487:     var oldVal;
                   2488:     for (var j=0; j<maxh; j++) {
                   2489:         if (current[j] == undefined) {
                   2490:             oldVal = j;
                   2491:         }
                   2492:     }
                   2493:     if (oldVal < changedVal) {
                   2494:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2495:            var elementName = current[k];
                   2496:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2497:         }
                   2498:     } else {
                   2499:         for (var k=changedVal; k<oldVal; k++) {
                   2500:             var elementName = current[k];
                   2501:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2502:         }
                   2503:     }
                   2504:     return;
                   2505: }
                   2506: 
                   2507: // ]]>
                   2508: </script>
                   2509: 
                   2510: ENDSCRIPT
                   2511: }
                   2512: 
1.3       raeburn  2513: sub print_autoenroll {
1.30      raeburn  2514:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2515:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68  raeburn  2516:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2517:     if (ref($settings) eq 'HASH') {
                   2518:         if (exists($settings->{'run'})) {
                   2519:             if ($settings->{'run'} eq '0') {
                   2520:                 $runoff = ' checked="checked" ';
                   2521:                 $runon = ' ';
                   2522:             } else {
                   2523:                 $runon = ' checked="checked" ';
                   2524:                 $runoff = ' ';
                   2525:             }
                   2526:         } else {
                   2527:             if ($autorun) {
                   2528:                 $runon = ' checked="checked" ';
                   2529:                 $runoff = ' ';
                   2530:             } else {
                   2531:                 $runoff = ' checked="checked" ';
                   2532:                 $runon = ' ';
                   2533:             }
                   2534:         }
1.129     raeburn  2535:         if (exists($settings->{'co-owners'})) {
                   2536:             if ($settings->{'co-owners'} eq '0') {
                   2537:                 $coownersoff = ' checked="checked" ';
                   2538:                 $coownerson = ' ';
                   2539:             } else {
                   2540:                 $coownerson = ' checked="checked" ';
                   2541:                 $coownersoff = ' ';
                   2542:             }
                   2543:         } else {
                   2544:             $coownersoff = ' checked="checked" ';
                   2545:             $coownerson = ' ';
                   2546:         }
1.3       raeburn  2547:         if (exists($settings->{'sender_domain'})) {
                   2548:             $defdom = $settings->{'sender_domain'};
                   2549:         }
1.160.6.68  raeburn  2550:         if (exists($settings->{'autofailsafe'})) {
                   2551:             $failsafe = $settings->{'autofailsafe'};
                   2552:         }
1.14      raeburn  2553:     } else {
                   2554:         if ($autorun) {
                   2555:             $runon = ' checked="checked" ';
                   2556:             $runoff = ' ';
                   2557:         } else {
                   2558:             $runoff = ' checked="checked" ';
                   2559:             $runon = ' ';
                   2560:         }
1.3       raeburn  2561:     }
                   2562:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2563:     my $notif_sender;
                   2564:     if (ref($settings) eq 'HASH') {
                   2565:         $notif_sender = $settings->{'sender_uname'};
                   2566:     }
1.3       raeburn  2567:     my $datatable='<tr class="LC_odd_row">'.
                   2568:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2569:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2570:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2571:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2572:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2573:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2574:                   '</tr><tr>'.
                   2575:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2576:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2577:                   &mt('username').':&nbsp;'.
                   2578:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2579:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2580:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2581:                   '<tr class="LC_odd_row">'.
                   2582:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2583:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2584:                   '<input type="radio" name="autoassign_coowners"'.
                   2585:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2586:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2587:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68  raeburn  2588:                   '</tr><tr>'.
                   2589:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2590:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2591:                   '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87  raeburn  2592:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68  raeburn  2593:     $$rowtotal += 4;
1.3       raeburn  2594:     return $datatable;
                   2595: }
                   2596: 
                   2597: sub print_autoupdate {
1.30      raeburn  2598:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2599:     my $datatable;
                   2600:     if ($position eq 'top') {
                   2601:         my $updateon = ' ';
                   2602:         my $updateoff = ' checked="checked" ';
                   2603:         my $classlistson = ' ';
                   2604:         my $classlistsoff = ' checked="checked" ';
                   2605:         if (ref($settings) eq 'HASH') {
                   2606:             if ($settings->{'run'} eq '1') {
                   2607:                 $updateon = $updateoff;
                   2608:                 $updateoff = ' ';
                   2609:             }
                   2610:             if ($settings->{'classlists'} eq '1') {
                   2611:                 $classlistson = $classlistsoff;
                   2612:                 $classlistsoff = ' ';
                   2613:             }
                   2614:         }
                   2615:         my %title = (
                   2616:                    run => 'Auto-update active?',
                   2617:                    classlists => 'Update information in classlists?',
                   2618:                     );
                   2619:         $datatable = '<tr class="LC_odd_row">'. 
                   2620:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2621:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2622:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2623:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2624:                   '<label><input type="radio" name="autoupdate_run"'.
                   2625:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2626:                   '</tr><tr>'.
                   2627:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2628:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2629:                   '<label><input type="radio" name="classlists"'.
                   2630:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2631:                   '<label><input type="radio" name="classlists"'.
                   2632:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2633:                   '</tr>';
1.30      raeburn  2634:         $$rowtotal += 2;
1.131     raeburn  2635:     } elsif ($position eq 'middle') {
                   2636:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2637:         my $numinrow = 3;
                   2638:         my $locknamesettings;
                   2639:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2640:                                      $dom,$numinrow,$othertitle,
1.160.6.93  raeburn  2641:                                     'lockablenames',$rowtotal);
1.131     raeburn  2642:         $$rowtotal ++;
1.3       raeburn  2643:     } else {
1.44      raeburn  2644:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2645:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2646:                       'permanentemail','id');
1.33      raeburn  2647:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2648:         my $numrows = 0;
1.26      raeburn  2649:         if (ref($types) eq 'ARRAY') {
                   2650:             if (@{$types} > 0) {
                   2651:                 $datatable = 
                   2652:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2653:                                          \@fields,$types,\$numrows);
1.30      raeburn  2654:                     $$rowtotal += @{$types}; 
1.26      raeburn  2655:             }
1.3       raeburn  2656:         }
                   2657:         $datatable .= 
                   2658:             &usertype_update_row($settings,{'default' => $othertitle},
                   2659:                                  \%fieldtitles,\@fields,['default'],
                   2660:                                  \$numrows);
1.30      raeburn  2661:         $$rowtotal ++;     
1.3       raeburn  2662:     }
                   2663:     return $datatable;
                   2664: }
                   2665: 
1.125     raeburn  2666: sub print_autocreate {
                   2667:     my ($dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  2668:     my (%createon,%createoff,%currhash);
1.125     raeburn  2669:     my @types = ('xml','req');
                   2670:     if (ref($settings) eq 'HASH') {
                   2671:         foreach my $item (@types) {
                   2672:             $createoff{$item} = ' checked="checked" ';
                   2673:             $createon{$item} = ' ';
                   2674:             if (exists($settings->{$item})) {
                   2675:                 if ($settings->{$item}) {
                   2676:                     $createon{$item} = ' checked="checked" ';
                   2677:                     $createoff{$item} = ' ';
                   2678:                 }
                   2679:             }
                   2680:         }
1.160.6.16  raeburn  2681:         if ($settings->{'xmldc'} ne '') {
                   2682:             $currhash{$settings->{'xmldc'}} = 1;
                   2683:         }
1.125     raeburn  2684:     } else {
                   2685:         foreach my $item (@types) {
                   2686:             $createoff{$item} = ' checked="checked" ';
                   2687:             $createon{$item} = ' ';
                   2688:         }
                   2689:     }
                   2690:     $$rowtotal += 2;
1.160.6.16  raeburn  2691:     my $numinrow = 2;
1.125     raeburn  2692:     my $datatable='<tr class="LC_odd_row">'.
                   2693:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2694:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2695:                   '<input type="radio" name="autocreate_xml"'.
                   2696:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2697:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2698:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2699:                   '</td></tr><tr>'.
                   2700:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2701:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2702:                   '<input type="radio" name="autocreate_req"'.
                   2703:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2704:                   '<label><input type="radio" name="autocreate_req"'.
                   2705:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16  raeburn  2706:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2707:                                                    'autocreate_xmldc',%currhash);
1.160.6.50  raeburn  2708:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2709:     if ($numdc > 1) {
1.160.6.50  raeburn  2710:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2711:                       '</td><td class="LC_left_item">';
1.125     raeburn  2712:     } else {
1.160.6.50  raeburn  2713:         $datatable .= &mt('Course creation processed as:').
                   2714:                       '</td><td class="LC_right_item">';
1.125     raeburn  2715:     }
1.160.6.50  raeburn  2716:     $datatable .= $dctable.'</td></tr>';
1.160.6.16  raeburn  2717:     $$rowtotal += $rows;
1.125     raeburn  2718:     return $datatable;
                   2719: }
                   2720: 
1.23      raeburn  2721: sub print_directorysrch {
1.160.6.72  raeburn  2722:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2723:     my $datatable;
                   2724:     if ($position eq 'top') {
                   2725:         my $instsrchon = ' ';
                   2726:         my $instsrchoff = ' checked="checked" ';
                   2727:         my ($exacton,$containson,$beginson);
                   2728:         my $instlocalon = ' ';
                   2729:         my $instlocaloff = ' checked="checked" ';
                   2730:         if (ref($settings) eq 'HASH') {
                   2731:             if ($settings->{'available'} eq '1') {
                   2732:                 $instsrchon = $instsrchoff;
                   2733:                 $instsrchoff = ' ';
                   2734:             }
                   2735:             if ($settings->{'localonly'} eq '1') {
                   2736:                 $instlocalon = $instlocaloff;
                   2737:                 $instlocaloff = ' ';
                   2738:             }
                   2739:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2740:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2741:                     if ($type eq 'exact') {
                   2742:                         $exacton = ' checked="checked" ';
                   2743:                     } elsif ($type eq 'contains') {
                   2744:                         $containson = ' checked="checked" ';
                   2745:                     } elsif ($type eq 'begins') {
                   2746:                         $beginson = ' checked="checked" ';
                   2747:                     }
                   2748:                 }
                   2749:             } else {
                   2750:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2751:                     $exacton = ' checked="checked" ';
                   2752:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2753:                     $containson = ' checked="checked" ';
                   2754:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2755:                     $exacton = ' checked="checked" ';
                   2756:                     $containson = ' checked="checked" ';
                   2757:                 }
                   2758:             }
1.23      raeburn  2759:         }
1.160.6.72  raeburn  2760:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2761:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2762: 
1.160.6.72  raeburn  2763:         my $numinrow = 4;
                   2764:         my $cansrchrow = 0;
                   2765:         $datatable='<tr class="LC_odd_row">'.
                   2766:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2767:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2768:                    '<input type="radio" name="dirsrch_available"'.
                   2769:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2770:                    '<label><input type="radio" name="dirsrch_available"'.
                   2771:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2772:                    '</tr><tr>'.
                   2773:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2774:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2775:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2776:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2777:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2778:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2779:                    '</tr>';
                   2780:         $$rowtotal += 2;
                   2781:         if (ref($usertypes) eq 'HASH') {
                   2782:             if (keys(%{$usertypes}) > 0) {
                   2783:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93  raeburn  2784:                                              $numinrow,$othertitle,'cansearch',
                   2785:                                              $rowtotal);
1.160.6.72  raeburn  2786:                 $cansrchrow = 1;
                   2787:             }
1.26      raeburn  2788:         }
1.160.6.72  raeburn  2789:         if ($cansrchrow) {
                   2790:             $$rowtotal ++;
                   2791:             $datatable .= '<tr>';
                   2792:         } else {
                   2793:             $datatable .= '<tr class="LC_odd_row">';
                   2794:         }
                   2795:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2796:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2797:         foreach my $title (@{$titleorder}) {
                   2798:             if (defined($searchtitles->{$title})) {
                   2799:                 my $check = ' ';
                   2800:                 if (ref($settings) eq 'HASH') {
                   2801:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2802:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2803:                             $check = ' checked="checked" ';
                   2804:                         }
1.39      raeburn  2805:                     }
1.25      raeburn  2806:                 }
1.160.6.72  raeburn  2807:                 $datatable .= '<td class="LC_left_item">'.
                   2808:                               '<span class="LC_nobreak"><label>'.
                   2809:                               '<input type="checkbox" name="searchby" '.
                   2810:                               'value="'.$title.'"'.$check.'/>'.
                   2811:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2812:             }
                   2813:         }
1.160.6.72  raeburn  2814:         $datatable .= '</tr></table></td></tr>';
                   2815:         $$rowtotal ++;
                   2816:         if ($cansrchrow) {
                   2817:             $datatable .= '<tr class="LC_odd_row">';
                   2818:         } else {
                   2819:             $datatable .= '<tr>';
                   2820:         }
                   2821:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2822:                       '<td class="LC_left_item" colspan="2">'.
                   2823:                       '<span class="LC_nobreak"><label>'.
                   2824:                       '<input type="checkbox" name="searchtypes" '.
                   2825:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2826:                       '</label>&nbsp;'.
                   2827:                       '<label><input type="checkbox" name="searchtypes" '.
                   2828:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2829:                       '</label>&nbsp;'.
                   2830:                       '<label><input type="checkbox" name="searchtypes" '.
                   2831:                       $containson.' value="contains" />'.&mt('Contains').
                   2832:                       '</label></span></td></tr>';
                   2833:         $$rowtotal ++;
1.26      raeburn  2834:     } else {
1.160.6.72  raeburn  2835:         my $domsrchon = ' checked="checked" ';
                   2836:         my $domsrchoff = ' ';
                   2837:         my $domlocalon = ' ';
                   2838:         my $domlocaloff = ' checked="checked" ';
                   2839:         if (ref($settings) eq 'HASH') {
                   2840:             if ($settings->{'lclocalonly'} eq '1') {
                   2841:                 $domlocalon = $domlocaloff;
                   2842:                 $domlocaloff = ' ';
                   2843:             }
                   2844:             if ($settings->{'lcavailable'} eq '0') {
                   2845:                 $domsrchoff = $domsrchon;
                   2846:                 $domsrchon = ' ';
                   2847:             }
                   2848:         }
                   2849:         $datatable='<tr class="LC_odd_row">'.
                   2850:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2851:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2852:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2853:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2854:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2855:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2856:                       '</tr><tr>'.
                   2857:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   2858:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2859:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   2860:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2861:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   2862:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2863:                       '</tr>';
                   2864:         $$rowtotal += 2;
1.26      raeburn  2865:     }
1.25      raeburn  2866:     return $datatable;
                   2867: }
                   2868: 
1.28      raeburn  2869: sub print_contacts {
1.160.6.78  raeburn  2870:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  2871:     my $datatable;
                   2872:     my @contacts = ('adminemail','supportemail');
1.160.6.78  raeburn  2873:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107  raeburn  2874:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78  raeburn  2875:     if ($position eq 'top') {
                   2876:         if (ref($settings) eq 'HASH') {
                   2877:             foreach my $item (@contacts) {
                   2878:                 if (exists($settings->{$item})) {
                   2879:                     $to{$item} = $settings->{$item};
                   2880:                 }
1.28      raeburn  2881:             }
                   2882:         }
1.160.6.78  raeburn  2883:     } elsif ($position eq 'middle') {
                   2884:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91  raeburn  2885:                      'updatesmail','idconflictsmail','hostipmail');
1.28      raeburn  2886:         foreach my $type (@mailings) {
1.160.6.78  raeburn  2887:             $otheremails{$type} = '';
                   2888:         }
1.160.6.107  raeburn  2889:     } elsif ($position eq 'lower') {
                   2890:         if (ref($settings) eq 'HASH') {
                   2891:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   2892:                 %lonstatus = %{$settings->{'lonstatus'}};
                   2893:             }
                   2894:         }
1.160.6.78  raeburn  2895:     } else {
                   2896:         @mailings = ('helpdeskmail','otherdomsmail');
                   2897:         foreach my $type (@mailings) {
                   2898:             $otheremails{$type} = '';
                   2899:         }
                   2900:         $bccemails{'helpdeskmail'} = '';
                   2901:         $bccemails{'otherdomsmail'} = '';
                   2902:         $includestr{'helpdeskmail'} = '';
                   2903:         $includestr{'otherdomsmail'} = '';
                   2904:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   2905:     }
                   2906:     if (ref($settings) eq 'HASH') {
1.160.6.107  raeburn  2907:         unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78  raeburn  2908:             foreach my $type (@mailings) {
                   2909:                 if (exists($settings->{$type})) {
                   2910:                     if (ref($settings->{$type}) eq 'HASH') {
                   2911:                         foreach my $item (@contacts) {
                   2912:                             if ($settings->{$type}{$item}) {
                   2913:                                 $checked{$type}{$item} = ' checked="checked" ';
                   2914:                             }
1.28      raeburn  2915:                         }
1.160.6.78  raeburn  2916:                         $otheremails{$type} = $settings->{$type}{'others'};
                   2917:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   2918:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   2919:                             if ($settings->{$type}{'include'} ne '') {
                   2920:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2921:                                 $includestr{$type} = &unescape($includestr{$type});
                   2922:                             }
                   2923:                         }
                   2924:                     }
                   2925:                 } elsif ($type eq 'lonstatusmail') {
                   2926:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2927:                 }
                   2928:             }
                   2929:         }
                   2930:         if ($position eq 'bottom') {
                   2931:             foreach my $type (@mailings) {
                   2932:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   2933:                 if ($settings->{$type}{'include'} ne '') {
                   2934:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2935:                     $includestr{$type} = &unescape($includestr{$type});
                   2936:                 }
                   2937:             }
                   2938:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   2939:                 if (ref($fields) eq 'ARRAY') {
                   2940:                     foreach my $field (@{$fields}) {
                   2941:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  2942:                     }
1.160.6.78  raeburn  2943:                 }
                   2944:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   2945:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   2946:                 } else {
                   2947:                     $maxsize = '1.0';
                   2948:                 }
                   2949:             } else {
                   2950:                 if (ref($fields) eq 'ARRAY') {
                   2951:                     foreach my $field (@{$fields}) {
                   2952:                         $currfield{$field} = 'yes';
1.134     raeburn  2953:                     }
1.28      raeburn  2954:                 }
1.160.6.78  raeburn  2955:                 $maxsize = '1.0';
1.28      raeburn  2956:             }
                   2957:         }
                   2958:     } else {
1.160.6.78  raeburn  2959:         if ($position eq 'top') {
                   2960:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2961:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2962:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2963:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   2964:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2965:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   2966:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   2967:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91  raeburn  2968:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78  raeburn  2969:         } elsif ($position eq 'bottom') {
                   2970:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2971:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   2972:             if (ref($fields) eq 'ARRAY') {
                   2973:                 foreach my $field (@{$fields}) {
                   2974:                     $currfield{$field} = 'yes';
                   2975:                 }
                   2976:             }
                   2977:             $maxsize = '1.0';
                   2978:         }
1.28      raeburn  2979:     }
                   2980:     my ($titles,$short_titles) = &contact_titles();
                   2981:     my $rownum = 0;
                   2982:     my $css_class;
1.160.6.78  raeburn  2983:     if ($position eq 'top') {
                   2984:         foreach my $item (@contacts) {
                   2985:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   2986:             $datatable .= '<tr'.$css_class.'>'. 
                   2987:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2988:                           '</span></td><td class="LC_right_item">'.
                   2989:                           '<input type="text" name="'.$item.'" value="'.
                   2990:                           $to{$item}.'" /></td></tr>';
                   2991:             $rownum ++;
                   2992:         }
1.160.6.101  raeburn  2993:     } elsif ($position eq 'bottom') {
                   2994:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   2995:         $datatable .= '<tr'.$css_class.'>'.
                   2996:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   2997:                       &mt('(e-mail, subject, and description always shown)').
                   2998:                       '</td><td class="LC_left_item">';
                   2999:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3000:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3001:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3002:             foreach my $field (@{$fields}) {
                   3003:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3004:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3005:                     $datatable .= ' '.&mt('(logged-in users)');
                   3006:                 }
                   3007:                 $datatable .='</td><td>';
                   3008:                 my $clickaction;
                   3009:                 if ($field eq 'screenshot') {
                   3010:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3011:                 }
                   3012:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3013:                     foreach my $option (@{$possoptions->{$field}}) {
                   3014:                         my $checked;
                   3015:                         if ($currfield{$field} eq $option) {
                   3016:                             $checked = ' checked="checked"';
                   3017:                         }
                   3018:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3019:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3020:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3021:                                       '</label></span>'.('&nbsp;'x2);
                   3022:                     }
                   3023:                 }
                   3024:                 if ($field eq 'screenshot') {
                   3025:                     my $display;
                   3026:                     if ($currfield{$field} eq 'no') {
                   3027:                         $display = ' style="display:none"';
                   3028:                     }
                   3029:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
                   3030:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3031:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3032:                 }
                   3033:                 $datatable .= '</td></tr>';
                   3034:             }
                   3035:             $datatable .= '</table>';
                   3036:         }
                   3037:         $datatable .= '</td></tr>'."\n";
                   3038:         $rownum ++;
                   3039:     }
1.160.6.107  raeburn  3040:     unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78  raeburn  3041:         foreach my $type (@mailings) {
                   3042:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3043:             $datatable .= '<tr'.$css_class.'>'.
                   3044:                           '<td><span class="LC_nobreak">'.
                   3045:                           $titles->{$type}.': </span></td>'.
                   3046:                           '<td class="LC_left_item">';
                   3047:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3048:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3049:             }
                   3050:             $datatable .= '<span class="LC_nobreak">';
                   3051:             foreach my $item (@contacts) {
                   3052:                 $datatable .= '<label>'.
                   3053:                               '<input type="checkbox" name="'.$type.'"'.
                   3054:                               $checked{$type}{$item}.
                   3055:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3056:                               '</label>&nbsp;';
                   3057:             }
                   3058:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3059:                           '<input type="text" name="'.$type.'_others" '.
                   3060:                           'value="'.$otheremails{$type}.'"  />';
                   3061:             my %locchecked;
                   3062:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3063:                 foreach my $loc ('s','b') {
                   3064:                     if ($includeloc{$type} eq $loc) {
                   3065:                         $locchecked{$loc} = ' checked="checked"';
                   3066:                         last;
                   3067:                     }
                   3068:                 }
                   3069:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3070:                               '<input type="text" name="'.$type.'_bcc" '.
                   3071:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3072:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3073:                               &mt('Text automatically added to e-mail:').' '.
1.160.6.87  raeburn  3074:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78  raeburn  3075:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3076:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3077:                               ('&nbsp;'x2).
                   3078:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3079:                               '</span></fieldset>';
                   3080:             }
                   3081:             $datatable .= '</td></tr>'."\n";
                   3082:             $rownum ++;
                   3083:         }
1.28      raeburn  3084:     }
1.160.6.78  raeburn  3085:     if ($position eq 'middle') {
                   3086:         my %choices;
1.160.6.107  raeburn  3087:         my $corelink = &core_link_msu();
                   3088:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78  raeburn  3089:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107  raeburn  3090:                                         $corelink);
                   3091:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   3092:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78  raeburn  3093:         my %defaultchecked = ('reporterrors'  => 'on',
1.160.6.107  raeburn  3094:                               'reportupdates' => 'on',
                   3095:                               'reportstatus'  => 'on');
1.160.6.78  raeburn  3096:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3097:                                                    \%choices,$rownum);
                   3098:         $datatable .= $reports;
1.160.6.107  raeburn  3099:     } elsif ($position eq 'lower') {
1.160.6.109  raeburn  3100:         my (%current,%excluded,%weights);
1.160.6.107  raeburn  3101:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   3102:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109  raeburn  3103:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107  raeburn  3104:         } else {
1.160.6.109  raeburn  3105:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107  raeburn  3106:         }
                   3107:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109  raeburn  3108:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107  raeburn  3109:         } else {
1.160.6.109  raeburn  3110:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107  raeburn  3111:         }
                   3112:         if (ref($lonstatus{'weights'}) eq 'HASH') {
                   3113:             foreach my $type ('E','W','N','U') {
                   3114:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   3115:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   3116:                 } else {
                   3117:                     $weights{$type} = $defaults->{$type};
                   3118:                 }
                   3119:             }
                   3120:         } else {
                   3121:             foreach my $type ('E','W','N','U') {
                   3122:                 $weights{$type} = $defaults->{$type};
                   3123:             }
                   3124:         }
                   3125:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   3126:             if (@{$lonstatus{'excluded'}} > 0) {
                   3127:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   3128:             }
                   3129:         }
1.160.6.109  raeburn  3130:         foreach my $item ('errorthreshold','errorsysmail') {
                   3131:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3132:             $datatable .= '<tr'.$css_class.'>'.
                   3133:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3134:                           $titles->{$item}.
                   3135:                           '</span></td><td class="LC_left_item">'.
                   3136:                           '<input type="text" name="'.$item.'" value="'.
                   3137:                           $current{$item}.'" size="5" /></td></tr>';
                   3138:             $rownum ++;
                   3139:         }
1.160.6.107  raeburn  3140:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3141:         $datatable .= '<tr'.$css_class.'>'.
                   3142:                       '<td class="LC_left_item">'.
                   3143:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   3144:                       '</span></td><td class="LC_left_item"><table><tr>';
                   3145:         foreach my $type ('E','W','N','U') {
                   3146:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   3147:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   3148:                           $weights{$type}.'" size="5" /></td>';
                   3149:         }
                   3150:         $datatable .= '</tr></table></tr>';
                   3151:         $rownum ++;
                   3152:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3153:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   3154:                       $titles->{'errorexcluded'}.'</td>'.
                   3155:                       '<td class="LC_left_item"><table>';
                   3156:         my $numinrow = 4;
                   3157:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   3158:         for (my $i=0; $i<@ids; $i++) {
                   3159:             my $rem = $i%($numinrow);
                   3160:             if ($rem == 0) {
                   3161:                 if ($i > 0) {
                   3162:                     $datatable .= '</tr>';
                   3163:                 }
                   3164:                 $datatable .= '<tr>';
                   3165:             }
                   3166:             my $check;
                   3167:             if ($excluded{$ids[$i]}) {
                   3168:                 $check = ' checked="checked" ';
                   3169:             }
                   3170:             $datatable .= '<td class="LC_left_item">'.
                   3171:                           '<span class="LC_nobreak"><label>'.
                   3172:                           '<input type="checkbox" name="errorexcluded" '.
                   3173:                           'value="'.$ids[$i].'"'.$check.' />'.
                   3174:                           $ids[$i].'</label></span></td>';
                   3175:         }
                   3176:         my $colsleft = $numinrow - @ids%($numinrow);
                   3177:         if ($colsleft > 1 ) {
                   3178:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3179:                           '&nbsp;</td>';
                   3180:         } elsif ($colsleft == 1) {
                   3181:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   3182:         }
                   3183:         $datatable .= '</tr></table></td></tr>';
                   3184:         $rownum ++;
1.160.6.78  raeburn  3185:     } elsif ($position eq 'bottom') {
1.160.6.101  raeburn  3186:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3187:         my (@posstypes,%usertypeshash);
                   3188:         if (ref($types) eq 'ARRAY') {
                   3189:             @posstypes = @{$types};
                   3190:         }
                   3191:         if (@posstypes) {
                   3192:             if (ref($usertypes) eq 'HASH') {
                   3193:                 %usertypeshash = %{$usertypes};
                   3194:             }
                   3195:             my @overridden;
                   3196:             my $numinrow = 4;
                   3197:             if (ref($settings) eq 'HASH') {
                   3198:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   3199:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   3200:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   3201:                             push(@overridden,$key);
                   3202:                             foreach my $item (@contacts) {
                   3203:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   3204:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   3205:                                 }
                   3206:                             }
                   3207:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   3208:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   3209:                             $includeloc{'override_'.$key} = '';
                   3210:                             $includestr{'override_'.$key} = '';
                   3211:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   3212:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
                   3213:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   3214:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   3215:                             }
1.160.6.78  raeburn  3216:                         }
                   3217:                     }
                   3218:                 }
1.160.6.101  raeburn  3219:             }
                   3220:             my $customclass = 'LC_helpdesk_override';
                   3221:             my $optionsprefix = 'LC_options_helpdesk_';
                   3222: 
                   3223:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   3224: 
                   3225:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   3226:                                          $numinrow,$othertitle,'overrides',
                   3227:                                          \$rownum,$onclicktypes,$customclass);
                   3228:             $rownum ++;
                   3229:             $usertypeshash{'default'} = $othertitle;
                   3230:             foreach my $status (@posstypes) {
                   3231:                 my $css_class;
                   3232:                 if ($rownum%2) {
                   3233:                     $css_class = 'LC_odd_row ';
                   3234:                 }
                   3235:                 $css_class .= $customclass;
                   3236:                 my $rowid = $optionsprefix.$status;
                   3237:                 my $hidden = 1;
                   3238:                 my $currstyle = 'display:none';
                   3239:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   3240:                     $currstyle = 'display:table-row';
                   3241:                     $hidden = 0;
                   3242:                 }
                   3243:                 my $key = 'override_'.$status;
                   3244:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   3245:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   3246:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   3247:                                                   \@contacts,$short_titles);
                   3248:                 unless ($hidden) {
                   3249:                     $rownum ++;
1.160.6.78  raeburn  3250:                 }
                   3251:             }
1.134     raeburn  3252:         }
1.28      raeburn  3253:     }
1.30      raeburn  3254:     $$rowtotal += $rownum;
1.28      raeburn  3255:     return $datatable;
                   3256: }
                   3257: 
1.160.6.107  raeburn  3258: sub core_link_msu {
                   3259:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3260:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   3261: }
                   3262: 
1.160.6.101  raeburn  3263: sub overridden_helpdesk {
                   3264:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   3265:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   3266:     my $class = 'LC_left_item';
                   3267:     if ($css_class) {
                   3268:         $css_class = ' class="'.$css_class.'"';
                   3269:     }
                   3270:     if ($rowid) {
                   3271:         $rowid = ' id="'.$rowid.'"';
                   3272:     }
                   3273:     if ($rowstyle) {
                   3274:         $rowstyle = ' style="'.$rowstyle.'"';
                   3275:     }
                   3276:     my ($output,$description);
                   3277:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   3278:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   3279:               "<td>$description</td>\n".
                   3280:               '<td class="'.$class.'" colspan="2">'.
                   3281:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   3282:               '<span class="LC_nobreak">';
                   3283:     if (ref($contacts) eq 'ARRAY') {
                   3284:         foreach my $item (@{$contacts}) {
                   3285:             my $check;
                   3286:             if (ref($checked) eq 'HASH') {
                   3287:                $check = $checked->{$item};
                   3288:             }
                   3289:             my $title;
                   3290:             if (ref($short_titles) eq 'HASH') {
                   3291:                 $title = $short_titles->{$item};
                   3292:             }
                   3293:             $output .= '<label>'.
                   3294:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   3295:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   3296:         }
                   3297:     }
                   3298:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3299:                '<input type="text" name="override_'.$type.'_others" '.
                   3300:                'value="'.$otheremails.'"  />';
                   3301:     my %locchecked;
                   3302:     foreach my $loc ('s','b') {
                   3303:         if ($includeloc eq $loc) {
                   3304:             $locchecked{$loc} = ' checked="checked"';
                   3305:             last;
                   3306:         }
                   3307:     }
                   3308:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3309:                '<input type="text" name="override_'.$type.'_bcc" '.
                   3310:                'value="'.$bccemails.'"  /></fieldset>'.
                   3311:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3312:                &mt('Text automatically added to e-mail:').' '.
                   3313:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
                   3314:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3315:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3316:                ('&nbsp;'x2).
                   3317:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3318:                '</span></fieldset>'.
                   3319:                '</td></tr>'."\n";
                   3320:     return $output;
                   3321: }
                   3322: 
1.160.6.78  raeburn  3323: sub contacts_javascript {
                   3324:     return <<"ENDSCRIPT";
                   3325: 
                   3326: <script type="text/javascript">
                   3327: // <![CDATA[
                   3328: 
                   3329: function screenshotSize(field) {
                   3330:     if (document.getElementById('help_screenshotsize')) {
                   3331:         if (field.value == 'no') {
                   3332:             document.getElementById('help_screenshotsize').style.display="none";
                   3333:         } else {
                   3334:             document.getElementById('help_screenshotsize').style.display="";
                   3335:         }
                   3336:     }
                   3337:     return;
                   3338: }
                   3339: 
1.160.6.101  raeburn  3340: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   3341:     if (form.elements[checkbox].length != undefined) {
                   3342:         var count = 0;
                   3343:         if (docount) {
                   3344:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   3345:                 if (form.elements[checkbox][i].checked) {
                   3346:                     count ++;
                   3347:                 }
                   3348:             }
                   3349:         }
                   3350:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3351:             var type = form.elements[checkbox][i].value;
                   3352:             if (document.getElementById(prefix+type)) {
                   3353:                 if (form.elements[checkbox][i].checked) {
                   3354:                     document.getElementById(prefix+type).style.display = 'table-row';
                   3355:                     if (count % 2 == 1) {
                   3356:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   3357:                     } else {
                   3358:                         document.getElementById(prefix+type).className = target;
                   3359:                     }
                   3360:                     count ++;
                   3361:                 } else {
                   3362:                     document.getElementById(prefix+type).style.display = 'none';
                   3363:                 }
                   3364:             }
                   3365:         }
                   3366:     }
                   3367:     return;
                   3368: }
                   3369: 
1.160.6.78  raeburn  3370: // ]]>
                   3371: </script>
                   3372: 
                   3373: ENDSCRIPT
                   3374: }
                   3375: 
1.118     jms      3376: sub print_helpsettings {
1.160.6.73  raeburn  3377:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3378:     my $confname = $dom.'-domainconfig';
1.160.6.77  raeburn  3379:     my $formname = 'display';
1.160.6.5  raeburn  3380:     my ($datatable,$itemcount);
1.160.6.73  raeburn  3381:     if ($position eq 'top') {
                   3382:         $itemcount = 1;
                   3383:         my (%choices,%defaultchecked,@toggles);
                   3384:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3385:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3386:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3387:         %defaultchecked = ('submitbugs' => 'on');
                   3388:         @toggles = ('submitbugs');
                   3389:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3390:                                                      \%choices,$itemcount);
                   3391:         $$rowtotal ++;
                   3392:     } else {
                   3393:         my $css_class;
                   3394:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  3395:         my (%customroles,%ordered,%current);
1.160.6.84  raeburn  3396:         if (ref($settings) eq 'HASH') {
                   3397:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3398:                 %current = %{$settings->{'adhoc'}};
                   3399:             }
1.160.6.77  raeburn  3400:         }
                   3401:         my $count = 0;
                   3402:         foreach my $key (sort(keys(%existing))) {
1.160.6.73  raeburn  3403:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3404:                 my $rolename = $1;
1.160.6.77  raeburn  3405:                 my (%privs,$order);
1.160.6.73  raeburn  3406:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3407:                 $customroles{$rolename} = \%privs;
1.160.6.77  raeburn  3408:                 if (ref($current{$rolename}) eq 'HASH') {
                   3409:                     $order = $current{$rolename}{'order'};
                   3410:                 }
                   3411:                 if ($order eq '') {
                   3412:                     $order = $count;
                   3413:                 }
                   3414:                 $ordered{$order} = $rolename;
                   3415:                 $count++;
1.160.6.73  raeburn  3416:             }
                   3417:         }
1.160.6.77  raeburn  3418:         my $maxnum = scalar(keys(%ordered));
                   3419:         my @roles_by_num = ();
                   3420:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3421:             push(@roles_by_num,$item);
                   3422:         }
                   3423:         my $context = 'domprefs';
                   3424:         my $crstype = 'Course';
                   3425:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  3426:         my @accesstypes = ('all','dh','da','none');
1.160.6.77  raeburn  3427:         my ($numstatustypes,@jsarray);
                   3428:         if (ref($types) eq 'ARRAY') {
                   3429:             if (@{$types} > 0) {
                   3430:                 $numstatustypes = scalar(@{$types});
                   3431:                 push(@accesstypes,'status');
                   3432:                 @jsarray = ('bystatus');
                   3433:             }
                   3434:         }
1.160.6.86  raeburn  3435:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  3436:         if (keys(%domhelpdesk)) {
                   3437:             push(@accesstypes,('inc','exc'));
                   3438:             push(@jsarray,('notinc','notexc'));
                   3439:         }
                   3440:         my $hiddenstr = join("','",@jsarray);
                   3441:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73  raeburn  3442:         my $context = 'domprefs';
                   3443:         my $crstype = 'Course';
1.160.6.77  raeburn  3444:         my $prefix = 'helproles_';
                   3445:         my $add_class = 'LC_hidden';
                   3446:         foreach my $num (@roles_by_num) {
                   3447:             my $role = $ordered{$num};
                   3448:             my ($desc,$access,@statuses);
                   3449:             if (ref($current{$role}) eq 'HASH') {
                   3450:                 $desc = $current{$role}{'desc'};
                   3451:                 $access = $current{$role}{'access'};
                   3452:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3453:                     @statuses = @{$current{$role}{'insttypes'}};
                   3454:                 }
                   3455:             }
                   3456:             if ($desc eq '') {
                   3457:                 $desc = $role;
                   3458:             }
                   3459:             my $identifier = 'custhelp'.$num;
1.160.6.73  raeburn  3460:             my %full=();
                   3461:             my %levels= (
                   3462:                          course => {},
                   3463:                          domain => {},
                   3464:                          system => {},
                   3465:                         );
                   3466:             my %levelscurrent=(
                   3467:                                course => {},
                   3468:                                domain => {},
                   3469:                                system => {},
                   3470:                               );
                   3471:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3472:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3473:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77  raeburn  3474:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
                   3475:             $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                   3476:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   3477:             for (my $k=0; $k<=$maxnum; $k++) {
                   3478:                 my $vpos = $k+1;
                   3479:                 my $selstr;
                   3480:                 if ($k == $num) {
                   3481:                     $selstr = ' selected="selected" ';
                   3482:                 }
                   3483:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3484:             }
                   3485:             $datatable .= '</select>'.('&nbsp;'x2).
                   3486:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   3487:                           '</td>'.
                   3488:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3489:                           &mt('Name shown to users:').
                   3490:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   3491:                           '</fieldset>'.
                   3492:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   3493:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   3494:                           '<fieldset>'.
                   3495:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73  raeburn  3496:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77  raeburn  3497:                                                                    \%levelscurrent,$identifier,
                   3498:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   3499:                           '</fieldset></td>';
1.160.6.73  raeburn  3500:             $itemcount ++;
                   3501:         }
                   3502:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3503:         my $newcust = 'custhelp'.$count;
                   3504:         my (%privs,%levelscurrent);
                   3505:         my %full=();
                   3506:         my %levels= (
                   3507:                      course => {},
                   3508:                      domain => {},
                   3509:                      system => {},
                   3510:                     );
                   3511:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3512:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77  raeburn  3513:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
                   3514:         $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                   3515:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   3516:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   3517:         for (my $k=0; $k<$maxnum+1; $k++) {
                   3518:             my $vpos = $k+1;
                   3519:             my $selstr;
                   3520:             if ($k == $maxnum) {
                   3521:                 $selstr = ' selected="selected" ';
                   3522:             }
                   3523:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3524:         }
                   3525:         $datatable .= '</select>&nbsp;'."\n".
1.160.6.73  raeburn  3526:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3527:                       '</label></span></td>'.
1.160.6.77  raeburn  3528:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3529:                       '<span class="LC_nobreak">'.
                   3530:                       &mt('Internal name:').
                   3531:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   3532:                       '</span>'.('&nbsp;'x4).
                   3533:                       '<span class="LC_nobreak">'.
                   3534:                       &mt('Name shown to users:').
                   3535:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   3536:                       '</span></fieldset>'.
                   3537:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   3538:                                              $usertypes,$types,\%domhelpdesk).
                   3539:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73  raeburn  3540:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3541:                                                                 \@templateroles,$newcust).
                   3542:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3543:                                                                \%levelscurrent,$newcust).
1.160.6.87  raeburn  3544:                       '</fieldset>'.
                   3545:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   3546:                       '</td></tr>';
1.160.6.73  raeburn  3547:         $count ++;
                   3548:         $$rowtotal += $count;
                   3549:     }
1.160.6.5  raeburn  3550:     return $datatable;
1.121     raeburn  3551: }
                   3552: 
1.160.6.77  raeburn  3553: sub adhocbutton {
                   3554:     my ($prefix,$num,$field,$visibility) = @_;
                   3555:     my %lt = &Apache::lonlocal::texthash(
                   3556:                                           show => 'Show details',
                   3557:                                           hide => 'Hide details',
                   3558:                                         );
                   3559:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   3560:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   3561:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   3562:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   3563: }
                   3564: 
                   3565: sub helpsettings_javascript {
                   3566:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   3567:     return unless(ref($roles_by_num) eq 'ARRAY');
                   3568:     my %html_js_lt = &Apache::lonlocal::texthash(
                   3569:                                           show => 'Show details',
                   3570:                                           hide => 'Hide details',
                   3571:                                         );
                   3572:     &html_escape(\%html_js_lt);
                   3573:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   3574:     return <<"ENDSCRIPT";
                   3575: <script type="text/javascript">
                   3576: // <![CDATA[
                   3577: 
                   3578: function reorderHelpRoles(form,item) {
                   3579:     var changedVal;
                   3580: $jstext
                   3581:     var newpos = 'helproles_${total}_pos';
                   3582:     var maxh = 1 + $total;
                   3583:     var current = new Array();
                   3584:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3585:     if (item == newpos) {
                   3586:         changedVal = newitemVal;
                   3587:     } else {
                   3588:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3589:         current[newitemVal] = newpos;
                   3590:     }
                   3591:     for (var i=0; i<helproles.length; i++) {
                   3592:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   3593:         if (elementName != item) {
                   3594:             if (form.elements[elementName]) {
                   3595:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3596:                 current[currVal] = elementName;
                   3597:             }
                   3598:         }
                   3599:     }
                   3600:     var oldVal;
                   3601:     for (var j=0; j<maxh; j++) {
                   3602:         if (current[j] == undefined) {
                   3603:             oldVal = j;
                   3604:         }
                   3605:     }
                   3606:     if (oldVal < changedVal) {
                   3607:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3608:            var elementName = current[k];
                   3609:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3610:         }
                   3611:     } else {
                   3612:         for (var k=changedVal; k<oldVal; k++) {
                   3613:             var elementName = current[k];
                   3614:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3615:         }
                   3616:     }
                   3617:     return;
                   3618: }
                   3619: 
                   3620: function helpdeskAccess(num) {
                   3621:     var curraccess = null;
                   3622:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   3623:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   3624:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   3625:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   3626:             }
                   3627:         }
                   3628:     }
                   3629:     var shown = Array();
                   3630:     var hidden = Array();
                   3631:     if (curraccess == 'none') {
                   3632:         hidden = Array('$hiddenstr');
                   3633:     } else {
                   3634:         if (curraccess == 'status') {
                   3635:             shown = Array('bystatus');
                   3636:             hidden = Array('notinc','notexc');
                   3637:         } else {
                   3638:             if (curraccess == 'exc') {
                   3639:                 shown = Array('notexc');
                   3640:                 hidden = Array('notinc','bystatus');
                   3641:             }
                   3642:             if (curraccess == 'inc') {
                   3643:                 shown = Array('notinc');
                   3644:                 hidden = Array('notexc','bystatus');
                   3645:             }
1.160.6.79  raeburn  3646:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77  raeburn  3647:                 hidden = Array('notinc','notexc','bystatus');
                   3648:             }
                   3649:         }
                   3650:     }
                   3651:     if (hidden.length > 0) {
                   3652:         for (var i=0; i<hidden.length; i++) {
                   3653:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   3654:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   3655:             }
                   3656:         }
                   3657:     }
                   3658:     if (shown.length > 0) {
                   3659:         for (var i=0; i<shown.length; i++) {
                   3660:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   3661:                 if (shown[i] == 'privs') {
                   3662:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   3663:                 } else {
                   3664:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   3665:                 }
                   3666:             }
                   3667:         }
                   3668:     }
                   3669:     return;
                   3670: }
                   3671: 
                   3672: function toggleHelpdeskItem(num,field) {
                   3673:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   3674:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
                   3675:             document.getElementById('helproles_'+num+'_'+field).className =
                   3676:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   3677:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3678:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   3679:             }
                   3680:         } else {
                   3681:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   3682:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3683:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   3684:             }
                   3685:         }
                   3686:     }
                   3687:     return;
                   3688: }
                   3689: 
                   3690: // ]]>
                   3691: </script>
                   3692: 
                   3693: ENDSCRIPT
                   3694: }
                   3695: 
                   3696: sub helpdeskroles_access {
                   3697:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   3698:         $usertypes,$types,$domhelpdesk) = @_;
                   3699:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   3700:     my %lt = &Apache::lonlocal::texthash(
                   3701:                     'rou'    => 'Role usage',
                   3702:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.160.6.79  raeburn  3703:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   3704:                     'dh'     => 'All with domain helpdesk role',
                   3705:                     'da'     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  3706:                     'none'   => 'None',
                   3707:                     'status' => 'Determined based on institutional status',
                   3708:                     'inc'    => 'Include all, but exclude specific personnel',
                   3709:                     'exc'    => 'Exclude all, but include specific personnel',
                   3710:                   );
                   3711:     my %usecheck = (
                   3712:                      all => ' checked="checked"',
                   3713:                    );
                   3714:     my %displaydiv = (
                   3715:                       status => 'none',
                   3716:                       inc    => 'none',
                   3717:                       exc    => 'none',
                   3718:                       priv   => 'block',
                   3719:                      );
                   3720:     my $output;
                   3721:     if (ref($current) eq 'HASH') {
                   3722:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   3723:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   3724:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   3725:                 delete($usecheck{'all'});
                   3726:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   3727:                     my $access = $1;
                   3728:                     $displaydiv{$access} = 'inline';
                   3729:                 } elsif ($current->{access} eq 'none') {
                   3730:                     $displaydiv{'priv'} = 'none';
                   3731:                 }
                   3732:             }
                   3733:         }
                   3734:     }
                   3735:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   3736:               '<p>'.$lt{'whi'}.'</p>';
                   3737:     foreach my $access (@{$accesstypes}) {
                   3738:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   3739:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   3740:                    $lt{$access}.'</label>';
                   3741:         if ($access eq 'status') {
                   3742:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   3743:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   3744:                                                                  $othertitle,$usertypes,$types).
                   3745:                        '</div>';
                   3746:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   3747:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   3748:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3749:                        '</div>';
                   3750:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   3751:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   3752:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3753:                        '</div>';
                   3754:         }
                   3755:         $output .= '</p>';
                   3756:     }
                   3757:     $output .= '</fieldset>';
                   3758:     return $output;
                   3759: }
                   3760: 
1.121     raeburn  3761: sub radiobutton_prefs {
1.160.6.16  raeburn  3762:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57  raeburn  3763:         $additional,$align) = @_;
1.121     raeburn  3764:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3765:                    (ref($choices) eq 'HASH'));
                   3766: 
                   3767:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   3768: 
                   3769:     foreach my $item (@{$toggles}) {
                   3770:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3771:             $checkedon{$item} = ' checked="checked" ';
                   3772:             $checkedoff{$item} = ' ';
1.121     raeburn  3773:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3774:             $checkedoff{$item} = ' checked="checked" ';
                   3775:             $checkedon{$item} = ' ';
                   3776:         }
                   3777:     }
                   3778:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3779:         foreach my $item (@{$toggles}) {
1.118     jms      3780:             if ($settings->{$item} eq '1') {
                   3781:                 $checkedon{$item} =  ' checked="checked" ';
                   3782:                 $checkedoff{$item} = ' ';
                   3783:             } elsif ($settings->{$item} eq '0') {
                   3784:                 $checkedoff{$item} =  ' checked="checked" ';
                   3785:                 $checkedon{$item} = ' ';
                   3786:             }
                   3787:         }
1.121     raeburn  3788:     }
1.160.6.16  raeburn  3789:     if ($onclick) {
                   3790:         $onclick = ' onclick="'.$onclick.'"';
                   3791:     }
1.121     raeburn  3792:     foreach my $item (@{$toggles}) {
1.118     jms      3793:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3794:         $datatable .=
1.160.6.16  raeburn  3795:             '<tr'.$css_class.'><td valign="top">'.
                   3796:             '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57  raeburn  3797:             '</span></td>';
                   3798:         if ($align eq 'left') {
                   3799:             $datatable .= '<td class="LC_left_item">';
                   3800:         } else {
                   3801:             $datatable .= '<td class="LC_right_item">';
                   3802:         }
                   3803:         $datatable .=
                   3804:             '<span class="LC_nobreak">'.
1.118     jms      3805:             '<label><input type="radio" name="'.
1.160.6.16  raeburn  3806:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3807:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.160.6.16  raeburn  3808:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3809:             '</span>'.$additional.
                   3810:             '</td>'.
1.118     jms      3811:             '</tr>';
                   3812:         $itemcount ++;
1.121     raeburn  3813:     }
                   3814:     return ($datatable,$itemcount);
                   3815: }
                   3816: 
                   3817: sub print_coursedefaults {
1.139     raeburn  3818:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  3819:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  3820:     my $itemcount = 1;
1.160.6.16  raeburn  3821:     my %choices =  &Apache::lonlocal::texthash (
1.160.6.21  raeburn  3822:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16  raeburn  3823:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   3824:         coursecredits        => 'Credits can be specified for courses',
1.160.6.57  raeburn  3825:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   3826:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90  raeburn  3827:         texengine            => 'Default method to display mathematics',
1.160.6.57  raeburn  3828:         postsubmit           => 'Disable submit button/keypress following student submission',
1.160.6.64  raeburn  3829:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70  raeburn  3830:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16  raeburn  3831:     );
1.160.6.21  raeburn  3832:     my %staticdefaults = (
                   3833:                            anonsurvey_threshold => 10,
                   3834:                            uploadquota          => 500,
1.160.6.57  raeburn  3835:                            postsubmit           => 60,
1.160.6.70  raeburn  3836:                            mysqltables          => 172800,
1.160.6.21  raeburn  3837:                          );
1.139     raeburn  3838:     if ($position eq 'top') {
1.160.6.57  raeburn  3839:         %defaultchecked = (
                   3840:                             'uselcmath'       => 'on',
                   3841:                             'usejsme'         => 'on',
1.160.6.64  raeburn  3842:                             'canclone'        => 'none',
1.160.6.57  raeburn  3843:                           );
                   3844:         @toggles = ('uselcmath','usejsme');
1.160.6.90  raeburn  3845:         my $deftex = $Apache::lonnet::deftex;
                   3846:         if (ref($settings) eq 'HASH') {
                   3847:             if ($settings->{'texengine'}) {
                   3848:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   3849:                     $deftex = $settings->{'texengine'};
                   3850:                 }
                   3851:             }
                   3852:         }
                   3853:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3854:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   3855:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   3856:                        '</span></td><td class="LC_right_item">'.
                   3857:                        '<select name="texengine">'."\n";
                   3858:         my %texoptions = (
                   3859:                             MathJax  => 'MathJax',
                   3860:                             mimetex  => &mt('Convert to Images'),
                   3861:                             tth      => &mt('TeX to HTML'),
                   3862:                          );
                   3863:         foreach my $renderer ('MathJax','mimetex','tth') {
                   3864:             my $selected = '';
                   3865:             if ($renderer eq $deftex) {
                   3866:                 $selected = ' selected="selected"';
                   3867:             }
                   3868:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   3869:         }
                   3870:         $mathdisp .= '</select></td></tr>'."\n";
                   3871:         $itemcount ++;
1.139     raeburn  3872:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  3873:                                                      \%choices,$itemcount);
1.160.6.90  raeburn  3874:         $datatable = $mathdisp.$datatable;
1.160.6.64  raeburn  3875:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3876:         $datatable .=
                   3877:             '<tr'.$css_class.'><td valign="top">'.
                   3878:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   3879:             '</span></td><td class="LC_left_item">';
                   3880:         my $currcanclone = 'none';
                   3881:         my $onclick;
                   3882:         my @cloneoptions = ('none','domain');
1.160.6.111  raeburn  3883:         my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64  raeburn  3884:                              none     => 'No additional course requesters',
                   3885:                              domain   => "Any course requester in course's domain",
                   3886:                              instcode => 'Course requests for official courses ...',
                   3887:                           );
                   3888:         my (%codedefaults,@code_order,@posscodes);
                   3889:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   3890:                                                     \@code_order) eq 'ok') {
                   3891:             if (@code_order > 0) {
                   3892:                 push(@cloneoptions,'instcode');
                   3893:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   3894:             }
                   3895:         }
                   3896:         if (ref($settings) eq 'HASH') {
                   3897:             if ($settings->{'canclone'}) {
                   3898:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   3899:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   3900:                         if (@code_order > 0) {
                   3901:                             $currcanclone = 'instcode';
                   3902:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   3903:                         }
                   3904:                     }
                   3905:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   3906:                     $currcanclone = $settings->{'canclone'};
                   3907:                 }
                   3908:             }
                   3909:         }
                   3910:         foreach my $option (@cloneoptions) {
                   3911:             my ($checked,$additional);
                   3912:             if ($currcanclone eq $option) {
                   3913:                 $checked = ' checked="checked"';
                   3914:             }
                   3915:             if ($option eq 'instcode') {
                   3916:                 if (@code_order) {
                   3917:                     my $show = 'none';
                   3918:                     if ($checked) {
                   3919:                         $show = 'block';
                   3920:                     }
                   3921:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   3922:                                   &mt('Institutional codes for new and cloned course have identical:').
                   3923:                                   '<br />';
                   3924:                     foreach my $item (@code_order) {
                   3925:                         my $codechk;
                   3926:                         if ($checked) {
                   3927:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   3928:                                 $codechk = ' checked="checked"';
                   3929:                             }
                   3930:                         }
                   3931:                         $additional .= '<label>'.
                   3932:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   3933:                                        $item.'</label>';
                   3934:                     }
                   3935:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   3936:                 }
                   3937:             }
                   3938:             $datatable .=
                   3939:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   3940:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   3941:                 '</label>&nbsp;'.$additional.'</span><br />';
                   3942:         }
                   3943:         $datatable .= '</td>'.
                   3944:                       '</tr>';
                   3945:         $itemcount ++;
1.139     raeburn  3946:     } else {
                   3947:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71  raeburn  3948:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16  raeburn  3949:         my $currusecredits = 0;
1.160.6.57  raeburn  3950:         my $postsubmitclient = 1;
1.160.6.30  raeburn  3951:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  3952:         if (ref($settings) eq 'HASH') {
                   3953:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21  raeburn  3954:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   3955:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   3956:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   3957:                 }
                   3958:             }
1.160.6.16  raeburn  3959:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  3960:                 foreach my $type (@types) {
                   3961:                     next if ($type eq 'community');
                   3962:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   3963:                     if ($defcredits{$type} ne '') {
                   3964:                         $currusecredits = 1;
                   3965:                     }
                   3966:                 }
                   3967:             }
                   3968:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   3969:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   3970:                     $postsubmitclient = 0;
                   3971:                     foreach my $type (@types) {
                   3972:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3973:                     }
                   3974:                 } else {
                   3975:                     foreach my $type (@types) {
                   3976:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   3977:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   3978:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
                   3979:                             } else {
                   3980:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3981:                             }
                   3982:                         } else {
                   3983:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3984:                         }
                   3985:                     }
                   3986:                 }
                   3987:             } else {
                   3988:                 foreach my $type (@types) {
                   3989:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16  raeburn  3990:                 }
                   3991:             }
1.160.6.70  raeburn  3992:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   3993:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   3994:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   3995:                 }
                   3996:             } else {
                   3997:                 foreach my $type (@types) {
                   3998:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   3999:                 }
                   4000:             }
1.160.6.58  raeburn  4001:         } else {
                   4002:             foreach my $type (@types) {
                   4003:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4004:             }
1.139     raeburn  4005:         }
                   4006:         if (!$currdefresponder) {
1.160.6.21  raeburn  4007:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  4008:         } elsif ($currdefresponder < 1) {
                   4009:             $currdefresponder = 1;
                   4010:         }
1.160.6.21  raeburn  4011:         foreach my $type (@types) {
                   4012:             if ($curruploadquota{$type} eq '') {
                   4013:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   4014:             }
                   4015:         }
1.139     raeburn  4016:         $datatable .=
1.160.6.16  raeburn  4017:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4018:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  4019:                 '</span></td>'.
                   4020:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4021:                 '<input type="text" name="anonsurvey_threshold"'.
                   4022:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37  raeburn  4023:                 '</td></tr>'."\n";
                   4024:         $itemcount ++;
                   4025:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4026:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4027:                       $choices{'uploadquota'}.
                   4028:                       '</span></td>'.
                   4029:                       '<td align="right" class="LC_right_item">'.
                   4030:                       '<table><tr>';
1.160.6.21  raeburn  4031:         foreach my $type (@types) {
                   4032:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4033:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   4034:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   4035:         }
                   4036:         $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37  raeburn  4037:         $itemcount ++;
1.160.6.40  raeburn  4038:         my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16  raeburn  4039:         my $display = 'none';
                   4040:         if ($currusecredits) {
                   4041:             $display = 'block';
                   4042:         }
                   4043:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57  raeburn  4044:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   4045:         foreach my $type (@types) {
                   4046:             next if ($type eq 'community');
                   4047:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4048:                            '<input type="text" name="'.$type.'_credits"'.
                   4049:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
                   4050:         }
                   4051:         $additional .= '</tr></table></div>'."\n";
1.160.6.16  raeburn  4052:         %defaultchecked = ('coursecredits' => 'off');
                   4053:         @toggles = ('coursecredits');
                   4054:         my $current = {
                   4055:                         'coursecredits' => $currusecredits,
                   4056:                       };
                   4057:         (my $table,$itemcount) =
                   4058:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  4059:                                \%choices,$itemcount,$onclick,$additional,'left');
                   4060:         $datatable .= $table;
                   4061:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   4062:         my $display = 'none';
                   4063:         if ($postsubmitclient) {
                   4064:             $display = 'block';
                   4065:         }
                   4066:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59  raeburn  4067:                       &mt('Number of seconds submit is disabled').'<br />'.
                   4068:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   4069:                       '<table><tr>';
1.160.6.57  raeburn  4070:         foreach my $type (@types) {
                   4071:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4072:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   4073:                            $deftimeout{$type}.'" size="5" /></td>';
                   4074:         }
                   4075:         $additional .= '</tr></table></div>'."\n";
                   4076:         %defaultchecked = ('postsubmit' => 'on');
                   4077:         @toggles = ('postsubmit');
1.160.6.70  raeburn  4078:         $current = {
                   4079:                        'postsubmit' => $postsubmitclient,
                   4080:                    };
1.160.6.57  raeburn  4081:         ($table,$itemcount) =
                   4082:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   4083:                                \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16  raeburn  4084:         $datatable .= $table;
1.160.6.70  raeburn  4085:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4086:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4087:                       $choices{'mysqltables'}.
                   4088:                       '</span></td>'.
                   4089:                       '<td align="right" class="LC_right_item">'.
                   4090:                       '<table><tr>';
                   4091:         foreach my $type (@types) {
                   4092:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4093:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81  raeburn  4094:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70  raeburn  4095:         }
                   4096:         $datatable .= '</tr></table></td></tr>'."\n";
                   4097:         $itemcount ++;
                   4098: 
1.160.6.37  raeburn  4099:     }
                   4100:     $$rowtotal += $itemcount;
                   4101:     return $datatable;
                   4102: }
                   4103: 
                   4104: sub print_selfenrollment {
                   4105:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4106:     my ($css_class,$datatable);
                   4107:     my $itemcount = 1;
                   4108:     my @types = ('official','unofficial','community','textbook');
                   4109:     if (($position eq 'top') || ($position eq 'middle')) {
                   4110:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   4111:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   4112:         my @rows;
                   4113:         my $key;
                   4114:         if ($position eq 'top') {
                   4115:             $key = 'admin'; 
                   4116:             if (ref($rowsref) eq 'ARRAY') {
                   4117:                 @rows = @{$rowsref};
                   4118:             }
                   4119:         } elsif ($position eq 'middle') {
                   4120:             $key = 'default';
                   4121:             @rows = ('types','registered','approval','limit');
                   4122:         }
                   4123:         foreach my $row (@rows) {
                   4124:             if (defined($titlesref->{$row})) {
                   4125:                 $itemcount ++;
                   4126:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4127:                 $datatable .= '<tr'.$css_class.'>'.
                   4128:                               '<td>'.$titlesref->{$row}.'</td>'.
                   4129:                               '<td class="LC_left_item">'.
                   4130:                               '<table><tr>';
                   4131:                 my (%current,%currentcap);
                   4132:                 if (ref($settings) eq 'HASH') {
                   4133:                     if (ref($settings->{$key}) eq 'HASH') {
                   4134:                         foreach my $type (@types) {
                   4135:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4136:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   4137:                             }
                   4138:                             if (($row eq 'limit') && ($key eq 'default')) {
                   4139:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4140:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   4141:                                 }
                   4142:                             }
                   4143:                         }
                   4144:                     }
                   4145:                 }
                   4146:                 my %roles = (
                   4147:                              '0' => &Apache::lonnet::plaintext('dc'),
                   4148:                             ); 
                   4149:             
                   4150:                 foreach my $type (@types) {
                   4151:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   4152:                         $datatable .= '<th>'.&mt($type).'</th>';
                   4153:                     }
                   4154:                 }
                   4155:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   4156:                     $datatable .= '</tr><tr>';
                   4157:                 }
                   4158:                 foreach my $type (@types) {
                   4159:                     if ($type eq 'community') {
                   4160:                         $roles{'1'} = &mt('Community personnel');
                   4161:                     } else {
                   4162:                         $roles{'1'} = &mt('Course personnel');
                   4163:                     }
                   4164:                     $datatable .= '<td style="vertical-align: top">';
                   4165:                     if ($position eq 'top') {
                   4166:                         my %checked;
                   4167:                         if ($current{$type} eq '0') {
                   4168:                             $checked{'0'} = ' checked="checked"';
                   4169:                         } else {
                   4170:                             $checked{'1'} = ' checked="checked"';
                   4171:                         }
                   4172:                         foreach my $role ('1','0') {
                   4173:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   4174:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   4175:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   4176:                                           $roles{$role}.'</label></span> ';
                   4177:                         }
                   4178:                     } else {
                   4179:                         if ($row eq 'types') {
                   4180:                             my %checked;
                   4181:                             if ($current{$type} =~ /^(all|dom)$/) {
                   4182:                                 $checked{$1} = ' checked="checked"';
                   4183:                             } else {
                   4184:                                 $checked{''} = ' checked="checked"';
                   4185:                             }
                   4186:                             foreach my $val ('','dom','all') {
                   4187:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4188:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4189:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4190:                             }
                   4191:                         } elsif ($row eq 'registered') {
                   4192:                             my %checked;
                   4193:                             if ($current{$type} eq '1') {
                   4194:                                 $checked{'1'} = ' checked="checked"';
                   4195:                             } else {
                   4196:                                 $checked{'0'} = ' checked="checked"';
                   4197:                             }
                   4198:                             foreach my $val ('0','1') {
                   4199:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4200:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4201:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4202:                             }
                   4203:                         } elsif ($row eq 'approval') {
                   4204:                             my %checked;
                   4205:                             if ($current{$type} =~ /^([12])$/) {
                   4206:                                 $checked{$1} = ' checked="checked"';
                   4207:                             } else {
                   4208:                                 $checked{'0'} = ' checked="checked"';
                   4209:                             }
                   4210:                             for my $val (0..2) {
                   4211:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4212:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4213:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4214:                             }
                   4215:                         } elsif ($row eq 'limit') {
                   4216:                             my %checked;
                   4217:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   4218:                                 $checked{$1} = ' checked="checked"';
                   4219:                             } else {
                   4220:                                 $checked{'none'} = ' checked="checked"';
                   4221:                             }
                   4222:                             my $cap;
                   4223:                             if ($currentcap{$type} =~ /^\d+$/) {
                   4224:                                 $cap = $currentcap{$type};
                   4225:                             }
                   4226:                             foreach my $val ('none','allstudents','selfenrolled') {
                   4227:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4228:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4229:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4230:                             }
                   4231:                             $datatable .= '<br />'.
                   4232:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   4233:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   4234:                                           '</span>'; 
                   4235:                         }
                   4236:                     }
                   4237:                     $datatable .= '</td>';
                   4238:                 }
                   4239:                 $datatable .= '</tr>';
                   4240:             }
                   4241:             $datatable .= '</table></td></tr>';
                   4242:         }
                   4243:     } elsif ($position eq 'bottom') {
1.160.6.39  raeburn  4244:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   4245:     }
                   4246:     $$rowtotal += $itemcount;
                   4247:     return $datatable;
                   4248: }
                   4249: 
                   4250: sub print_validation_rows {
                   4251:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   4252:     my ($itemsref,$namesref,$fieldsref);
                   4253:     if ($caller eq 'selfenroll') { 
                   4254:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   4255:     } elsif ($caller eq 'requestcourses') {
                   4256:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   4257:     }
                   4258:     my %currvalidation;
                   4259:     if (ref($settings) eq 'HASH') {
                   4260:         if (ref($settings->{'validation'}) eq 'HASH') {
                   4261:             %currvalidation = %{$settings->{'validation'}};
1.160.6.37  raeburn  4262:         }
1.160.6.39  raeburn  4263:     }
                   4264:     my $datatable;
                   4265:     my $itemcount = 0;
                   4266:     foreach my $item (@{$itemsref}) {
                   4267:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4268:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4269:                       $namesref->{$item}.
                   4270:                       '</span></td>'.
                   4271:                       '<td class="LC_left_item">';
                   4272:         if (($item eq 'url') || ($item eq 'button')) {
                   4273:             $datatable .= '<span class="LC_nobreak">'.
                   4274:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   4275:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   4276:         } elsif ($item eq 'fields') {
                   4277:             my @currfields;
                   4278:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   4279:                 @currfields = @{$currvalidation{$item}};
                   4280:             }
                   4281:             foreach my $field (@{$fieldsref}) {
                   4282:                 my $check = '';
                   4283:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   4284:                     $check = ' checked="checked"';
                   4285:                 }
                   4286:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4287:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   4288:                               ' value="'.$field.'"'.$check.' />'.$field.
                   4289:                               '</label></span> ';
                   4290:             }
                   4291:         } elsif ($item eq 'markup') {
1.160.6.87  raeburn  4292:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39  raeburn  4293:                            $currvalidation{$item}.
1.160.6.37  raeburn  4294:                               '</textarea>';
1.160.6.39  raeburn  4295:         }
                   4296:         $datatable .= '</td></tr>'."\n";
                   4297:         if (ref($rowtotal)) {
1.160.6.37  raeburn  4298:             $itemcount ++;
                   4299:         }
1.139     raeburn  4300:     }
1.160.6.39  raeburn  4301:     if ($caller eq 'requestcourses') {
                   4302:         my %currhash;
1.160.6.51  raeburn  4303:         if (ref($settings) eq 'HASH') {
                   4304:             if (ref($settings->{'validation'}) eq 'HASH') {
                   4305:                 if ($settings->{'validation'}{'dc'} ne '') {
                   4306:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   4307:                 }
1.160.6.39  raeburn  4308:             }
                   4309:         }
                   4310:         my $numinrow = 2;
                   4311:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4312:                                                        'validationdc',%currhash);
1.160.6.50  raeburn  4313:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87  raeburn  4314:         $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39  raeburn  4315:         if ($numdc > 1) {
1.160.6.50  raeburn  4316:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39  raeburn  4317:         } else {
1.160.6.50  raeburn  4318:             $datatable .=  &mt('Course creation processed as: ');
1.160.6.39  raeburn  4319:         }
1.160.6.50  raeburn  4320:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39  raeburn  4321:         $itemcount ++;
                   4322:     }
                   4323:     if (ref($rowtotal)) {
                   4324:         $$rowtotal += $itemcount;
                   4325:     }
1.121     raeburn  4326:     return $datatable;
1.118     jms      4327: }
                   4328: 
1.160.6.98  raeburn  4329: sub print_passwords {
                   4330:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   4331:     my ($datatable,$css_class);
                   4332:     my $itemcount = 0;
                   4333:     my %titles = &Apache::lonlocal::texthash (
                   4334:         captcha        => '"Forgot Password" CAPTCHA validation',
                   4335:         link           => 'Reset link expiration (hours)',
                   4336:         case           => 'Case-sensitive usernames/e-mail',
                   4337:         prelink        => 'Information required (form 1)',
                   4338:         postlink       => 'Information required (form 2)',
                   4339:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   4340:         customtext     => 'Domain specific text (HTML)',
                   4341:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   4342:         intauth_check  => 'Check bcrypt cost if authenticated',
                   4343:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   4344:         permanent      => 'Permanent e-mail address',
                   4345:         critical       => 'Critical notification address',
                   4346:         notify         => 'Notification address',
                   4347:         min            => 'Minimum password length',
                   4348:         max            => 'Maximum password length',
                   4349:         chars          => 'Required characters',
                   4350:         numsaved       => 'Number of previous passwords to save and disallow reuse',
                   4351:     );
                   4352:     if ($position eq 'top') {
                   4353:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4354:         my $shownlinklife = 2;
                   4355:         my $prelink = 'both';
                   4356:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   4357:         if (ref($settings) eq 'HASH') {
                   4358:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   4359:                 $shownlinklife = $settings->{resetlink};
                   4360:             }
                   4361:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   4362:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   4363:             }
                   4364:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   4365:                 $prelink = $settings->{resetprelink};
                   4366:             }
                   4367:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   4368:                 %postlink = %{$settings->{resetpostlink}};
                   4369:             }
                   4370:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   4371:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   4372:             }
                   4373:             if ($settings->{resetremove}) {
                   4374:                 $nostdtext = 1;
                   4375:             }
                   4376:             if ($settings->{resetcustom}) {
                   4377:                 $customurl = $settings->{resetcustom};
                   4378:             }
                   4379:         } else {
                   4380:             if (ref($types) eq 'ARRAY') {
                   4381:                 foreach my $item (@{$types}) {
                   4382:                     $casesens{$item} = 1;
                   4383:                     $postlink{$item} = ['username','email'];
                   4384:                 }
                   4385:             }
                   4386:             $casesens{'default'} = 1;
                   4387:             $postlink{'default'} = ['username','email'];
                   4388:             $prelink = 'both';
                   4389:             %emailsrc = (
                   4390:                           permanent => 1,
                   4391:                           critical  => 1,
                   4392:                           notify    => 1,
                   4393:             );
                   4394:         }
                   4395:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   4396:         $itemcount ++;
                   4397:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4398:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   4399:                       '<td class="LC_left_item">'.
                   4400:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   4401:                       'name="passwords_link" size="3" /></td></tr>';
                   4402:         $itemcount ++;
                   4403:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4404:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   4405:                       '<td class="LC_left_item">';
                   4406:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   4407:             foreach my $item (@{$types}) {
                   4408:                 my $checkedcase;
                   4409:                 if ($casesens{$item}) {
                   4410:                     $checkedcase = ' checked="checked"';
                   4411:                 }
                   4412:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4413:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   4414:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104  raeburn  4415:                               '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  4416:             }
                   4417:         }
                   4418:         my $checkedcase;
                   4419:         if ($casesens{'default'}) {
                   4420:             $checkedcase = ' checked="checked"';
                   4421:         }
                   4422:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   4423:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   4424:                       $othertitle.'</label></span></td>';
                   4425:         $itemcount ++;
                   4426:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4427:         my %checkedpre = (
                   4428:                              both => ' checked="checked"',
                   4429:                              either => '',
                   4430:                          );
                   4431:         if ($prelink eq 'either') {
                   4432:             $checkedpre{either} = ' checked="checked"';
                   4433:             $checkedpre{both} = '';
                   4434:         }
                   4435:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   4436:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4437:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   4438:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   4439:                       '<span class="LC_nobreak"><label>'.
                   4440:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   4441:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   4442:         $itemcount ++;
                   4443:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4444:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   4445:                       '<td class="LC_left_item">';
                   4446:         my %postlinked;
                   4447:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   4448:             foreach my $item (@{$types}) {
                   4449:                 undef(%postlinked);
                   4450:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   4451:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   4452:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   4453:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   4454:                 }
                   4455:                 foreach my $field ('email','username') {
                   4456:                     my $checked;
                   4457:                     if ($postlinked{$field}) {
                   4458:                         $checked = ' checked="checked"';
                   4459:                     }
                   4460:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   4461:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   4462:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   4463:                                   '<span>&nbsp;&nbsp; ';
                   4464:                 }
                   4465:                 $datatable .= '</fieldset>';
                   4466:             }
                   4467:         }
                   4468:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   4469:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   4470:         }
                   4471:         $datatable .= '<fieldset style="display: inline-block;">'.
                   4472:                       '<legend>'.$othertitle.'</legend>';
                   4473:         foreach my $field ('email','username') {
                   4474:             my $checked;
                   4475:             if ($postlinked{$field}) {
                   4476:                 $checked = ' checked="checked"';
                   4477:             }
                   4478:             $datatable .= '<span class="LC_nobreak"><label>'.
                   4479:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   4480:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   4481:                           '<span>&nbsp;&nbsp; ';
                   4482:         }
                   4483:         $datatable .= '</fieldset></td></tr>';
                   4484:         $itemcount ++;
                   4485:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4486:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   4487:                       '<td class="LC_left_item">';
                   4488:         foreach my $type ('permanent','critical','notify') {
                   4489:             my $checkedemail;
                   4490:             if ($emailsrc{$type}) {
                   4491:                 $checkedemail = ' checked="checked"';
                   4492:             }
                   4493:             $datatable .= '<span class="LC_nobreak"><label>'.
                   4494:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   4495:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   4496:                           '<span>&nbsp;&nbsp; ';
                   4497:         }
                   4498:         $datatable .= '</td></tr>';
                   4499:         $itemcount ++;
                   4500:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4501:         my $switchserver = &check_switchserver($dom,$confname);
                   4502:         my ($showstd,$noshowstd);
                   4503:         if ($nostdtext) {
                   4504:             $noshowstd = ' checked="checked"';
                   4505:         } else {
                   4506:             $showstd = ' checked="checked"';
                   4507:         }
                   4508:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   4509:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4510:                       &mt('Retain standard text:').
                   4511:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   4512:                       &mt('Yes').'</label>'.'&nbsp;'.
                   4513:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   4514:                       &mt('No').'</label></span><br />'.
                   4515:                       '<span class="LC_fontsize_small">'.
                   4516:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   4517:                       &mt('Include custom text:');
                   4518:         if ($customurl) {
1.160.6.104  raeburn  4519:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98  raeburn  4520:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   4521:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   4522:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   4523:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   4524:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   4525:         }
                   4526:         if ($switchserver) {
                   4527:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   4528:         } else {
                   4529:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   4530:                          '<input type="file" name="passwords_customfile" /></span>';
                   4531:         }
                   4532:         $datatable .= '</td></tr>';
                   4533:     } elsif ($position eq 'middle') {
                   4534:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   4535:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   4536:         my %defaults;
                   4537:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   4538:             %defaults = %{$domconf{'defaults'}};
                   4539:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   4540:                 $defaults{'intauth_cost'} = 10;
                   4541:             }
                   4542:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   4543:                 $defaults{'intauth_check'} = 0;
                   4544:             }
                   4545:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   4546:                 $defaults{'intauth_switch'} = 0;
                   4547:             }
                   4548:         } else {
                   4549:             %defaults = (
                   4550:                           'intauth_cost'   => 10,
                   4551:                           'intauth_check'  => 0,
                   4552:                           'intauth_switch' => 0,
                   4553:                         );
                   4554:         }
                   4555:         foreach my $item (@items) {
                   4556:             if ($itemcount%2) {
                   4557:                 $css_class = '';
                   4558:             } else {
                   4559:                 $css_class = ' class="LC_odd_row" ';
                   4560:             }
                   4561:             $datatable .= '<tr'.$css_class.'>'.
                   4562:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   4563:                           '</span></td><td class="LC_left_item" colspan="3">';
                   4564:             if ($item eq 'intauth_switch') {
                   4565:                 my @options = (0,1,2);
                   4566:                 my %optiondesc = &Apache::lonlocal::texthash (
                   4567:                                    0 => 'No',
                   4568:                                    1 => 'Yes',
                   4569:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   4570:                                  );
                   4571:                 $datatable .= '<table width="100%">';
                   4572:                 foreach my $option (@options) {
                   4573:                     my $checked = ' ';
                   4574:                     if ($defaults{$item} eq $option) {
                   4575:                         $checked = ' checked="checked"';
                   4576:                     }
                   4577:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   4578:                                   '<label><input type="radio" name="'.$item.
                   4579:                                   '" value="'.$option.'"'.$checked.' />'.
                   4580:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   4581:                 }
                   4582:                 $datatable .= '</table>';
                   4583:             } elsif ($item eq 'intauth_check') {
                   4584:                 my @options = (0,1,2);
                   4585:                 my %optiondesc = &Apache::lonlocal::texthash (
                   4586:                                    0 => 'No',
                   4587:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   4588:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   4589:                                  );
                   4590:                 $datatable .= '<table width="100%">';
                   4591:                 foreach my $option (@options) {
                   4592:                     my $checked = ' ';
                   4593:                     my $onclick;
                   4594:                     if ($defaults{$item} eq $option) {
                   4595:                         $checked = ' checked="checked"';
                   4596:                     }
                   4597:                     if ($option == 2) {
                   4598:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   4599:                     }
                   4600:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   4601:                                   '<label><input type="radio" name="'.$item.
                   4602:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   4603:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   4604:                 }
                   4605:                 $datatable .= '</table>';
                   4606:             } else {
                   4607:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   4608:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   4609:             }
                   4610:             $datatable .= '</td></tr>';
                   4611:             $itemcount ++;
                   4612:         }
                   4613:     } elsif ($position eq 'lower') {
                   4614:         my ($min,$max,%chars,$numsaved);
1.160.6.99  raeburn  4615:         $min = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  4616:         if (ref($settings) eq 'HASH') {
                   4617:             if ($settings->{min}) {
                   4618:                 $min = $settings->{min};
                   4619:             }
                   4620:             if ($settings->{max}) {
                   4621:                 $max = $settings->{max};
                   4622:             }
                   4623:             if (ref($settings->{chars}) eq 'ARRAY') {
                   4624:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   4625:             }
                   4626:             if ($settings->{numsaved}) {
                   4627:                 $numsaved = $settings->{numsaved};
                   4628:             }
                   4629:         }
                   4630:         my %rulenames = &Apache::lonlocal::texthash(
                   4631:                                                      uc => 'At least one upper case letter',
                   4632:                                                      lc => 'At least one lower case letter',
                   4633:                                                      num => 'At least one number',
                   4634:                                                      spec => 'At least one non-alphanumeric',
                   4635:                                                    );
                   4636:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4637:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   4638:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99  raeburn  4639:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   4640:                       'onblur="javascript:warnIntPass(this);" />'.
                   4641:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98  raeburn  4642:                       '</span></td></tr>';
                   4643:         $itemcount ++;
                   4644:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4645:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   4646:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99  raeburn  4647:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   4648:                       'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98  raeburn  4649:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   4650:                       '</span></td></tr>';
                   4651:         $itemcount ++;
                   4652:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4653:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   4654:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   4655:                       '</span></td>';
                   4656:         my $numinrow = 2;
                   4657:         my @possrules = ('uc','lc','num','spec');
                   4658:         $datatable .= '<td class="LC_left_item"><table>';
                   4659:         for (my $i=0; $i<@possrules; $i++) {
                   4660:             my ($rem,$checked);
                   4661:             if ($chars{$possrules[$i]}) {
                   4662:                 $checked = ' checked="checked"';
                   4663:             }
                   4664:             $rem = $i%($numinrow);
                   4665:             if ($rem == 0) {
                   4666:                 if ($i > 0) {
                   4667:                     $datatable .= '</tr>';
                   4668:                 }
                   4669:                 $datatable .= '<tr>';
                   4670:             }
                   4671:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   4672:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   4673:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   4674:         }
                   4675:         my $rem = @possrules%($numinrow);
                   4676:         my $colsleft = $numinrow - $rem;
                   4677:         if ($colsleft > 1 ) {
                   4678:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4679:                           '&nbsp;</td>';
                   4680:         } elsif ($colsleft == 1) {
                   4681:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4682:         }
                   4683:         $datatable .='</table></td></tr>';
                   4684:         $itemcount ++;
                   4685:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4686:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   4687:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100  raeburn  4688:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99  raeburn  4689:                       'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98  raeburn  4690:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   4691:                       '</span></td></tr>';
                   4692:     } else {
                   4693:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4694:         my %ownerchg = (
                   4695:                           by  => {},
                   4696:                           for => {},
                   4697:                        );
                   4698:         my %ownertitles = &Apache::lonlocal::texthash (
                   4699:                             by  => 'Course owner status(es) allowed',
                   4700:                             for => 'Student status(es) allowed',
                   4701:                           );
                   4702:         if (ref($settings) eq 'HASH') {
                   4703:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   4704:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   4705:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   4706:                 }
                   4707:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   4708:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   4709:                 }
                   4710:             }
                   4711:         }
                   4712:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4713:         $datatable .= '<tr '.$css_class.'>'.
                   4714:                       '<td>'.
                   4715:                       &mt('Requirements').'<ul>'.
                   4716:                       '<li>'.&mt("Course 'type' is not a Community").'</li>'.
                   4717:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   4718:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
                   4719:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
                   4720:                       '</ul>'.
                   4721:                       '</td>'.
                   4722:                       '<td class="LC_left_item">';
                   4723:         foreach my $item ('by','for') {
                   4724:             $datatable .= '<fieldset style="display: inline-block;">'.
                   4725:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   4726:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   4727:                 foreach my $type (@{$types}) {
                   4728:                     my $checked;
                   4729:                     if ($ownerchg{$item}{$type}) {
                   4730:                         $checked = ' checked="checked"';
                   4731:                     }
                   4732:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   4733:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   4734:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104  raeburn  4735:                                   '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  4736:                 }
                   4737:             }
                   4738:             my $checked;
                   4739:             if ($ownerchg{$item}{'default'}) {
                   4740:                 $checked = ' checked="checked"';
                   4741:             }
                   4742:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   4743:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   4744:                           $othertitle.'</label></span></fieldset>';
                   4745:         }
                   4746:         $datatable .= '</td></tr>';
                   4747:     }
                   4748:     return $datatable;
                   4749: }
                   4750: 
1.137     raeburn  4751: sub print_usersessions {
                   4752:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4753:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  4754:     my (%by_ip,%by_location,@intdoms);
                   4755:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  4756: 
                   4757:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  4758:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  4759:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  4760:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  4761:     my $itemcount = 1;
                   4762:     if ($position eq 'top') {
1.152     raeburn  4763:         if (keys(%serverhomes) > 1) {
1.145     raeburn  4764:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.160.6.105  raeburn  4765:             my ($curroffloadnow,$curroffloadoth);
1.160.6.61  raeburn  4766:             if (ref($settings) eq 'HASH') {
                   4767:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   4768:                     $curroffloadnow = $settings->{'offloadnow'};
                   4769:                 }
1.160.6.105  raeburn  4770:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   4771:                     $curroffloadoth = $settings->{'offloadoth'};
                   4772:                 }
1.160.6.61  raeburn  4773:             }
1.160.6.105  raeburn  4774:             my $other_insts = scalar(keys(%by_location));
                   4775:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   4776:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  4777:         } else {
1.140     raeburn  4778:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4779:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  4780:         }
1.137     raeburn  4781:     } else {
1.145     raeburn  4782:         if (keys(%by_location) == 0) {
                   4783:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4784:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  4785:         } else {
                   4786:             my %lt = &usersession_titles();
                   4787:             my $numinrow = 5;
                   4788:             my $prefix;
                   4789:             my @types;
                   4790:             if ($position eq 'bottom') {
                   4791:                 $prefix = 'remote';
                   4792:                 @types = ('version','excludedomain','includedomain');
                   4793:             } else {
                   4794:                 $prefix = 'hosted';
                   4795:                 @types = ('excludedomain','includedomain');
                   4796:             }
                   4797:             my (%current,%checkedon,%checkedoff);
                   4798:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   4799:             my @locations = sort(keys(%by_location));
                   4800:             foreach my $type (@types) {
                   4801:                 $checkedon{$type} = '';
                   4802:                 $checkedoff{$type} = ' checked="checked"';
                   4803:             }
                   4804:             if (ref($settings) eq 'HASH') {
                   4805:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   4806:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   4807:                         $current{$key} = $settings->{$prefix}{$key};
                   4808:                         if ($key eq 'version') {
                   4809:                             if ($current{$key} ne '') {
                   4810:                                 $checkedon{$key} = ' checked="checked"';
                   4811:                                 $checkedoff{$key} = '';
                   4812:                             }
                   4813:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   4814:                             $checkedon{$key} = ' checked="checked"';
                   4815:                             $checkedoff{$key} = '';
                   4816:                         }
1.137     raeburn  4817:                     }
                   4818:                 }
                   4819:             }
1.145     raeburn  4820:             foreach my $type (@types) {
                   4821:                 next if ($type ne 'version' && !@locations);
                   4822:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4823:                 $datatable .= '<tr'.$css_class.'>
                   4824:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   4825:                                <span class="LC_nobreak">&nbsp;
                   4826:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   4827:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   4828:                 if ($type eq 'version') {
                   4829:                     my $selector = '<select name="'.$prefix.'_version">';
                   4830:                     foreach my $version (@lcversions) {
                   4831:                         my $selected = '';
                   4832:                         if ($current{'version'} eq $version) {
                   4833:                             $selected = ' selected="selected"';
                   4834:                         }
                   4835:                         $selector .= ' <option value="'.$version.'"'.
                   4836:                                      $selected.'>'.$version.'</option>';
                   4837:                     }
                   4838:                     $selector .= '</select> ';
                   4839:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   4840:                 } else {
                   4841:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   4842:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   4843:                                  ' />'.('&nbsp;'x2).
                   4844:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   4845:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   4846:                                  "\n".
                   4847:                                  '</div><div><table>';
                   4848:                     my $rem;
                   4849:                     for (my $i=0; $i<@locations; $i++) {
                   4850:                         my ($showloc,$value,$checkedtype);
                   4851:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   4852:                             my $ip = $by_location{$locations[$i]}->[0];
                   4853:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   4854:                                  $value = join(':',@{$by_ip{$ip}});
                   4855:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   4856:                                 if (ref($current{$type}) eq 'ARRAY') {
                   4857:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   4858:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   4859:                                             $checkedtype = ' checked="checked"';
                   4860:                                             last;
                   4861:                                         }
                   4862:                                     }
1.138     raeburn  4863:                                 }
                   4864:                             }
                   4865:                         }
1.145     raeburn  4866:                         $rem = $i%($numinrow);
                   4867:                         if ($rem == 0) {
                   4868:                             if ($i > 0) {
                   4869:                                 $datatable .= '</tr>';
                   4870:                             }
                   4871:                             $datatable .= '<tr>';
                   4872:                         }
                   4873:                         $datatable .= '<td class="LC_left_item">'.
                   4874:                                       '<span class="LC_nobreak"><label>'.
                   4875:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   4876:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   4877:                                       '</label></span></td>';
1.137     raeburn  4878:                     }
1.145     raeburn  4879:                     $rem = @locations%($numinrow);
                   4880:                     my $colsleft = $numinrow - $rem;
                   4881:                     if ($colsleft > 1 ) {
                   4882:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4883:                                       '&nbsp;</td>';
                   4884:                     } elsif ($colsleft == 1) {
                   4885:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  4886:                     }
1.145     raeburn  4887:                     $datatable .= '</tr></table>';
1.137     raeburn  4888:                 }
1.145     raeburn  4889:                 $datatable .= '</td></tr>';
                   4890:                 $itemcount ++;
1.137     raeburn  4891:             }
                   4892:         }
                   4893:     }
                   4894:     $$rowtotal += $itemcount;
                   4895:     return $datatable;
                   4896: }
                   4897: 
1.138     raeburn  4898: sub build_location_hashes {
                   4899:     my ($intdoms,$by_ip,$by_location) = @_;
                   4900:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   4901:                   (ref($by_location) eq 'HASH')); 
                   4902:     my %iphost = &Apache::lonnet::get_iphost();
                   4903:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   4904:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   4905:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   4906:         foreach my $id (@{$iphost{$primary_ip}}) {
                   4907:             my $intdom = &Apache::lonnet::internet_dom($id);
                   4908:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   4909:                 push(@{$intdoms},$intdom);
                   4910:             }
                   4911:         }
                   4912:     }
                   4913:     foreach my $ip (keys(%iphost)) {
                   4914:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   4915:             foreach my $id (@{$iphost{$ip}}) {
                   4916:                 my $location = &Apache::lonnet::internet_dom($id);
                   4917:                 if ($location) {
                   4918:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   4919:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4920:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   4921:                             push(@{$by_ip->{$ip}},$location);
                   4922:                         }
                   4923:                     } else {
                   4924:                         $by_ip->{$ip} = [$location];
                   4925:                     }
                   4926:                 }
                   4927:             }
                   4928:         }
                   4929:     }
                   4930:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   4931:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4932:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   4933:             my $first = $by_ip->{$ip}->[0];
                   4934:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   4935:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   4936:                     push(@{$by_location->{$first}},$ip);
                   4937:                 }
                   4938:             } else {
                   4939:                 $by_location->{$first} = [$ip];
                   4940:             }
                   4941:         }
                   4942:     }
                   4943:     return;
                   4944: }
                   4945: 
1.145     raeburn  4946: sub current_offloads_to {
                   4947:     my ($dom,$settings,$servers) = @_;
                   4948:     my (%spareid,%otherdomconfigs);
1.152     raeburn  4949:     if (ref($servers) eq 'HASH') {
1.145     raeburn  4950:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   4951:             my $gotspares;
1.152     raeburn  4952:             if (ref($settings) eq 'HASH') {
                   4953:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   4954:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   4955:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   4956:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   4957:                         $gotspares = 1;
                   4958:                     }
1.145     raeburn  4959:                 }
                   4960:             }
                   4961:             unless ($gotspares) {
                   4962:                 my $gotspares;
                   4963:                 my $serverhomeID =
                   4964:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   4965:                 my $serverhomedom =
                   4966:                     &Apache::lonnet::host_domain($serverhomeID);
                   4967:                 if ($serverhomedom ne $dom) {
                   4968:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   4969:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4970:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4971:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4972:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4973:                                 $gotspares = 1;
                   4974:                             }
                   4975:                         }
                   4976:                     } else {
                   4977:                         $otherdomconfigs{$serverhomedom} =
                   4978:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   4979:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   4980:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4981:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4982:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   4983:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4984:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4985:                                         $gotspares = 1;
                   4986:                                     }
                   4987:                                 }
                   4988:                             }
                   4989:                         }
                   4990:                     }
                   4991:                 }
                   4992:             }
                   4993:             unless ($gotspares) {
                   4994:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4995:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4996:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4997:                } else {
                   4998:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   4999:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   5000:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   5001:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   5002:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   5003:                     } else {
1.150     raeburn  5004:                         my %what = (
                   5005:                              spareid => 1,
                   5006:                         );
                   5007:                         my ($result,$returnhash) = 
                   5008:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   5009:                         if ($result eq 'ok') { 
                   5010:                             if (ref($returnhash) eq 'HASH') {
                   5011:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   5012:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   5013:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   5014:                                 }
                   5015:                             }
1.145     raeburn  5016:                         }
                   5017:                     }
                   5018:                 }
                   5019:             }
                   5020:         }
                   5021:     }
                   5022:     return %spareid;
                   5023: }
                   5024: 
                   5025: sub spares_row {
1.160.6.105  raeburn  5026:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   5027:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  5028:     my $css_class;
                   5029:     my $numinrow = 4;
                   5030:     my $itemcount = 1;
                   5031:     my $datatable;
1.152     raeburn  5032:     my %typetitles = &sparestype_titles();
                   5033:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  5034:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  5035:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   5036:             my ($othercontrol,$serverdom);
                   5037:             if ($serverhome ne $server) {
                   5038:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   5039:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5040:             } else {
                   5041:                 $serverdom = &Apache::lonnet::host_domain($server);
                   5042:                 if ($serverdom ne $dom) {
                   5043:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5044:                 }
                   5045:             }
                   5046:             next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105  raeburn  5047:             my ($checkednow,$checkedoth);
1.160.6.61  raeburn  5048:             if (ref($curroffloadnow) eq 'HASH') {
                   5049:                 if ($curroffloadnow->{$server}) {
                   5050:                     $checkednow = ' checked="checked"';
                   5051:                 }
                   5052:             }
1.160.6.105  raeburn  5053:             if (ref($curroffloadoth) eq 'HASH') {
                   5054:                 if ($curroffloadoth->{$server}) {
                   5055:                     $checkedoth = ' checked="checked"';
                   5056:                 }
                   5057:             }
1.145     raeburn  5058:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5059:             $datatable .= '<tr'.$css_class.'>
                   5060:                            <td rowspan="2">
1.160.6.13  raeburn  5061:                             <span class="LC_nobreak">'.
                   5062:                           &mt('[_1] when busy, offloads to:'
1.160.6.61  raeburn  5063:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   5064:                           '<span class="LC_nobreak">'."\n".
                   5065:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105  raeburn  5066:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13  raeburn  5067:                           "\n";
1.160.6.105  raeburn  5068:             if ($other_insts) {
                   5069:                 $datatable .= '<br />'.
                   5070:                               '<span class="LC_nobreak">'."\n".
                   5071:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   5072:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   5073:                           "\n";
                   5074:             }
1.145     raeburn  5075:             my (%current,%canselect);
1.152     raeburn  5076:             my @choices = 
                   5077:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   5078:             foreach my $type ('primary','default') {
                   5079:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  5080:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   5081:                         my @spares = @{$spareid->{$server}{$type}};
                   5082:                         if (@spares > 0) {
1.152     raeburn  5083:                             if ($othercontrol) {
                   5084:                                 $current{$type} = join(', ',@spares);
                   5085:                             } else {
                   5086:                                 $current{$type} .= '<table>';
                   5087:                                 my $numspares = scalar(@spares);
                   5088:                                 for (my $i=0;  $i<@spares; $i++) {
                   5089:                                     my $rem = $i%($numinrow);
                   5090:                                     if ($rem == 0) {
                   5091:                                         if ($i > 0) {
                   5092:                                             $current{$type} .= '</tr>';
                   5093:                                         }
                   5094:                                         $current{$type} .= '<tr>';
1.145     raeburn  5095:                                     }
1.152     raeburn  5096:                                     $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;'.
                   5097:                                                        $spareid->{$server}{$type}[$i].
                   5098:                                                        '</label></td>'."\n";
                   5099:                                 }
                   5100:                                 my $rem = @spares%($numinrow);
                   5101:                                 my $colsleft = $numinrow - $rem;
                   5102:                                 if ($colsleft > 1 ) {
                   5103:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   5104:                                                        '" class="LC_left_item">'.
                   5105:                                                        '&nbsp;</td>';
                   5106:                                 } elsif ($colsleft == 1) {
                   5107:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  5108:                                 }
1.152     raeburn  5109:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  5110:                             }
1.145     raeburn  5111:                         }
                   5112:                     }
                   5113:                     if ($current{$type} eq '') {
                   5114:                         $current{$type} = &mt('None specified');
                   5115:                     }
1.152     raeburn  5116:                     if ($othercontrol) {
                   5117:                         if ($type eq 'primary') {
                   5118:                             $canselect{$type} = $othercontrol;
                   5119:                         }
                   5120:                     } else {
                   5121:                         $canselect{$type} = 
                   5122:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   5123:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   5124:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   5125:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   5126:                         if (@choices > 0) {
                   5127:                             foreach my $lonhost (@choices) {
                   5128:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   5129:                             }
                   5130:                         }
                   5131:                         $canselect{$type} .= '</select>'."\n";
                   5132:                     }
                   5133:                 } else {
                   5134:                     $current{$type} = &mt('Could not be determined');
                   5135:                     if ($type eq 'primary') {
                   5136:                         $canselect{$type} =  $othercontrol;
                   5137:                     }
1.145     raeburn  5138:                 }
1.152     raeburn  5139:                 if ($type eq 'default') {
                   5140:                     $datatable .= '<tr'.$css_class.'>';
                   5141:                 }
                   5142:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   5143:                               '<td>'.$current{$type}.'</td>'."\n".
                   5144:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  5145:             }
                   5146:             $itemcount ++;
                   5147:         }
                   5148:     }
                   5149:     $$rowtotal += $itemcount;
                   5150:     return $datatable;
                   5151: }
                   5152: 
1.152     raeburn  5153: sub possible_newspares {
                   5154:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   5155:     my $serverhostname = &Apache::lonnet::hostname($server);
                   5156:     my %excluded;
                   5157:     if ($serverhostname ne '') {
                   5158:         %excluded = (
                   5159:                        $serverhostname => 1,
                   5160:                     );
                   5161:     }
                   5162:     if (ref($currspares) eq 'HASH') {
                   5163:         foreach my $type (keys(%{$currspares})) {
                   5164:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   5165:                 if (@{$currspares->{$type}} > 0) {
                   5166:                     foreach my $curr (@{$currspares->{$type}}) {
                   5167:                         my $hostname = &Apache::lonnet::hostname($curr);
                   5168:                         $excluded{$hostname} = 1;
                   5169:                     }
                   5170:                 }
                   5171:             }
                   5172:         }
                   5173:     }
                   5174:     my @choices;
                   5175:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   5176:         if (keys(%{$serverhomes}) > 1) {
                   5177:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   5178:                 unless ($excluded{$name}) {
                   5179:                     if (exists($altids->{$serverhomes->{$name}})) {
                   5180:                         push(@choices,$altids->{$serverhomes->{$name}});
                   5181:                     } else {
                   5182:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  5183:                     }
                   5184:                 }
                   5185:             }
                   5186:         }
                   5187:     }
1.152     raeburn  5188:     return sort(@choices);
1.145     raeburn  5189: }
                   5190: 
1.150     raeburn  5191: sub print_loadbalancing {
                   5192:     my ($dom,$settings,$rowtotal) = @_;
                   5193:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5194:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5195:     my $numinrow = 1;
                   5196:     my $datatable;
                   5197:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94  raeburn  5198:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  5199:     if (ref($settings) eq 'HASH') {
                   5200:         %existing = %{$settings};
                   5201:     }
                   5202:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   5203:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  5204:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  5205:     } else {
                   5206:         return;
                   5207:     }
                   5208:     my ($othertitle,$usertypes,$types) =
                   5209:         &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26  raeburn  5210:     my $rownum = 8;
1.150     raeburn  5211:     if (ref($types) eq 'ARRAY') {
                   5212:         $rownum += scalar(@{$types});
                   5213:     }
1.160.6.7  raeburn  5214:     my @css_class = ('LC_odd_row','LC_even_row');
                   5215:     my $balnum = 0;
                   5216:     my $islast;
                   5217:     my (@toshow,$disabledtext);
                   5218:     if (keys(%currbalancer) > 0) {
                   5219:         @toshow = sort(keys(%currbalancer));
                   5220:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   5221:             push(@toshow,'');
                   5222:         }
                   5223:     } else {
                   5224:         @toshow = ('');
                   5225:         $disabledtext = &mt('No existing load balancer');
                   5226:     }
                   5227:     foreach my $lonhost (@toshow) {
                   5228:         if ($balnum == scalar(@toshow)-1) {
                   5229:             $islast = 1;
                   5230:         } else {
                   5231:             $islast = 0;
                   5232:         }
                   5233:         my $cssidx = $balnum%2;
                   5234:         my $targets_div_style = 'display: none';
                   5235:         my $disabled_div_style = 'display: block';
                   5236:         my $homedom_div_style = 'display: none';
                   5237:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   5238:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   5239:                       '<p>';
                   5240:         if ($lonhost eq '') {
                   5241:             $datatable .= '<span class="LC_nobreak">';
                   5242:             if (keys(%currbalancer) > 0) {
                   5243:                 $datatable .= &mt('Add balancer:');
                   5244:             } else {
                   5245:                 $datatable .= &mt('Enable balancer:');
                   5246:             }
                   5247:             $datatable .= '&nbsp;'.
                   5248:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   5249:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   5250:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   5251:                           '<option value="" selected="selected">'.&mt('None').
                   5252:                           '</option>'."\n";
                   5253:             foreach my $server (sort(keys(%servers))) {
                   5254:                 next if ($currbalancer{$server});
                   5255:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   5256:             }
                   5257:             $datatable .=
                   5258:                 '</select>'."\n".
                   5259:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   5260:         } else {
                   5261:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   5262:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   5263:                            &mt('Stop balancing').'</label>'.
                   5264:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   5265:             $targets_div_style = 'display: block';
                   5266:             $disabled_div_style = 'display: none';
                   5267:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   5268:                 $homedom_div_style = 'display: block';
                   5269:             }
                   5270:         }
                   5271:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   5272:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   5273:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   5274:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   5275:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   5276:         my @sparestypes = ('primary','default');
                   5277:         my %typetitles = &sparestype_titles();
1.160.6.76  raeburn  5278:         my %hostherechecked = (
                   5279:                                   no => ' checked="checked"',
                   5280:                               );
1.160.6.94  raeburn  5281:         my %balcookiechecked = (
                   5282:                                   no => ' checked="checked"',
                   5283:                                );
1.160.6.7  raeburn  5284:         foreach my $sparetype (@sparestypes) {
                   5285:             my $targettable;
                   5286:             for (my $i=0; $i<$numspares; $i++) {
                   5287:                 my $checked;
                   5288:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5289:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5290:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5291:                             $checked = ' checked="checked"';
                   5292:                         }
                   5293:                     }
                   5294:                 }
                   5295:                 my ($chkboxval,$disabled);
                   5296:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   5297:                     $chkboxval = $spares[$i];
                   5298:                 }
                   5299:                 if (exists($currbalancer{$spares[$i]})) {
                   5300:                     $disabled = ' disabled="disabled"';
                   5301:                 }
                   5302:                 $targettable .=
1.160.6.55  raeburn  5303:                     '<td><span class="LC_nobreak"><label>'.
                   5304:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7  raeburn  5305:                     $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.160.6.55  raeburn  5306:                     '</span></label></span></td>';
1.160.6.7  raeburn  5307:                 my $rem = $i%($numinrow);
                   5308:                 if ($rem == 0) {
                   5309:                     if (($i > 0) && ($i < $numspares-1)) {
                   5310:                         $targettable .= '</tr>';
                   5311:                     }
                   5312:                     if ($i < $numspares-1) {
                   5313:                         $targettable .= '<tr>';
1.150     raeburn  5314:                     }
                   5315:                 }
                   5316:             }
1.160.6.7  raeburn  5317:             if ($targettable ne '') {
                   5318:                 my $rem = $numspares%($numinrow);
                   5319:                 my $colsleft = $numinrow - $rem;
                   5320:                 if ($colsleft > 1 ) {
                   5321:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5322:                                     '&nbsp;</td>';
                   5323:                 } elsif ($colsleft == 1) {
                   5324:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   5325:                 }
                   5326:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   5327:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   5328:             }
1.160.6.76  raeburn  5329:             $hostherechecked{$sparetype} = '';
                   5330:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5331:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5332:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5333:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   5334:                         $hostherechecked{'no'} = '';
                   5335:                     }
                   5336:                 }
                   5337:             }
                   5338:         }
1.160.6.94  raeburn  5339:         if ($currcookies{$lonhost}) {
                   5340:             %balcookiechecked = (
                   5341:                                     yes => ' checked="checked"',
                   5342:                                 );
                   5343:         }
1.160.6.76  raeburn  5344:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   5345:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   5346:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   5347:         foreach my $sparetype (@sparestypes) {
                   5348:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   5349:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   5350:                           '</i></label><br />';
1.160.6.7  raeburn  5351:         }
1.160.6.94  raeburn  5352:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   5353:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   5354:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   5355:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   5356:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   5357:                       '</div></td></tr>'.
1.160.6.7  raeburn  5358:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   5359:                                            $othertitle,$usertypes,$types,\%servers,
                   5360:                                            \%currbalancer,$lonhost,
                   5361:                                            $targets_div_style,$homedom_div_style,
                   5362:                                            $css_class[$cssidx],$balnum,$islast);
                   5363:         $$rowtotal += $rownum;
                   5364:         $balnum ++;
                   5365:     }
                   5366:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   5367:     return $datatable;
                   5368: }
                   5369: 
                   5370: sub get_loadbalancers_config {
1.160.6.94  raeburn  5371:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7  raeburn  5372:     return unless ((ref($servers) eq 'HASH') &&
                   5373:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94  raeburn  5374:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   5375:                    (ref($currcookies) eq 'HASH'));
1.160.6.7  raeburn  5376:     if (keys(%{$existing}) > 0) {
                   5377:         my $oldlonhost;
                   5378:         foreach my $key (sort(keys(%{$existing}))) {
                   5379:             if ($key eq 'lonhost') {
                   5380:                 $oldlonhost = $existing->{'lonhost'};
                   5381:                 $currbalancer->{$oldlonhost} = 1;
                   5382:             } elsif ($key eq 'targets') {
                   5383:                 if ($oldlonhost) {
                   5384:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   5385:                 }
                   5386:             } elsif ($key eq 'rules') {
                   5387:                 if ($oldlonhost) {
                   5388:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   5389:                 }
                   5390:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   5391:                 $currbalancer->{$key} = 1;
                   5392:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   5393:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94  raeburn  5394:                 if ($existing->{$key}{'cookie'}) {
                   5395:                     $currcookies->{$key} = 1;
                   5396:                 }
1.150     raeburn  5397:             }
                   5398:         }
1.160.6.7  raeburn  5399:     } else {
                   5400:         my ($balancerref,$targetsref) =
                   5401:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   5402:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   5403:             foreach my $server (sort(keys(%{$balancerref}))) {
                   5404:                 $currbalancer->{$server} = 1;
                   5405:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  5406:             }
                   5407:         }
                   5408:     }
1.160.6.7  raeburn  5409:     return;
1.150     raeburn  5410: }
                   5411: 
                   5412: sub loadbalancing_rules {
                   5413:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7  raeburn  5414:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   5415:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  5416:     my $output;
1.160.6.7  raeburn  5417:     my $num = 0;
                   5418:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  5419:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   5420:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   5421:         foreach my $type (@{$alltypes}) {
1.160.6.7  raeburn  5422:             $num ++;
1.150     raeburn  5423:             my $current;
                   5424:             if (ref($currrules) eq 'HASH') {
                   5425:                 $current = $currrules->{$type};
                   5426:             }
1.160.6.55  raeburn  5427:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7  raeburn  5428:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  5429:                     $current = '';
                   5430:                 }
                   5431:             }
                   5432:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7  raeburn  5433:                                              $servers,$currbalancer,$lonhost,$dom,
                   5434:                                              $targets_div_style,$homedom_div_style,
                   5435:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  5436:         }
                   5437:     }
                   5438:     return $output;
                   5439: }
                   5440: 
                   5441: sub loadbalancing_titles {
                   5442:     my ($dom,$intdom,$usertypes,$types) = @_;
                   5443:     my %othertypes = (
                   5444:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   5445:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   5446:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   5447:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.160.6.26  raeburn  5448:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   5449:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  5450:                      );
1.160.6.26  raeburn  5451:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89  raeburn  5452:     my @available;
1.150     raeburn  5453:     if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  5454:         @available = @{$types};
1.150     raeburn  5455:     }
1.160.6.89  raeburn  5456:     unless (grep(/^default$/,@available)) {
                   5457:         push(@available,'default');
                   5458:     }
                   5459:     unshift(@alltypes,@available);
1.150     raeburn  5460:     my %titles;
                   5461:     foreach my $type (@alltypes) {
                   5462:         if ($type =~ /^_LC_/) {
                   5463:             $titles{$type} = $othertypes{$type};
                   5464:         } elsif ($type eq 'default') {
                   5465:             $titles{$type} = &mt('All users from [_1]',$dom);
                   5466:             if (ref($types) eq 'ARRAY') {
                   5467:                 if (@{$types} > 0) {
                   5468:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   5469:                 }
                   5470:             }
                   5471:         } elsif (ref($usertypes) eq 'HASH') {
                   5472:             $titles{$type} = $usertypes->{$type};
                   5473:         }
                   5474:     }
                   5475:     return (\@alltypes,\%othertypes,\%titles);
                   5476: }
                   5477: 
                   5478: sub loadbalance_rule_row {
1.160.6.7  raeburn  5479:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   5480:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26  raeburn  5481:     my @rulenames;
1.150     raeburn  5482:     my %ruletitles = &offloadtype_text();
1.160.6.26  raeburn  5483:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55  raeburn  5484:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  5485:     } else {
1.160.6.26  raeburn  5486:         @rulenames = ('default','homeserver');
                   5487:         if ($type eq '_LC_external') {
                   5488:             push(@rulenames,'externalbalancer');
                   5489:         } else {
                   5490:             push(@rulenames,'specific');
                   5491:         }
                   5492:         push(@rulenames,'none');
1.150     raeburn  5493:     }
                   5494:     my $style = $targets_div_style;
1.160.6.55  raeburn  5495:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  5496:         $style = $homedom_div_style;
                   5497:     }
1.160.6.7  raeburn  5498:     my $space;
                   5499:     if ($islast && $num == 1) {
                   5500:         $space = '<div display="inline-block">&nbsp;</div>';
                   5501:     }
                   5502:     my $output =
                   5503:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   5504:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   5505:         '<td valaign="top">'.$space.
                   5506:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  5507:     for (my $i=0; $i<@rulenames; $i++) {
                   5508:         my $rule = $rulenames[$i];
                   5509:         my ($checked,$extra);
                   5510:         if ($rulenames[$i] eq 'default') {
                   5511:             $rule = '';
                   5512:         }
                   5513:         if ($rulenames[$i] eq 'specific') {
                   5514:             if (ref($servers) eq 'HASH') {
                   5515:                 my $default;
                   5516:                 if (($current ne '') && (exists($servers->{$current}))) {
                   5517:                     $checked = ' checked="checked"';
                   5518:                 }
                   5519:                 unless ($checked) {
                   5520:                     $default = ' selected="selected"';
                   5521:                 }
1.160.6.7  raeburn  5522:                 $extra =
                   5523:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5524:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5525:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   5526:                     '<option value=""'.$default.'></option>'."\n";
                   5527:                 foreach my $server (sort(keys(%{$servers}))) {
                   5528:                     if (ref($currbalancer) eq 'HASH') {
                   5529:                         next if (exists($currbalancer->{$server}));
                   5530:                     }
1.150     raeburn  5531:                     my $selected;
1.160.6.7  raeburn  5532:                     if ($server eq $current) {
1.150     raeburn  5533:                         $selected = ' selected="selected"';
                   5534:                     }
1.160.6.7  raeburn  5535:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  5536:                 }
                   5537:                 $extra .= '</select>';
                   5538:             }
                   5539:         } elsif ($rule eq $current) {
                   5540:             $checked = ' checked="checked"';
                   5541:         }
                   5542:         $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7  raeburn  5543:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   5544:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   5545:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55  raeburn  5546:                    ')"'.$checked.' />&nbsp;';
1.160.6.56  raeburn  5547:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55  raeburn  5548:             $output .= $ruletitles{'particular'};
                   5549:         } else {
                   5550:             $output .= $ruletitles{$rulenames[$i]};
                   5551:         }
                   5552:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  5553:     }
                   5554:     $output .= '</div></td></tr>'."\n";
                   5555:     return $output;
                   5556: }
                   5557: 
                   5558: sub offloadtype_text {
                   5559:     my %ruletitles = &Apache::lonlocal::texthash (
                   5560:            'default'          => 'Offloads to default destinations',
                   5561:            'homeserver'       => "Offloads to user's home server",
                   5562:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   5563:            'specific'         => 'Offloads to specific server',
1.160.6.3  raeburn  5564:            'none'             => 'No offload',
1.160.6.26  raeburn  5565:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   5566:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.160.6.55  raeburn  5567:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  5568:     );
                   5569:     return %ruletitles;
                   5570: }
                   5571: 
                   5572: sub sparestype_titles {
                   5573:     my %typestitles = &Apache::lonlocal::texthash (
                   5574:                           'primary' => 'primary',
                   5575:                           'default' => 'default',
                   5576:                       );
                   5577:     return %typestitles;
                   5578: }
                   5579: 
1.28      raeburn  5580: sub contact_titles {
                   5581:     my %titles = &Apache::lonlocal::texthash (
1.160.6.78  raeburn  5582:                    'supportemail'    => 'Support E-mail address',
                   5583:                    'adminemail'      => 'Default Server Admin E-mail address',
                   5584:                    'errormail'       => 'Error reports to be e-mailed to',
                   5585:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.160.6.101  raeburn  5586:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   5587:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78  raeburn  5588:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   5589:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   5590:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23  raeburn  5591:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91  raeburn  5592:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109  raeburn  5593:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   5594:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.160.6.107  raeburn  5595:                    'errorweights'    => 'Weights used to compute error count',
                   5596:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  5597:                  );
                   5598:     my %short_titles = &Apache::lonlocal::texthash (
                   5599:                            adminemail   => 'Admin E-mail address',
                   5600:                            supportemail => 'Support E-mail',
                   5601:                        );   
                   5602:     return (\%titles,\%short_titles);
                   5603: }
                   5604: 
1.160.6.78  raeburn  5605: sub helpform_fields {
                   5606:     my %titles =  &Apache::lonlocal::texthash (
                   5607:                        'username'   => 'Name',
                   5608:                        'user'       => 'Username/domain',
                   5609:                        'phone'      => 'Phone',
                   5610:                        'cc'         => 'Cc e-mail',
                   5611:                        'course'     => 'Course Details',
                   5612:                        'section'    => 'Sections',
                   5613:                        'screenshot' => 'File upload',
                   5614:     );
                   5615:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   5616:     my %possoptions = (
                   5617:                         username     => ['yes','no','req'],
                   5618:                         phone        => ['yes','no','req'],
                   5619:                         user         => ['yes','no'],
                   5620:                         cc           => ['yes','no'],
                   5621:                         course       => ['yes','no'],
                   5622:                         section      => ['yes','no'],
                   5623:                         screenshot   => ['yes','no'],
                   5624:                       );
                   5625:     my %fieldoptions = &Apache::lonlocal::texthash (
                   5626:                          'yes'  => 'Optional',
                   5627:                          'req'  => 'Required',
                   5628:                          'no'   => "Not shown",
                   5629:     );
                   5630:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   5631: }
                   5632: 
1.72      raeburn  5633: sub tool_titles {
                   5634:     my %titles = &Apache::lonlocal::texthash (
1.160.6.4  raeburn  5635:                      aboutme    => 'Personal web page',
1.86      raeburn  5636:                      blog       => 'Blog',
1.160.6.4  raeburn  5637:                      webdav     => 'WebDAV',
1.86      raeburn  5638:                      portfolio  => 'Portfolio',
1.88      bisitz   5639:                      official   => 'Official courses (with institutional codes)',
                   5640:                      unofficial => 'Unofficial courses',
1.98      raeburn  5641:                      community  => 'Communities',
1.160.6.30  raeburn  5642:                      textbook   => 'Textbook courses',
1.86      raeburn  5643:                  );
1.72      raeburn  5644:     return %titles;
                   5645: }
                   5646: 
1.101     raeburn  5647: sub courserequest_titles {
                   5648:     my %titles = &Apache::lonlocal::texthash (
                   5649:                                    official   => 'Official',
                   5650:                                    unofficial => 'Unofficial',
                   5651:                                    community  => 'Communities',
1.160.6.30  raeburn  5652:                                    textbook   => 'Textbook',
1.101     raeburn  5653:                                    norequest  => 'Not allowed',
1.104     raeburn  5654:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  5655:                                    validate   => 'With validation',
                   5656:                                    autolimit  => 'Numerical limit',
1.103     raeburn  5657:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  5658:                  );
                   5659:     return %titles;
                   5660: }
                   5661: 
1.160.6.5  raeburn  5662: sub authorrequest_titles {
                   5663:     my %titles = &Apache::lonlocal::texthash (
                   5664:                                    norequest  => 'Not allowed',
                   5665:                                    approval   => 'Approval by Dom. Coord.',
                   5666:                                    automatic  => 'Automatic approval',
                   5667:                  );
                   5668:     return %titles;
                   5669: }
                   5670: 
1.101     raeburn  5671: sub courserequest_conditions {
                   5672:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  5673:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17  raeburn  5674:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  5675:                  );
                   5676:     return %conditions;
                   5677: }
                   5678: 
                   5679: 
1.27      raeburn  5680: sub print_usercreation {
1.30      raeburn  5681:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  5682:     my $numinrow = 4;
1.28      raeburn  5683:     my $datatable;
                   5684:     if ($position eq 'top') {
1.30      raeburn  5685:         $$rowtotal ++;
1.34      raeburn  5686:         my $rowcount = 0;
1.32      raeburn  5687:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  5688:         if (ref($rules) eq 'HASH') {
                   5689:             if (keys(%{$rules}) > 0) {
1.32      raeburn  5690:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   5691:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  5692:                 $$rowtotal ++;
1.32      raeburn  5693:                 $rowcount ++;
                   5694:             }
                   5695:         }
                   5696:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   5697:         if (ref($idrules) eq 'HASH') {
                   5698:             if (keys(%{$idrules}) > 0) {
                   5699:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   5700:                                                 $idruleorder,$numinrow,$rowcount);
                   5701:                 $$rowtotal ++;
                   5702:                 $rowcount ++;
1.28      raeburn  5703:             }
                   5704:         }
1.39      raeburn  5705:         if ($rowcount == 0) {
                   5706:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   5707:             $$rowtotal ++;
                   5708:             $rowcount ++;
                   5709:         }
1.34      raeburn  5710:     } elsif ($position eq 'middle') {
1.160.6.34  raeburn  5711:         my @creators = ('author','course','requestcrs');
1.37      raeburn  5712:         my ($rules,$ruleorder) =
                   5713:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  5714:         my %lt = &usercreation_types();
                   5715:         my %checked;
                   5716:         if (ref($settings) eq 'HASH') {
                   5717:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5718:                 foreach my $item (@creators) {
                   5719:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   5720:                 }
                   5721:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   5722:                 foreach my $item (@creators) {
                   5723:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   5724:                         $checked{$item} = 'none';
                   5725:                     }
                   5726:                 }
                   5727:             }
                   5728:         }
                   5729:         my $rownum = 0;
                   5730:         foreach my $item (@creators) {
                   5731:             $rownum ++;
1.160.6.34  raeburn  5732:             if ($checked{$item} eq '') {
                   5733:                 $checked{$item} = 'any';
1.34      raeburn  5734:             }
                   5735:             my $css_class;
                   5736:             if ($rownum%2) {
                   5737:                 $css_class = '';
                   5738:             } else {
                   5739:                 $css_class = ' class="LC_odd_row" ';
                   5740:             }
                   5741:             $datatable .= '<tr'.$css_class.'>'.
                   5742:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   5743:                          '</span></td><td align="right">';
1.160.6.34  raeburn  5744:             my @options = ('any');
                   5745:             if (ref($rules) eq 'HASH') {
                   5746:                 if (keys(%{$rules}) > 0) {
                   5747:                     push(@options,('official','unofficial'));
1.37      raeburn  5748:                 }
                   5749:             }
1.160.6.34  raeburn  5750:             push(@options,'none');
1.37      raeburn  5751:             foreach my $option (@options) {
1.50      raeburn  5752:                 my $type = 'radio';
1.34      raeburn  5753:                 my $check = ' ';
1.160.6.34  raeburn  5754:                 if ($checked{$item} eq $option) {
                   5755:                     $check = ' checked="checked" ';
1.34      raeburn  5756:                 } 
                   5757:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  5758:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  5759:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   5760:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   5761:             }
                   5762:             $datatable .= '</td></tr>';
                   5763:         }
1.28      raeburn  5764:     } else {
                   5765:         my @contexts = ('author','course','domain');
                   5766:         my @authtypes = ('int','krb4','krb5','loc');
                   5767:         my %checked;
                   5768:         if (ref($settings) eq 'HASH') {
                   5769:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   5770:                 foreach my $item (@contexts) {
                   5771:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   5772:                         foreach my $auth (@authtypes) {
                   5773:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   5774:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   5775:                             }
                   5776:                         }
                   5777:                     }
                   5778:                 }
1.27      raeburn  5779:             }
1.35      raeburn  5780:         } else {
                   5781:             foreach my $item (@contexts) {
1.36      raeburn  5782:                 foreach my $auth (@authtypes) {
1.35      raeburn  5783:                     $checked{$item}{$auth} = ' checked="checked" ';
                   5784:                 }
                   5785:             }
1.27      raeburn  5786:         }
1.28      raeburn  5787:         my %title = &context_names();
                   5788:         my %authname = &authtype_names();
                   5789:         my $rownum = 0;
                   5790:         my $css_class; 
                   5791:         foreach my $item (@contexts) {
                   5792:             if ($rownum%2) {
                   5793:                 $css_class = '';
                   5794:             } else {
                   5795:                 $css_class = ' class="LC_odd_row" ';
                   5796:             }
1.30      raeburn  5797:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  5798:                             '<td>'.$title{$item}.
                   5799:                             '</td><td class="LC_left_item">'.
                   5800:                             '<span class="LC_nobreak">';
                   5801:             foreach my $auth (@authtypes) {
                   5802:                 $datatable .= '<label>'. 
                   5803:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   5804:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   5805:                               $authname{$auth}.'</label>&nbsp;';
                   5806:             }
                   5807:             $datatable .= '</span></td></tr>';
                   5808:             $rownum ++;
1.27      raeburn  5809:         }
1.30      raeburn  5810:         $$rowtotal += $rownum;
1.27      raeburn  5811:     }
                   5812:     return $datatable;
                   5813: }
                   5814: 
1.160.6.34  raeburn  5815: sub print_selfcreation {
                   5816:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93  raeburn  5817:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   5818:         $emaildomain,$datatable);
1.160.6.34  raeburn  5819:     if (ref($settings) eq 'HASH') {
                   5820:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5821:             $createsettings = $settings->{'cancreate'};
1.160.6.40  raeburn  5822:             if (ref($createsettings) eq 'HASH') {
                   5823:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   5824:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   5825:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   5826:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   5827:                         @selfcreate = ('email','login','sso');
                   5828:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   5829:                         @selfcreate = ($createsettings->{'selfcreate'});
                   5830:                     }
                   5831:                 }
                   5832:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   5833:                     $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34  raeburn  5834:                 }
1.160.6.93  raeburn  5835:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   5836:                     $emailoptions = $createsettings->{'emailoptions'};
                   5837:                 }
                   5838:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   5839:                     $emailverified = $createsettings->{'emailverified'};
                   5840:                 }
                   5841:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   5842:                     $emaildomain = $createsettings->{'emaildomain'};
                   5843:                 }
1.160.6.34  raeburn  5844:             }
                   5845:         }
                   5846:     }
                   5847:     my %radiohash;
                   5848:     my $numinrow = 4;
                   5849:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89  raeburn  5850:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34  raeburn  5851:     if ($position eq 'top') {
                   5852:         my %choices = &Apache::lonlocal::texthash (
                   5853:                                                       cancreate_login      => 'Institutional Login',
                   5854:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   5855:                                                   );
                   5856:         my @toggles = sort(keys(%choices));
                   5857:         my %defaultchecked = (
                   5858:                                'cancreate_login' => 'off',
                   5859:                                'cancreate_sso'   => 'off',
                   5860:                              );
1.160.6.35  raeburn  5861:         my ($onclick,$itemcount);
1.160.6.34  raeburn  5862:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   5863:                                                      \%choices,$itemcount,$onclick);
1.160.6.35  raeburn  5864:         $$rowtotal += $itemcount;
1.160.6.34  raeburn  5865: 
                   5866:         if (ref($usertypes) eq 'HASH') {
                   5867:             if (keys(%{$usertypes}) > 0) {
                   5868:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   5869:                                              $dom,$numinrow,$othertitle,
1.160.6.89  raeburn  5870:                                              'statustocreate',$rowtotal);
1.160.6.34  raeburn  5871:                 $$rowtotal ++;
                   5872:             }
                   5873:         }
1.160.6.44  raeburn  5874:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   5875:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   5876:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   5877:         my $rem;
                   5878:         my $numperrow = 2;
                   5879:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   5880:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.45  raeburn  5881:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44  raeburn  5882:                      '<td class="LC_left_item">'."\n".
1.160.6.87  raeburn  5883:                      '<table>'."\n";
1.160.6.44  raeburn  5884:         for (my $i=0; $i<@fields; $i++) {
                   5885:             $rem = $i%($numperrow);
                   5886:             if ($rem == 0) {
                   5887:                 if ($i > 0) {
                   5888:                     $datatable .= '</tr>';
                   5889:                 }
                   5890:                 $datatable .= '<tr>';
                   5891:             }
                   5892:             my $currval;
1.160.6.51  raeburn  5893:             if (ref($createsettings) eq 'HASH') {
                   5894:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   5895:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   5896:                 }
1.160.6.44  raeburn  5897:             }
                   5898:             $datatable .= '<td class="LC_left_item">'.
                   5899:                           '<span class="LC_nobreak">'.
                   5900:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   5901:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   5902:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   5903:         }
                   5904:         my $colsleft = $numperrow - $rem;
                   5905:         if ($colsleft > 1 ) {
                   5906:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5907:                          '&nbsp;</td>';
                   5908:         } elsif ($colsleft == 1) {
                   5909:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   5910:         }
                   5911:         $datatable .= '</tr></table></td></tr>';
                   5912:         $$rowtotal ++;
1.160.6.34  raeburn  5913:     } elsif ($position eq 'middle') {
                   5914:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89  raeburn  5915:         my @posstypes;
1.160.6.34  raeburn  5916:         if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  5917:             @posstypes = @{$types};
                   5918:         }
                   5919:         unless (grep(/^default$/,@posstypes)) {
                   5920:             push(@posstypes,'default');
                   5921:         }
                   5922:         my %usertypeshash;
                   5923:         if (ref($usertypes) eq 'HASH') {
                   5924:             %usertypeshash = %{$usertypes};
                   5925:         }
                   5926:         $usertypeshash{'default'} = $othertitle;
                   5927:         foreach my $status (@posstypes) {
                   5928:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   5929:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   5930:             $$rowtotal ++;
1.160.6.34  raeburn  5931:         }
                   5932:     } else {
1.160.6.40  raeburn  5933:         my %choices = &Apache::lonlocal::texthash (
1.160.6.93  raeburn  5934:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40  raeburn  5935:                                                   );
                   5936:         my @toggles = sort(keys(%choices));
                   5937:         my %defaultchecked = (
                   5938:                                'cancreate_email' => 'off',
                   5939:                              );
1.160.6.93  raeburn  5940:         my $customclass = 'LC_selfcreate_email';
                   5941:         my $classprefix = 'LC_canmodify_emailusername_';
                   5942:         my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40  raeburn  5943:         my $display = 'none';
1.160.6.93  raeburn  5944:         my $rowstyle = 'display:none';
1.160.6.40  raeburn  5945:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   5946:             $display = 'block';
1.160.6.93  raeburn  5947:             $rowstyle = 'display:table-row';
1.160.6.40  raeburn  5948:         }
1.160.6.93  raeburn  5949:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   5950:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   5951:                                                      \%choices,$$rowtotal,$onclick);
                   5952:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   5953:                                          $rowstyle);
                   5954:         $$rowtotal ++;
                   5955:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   5956:                                       $rowstyle);
                   5957:         $$rowtotal ++;
                   5958:         my (@ordered,@posstypes,%usertypeshash);
1.160.6.40  raeburn  5959:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93  raeburn  5960:         my ($emailrules,$emailruleorder) =
                   5961:             &Apache::lonnet::inst_userrules($dom,'email');
                   5962:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5963:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5964:         if (ref($types) eq 'ARRAY') {
                   5965:             @posstypes = @{$types};
                   5966:         }
                   5967:         if (@posstypes) {
                   5968:             unless (grep(/^default$/,@posstypes)) {
                   5969:                 push(@posstypes,'default');
1.160.6.89  raeburn  5970:             }
                   5971:             if (ref($usertypes) eq 'HASH') {
                   5972:                 %usertypeshash = %{$usertypes};
                   5973:             }
1.160.6.93  raeburn  5974:             my $currassign;
                   5975:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   5976:                 $currassign = {
                   5977:                                   selfassign => $domdefaults{'inststatusguest'},
                   5978:                               };
                   5979:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   5980:             } else {
                   5981:                 $currassign = { selfassign => [] };
                   5982:             }
                   5983:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   5984:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   5985:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   5986:                                          $numinrow,$othertitle,'selfassign',
                   5987:                                          $rowtotal,$onclicktypes,$customclass,
                   5988:                                          $rowstyle);
                   5989:             $$rowtotal ++;
1.160.6.89  raeburn  5990:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  5991:             foreach my $status (@posstypes) {
                   5992:                 my $css_class;
                   5993:                 if ($$rowtotal%2) {
                   5994:                     $css_class = 'LC_odd_row ';
                   5995:                 }
                   5996:                 $css_class .= $customclass;
                   5997:                 my $rowid = $optionsprefix.$status;
                   5998:                 my $hidden = 1;
                   5999:                 my $currstyle = 'display:none';
                   6000:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   6001:                     $currstyle = $rowstyle;
                   6002:                     $hidden = 0;
                   6003:                 }
                   6004:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6005:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   6006:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   6007:                 unless ($hidden) {
                   6008:                     $$rowtotal ++;
                   6009:                 }
1.160.6.89  raeburn  6010:             }
                   6011:         } else {
1.160.6.93  raeburn  6012:             my $css_class;
                   6013:             if ($$rowtotal%2) {
                   6014:                 $css_class = 'LC_odd_row ';
                   6015:             }
                   6016:             $css_class .= $customclass;
1.160.6.89  raeburn  6017:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  6018:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6019:                                          $emailrules,$emailruleorder,$settings,'default','',
                   6020:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   6021:             $$rowtotal ++;
1.160.6.34  raeburn  6022:         }
1.160.6.35  raeburn  6023:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   6024:         $numinrow = 1;
1.160.6.93  raeburn  6025:         if (@posstypes) {
                   6026:             foreach my $status (@posstypes) {
                   6027:                 my $rowid = $classprefix.$status;
                   6028:                 my $datarowstyle = 'display:none';
                   6029:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   6030:                     $datarowstyle = $rowstyle;
                   6031:                 }
                   6032:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   6033:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6034:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   6035:                 unless ($datarowstyle eq 'display:none') {
                   6036:                     $$rowtotal ++;
                   6037:                 }
1.160.6.34  raeburn  6038:             }
1.160.6.93  raeburn  6039:         } else {
                   6040:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   6041:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6042:                                                    $infotitles,'',$customclass,$rowstyle);
1.160.6.34  raeburn  6043:         }
                   6044:     }
                   6045:     return $datatable;
                   6046: }
                   6047: 
1.160.6.93  raeburn  6048: sub selfcreate_javascript {
                   6049:     return <<"ENDSCRIPT";
                   6050: 
                   6051: <script type="text/javascript">
                   6052: // <![CDATA[
                   6053: 
                   6054: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   6055:     var x = document.getElementsByClassName(target);
                   6056:     var insttypes = 0;
                   6057:     var insttypeRegExp = new RegExp(prefix);
                   6058:     if ((x.length != undefined) && (x.length > 0)) {
                   6059:         if (form.elements[radio].length != undefined) {
                   6060:             for (var i=0; i<form.elements[radio].length; i++) {
                   6061:                 if (form.elements[radio][i].checked) {
                   6062:                     if (form.elements[radio][i].value == 1) {
                   6063:                         for (var j=0; j<x.length; j++) {
                   6064:                             if (x[j].id == 'undefined') {
                   6065:                                 x[j].style.display = 'table-row';
                   6066:                             } else if (insttypeRegExp.test(x[j].id)) {
                   6067:                                 insttypes ++;
                   6068:                             } else {
                   6069:                                 x[j].style.display = 'table-row';
                   6070:                             }
                   6071:                         }
                   6072:                     } else {
                   6073:                         for (var j=0; j<x.length; j++) {
                   6074:                             x[j].style.display = 'none';
                   6075:                         }
1.160.6.40  raeburn  6076:                     }
1.160.6.93  raeburn  6077:                     break;
                   6078:                 }
                   6079:             }
                   6080:             if (insttypes > 0) {
                   6081:                 toggleDataRow(form,checkbox,target,altprefix);
                   6082:                 toggleDataRow(form,checkbox,target,prefix,1);
                   6083:             }
                   6084:         }
                   6085:     }
                   6086:     return;
                   6087: }
                   6088: 
                   6089: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   6090:     if (form.elements[checkbox].length != undefined) {
                   6091:         var count = 0;
                   6092:         if (docount) {
                   6093:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   6094:                 if (form.elements[checkbox][i].checked) {
                   6095:                     count ++;
                   6096:                 }
                   6097:             }
                   6098:         }
                   6099:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   6100:             var type = form.elements[checkbox][i].value;
                   6101:             if (document.getElementById(prefix+type)) {
                   6102:                 if (form.elements[checkbox][i].checked) {
                   6103:                     document.getElementById(prefix+type).style.display = 'table-row';
                   6104:                     if (count % 2 == 1) {
                   6105:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   6106:                     } else {
                   6107:                         document.getElementById(prefix+type).className = target;
                   6108:                     }
                   6109:                     count ++;
1.160.6.40  raeburn  6110:                 } else {
1.160.6.93  raeburn  6111:                     document.getElementById(prefix+type).style.display = 'none';
                   6112:                 }
                   6113:             }
                   6114:         }
                   6115:     }
                   6116:     return;
                   6117: }
                   6118: 
                   6119: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   6120:     var caller = radio+'_'+status;
                   6121:     if (form.elements[caller].length != undefined) {
                   6122:         for (var i=0; i<form.elements[caller].length; i++) {
                   6123:             if (form.elements[caller][i].checked) {
                   6124:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   6125:                     var curr = form.elements[caller][i].value;
                   6126:                     if (prefix) {
                   6127:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   6128:                     }
                   6129:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   6130:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   6131:                     if (curr == 'custom') {
                   6132:                         if (prefix) {
                   6133:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   6134:                         }
                   6135:                     } else if (curr == 'inst') {
                   6136:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   6137:                     } else if (curr == 'noninst') {
                   6138:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40  raeburn  6139:                     }
1.160.6.93  raeburn  6140:                     break;
1.160.6.40  raeburn  6141:                 }
1.160.6.93  raeburn  6142:             }
                   6143:         }
                   6144:     }
                   6145: }
                   6146: 
                   6147: // ]]>
                   6148: </script>
                   6149: 
                   6150: ENDSCRIPT
                   6151: }
                   6152: 
                   6153: sub noninst_users {
                   6154:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   6155:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
                   6156:     my $class = 'LC_left_item';
                   6157:     if ($css_class) {
                   6158:         $css_class = ' class="'.$css_class.'"';
                   6159:     }
                   6160:     if ($rowid) {
                   6161:         $rowid = ' id="'.$rowid.'"';
                   6162:     }
                   6163:     if ($rowstyle) {
                   6164:         $rowstyle = ' style="'.$rowstyle.'"';
                   6165:     }
                   6166:     my ($output,$description);
                   6167:     if ($type eq 'default') {
                   6168:         $description = &mt('Requests for: [_1]',$typetitle);
                   6169:     } else {
                   6170:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   6171:     }
                   6172:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   6173:               "<td>$description</td>\n".
                   6174:               '<td class="'.$class.'" colspan="2">'.
                   6175:               '<table><tr>';
                   6176:     my %headers = &Apache::lonlocal::texthash(
                   6177:               approve  => 'Processing',
                   6178:               email    => 'E-mail',
                   6179:               username => 'Username',
                   6180:     );
                   6181:     foreach my $item ('approve','email','username') {
                   6182:         $output .= '<th>'.$headers{$item}.'</th>';
                   6183:     }
                   6184:     $output .= '</tr><tr>';
                   6185:     foreach my $item ('approve','email','username') {
                   6186:         $output .= '<td valign="top">';
                   6187:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   6188:         if ($item eq 'approve') {
                   6189:             %choices = &Apache::lonlocal::texthash (
                   6190:                                                      automatic => 'Automatically approved',
                   6191:                                                      approval  => 'Queued for approval',
                   6192:                                                    );
                   6193:             @options = ('automatic','approval');
                   6194:             $hashref = $processing;
                   6195:             $defoption = 'automatic';
                   6196:             $name = 'cancreate_emailprocess_'.$type;
                   6197:         } elsif ($item eq 'email') {
                   6198:             %choices = &Apache::lonlocal::texthash (
                   6199:                                                      any     => 'Any e-mail',
                   6200:                                                      inst    => 'Institutional only',
                   6201:                                                      noninst => 'Non-institutional only',
                   6202:                                                      custom  => 'Custom restrictions',
                   6203:                                                    );
                   6204:             @options = ('any','inst','noninst');
                   6205:             my $showcustom;
                   6206:             if (ref($emailrules) eq 'HASH') {
                   6207:                 if (keys(%{$emailrules}) > 0) {
                   6208:                     push(@options,'custom');
                   6209:                     $showcustom = 'cancreate_emailrule';
                   6210:                     if (ref($settings) eq 'HASH') {
                   6211:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   6212:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   6213:                                 if (exists($emailrules->{$rule})) {
                   6214:                                     $hascustom ++;
                   6215:                                 }
                   6216:                             }
                   6217:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   6218:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   6219:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   6220:                                     if (exists($emailrules->{$rule})) {
                   6221:                                         $hascustom ++;
                   6222:                                     }
                   6223:                                 }
                   6224:                             }
                   6225:                         }
                   6226:                     }
                   6227:                 }
                   6228:             }
                   6229:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   6230:                                                      "'cancreate_emaildomain','$type'".');"';
                   6231:             $hashref = $emailoptions;
                   6232:             $defoption = 'any';
                   6233:             $name = 'cancreate_emailoptions_'.$type;
                   6234:         } elsif ($item eq 'username') {
                   6235:             %choices = &Apache::lonlocal::texthash (
                   6236:                                                      all    => 'Same as e-mail',
                   6237:                                                      first  => 'Omit @domain',
                   6238:                                                      free   => 'Free to choose',
                   6239:                                                    );
                   6240:             @options = ('all','first','free');
                   6241:             $hashref = $emailverified;
                   6242:             $defoption = 'all';
                   6243:             $name = 'cancreate_usernameoptions_'.$type;
                   6244:         }
                   6245:         foreach my $option (@options) {
                   6246:             my $checked;
                   6247:             if (ref($hashref) eq 'HASH') {
                   6248:                 if ($type eq '') {
                   6249:                     if (!exists($hashref->{'default'})) {
                   6250:                         if ($option eq $defoption) {
                   6251:                             $checked = ' checked="checked"';
                   6252:                         }
                   6253:                     } else {
                   6254:                         if ($hashref->{'default'} eq $option) {
                   6255:                             $checked = ' checked="checked"';
                   6256:                         }
1.160.6.40  raeburn  6257:                     }
                   6258:                 } else {
1.160.6.93  raeburn  6259:                     if (!exists($hashref->{$type})) {
                   6260:                         if ($option eq $defoption) {
                   6261:                             $checked = ' checked="checked"';
                   6262:                         }
                   6263:                     } else {
                   6264:                         if ($hashref->{$type} eq $option) {
                   6265:                             $checked = ' checked="checked"';
                   6266:                         }
1.160.6.40  raeburn  6267:                     }
                   6268:                 }
1.160.6.93  raeburn  6269:             } elsif (($item eq 'email') && ($hascustom)) {
                   6270:                 if ($option eq 'custom') {
                   6271:                     $checked = ' checked="checked"';
                   6272:                 }
                   6273:             } elsif ($option eq $defoption) {
                   6274:                 $checked = ' checked="checked"';
                   6275:             }
                   6276:             $output .= '<span class="LC_nobreak"><label>'.
                   6277:                        '<input type="radio" name="'.$name.'"'.
                   6278:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   6279:                        $choices{$option}.'</label></span><br />';
                   6280:             if ($item eq 'email') {
                   6281:                 if ($option eq 'custom') {
                   6282:                     my $id = 'cancreate_emailrule_'.$type;
                   6283:                     my $display = 'none';
                   6284:                     if ($checked) {
                   6285:                         $display = 'inline';
                   6286:                     }
                   6287:                     my $numinrow = 2;
                   6288:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   6289:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   6290:                                &user_formats_row('email',$settings,$emailrules,
                   6291:                                                  $emailruleorder,$numinrow,'',$type);
                   6292:                               '</table></fieldset>';
                   6293:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   6294:                     my %text = &Apache::lonlocal::texthash (
                   6295:                                                              inst    => 'must end:',
                   6296:                                                              noninst => 'cannot end:',
                   6297:                                                            );
                   6298:                     my $value;
                   6299:                     if (ref($emaildomain) eq 'HASH') {
                   6300:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   6301:                             $value = $emaildomain->{$type}->{$option};
                   6302:                         }
                   6303:                     }
                   6304:                     if ($value eq '') {
                   6305:                         $value = '@'.$intdom;
                   6306:                     }
                   6307:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   6308:                     my $display = 'none';
                   6309:                     if ($checked) {
                   6310:                         $display = 'inline';
                   6311:                     }
                   6312:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   6313:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   6314:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   6315:                                '</div>';
                   6316:                 }
1.160.6.40  raeburn  6317:             }
                   6318:         }
1.160.6.93  raeburn  6319:         $output .= '</td>'."\n";
1.160.6.40  raeburn  6320:     }
1.160.6.93  raeburn  6321:     $output .= "</tr></table></td></tr>\n";
1.160.6.40  raeburn  6322:     return $output;
                   6323: }
                   6324: 
1.160.6.5  raeburn  6325: sub captcha_choice {
1.160.6.93  raeburn  6326:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69  raeburn  6327:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   6328:         $vertext,$currver); 
1.160.6.5  raeburn  6329:     my %lt = &captcha_phrases();
                   6330:     $keyentry = 'hidden';
1.160.6.98  raeburn  6331:     my $colspan=2;
1.160.6.5  raeburn  6332:     if ($context eq 'cancreate') {
1.160.6.34  raeburn  6333:         $rowname = &mt('CAPTCHA validation');
1.160.6.5  raeburn  6334:     } elsif ($context eq 'login') {
                   6335:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98  raeburn  6336:     } elsif ($context eq 'passwords') {
                   6337:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   6338:         $colspan=1;
1.160.6.5  raeburn  6339:     }
                   6340:     if (ref($settings) eq 'HASH') {
                   6341:         if ($settings->{'captcha'}) {
                   6342:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   6343:         } else {
                   6344:             $checked{'original'} = ' checked="checked"';
                   6345:         }
                   6346:         if ($settings->{'captcha'} eq 'recaptcha') {
                   6347:             $pubtext = $lt{'pub'};
                   6348:             $privtext = $lt{'priv'};
                   6349:             $keyentry = 'text';
1.160.6.69  raeburn  6350:             $vertext = $lt{'ver'};
                   6351:             $currver = $settings->{'recaptchaversion'};
                   6352:             if ($currver ne '2') {
                   6353:                 $currver = 1;
                   6354:             }
1.160.6.5  raeburn  6355:         }
                   6356:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   6357:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   6358:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   6359:         }
                   6360:     } else {
                   6361:         $checked{'original'} = ' checked="checked"';
                   6362:     }
1.160.6.93  raeburn  6363:     my $css_class;
                   6364:     if ($itemcount%2) {
                   6365:         $css_class = 'LC_odd_row';
                   6366:     }
                   6367:     if ($customcss) {
                   6368:         $css_class .= " $customcss";
                   6369:     }
                   6370:     $css_class =~ s/^\s+//;
                   6371:     if ($css_class) {
                   6372:         $css_class = ' class="'.$css_class.'"';
                   6373:     }
                   6374:     if ($rowstyle) {
                   6375:         $css_class .= ' style="'.$rowstyle.'"';
                   6376:     }
1.160.6.5  raeburn  6377:     my $output = '<tr'.$css_class.'>'.
1.160.6.98  raeburn  6378:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5  raeburn  6379:                  '<table><tr><td>'."\n";
                   6380:     foreach my $option ('original','recaptcha','notused') {
                   6381:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   6382:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   6383:                    $lt{$option}.'</label></span>';
                   6384:         unless ($option eq 'notused') {
                   6385:             $output .= ('&nbsp;'x2)."\n";
                   6386:         }
                   6387:     }
                   6388: #
                   6389: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   6390: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   6391: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
                   6392: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   6393: #
                   6394:     $output .= '</td></tr>'."\n".
1.160.6.93  raeburn  6395:                '<tr><td class="LC_zero_height">'."\n".
1.160.6.5  raeburn  6396:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   6397:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   6398:                $currpub.'" size="40" /></span><br />'."\n".
                   6399:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   6400:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69  raeburn  6401:                $currpriv.'" size="40" /></span><br />'.
                   6402:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   6403:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   6404:                $currver.'" size="3" /></span><br />'.
                   6405:                '</td></tr></table>'."\n".
1.160.6.5  raeburn  6406:                '</td></tr>';
                   6407:     return $output;
                   6408: }
                   6409: 
1.32      raeburn  6410: sub user_formats_row {
1.160.6.93  raeburn  6411:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  6412:     my $output;
                   6413:     my %text = (
                   6414:                    'username' => 'new usernames',
                   6415:                    'id'       => 'IDs',
                   6416:                );
1.160.6.93  raeburn  6417:     unless ($type eq 'email') {
                   6418:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6419:         $output = '<tr '.$css_class.'>'.
                   6420:                   '<td><span class="LC_nobreak">'.
                   6421:                   &mt("Format rules to check for $text{$type}: ").
                   6422:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  6423:     }
1.27      raeburn  6424:     my $rem;
                   6425:     if (ref($ruleorder) eq 'ARRAY') {
                   6426:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   6427:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   6428:                 my $rem = $i%($numinrow);
                   6429:                 if ($rem == 0) {
                   6430:                     if ($i > 0) {
                   6431:                         $output .= '</tr>';
                   6432:                     }
                   6433:                     $output .= '<tr>';
                   6434:                 }
                   6435:                 my $check = ' ';
1.39      raeburn  6436:                 if (ref($settings) eq 'HASH') {
                   6437:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   6438:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   6439:                             $check = ' checked="checked" ';
                   6440:                         }
1.160.6.93  raeburn  6441:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   6442:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   6443:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   6444:                                 $check = ' checked="checked" ';
                   6445:                             }
                   6446:                         }
1.27      raeburn  6447:                     }
                   6448:                 }
1.160.6.93  raeburn  6449:                 my $name = $type.'_rule';
                   6450:                 if ($type eq 'email') {
                   6451:                     $name .= '_'.$status;
                   6452:                 }
1.27      raeburn  6453:                 $output .= '<td class="LC_left_item">'.
                   6454:                            '<span class="LC_nobreak"><label>'.
1.160.6.93  raeburn  6455:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  6456:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   6457:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   6458:             }
                   6459:         }
                   6460:         $rem = @{$ruleorder}%($numinrow);
                   6461:     }
1.160.6.93  raeburn  6462:     my $colsleft;
                   6463:     if ($rem) {
                   6464:         $colsleft = $numinrow - $rem;
                   6465:     }
1.27      raeburn  6466:     if ($colsleft > 1 ) {
                   6467:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6468:                    '&nbsp;</td>';
                   6469:     } elsif ($colsleft == 1) {
                   6470:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6471:     }
1.160.6.93  raeburn  6472:     $output .= '</tr></table>';
                   6473:     unless ($type eq 'email') {
                   6474:         $output .= '</td></tr>';
                   6475:     }
1.27      raeburn  6476:     return $output;
                   6477: }
                   6478: 
1.34      raeburn  6479: sub usercreation_types {
                   6480:     my %lt = &Apache::lonlocal::texthash (
                   6481:                     author     => 'When adding a co-author',
                   6482:                     course     => 'When adding a user to a course',
1.100     raeburn  6483:                     requestcrs => 'When requesting a course',
1.34      raeburn  6484:                     any        => 'Any',
                   6485:                     official   => 'Institutional only ',
                   6486:                     unofficial => 'Non-institutional only',
                   6487:                     none       => 'None',
                   6488:     );
                   6489:     return %lt;
1.48      raeburn  6490: }
1.34      raeburn  6491: 
1.160.6.34  raeburn  6492: sub selfcreation_types {
                   6493:     my %lt = &Apache::lonlocal::texthash (
                   6494:                     selfcreate => 'User creates own account',
                   6495:                     any        => 'Any',
                   6496:                     official   => 'Institutional only ',
                   6497:                     unofficial => 'Non-institutional only',
                   6498:                     email      => 'E-mail address',
                   6499:                     login      => 'Institutional Login',
                   6500:                     sso        => 'SSO',
                   6501:              );
                   6502: }
                   6503: 
1.28      raeburn  6504: sub authtype_names {
                   6505:     my %lt = &Apache::lonlocal::texthash(
                   6506:                       int    => 'Internal',
                   6507:                       krb4   => 'Kerberos 4',
                   6508:                       krb5   => 'Kerberos 5',
                   6509:                       loc    => 'Local',
                   6510:                   );
                   6511:     return %lt;
                   6512: }
                   6513: 
                   6514: sub context_names {
                   6515:     my %context_title = &Apache::lonlocal::texthash(
                   6516:        author => 'Creating users when an Author',
                   6517:        course => 'Creating users when in a course',
                   6518:        domain => 'Creating users when a Domain Coordinator',
                   6519:     );
                   6520:     return %context_title;
                   6521: }
                   6522: 
1.33      raeburn  6523: sub print_usermodification {
                   6524:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6525:     my $numinrow = 4;
                   6526:     my ($context,$datatable,$rowcount);
                   6527:     if ($position eq 'top') {
                   6528:         $rowcount = 0;
                   6529:         $context = 'author'; 
                   6530:         foreach my $role ('ca','aa') {
                   6531:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6532:                                                    $numinrow,$rowcount);
                   6533:             $$rowtotal ++;
                   6534:             $rowcount ++;
                   6535:         }
1.160.6.37  raeburn  6536:     } elsif ($position eq 'bottom') {
1.33      raeburn  6537:         $context = 'course';
                   6538:         $rowcount = 0;
                   6539:         foreach my $role ('st','ep','ta','in','cr') {
                   6540:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6541:                                                    $numinrow,$rowcount);
                   6542:             $$rowtotal ++;
                   6543:             $rowcount ++;
                   6544:         }
                   6545:     }
                   6546:     return $datatable;
                   6547: }
                   6548: 
1.43      raeburn  6549: sub print_defaults {
1.160.6.40  raeburn  6550:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  6551:     my $rownum = 0;
1.160.6.80  raeburn  6552:     my ($datatable,$css_class,$titles);
                   6553:     unless ($position eq 'bottom') {
                   6554:         $titles = &defaults_titles($dom);
                   6555:     }
1.160.6.40  raeburn  6556:     if ($position eq 'top') {
                   6557:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   6558:                      'datelocale_def','portal_def');
                   6559:         my %defaults;
                   6560:         if (ref($settings) eq 'HASH') {
                   6561:             %defaults = %{$settings};
1.43      raeburn  6562:         } else {
1.160.6.40  raeburn  6563:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   6564:             foreach my $item (@items) {
                   6565:                 $defaults{$item} = $domdefaults{$item};
                   6566:             }
1.43      raeburn  6567:         }
1.160.6.40  raeburn  6568:         foreach my $item (@items) {
                   6569:             if ($rownum%2) {
                   6570:                 $css_class = '';
                   6571:             } else {
                   6572:                 $css_class = ' class="LC_odd_row" ';
1.43      raeburn  6573:             }
1.160.6.40  raeburn  6574:             $datatable .= '<tr'.$css_class.'>'.
                   6575:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   6576:                           '</span></td><td class="LC_right_item" colspan="3">';
                   6577:             if ($item eq 'auth_def') {
                   6578:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   6579:                 my %shortauth = (
                   6580:                                  internal => 'int',
                   6581:                                  krb4 => 'krb4',
                   6582:                                  krb5 => 'krb5',
                   6583:                                  localauth  => 'loc'
                   6584:                                 );
                   6585:                 my %authnames = &authtype_names();
                   6586:                 foreach my $auth (@authtypes) {
                   6587:                     my $checked = ' ';
                   6588:                     if ($defaults{$item} eq $auth) {
                   6589:                         $checked = ' checked="checked" ';
                   6590:                     }
                   6591:                     $datatable .= '<label><input type="radio" name="'.$item.
                   6592:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   6593:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   6594:                 }
                   6595:             } elsif ($item eq 'timezone_def') {
                   6596:                 my $includeempty = 1;
                   6597:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   6598:             } elsif ($item eq 'datelocale_def') {
1.160.6.98  raeburn  6599:                 my $includeempty = 1;
                   6600:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   6601:             } elsif ($item eq 'lang_def') {
                   6602:                 my $includeempty = 1;
                   6603:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80  raeburn  6604:             } else {
1.160.6.98  raeburn  6605:                 my $size;
                   6606:                 if ($item eq 'portal_def') {
                   6607:                     $size = ' size="25"';
                   6608:                 }
1.160.6.80  raeburn  6609:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98  raeburn  6610:                               $defaults{$item}.'"'.$size.' />';
1.160.6.80  raeburn  6611:             }
                   6612:             $datatable .= '</td></tr>';
                   6613:             $rownum ++;
                   6614:         }
1.160.6.40  raeburn  6615:     } else {
1.160.6.80  raeburn  6616:         my %defaults;
1.160.6.40  raeburn  6617:         if (ref($settings) eq 'HASH') {
1.160.6.93  raeburn  6618:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40  raeburn  6619:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   6620:                 for (my $i=0; $i<$maxnum; $i++) {
                   6621:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6622:                     my $item = $settings->{'inststatusorder'}->[$i];
                   6623:                     my $title = $settings->{'inststatustypes'}->{$item};
                   6624:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   6625:                     $datatable .= '<tr'.$css_class.'>'.
                   6626:                                   '<td><span class="LC_nobreak">'.
                   6627:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   6628:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6629:                         my $vpos = $k+1;
                   6630:                         my $selstr;
                   6631:                         if ($k == $i) {
                   6632:                             $selstr = ' selected="selected" ';
                   6633:                         }
                   6634:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6635:                     }
                   6636:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   6637:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   6638:                                   &mt('delete').'</span></td>'.
1.160.6.112! raeburn  6639:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40  raeburn  6640:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93  raeburn  6641:                                   '</span></td></tr>';
1.160.6.40  raeburn  6642:                 }
                   6643:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6644:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   6645:                 $datatable .= '<tr '.$css_class.'>'.
                   6646:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   6647:                 for (my $k=0; $k<=$maxnum; $k++) {
                   6648:                     my $vpos = $k+1;
                   6649:                     my $selstr;
                   6650:                     if ($k == $maxnum) {
                   6651:                         $selstr = ' selected="selected" ';
                   6652:                     }
                   6653:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6654:                 }
                   6655:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.160.6.63  raeburn  6656:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40  raeburn  6657:                               '&nbsp;'.&mt('(new)').
                   6658:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112! raeburn  6659:                               &mt('Name displayed').':'.
1.160.6.40  raeburn  6660:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   6661:                               '</tr>'."\n";
                   6662:                 $rownum ++;
1.141     raeburn  6663:             }
1.43      raeburn  6664:         }
                   6665:     }
                   6666:     $$rowtotal += $rownum;
                   6667:     return $datatable;
                   6668: }
                   6669: 
1.160.6.5  raeburn  6670: sub get_languages_hash {
                   6671:     my %langchoices;
                   6672:     foreach my $id (&Apache::loncommon::languageids()) {
                   6673:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   6674:         if ($code ne '') {
                   6675:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   6676:         }
                   6677:     }
                   6678:     return %langchoices;
                   6679: }
                   6680: 
1.43      raeburn  6681: sub defaults_titles {
1.141     raeburn  6682:     my ($dom) = @_;
1.43      raeburn  6683:     my %titles = &Apache::lonlocal::texthash (
                   6684:                    'auth_def'      => 'Default authentication type',
                   6685:                    'auth_arg_def'  => 'Default authentication argument',
                   6686:                    'lang_def'      => 'Default language',
1.54      raeburn  6687:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  6688:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  6689:                    'portal_def'     => 'Portal/Default URL',
1.160.6.80  raeburn  6690:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   6691:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   6692:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  6693:                  );
1.141     raeburn  6694:     if ($dom) {
                   6695:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   6696:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   6697:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   6698:         $protocol = 'http' if ($protocol ne 'https');
                   6699:         if ($uint_dom) {
                   6700:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   6701:                                          $uint_dom);
                   6702:         }
                   6703:     }
1.43      raeburn  6704:     return (\%titles);
                   6705: }
                   6706: 
1.160.6.97  raeburn  6707: sub print_scantron {
                   6708:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   6709:     if ($position eq 'top') {
                   6710:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   6711:     } else {
                   6712:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   6713:     }
                   6714: }
                   6715: 
                   6716: sub scantron_javascript {
                   6717:     return <<"ENDSCRIPT";
                   6718: 
                   6719: <script type="text/javascript">
                   6720: // <![CDATA[
                   6721: 
                   6722: function toggleScantron(form) {
                   6723:     var csvfieldset = new Array();
                   6724:     if (document.getElementById('scantroncsv_cols')) {
                   6725:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   6726:     }
                   6727:     if (document.getElementById('scantroncsv_options')) {
                   6728:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   6729:     }
                   6730:     if (csvfieldset.length) {
                   6731:         if (document.getElementById('scantronconfcsv')) {
                   6732:             var scantroncsv = document.getElementById('scantronconfcsv');
                   6733:             if (scantroncsv.checked) {
                   6734:                 for (var i=0; i<csvfieldset.length; i++) {
                   6735:                     csvfieldset[i].style.display = 'block';
                   6736:                 }
                   6737:             } else {
                   6738:                 for (var i=0; i<csvfieldset.length; i++) {
                   6739:                     csvfieldset[i].style.display = 'none';
                   6740:                 }
                   6741:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   6742:                 if (csvselects.length) {
                   6743:                     for (var j=0; j<csvselects.length; j++) {
                   6744:                         csvselects[j].selectedIndex = 0;
                   6745:                     }
                   6746:                 }
                   6747:             }
                   6748:         }
                   6749:     }
                   6750:     return;
                   6751: }
                   6752: // ]]>
                   6753: </script>
                   6754: 
                   6755: ENDSCRIPT
                   6756: 
                   6757: }
                   6758: 
1.46      raeburn  6759: sub print_scantronformat {
                   6760:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   6761:     my $itemcount = 1;
1.60      raeburn  6762:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   6763:         %confhash);
1.46      raeburn  6764:     my $switchserver = &check_switchserver($dom,$confname);
                   6765:     my %lt = &Apache::lonlocal::texthash (
1.95      www      6766:                 default => 'Default bubblesheet format file error',
                   6767:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  6768:              );
                   6769:     my %scantronfiles = (
                   6770:         default => 'default.tab',
                   6771:         custom => 'custom.tab',
                   6772:     );
                   6773:     foreach my $key (keys(%scantronfiles)) {
                   6774:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   6775:                               .$scantronfiles{$key};
                   6776:     }
                   6777:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   6778:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   6779:         if (!$switchserver) {
                   6780:             my $servadm = $r->dir_config('lonAdmEMail');
                   6781:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   6782:             if ($configuserok eq 'ok') {
                   6783:                 if ($author_ok eq 'ok') {
                   6784:                     my %legacyfile = (
1.160.6.97  raeburn  6785:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   6786:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  6787:                     );
                   6788:                     my %md5chk;
                   6789:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  6790:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   6791:                         chomp($md5chk{$type});
1.46      raeburn  6792:                     }
                   6793:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   6794:                         foreach my $type (keys(%legacyfile)) {
1.160.6.97  raeburn  6795:                             ($scantronurls{$type},my $error) =
1.46      raeburn  6796:                                 &legacy_scantronformat($r,$dom,$confname,
                   6797:                                                  $type,$legacyfile{$type},
                   6798:                                                  $scantronurls{$type},
                   6799:                                                  $scantronfiles{$type});
1.60      raeburn  6800:                             if ($error ne '') {
                   6801:                                 $error{$type} = $error;
                   6802:                             }
                   6803:                         }
                   6804:                         if (keys(%error) == 0) {
                   6805:                             $is_custom = 1;
1.160.6.97  raeburn  6806:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  6807:                                 $scantronurls{'custom'};
1.160.6.97  raeburn  6808:                             my $putresult =
1.60      raeburn  6809:                                 &Apache::lonnet::put_dom('configuration',
                   6810:                                                          \%confhash,$dom);
                   6811:                             if ($putresult ne 'ok') {
1.160.6.97  raeburn  6812:                                 $error{'custom'} =
1.60      raeburn  6813:                                     '<span class="LC_error">'.
                   6814:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   6815:                             }
1.46      raeburn  6816:                         }
                   6817:                     } else {
1.60      raeburn  6818:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  6819:                             &legacy_scantronformat($r,$dom,$confname,
                   6820:                                           'default',$legacyfile{'default'},
                   6821:                                           $scantronurls{'default'},
                   6822:                                           $scantronfiles{'default'});
1.60      raeburn  6823:                         if ($error eq '') {
                   6824:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   6825:                             my $putresult =
                   6826:                                 &Apache::lonnet::put_dom('configuration',
                   6827:                                                          \%confhash,$dom);
                   6828:                             if ($putresult ne 'ok') {
                   6829:                                 $error{'default'} =
                   6830:                                     '<span class="LC_error">'.
                   6831:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   6832:                             }
                   6833:                         } else {
                   6834:                             $error{'default'} = $error;
                   6835:                         }
1.46      raeburn  6836:                     }
                   6837:                 }
                   6838:             }
                   6839:         } else {
1.95      www      6840:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  6841:         }
                   6842:     }
                   6843:     if (ref($settings) eq 'HASH') {
                   6844:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   6845:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   6846:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   6847:                 $scantronurl = '';
                   6848:             } else {
                   6849:                 $scantronurl = $settings->{'scantronformat'};
                   6850:             }
                   6851:             $is_custom = 1;
                   6852:         } else {
                   6853:             $scantronurl = $scantronurls{'default'};
                   6854:         }
                   6855:     } else {
1.60      raeburn  6856:         if ($is_custom) {
                   6857:             $scantronurl = $scantronurls{'custom'};
                   6858:         } else {
                   6859:             $scantronurl = $scantronurls{'default'};
                   6860:         }
1.46      raeburn  6861:     }
                   6862:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6863:     $datatable .= '<tr'.$css_class.'>';
                   6864:     if (!$is_custom) {
1.65      raeburn  6865:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   6866:                       '<span class="LC_nobreak">';
1.46      raeburn  6867:         if ($scantronurl) {
1.160.6.21  raeburn  6868:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   6869:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  6870:         } else {
                   6871:             $datatable = &mt('File unavailable for display');
                   6872:         }
1.65      raeburn  6873:         $datatable .= '</span></td>';
1.60      raeburn  6874:         if (keys(%error) == 0) { 
                   6875:             $datatable .= '<td valign="bottom">';
                   6876:             if (!$switchserver) {
                   6877:                 $datatable .= &mt('Upload:').'<br />';
                   6878:             }
                   6879:         } else {
                   6880:             my $errorstr;
                   6881:             foreach my $key (sort(keys(%error))) {
                   6882:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   6883:             }
                   6884:             $datatable .= '<td>'.$errorstr;
                   6885:         }
1.46      raeburn  6886:     } else {
                   6887:         if (keys(%error) > 0) {
                   6888:             my $errorstr;
                   6889:             foreach my $key (sort(keys(%error))) {
                   6890:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   6891:             } 
1.60      raeburn  6892:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  6893:         } elsif ($scantronurl) {
1.160.6.26  raeburn  6894:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21  raeburn  6895:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  6896:             $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21  raeburn  6897:                           $link.
                   6898:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   6899:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  6900:                           '<td><span class="LC_nobreak">&nbsp;'.
                   6901:                           &mt('Replace:').'</span><br />';
1.46      raeburn  6902:         }
                   6903:     }
                   6904:     if (keys(%error) == 0) {
                   6905:         if ($switchserver) {
                   6906:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   6907:         } else {
1.65      raeburn  6908:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   6909:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  6910:         }
                   6911:     }
                   6912:     $datatable .= '</td></tr>';
                   6913:     $$rowtotal ++;
                   6914:     return $datatable;
                   6915: }
                   6916: 
                   6917: sub legacy_scantronformat {
                   6918:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   6919:     my ($url,$error);
                   6920:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   6921:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   6922:         (my $result,$url) =
                   6923:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   6924:                          '','',$newfile);
                   6925:         if ($result ne 'ok') {
1.130     raeburn  6926:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  6927:         }
                   6928:     }
                   6929:     return ($url,$error);
                   6930: }
1.43      raeburn  6931: 
1.160.6.97  raeburn  6932: sub print_scantronconfig {
                   6933:     my ($dom,$settings,$rowtotal) = @_;
                   6934:     my $itemcount = 2;
                   6935:     my $is_checked = ' checked="checked"';
                   6936:     my %optionson = (
                   6937:                      hdr => ' checked="checked"',
                   6938:                      pad => ' checked="checked"',
                   6939:                      rem => ' checked="checked"',
                   6940:                     );
                   6941:     my %optionsoff = (
                   6942:                       hdr => '',
                   6943:                       pad => '',
                   6944:                       rem => '',
                   6945:                      );
                   6946:     my $currcsvsty = 'none';
                   6947:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
                   6948:     my @fields = &scantroncsv_fields();
                   6949:     my %titles = &scantronconfig_titles();
                   6950:     if (ref($settings) eq 'HASH') {
                   6951:         if (ref($settings->{config}) eq 'HASH') {
                   6952:             if ($settings->{config}->{dat}) {
                   6953:                 $checked{'dat'} = $is_checked;
                   6954:             }
                   6955:             if (ref($settings->{config}->{csv}) eq 'HASH') {
                   6956:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   6957:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   6958:                     if (keys(%csvfields) > 0) {
                   6959:                         $checked{'csv'} = $is_checked;
                   6960:                         $currcsvsty = 'block';
                   6961:                     }
                   6962:                 }
                   6963:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   6964:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   6965:                     foreach my $option (keys(%optionson)) {
                   6966:                         unless ($csvoptions{$option}) {
                   6967:                             $optionsoff{$option} = $optionson{$option};
                   6968:                             $optionson{$option} = '';
                   6969:                         }
                   6970:                     }
                   6971:                 }
                   6972:             }
                   6973:         } else {
                   6974:             $checked{'dat'} = $is_checked;
                   6975:         }
                   6976:     } else {
                   6977:         $checked{'dat'} = $is_checked;
                   6978:     }
                   6979:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   6980:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   6981:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   6982:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   6983:     foreach my $item ('dat','csv') {
                   6984:         my $id;
                   6985:         if ($item eq 'csv') {
                   6986:             $id = 'id="scantronconfcsv" ';
                   6987:         }
                   6988:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   6989:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   6990:         if ($item eq 'csv') {
                   6991:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   6992:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   6993:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   6994:             foreach my $col (@fields) {
                   6995:                 my $selnone;
                   6996:                 if ($csvfields{$col} eq '') {
                   6997:                     $selnone = ' selected="selected"';
                   6998:                 }
                   6999:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   7000:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   7001:                               '<option value=""'.$selnone.'></option>';
                   7002:                 for (my $i=0; $i<20; $i++) {
                   7003:                     my $shown = $i+1;
                   7004:                     my $sel;
                   7005:                     unless ($selnone) {
                   7006:                         if (exists($csvfields{$col})) {
                   7007:                             if ($csvfields{$col} == $i) {
                   7008:                                 $sel = ' selected="selected"';
                   7009:                             }
                   7010:                         }
                   7011:                     }
                   7012:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   7013:                 }
                   7014:                 $datatable .= '</select></td></tr>';
                   7015:            }
                   7016:            $datatable .= '</table></fieldset>'.
                   7017:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   7018:                          '<legend>'.&mt('CSV Options').'</legend>';
                   7019:            foreach my $option ('hdr','pad','rem') {
                   7020:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   7021:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   7022:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   7023:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   7024:            }
                   7025:            $datatable .= '</fieldset>';
                   7026:            $itemcount ++;
                   7027:         }
                   7028:     }
                   7029:     $datatable .= '</td></tr>';
                   7030:     $$rowtotal ++;
                   7031:     return $datatable;
                   7032: }
                   7033: 
                   7034: sub scantronconfig_titles {
                   7035:     return &Apache::lonlocal::texthash(
                   7036:                                           dat => 'Standard format (.dat)',
                   7037:                                           csv => 'Comma separated values (.csv)',
                   7038:                                           hdr => 'Remove first line in file (contains column titles)',
                   7039:                                           pad => 'Prepend 0s to PaperID',
                   7040:                                           rem => 'Remove leading spaces (except Question Response columns)',
                   7041:                                           CODE => 'CODE',
                   7042:                                           ID   => 'Student ID',
                   7043:                                           PaperID => 'Paper ID',
                   7044:                                           FirstName => 'First Name',
                   7045:                                           LastName => 'Last Name',
                   7046:                                           FirstQuestion => 'First Question Response',
                   7047:                                           Section => 'Section',
                   7048:     );
                   7049: }
                   7050: 
                   7051: sub scantroncsv_fields {
                   7052:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   7053: }
                   7054: 
1.49      raeburn  7055: sub print_coursecategories {
1.57      raeburn  7056:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   7057:     my $datatable;
                   7058:     if ($position eq 'top') {
1.160.6.42  raeburn  7059:         my (%checked);
                   7060:         my @catitems = ('unauth','auth');
                   7061:         my @cattypes = ('std','domonly','codesrch','none');
                   7062:         $checked{'unauth'} = 'std';
                   7063:         $checked{'auth'} = 'std';
                   7064:         if (ref($settings) eq 'HASH') {
                   7065:             foreach my $type (@cattypes) {
                   7066:                 if ($type eq $settings->{'unauth'}) {
                   7067:                     $checked{'unauth'} = $type;
                   7068:                 }
                   7069:                 if ($type eq $settings->{'auth'}) {
                   7070:                     $checked{'auth'} = $type;
                   7071:                 }
                   7072:             }
                   7073:         }
                   7074:         my %lt = &Apache::lonlocal::texthash (
                   7075:                                                unauth   => 'Catalog type for unauthenticated users',
                   7076:                                                auth     => 'Catalog type for authenticated users',
                   7077:                                                none     => 'No catalog',
                   7078:                                                std      => 'Standard catalog',
                   7079:                                                domonly  => 'Domain-only catalog',
                   7080:                                                codesrch => "Code search form",
                   7081:                                              );
                   7082:        my $itemcount = 0;
                   7083:        foreach my $item (@catitems) {
                   7084:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   7085:            $datatable .= '<tr '.$css_class.'>'.
                   7086:                          '<td>'.$lt{$item}.'</td>'.
                   7087:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   7088:            foreach my $type (@cattypes) {
                   7089:                my $ischecked;
                   7090:                if ($checked{$item} eq $type) {
                   7091:                    $ischecked=' checked="checked"';
                   7092:                }
                   7093:                $datatable .= '<label>'.
                   7094:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   7095:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   7096:            }
1.160.6.87  raeburn  7097:            $datatable .= '</span></td></tr>';
1.160.6.42  raeburn  7098:            $itemcount ++;
                   7099:         }
                   7100:         $$rowtotal += $itemcount;
                   7101:     } elsif ($position eq 'middle') {
1.57      raeburn  7102:         my $toggle_cats_crs = ' ';
                   7103:         my $toggle_cats_dom = ' checked="checked" ';
                   7104:         my $can_cat_crs = ' ';
                   7105:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  7106:         my $toggle_catscomm_comm = ' ';
                   7107:         my $toggle_catscomm_dom = ' checked="checked" ';
                   7108:         my $can_catcomm_comm = ' ';
                   7109:         my $can_catcomm_dom = ' checked="checked" ';
                   7110: 
1.57      raeburn  7111:         if (ref($settings) eq 'HASH') {
                   7112:             if ($settings->{'togglecats'} eq 'crs') {
                   7113:                 $toggle_cats_crs = $toggle_cats_dom;
                   7114:                 $toggle_cats_dom = ' ';
                   7115:             }
                   7116:             if ($settings->{'categorize'} eq 'crs') {
                   7117:                 $can_cat_crs = $can_cat_dom;
                   7118:                 $can_cat_dom = ' ';
                   7119:             }
1.120     raeburn  7120:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   7121:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   7122:                 $toggle_catscomm_dom = ' ';
                   7123:             }
                   7124:             if ($settings->{'categorizecomm'} eq 'comm') {
                   7125:                 $can_catcomm_comm = $can_catcomm_dom;
                   7126:                 $can_catcomm_dom = ' ';
                   7127:             }
1.57      raeburn  7128:         }
                   7129:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  7130:                      togglecats     => 'Show/Hide a course in catalog',
                   7131:                      togglecatscomm => 'Show/Hide a community in catalog',
                   7132:                      categorize     => 'Assign a category to a course',
                   7133:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  7134:                     );
                   7135:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  7136:                      dom  => 'Set in Domain',
                   7137:                      crs  => 'Set in Course',
                   7138:                      comm => 'Set in Community',
1.57      raeburn  7139:                     );
                   7140:         $datatable = '<tr class="LC_odd_row">'.
                   7141:                   '<td>'.$title{'togglecats'}.'</td>'.
                   7142:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7143:                   '<input type="radio" name="togglecats"'.
                   7144:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7145:                   '<label><input type="radio" name="togglecats"'.
                   7146:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   7147:                   '</tr><tr>'.
                   7148:                   '<td>'.$title{'categorize'}.'</td>'.
                   7149:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7150:                   '<label><input type="radio" name="categorize"'.
                   7151:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7152:                   '<label><input type="radio" name="categorize"'.
                   7153:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  7154:                   '</tr><tr class="LC_odd_row">'.
                   7155:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   7156:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7157:                   '<input type="radio" name="togglecatscomm"'.
                   7158:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7159:                   '<label><input type="radio" name="togglecatscomm"'.
                   7160:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   7161:                   '</tr><tr>'.
                   7162:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   7163:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7164:                   '<label><input type="radio" name="categorizecomm"'.
                   7165:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7166:                   '<label><input type="radio" name="categorizecomm"'.
                   7167:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  7168:                   '</tr>';
1.120     raeburn  7169:         $$rowtotal += 4;
1.57      raeburn  7170:     } else {
                   7171:         my $css_class;
                   7172:         my $itemcount = 1;
                   7173:         my $cathash; 
                   7174:         if (ref($settings) eq 'HASH') {
                   7175:             $cathash = $settings->{'cats'};
                   7176:         }
                   7177:         if (ref($cathash) eq 'HASH') {
                   7178:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   7179:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   7180:                                                    \%allitems,\%idx,\@jsarray);
                   7181:             my $maxdepth = scalar(@cats);
                   7182:             my $colattrib = '';
                   7183:             if ($maxdepth > 2) {
                   7184:                 $colattrib = ' colspan="2" ';
                   7185:             }
                   7186:             my @path;
                   7187:             if (@cats > 0) {
                   7188:                 if (ref($cats[0]) eq 'ARRAY') {
                   7189:                     my $numtop = @{$cats[0]};
                   7190:                     my $maxnum = $numtop;
1.120     raeburn  7191:                     my %default_names = (
                   7192:                           instcode    => &mt('Official courses'),
                   7193:                           communities => &mt('Communities'),
                   7194:                     );
                   7195: 
                   7196:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   7197:                         ($cathash->{'instcode::0'} eq '') ||
                   7198:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   7199:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  7200:                         $maxnum ++;
                   7201:                     }
                   7202:                     my $lastidx;
                   7203:                     for (my $i=0; $i<$numtop; $i++) {
                   7204:                         my $parent = $cats[0][$i];
                   7205:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7206:                         my $item = &escape($parent).'::0';
                   7207:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   7208:                         $lastidx = $idx{$item};
                   7209:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   7210:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   7211:                         for (my $k=0; $k<=$maxnum; $k++) {
                   7212:                             my $vpos = $k+1;
                   7213:                             my $selstr;
                   7214:                             if ($k == $i) {
                   7215:                                 $selstr = ' selected="selected" ';
                   7216:                             }
                   7217:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7218:                         }
1.160.6.29  raeburn  7219:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  7220:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   7221:                             $datatable .=  '<span class="LC_nobreak">'
                   7222:                                            .$default_names{$parent}.'</span>';
                   7223:                             if ($parent eq 'instcode') {
                   7224:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   7225:                                               .&mt('with institutional codes')
                   7226:                                               .')</span></td><td'.$colattrib.'>';
                   7227:                             } else {
                   7228:                                 $datatable .= '<table><tr><td>';
                   7229:                             }
                   7230:                             $datatable .= '<span class="LC_nobreak">'
                   7231:                                           .'<label><input type="radio" name="'
                   7232:                                           .$parent.'" value="1" checked="checked" />'
                   7233:                                           .&mt('Display').'</label>';
                   7234:                             if ($parent eq 'instcode') {
                   7235:                                 $datatable .= '&nbsp;';
                   7236:                             } else {
                   7237:                                 $datatable .= '</span></td></tr><tr><td>'
                   7238:                                               .'<span class="LC_nobreak">';
                   7239:                             }
                   7240:                             $datatable .= '<label><input type="radio" name="'
                   7241:                                           .$parent.'" value="0" />'
                   7242:                                           .&mt('Do not display').'</label></span>';
                   7243:                             if ($parent eq 'communities') {
                   7244:                                 $datatable .= '</td></tr></table>';
                   7245:                             }
                   7246:                             $datatable .= '</td>';
1.57      raeburn  7247:                         } else {
                   7248:                             $datatable .= $parent
1.160.6.29  raeburn  7249:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   7250:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  7251:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   7252:                         }
                   7253:                         my $depth = 1;
                   7254:                         push(@path,$parent);
                   7255:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   7256:                         pop(@path);
                   7257:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   7258:                         $itemcount ++;
                   7259:                     }
1.48      raeburn  7260:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  7261:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   7262:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  7263:                     for (my $k=0; $k<=$maxnum; $k++) {
                   7264:                         my $vpos = $k+1;
                   7265:                         my $selstr;
1.57      raeburn  7266:                         if ($k == $numtop) {
1.48      raeburn  7267:                             $selstr = ' selected="selected" ';
                   7268:                         }
                   7269:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7270:                     }
1.59      bisitz   7271:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  7272:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   7273:                                   .'</tr>'."\n";
1.48      raeburn  7274:                     $itemcount ++;
1.120     raeburn  7275:                     foreach my $default ('instcode','communities') {
                   7276:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   7277:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7278:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   7279:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   7280:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   7281:                             for (my $k=0; $k<=$maxnum; $k++) {
                   7282:                                 my $vpos = $k+1;
                   7283:                                 my $selstr;
                   7284:                                 if ($k == $maxnum) {
                   7285:                                     $selstr = ' selected="selected" ';
                   7286:                                 }
                   7287:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  7288:                             }
1.120     raeburn  7289:                             $datatable .= '</select></span></td>'.
                   7290:                                           '<td><span class="LC_nobreak">'.
                   7291:                                           $default_names{$default}.'</span>';
                   7292:                             if ($default eq 'instcode') {
                   7293:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   7294:                                               .&mt('with institutional codes').')</span>';
                   7295:                             }
                   7296:                             $datatable .= '</td>'
                   7297:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   7298:                                           .&mt('Display').'</label>&nbsp;'
                   7299:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   7300:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  7301:                         }
                   7302:                     }
                   7303:                 }
1.57      raeburn  7304:             } else {
                   7305:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  7306:             }
                   7307:         } else {
1.160.6.87  raeburn  7308:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  7309:                           .&initialize_categories($itemcount);
1.48      raeburn  7310:         }
1.57      raeburn  7311:         $$rowtotal += $itemcount;
1.48      raeburn  7312:     }
                   7313:     return $datatable;
                   7314: }
                   7315: 
1.69      raeburn  7316: sub print_serverstatuses {
                   7317:     my ($dom,$settings,$rowtotal) = @_;
                   7318:     my $datatable;
                   7319:     my @pages = &serverstatus_pages();
                   7320:     my (%namedaccess,%machineaccess);
                   7321:     foreach my $type (@pages) {
                   7322:         $namedaccess{$type} = '';
                   7323:         $machineaccess{$type}= '';
                   7324:     }
                   7325:     if (ref($settings) eq 'HASH') {
                   7326:         foreach my $type (@pages) {
                   7327:             if (exists($settings->{$type})) {
                   7328:                 if (ref($settings->{$type}) eq 'HASH') {
                   7329:                     foreach my $key (keys(%{$settings->{$type}})) {
                   7330:                         if ($key eq 'namedusers') {
                   7331:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   7332:                         } elsif ($key eq 'machines') {
                   7333:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   7334:                         }
                   7335:                     }
                   7336:                 }
                   7337:             }
                   7338:         }
                   7339:     }
1.81      raeburn  7340:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7341:     my $rownum = 0;
                   7342:     my $css_class;
                   7343:     foreach my $type (@pages) {
                   7344:         $rownum ++;
                   7345:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   7346:         $datatable .= '<tr'.$css_class.'>'.
                   7347:                       '<td><span class="LC_nobreak">'.
                   7348:                       $titles->{$type}.'</span></td>'.
                   7349:                       '<td class="LC_left_item">'.
                   7350:                       '<input type="text" name="'.$type.'_namedusers" '.
                   7351:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   7352:                       '<td class="LC_right_item">'.
                   7353:                       '<span class="LC_nobreak">'.
                   7354:                       '<input type="text" name="'.$type.'_machines" '.
                   7355:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87  raeburn  7356:                       '</span></td></tr>'."\n";
1.69      raeburn  7357:     }
                   7358:     $$rowtotal += $rownum;
                   7359:     return $datatable;
                   7360: }
                   7361: 
                   7362: sub serverstatus_pages {
                   7363:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15  raeburn  7364:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31  raeburn  7365:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62  raeburn  7366:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  7367: }
                   7368: 
1.160.6.40  raeburn  7369: sub defaults_javascript {
                   7370:     my ($settings) = @_;
1.160.6.98  raeburn  7371:     return unless (ref($settings) eq 'HASH');
1.160.6.40  raeburn  7372:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   7373:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   7374:         if ($maxnum eq '') {
                   7375:             $maxnum = 0;
                   7376:         }
                   7377:         $maxnum ++;
1.160.6.51  raeburn  7378:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.160.6.40  raeburn  7379:         return <<"ENDSCRIPT";
                   7380: <script type="text/javascript">
                   7381: // <![CDATA[
                   7382: function reorderTypes(form,caller) {
                   7383:     var changedVal;
                   7384: $jstext 
                   7385:     var newpos = 'addinststatus_pos';
                   7386:     var current = new Array;
                   7387:     var maxh = $maxnum;
                   7388:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7389:     var oldVal;
                   7390:     if (caller == newpos) {
                   7391:         changedVal = newitemVal;
                   7392:     } else {
                   7393:         var curritem = 'inststatus_pos_'+caller;
                   7394:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   7395:         current[newitemVal] = newpos;
                   7396:     }
                   7397:     for (var i=0; i<inststatuses.length; i++) {
                   7398:         if (inststatuses[i] != caller) {
                   7399:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   7400:             if (form.elements[elementName]) {
                   7401:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   7402:                 current[currVal] = elementName;
                   7403:             }
                   7404:         }
                   7405:     }
                   7406:     for (var j=0; j<maxh; j++) {
                   7407:         if (current[j] == undefined) {
                   7408:             oldVal = j;
                   7409:         }
                   7410:     }
                   7411:     if (oldVal < changedVal) {
                   7412:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   7413:            var elementName = current[k];
                   7414:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   7415:         }
                   7416:     } else {
                   7417:         for (var k=changedVal; k<oldVal; k++) {
                   7418:             var elementName = current[k];
                   7419:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   7420:         }
                   7421:     }
                   7422:     return;
                   7423: }
                   7424: 
                   7425: // ]]>
                   7426: </script>
                   7427: 
                   7428: ENDSCRIPT
                   7429:     }
                   7430: }
                   7431: 
1.160.6.98  raeburn  7432: sub passwords_javascript {
1.160.6.99  raeburn  7433:     my %intalert = &Apache::lonlocal::texthash (
                   7434:         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.',
                   7435:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   7436:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   7437:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   7438:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   7439:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   7440:     );
                   7441:     &js_escape(\%intalert);
                   7442:     my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  7443:     my $intauthjs = <<"ENDSCRIPT";
                   7444: 
                   7445: function warnIntAuth(field) {
                   7446:     if (field.name == 'intauth_check') {
                   7447:         if (field.value == '2') {
1.160.6.99  raeburn  7448:             alert('$intalert{authcheck}');
1.160.6.98  raeburn  7449:         }
                   7450:     }
                   7451:     if (field.name == 'intauth_cost') {
                   7452:         field.value.replace(/\s/g,'');
                   7453:         if (field.value != '') {
                   7454:             var regexdigit=/^\\d+\$/;
                   7455:             if (!regexdigit.test(field.value)) {
1.160.6.99  raeburn  7456:                 alert('$intalert{authcost}');
                   7457:             }
                   7458:         }
                   7459:     }
                   7460:     return;
                   7461: }
                   7462: 
                   7463: function warnIntPass(field) {
                   7464:     field.value.replace(/^\s+/,'');
                   7465:     field.value.replace(/\s+\$/,'');
                   7466:     var regexdigit=/^\\d+\$/;
                   7467:     if (field.name == 'passwords_min') {
                   7468:         if (field.value == '') {
                   7469:             alert('$intalert{passmin}');
                   7470:             field.value = '$defmin';
                   7471:         } else {
                   7472:             if (!regexdigit.test(field.value)) {
                   7473:                 alert('$intalert{passmin}');
                   7474:                 field.value = '$defmin';
                   7475:             }
                   7476:             var minval = parseInt(field.value,10);
                   7477:             if (minval < $defmin) {
                   7478:                 alert('$intalert{passmin}');
                   7479:                 field.value = '$defmin';
                   7480:             }
                   7481:         }
                   7482:     } else {
                   7483:         if (field.value == '0') {
                   7484:             field.value = '';
                   7485:         }
                   7486:         if (field.value != '') {
                   7487:             if (field.name == 'passwords_expire') {
                   7488:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/;
                   7489:                 if (!regexpposnum.test(field.value)) {
                   7490:                     alert('$intalert{passexp}');
                   7491:                     field.value = '';
                   7492:                 } else {
                   7493:                     var expval = parseFloat(field.value);
                   7494:                     if (expval == 0) {
                   7495:                         alert('$intalert{passexp}');
                   7496:                         field.value = '';
                   7497:                     }
                   7498:                 }
                   7499:             } else {
                   7500:                 if (!regexdigit.test(field.value)) {
                   7501:                     if (field.name == 'passwords_max') {
                   7502:                         alert('$intalert{passmax}');
                   7503:                     } else {
                   7504:                         if (field.name == 'passwords_numsaved') {
                   7505:                             alert('$intalert{passnum}');
                   7506:                         }
                   7507:                     }
1.160.6.104  raeburn  7508:                     field.value = '';
1.160.6.99  raeburn  7509:                 }
1.160.6.98  raeburn  7510:             }
                   7511:         }
                   7512:     }
                   7513:     return;
                   7514: }
                   7515: 
                   7516: ENDSCRIPT
                   7517:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   7518: }
                   7519: 
1.49      raeburn  7520: sub coursecategories_javascript {
                   7521:     my ($settings) = @_;
1.57      raeburn  7522:     my ($output,$jstext,$cathash);
1.49      raeburn  7523:     if (ref($settings) eq 'HASH') {
1.57      raeburn  7524:         $cathash = $settings->{'cats'};
                   7525:     }
                   7526:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  7527:         my (@cats,@jsarray,%idx);
1.57      raeburn  7528:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  7529:         if (@jsarray > 0) {
                   7530:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   7531:             for (my $i=0; $i<@jsarray; $i++) {
                   7532:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   7533:                     my $catstr = join('","',@{$jsarray[$i]});
                   7534:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   7535:                 }
                   7536:             }
                   7537:         }
                   7538:     } else {
                   7539:         $jstext  = '    var categories = Array(1);'."\n".
                   7540:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   7541:     }
1.160.6.42  raeburn  7542:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   7543:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66  raeburn  7544:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   7545:     &js_escape(\$instcode_reserved);
                   7546:     &js_escape(\$communities_reserved);
                   7547:     &js_escape(\$choose_again);
1.49      raeburn  7548:     $output = <<"ENDSCRIPT";
                   7549: <script type="text/javascript">
1.109     raeburn  7550: // <![CDATA[
1.49      raeburn  7551: function reorderCats(form,parent,item,idx) {
                   7552:     var changedVal;
                   7553: $jstext
                   7554:     var newpos = 'addcategory_pos';
                   7555:     if (parent == '') {
                   7556:         var has_instcode = 0;
                   7557:         var maxtop = categories[idx].length;
                   7558:         for (var j=0; j<maxtop; j++) {
                   7559:             if (categories[idx][j] == 'instcode::0') {
                   7560:                 has_instcode == 1;
                   7561:             }
                   7562:         }
                   7563:         if (has_instcode == 0) {
                   7564:             categories[idx][maxtop] = 'instcode_pos';
                   7565:         }
                   7566:     } else {
                   7567:         newpos += '_'+parent;
                   7568:     }
                   7569:     var maxh = 1 + categories[idx].length;
                   7570:     var current = new Array;
                   7571:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7572:     if (item == newpos) {
                   7573:         changedVal = newitemVal;
                   7574:     } else {
                   7575:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   7576:         current[newitemVal] = newpos;
                   7577:     }
                   7578:     for (var i=0; i<categories[idx].length; i++) {
                   7579:         var elementName = categories[idx][i];
                   7580:         if (elementName != item) {
                   7581:             if (form.elements[elementName]) {
                   7582:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   7583:                 current[currVal] = elementName;
                   7584:             }
                   7585:         }
                   7586:     }
                   7587:     var oldVal;
                   7588:     for (var j=0; j<maxh; j++) {
                   7589:         if (current[j] == undefined) {
                   7590:             oldVal = j;
                   7591:         }
                   7592:     }
                   7593:     if (oldVal < changedVal) {
                   7594:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   7595:            var elementName = current[k];
                   7596:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   7597:         }
                   7598:     } else {
                   7599:         for (var k=changedVal; k<oldVal; k++) {
                   7600:             var elementName = current[k];
                   7601:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   7602:         }
                   7603:     }
                   7604:     return;
                   7605: }
1.120     raeburn  7606: 
                   7607: function categoryCheck(form) {
                   7608:     if (form.elements['addcategory_name'].value == 'instcode') {
                   7609:         alert('$instcode_reserved\\n$choose_again');
                   7610:         return false;
                   7611:     }
                   7612:     if (form.elements['addcategory_name'].value == 'communities') {
                   7613:         alert('$communities_reserved\\n$choose_again');
                   7614:         return false;
                   7615:     }
                   7616:     return true;
                   7617: }
                   7618: 
1.109     raeburn  7619: // ]]>
1.49      raeburn  7620: </script>
                   7621: 
                   7622: ENDSCRIPT
                   7623:     return $output;
                   7624: }
                   7625: 
1.48      raeburn  7626: sub initialize_categories {
                   7627:     my ($itemcount) = @_;
1.120     raeburn  7628:     my ($datatable,$css_class,$chgstr);
1.160.6.111  raeburn  7629:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  7630:                       instcode    => 'Official courses (with institutional codes)',
                   7631:                       communities => 'Communities',
                   7632:                         );
                   7633:     my $select0 = ' selected="selected"';
                   7634:     my $select1 = '';
                   7635:     foreach my $default ('instcode','communities') {
                   7636:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87  raeburn  7637:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120     raeburn  7638:         if ($default eq 'communities') {
                   7639:             $select1 = $select0;
                   7640:             $select0 = '';
                   7641:         }
                   7642:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   7643:                      .'<select name="'.$default.'_pos">'
                   7644:                      .'<option value="0"'.$select0.'>1</option>'
                   7645:                      .'<option value="1"'.$select1.'>2</option>'
                   7646:                      .'<option value="2">3</option></select>&nbsp;'
                   7647:                      .$default_names{$default}
                   7648:                      .'</span></td><td><span class="LC_nobreak">'
                   7649:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   7650:                      .&mt('Display').'</label>&nbsp;<label>'
                   7651:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  7652:                  .'</label></span></td></tr>';
1.120     raeburn  7653:         $itemcount ++;
                   7654:     }
1.48      raeburn  7655:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  7656:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  7657:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  7658:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   7659:                   .'<option value="0">1</option>'
                   7660:                   .'<option value="1">2</option>'
                   7661:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.160.6.103  raeburn  7662:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87  raeburn  7663:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   7664:                   .'</td></tr>';
1.48      raeburn  7665:     return $datatable;
                   7666: }
                   7667: 
                   7668: sub build_category_rows {
1.49      raeburn  7669:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   7670:     my ($text,$name,$item,$chgstr);
1.48      raeburn  7671:     if (ref($cats) eq 'ARRAY') {
                   7672:         my $maxdepth = scalar(@{$cats});
                   7673:         if (ref($cats->[$depth]) eq 'HASH') {
                   7674:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   7675:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   7676:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23  raeburn  7677:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  7678:                 my ($idxnum,$parent_name,$parent_item);
                   7679:                 my $higher = $depth - 1;
                   7680:                 if ($higher == 0) {
                   7681:                     $parent_name = &escape($parent).'::'.$higher;
                   7682:                 } else {
                   7683:                     if (ref($path) eq 'ARRAY') {
                   7684:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   7685:                     }
                   7686:                 }
                   7687:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  7688:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  7689:                     if ($j < $numchildren) {
1.48      raeburn  7690:                         $name = $cats->[$depth]{$parent}[$j];
                   7691:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  7692:                         $idxnum = $idx->{$item};
                   7693:                     } else {
                   7694:                         $name = $parent_name;
                   7695:                         $item = $parent_item;
1.48      raeburn  7696:                     }
1.49      raeburn  7697:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   7698:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  7699:                     for (my $i=0; $i<=$numchildren; $i++) {
                   7700:                         my $vpos = $i+1;
                   7701:                         my $selstr;
                   7702:                         if ($j == $i) {
                   7703:                             $selstr = ' selected="selected" ';
                   7704:                         }
                   7705:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   7706:                     }
                   7707:                     $text .= '</select>&nbsp;';
                   7708:                     if ($j < $numchildren) {
                   7709:                         my $deeper = $depth+1;
                   7710:                         $text .= $name.'&nbsp;'
                   7711:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   7712:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   7713:                         if(ref($path) eq 'ARRAY') {
                   7714:                             push(@{$path},$name);
1.49      raeburn  7715:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  7716:                             pop(@{$path});
                   7717:                         }
                   7718:                     } else {
1.160.6.87  raeburn  7719:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  7720:                         if ($j == $numchildren) {
                   7721:                             $text .= $name;
                   7722:                         } else {
                   7723:                             $text .= $item;
                   7724:                         }
                   7725:                         $text .= '" value="" />';
                   7726:                     }
                   7727:                     $text .= '</td></tr>';
                   7728:                 }
                   7729:                 $text .= '</table></td>';
                   7730:             } else {
                   7731:                 my $higher = $depth-1;
                   7732:                 if ($higher == 0) {
                   7733:                     $name = &escape($parent).'::'.$higher;
                   7734:                 } else {
                   7735:                     if (ref($path) eq 'ARRAY') {
                   7736:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   7737:                     }
                   7738:                 }
                   7739:                 my $colspan;
                   7740:                 if ($parent ne 'instcode') {
                   7741:                     $colspan = $maxdepth - $depth - 1;
1.160.6.87  raeburn  7742:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  7743:                 }
                   7744:             }
                   7745:         }
                   7746:     }
                   7747:     return $text;
                   7748: }
                   7749: 
1.33      raeburn  7750: sub modifiable_userdata_row {
1.160.6.93  raeburn  7751:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
                   7752:         $rowid,$customcss,$rowstyle) = @_;
1.160.6.35  raeburn  7753:     my ($role,$rolename,$statustype);
                   7754:     $role = $item;
1.160.6.34  raeburn  7755:     if ($context eq 'cancreate') {
1.160.6.93  raeburn  7756:         if ($item =~ /^(emailusername)_(.+)$/) {
                   7757:             $role = $1;
                   7758:             $statustype = $2;
1.160.6.35  raeburn  7759:             if (ref($usertypes) eq 'HASH') {
                   7760:                 if ($usertypes->{$statustype}) {
                   7761:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   7762:                 } else {
                   7763:                     $rolename = &mt('Data provided by user');
                   7764:                 }
                   7765:             }
1.160.6.34  raeburn  7766:         }
                   7767:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  7768:         if (ref($usertypes) eq 'HASH') {
                   7769:             $rolename = $usertypes->{$role};
                   7770:         } else {
                   7771:             $rolename = $role;
                   7772:         }
1.33      raeburn  7773:     } else {
1.63      raeburn  7774:         if ($role eq 'cr') {
                   7775:             $rolename = &mt('Custom role');
                   7776:         } else {
                   7777:             $rolename = &Apache::lonnet::plaintext($role);
                   7778:         }
1.33      raeburn  7779:     }
1.160.6.34  raeburn  7780:     my (@fields,%fieldtitles);
                   7781:     if (ref($fieldsref) eq 'ARRAY') {
                   7782:         @fields = @{$fieldsref};
                   7783:     } else {
                   7784:         @fields = ('lastname','firstname','middlename','generation',
                   7785:                    'permanentemail','id');
                   7786:     }
                   7787:     if ((ref($titlesref) eq 'HASH')) {
                   7788:         %fieldtitles = %{$titlesref};
                   7789:     } else {
                   7790:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7791:     }
1.33      raeburn  7792:     my $output;
1.160.6.93  raeburn  7793:     my $css_class;
                   7794:     if ($rowcount%2) {
                   7795:         $css_class = 'LC_odd_row';
                   7796:     }
                   7797:     if ($customcss) {
                   7798:         $css_class .= " $customcss";
                   7799:     }
                   7800:     $css_class =~ s/^\s+//;
                   7801:     if ($css_class) {
                   7802:         $css_class = ' class="'.$css_class.'"';
                   7803:     }
                   7804:     if ($rowstyle) {
                   7805:         $css_class .= ' style="'.$rowstyle.'"';
                   7806:     }
                   7807:     if ($rowid) {
                   7808:         $rowid = ' id="'.$rowid.'"';
                   7809:     }
                   7810: 
                   7811:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  7812:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   7813:               '<td class="LC_left_item" colspan="2"><table>';
                   7814:     my $rem;
                   7815:     my %checks;
                   7816:     if (ref($settings) eq 'HASH') {
                   7817:         if (ref($settings->{$context}) eq 'HASH') {
                   7818:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35  raeburn  7819:                 my $hashref = $settings->{$context}->{$role};
                   7820:                 if ($role eq 'emailusername') {
                   7821:                     if ($statustype) {
                   7822:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   7823:                             $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39  raeburn  7824:                             if (ref($hashref) eq 'HASH') { 
1.160.6.35  raeburn  7825:                                 foreach my $field (@fields) {
                   7826:                                     if ($hashref->{$field}) {
                   7827:                                         $checks{$field} = $hashref->{$field};
                   7828:                                     }
                   7829:                                 }
                   7830:                             }
                   7831:                         }
                   7832:                     }
                   7833:                 } else {
                   7834:                     if (ref($hashref) eq 'HASH') {
                   7835:                         foreach my $field (@fields) {
                   7836:                             if ($hashref->{$field}) {
                   7837:                                 $checks{$field} = ' checked="checked" ';
                   7838:                             }
                   7839:                         }
1.33      raeburn  7840:                     }
                   7841:                 }
                   7842:             }
                   7843:         }
                   7844:     }
1.160.6.93  raeburn  7845: 
                   7846:     my $total = scalar(@fields);
                   7847:     for (my $i=0; $i<$total; $i++) {
                   7848:         $rem = $i%($numinrow);
1.33      raeburn  7849:         if ($rem == 0) {
                   7850:             if ($i > 0) {
                   7851:                 $output .= '</tr>';
                   7852:             }
                   7853:             $output .= '<tr>';
                   7854:         }
                   7855:         my $check = ' ';
1.160.6.35  raeburn  7856:         unless ($role eq 'emailusername') {
                   7857:             if (exists($checks{$fields[$i]})) {
1.160.6.98  raeburn  7858:                 $check = $checks{$fields[$i]};
1.160.6.35  raeburn  7859:             } else {
                   7860:                 if ($role eq 'st') {
                   7861:                     if (ref($settings) ne 'HASH') {
1.160.6.39  raeburn  7862:                         $check = ' checked="checked" '; 
1.160.6.35  raeburn  7863:                     }
1.33      raeburn  7864:                 }
                   7865:             }
                   7866:         }
                   7867:         $output .= '<td class="LC_left_item">'.
1.160.6.35  raeburn  7868:                    '<span class="LC_nobreak">';
                   7869:         if ($role eq 'emailusername') {
                   7870:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   7871:                 $checks{$fields[$i]} = 'omit';
                   7872:             }
                   7873:             foreach my $option ('required','optional','omit') {
                   7874:                 my $checked='';
                   7875:                 if ($checks{$fields[$i]} eq $option) {
                   7876:                     $checked='checked="checked" ';
                   7877:                 }
                   7878:                 $output .= '<label>'.
                   7879:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   7880:                            &mt($option).'</label>'.('&nbsp;' x2);
                   7881:             }
                   7882:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   7883:         } else {
                   7884:             $output .= '<label>'.
                   7885:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   7886:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   7887:                        '</label>';
                   7888:         }
                   7889:         $output .= '</span></td>';
1.33      raeburn  7890:     }
1.160.6.93  raeburn  7891:     $rem = $total%$numinrow;
                   7892:     my $colsleft;
                   7893:     if ($rem) {
                   7894:         $colsleft = $numinrow - $rem;
                   7895:     }
                   7896:     if ($colsleft > 1) {
1.33      raeburn  7897:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7898:                    '&nbsp;</td>';
                   7899:     } elsif ($colsleft == 1) {
                   7900:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   7901:     }
                   7902:     $output .= '</tr></table></td></tr>';
                   7903:     return $output;
                   7904: }
1.28      raeburn  7905: 
1.93      raeburn  7906: sub insttypes_row {
1.160.6.93  raeburn  7907:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   7908:         $customcss,$rowstyle) = @_;
1.93      raeburn  7909:     my %lt = &Apache::lonlocal::texthash (
                   7910:                       cansearch => 'Users allowed to search',
                   7911:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  7912:                       lockablenames => 'User preference to lock name',
1.160.6.93  raeburn  7913:                       selfassign    => 'Self-reportable affiliations',
1.160.6.101  raeburn  7914:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  7915:              );
                   7916:     my $showdom;
                   7917:     if ($context eq 'cansearch') {
                   7918:         $showdom = ' ('.$dom.')';
                   7919:     }
1.160.6.5  raeburn  7920:     my $class = 'LC_left_item';
                   7921:     if ($context eq 'statustocreate') {
                   7922:         $class = 'LC_right_item';
                   7923:     }
1.160.6.93  raeburn  7924:     my $css_class;
                   7925:     if ($$rowtotal%2) {
                   7926:         $css_class = 'LC_odd_row';
                   7927:     }
                   7928:     if ($customcss) {
                   7929:         $css_class .= ' '.$customcss;
                   7930:     }
                   7931:     $css_class =~ s/^\s+//;
                   7932:     if ($css_class) {
                   7933:         $css_class = ' class="'.$css_class.'"';
                   7934:     }
                   7935:     if ($rowstyle) {
                   7936:         $css_class .= ' style="'.$rowstyle.'"';
                   7937:     }
                   7938:     if ($onclick) {
                   7939:         $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34  raeburn  7940:     }
                   7941:     my $output = '<tr'.$css_class.'>'.
                   7942:                  '<td>'.$lt{$context}.$showdom.
                   7943:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  7944:     my $rem;
                   7945:     if (ref($types) eq 'ARRAY') {
                   7946:         for (my $i=0; $i<@{$types}; $i++) {
                   7947:             if (defined($usertypes->{$types->[$i]})) {
                   7948:                 my $rem = $i%($numinrow);
                   7949:                 if ($rem == 0) {
                   7950:                     if ($i > 0) {
                   7951:                         $output .= '</tr>';
                   7952:                     }
                   7953:                     $output .= '<tr>';
1.23      raeburn  7954:                 }
1.26      raeburn  7955:                 my $check = ' ';
1.99      raeburn  7956:                 if (ref($settings) eq 'HASH') {
                   7957:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   7958:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   7959:                             $check = ' checked="checked" ';
                   7960:                         }
1.160.6.101  raeburn  7961:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   7962:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   7963:                             $check = ' checked="checked" ';
                   7964:                         }
1.99      raeburn  7965:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  7966:                         $check = ' checked="checked" ';
                   7967:                     }
1.23      raeburn  7968:                 }
1.26      raeburn  7969:                 $output .= '<td class="LC_left_item">'.
                   7970:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  7971:                            '<input type="checkbox" name="'.$context.'" '.
1.160.6.93  raeburn  7972:                            'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26      raeburn  7973:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  7974:             }
                   7975:         }
1.26      raeburn  7976:         $rem = @{$types}%($numinrow);
1.23      raeburn  7977:     }
                   7978:     my $colsleft = $numinrow - $rem;
1.160.6.101  raeburn  7979:     if ($context eq 'overrides') {
                   7980:         if ($colsleft > 1) {
                   7981:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   7982:         } else {
                   7983:             $output .= '<td class="LC_left_item">';
                   7984:         }
                   7985:         $output .= '&nbsp;';
1.23      raeburn  7986:     } else {
1.160.6.101  raeburn  7987:         if ($rem == 0) {
                   7988:             $output .= '<tr>';
                   7989:         }
                   7990:         if ($colsleft > 1) {
                   7991:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   7992:         } else {
                   7993:             $output .= '<td class="LC_left_item">';
                   7994:         }
                   7995:         my $defcheck = ' ';
                   7996:         if (ref($settings) eq 'HASH') {  
                   7997:             if (ref($settings->{$context}) eq 'ARRAY') {
                   7998:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   7999:                     $defcheck = ' checked="checked" ';
                   8000:                 }
                   8001:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  8002:                 $defcheck = ' checked="checked" ';
                   8003:             }
1.26      raeburn  8004:         }
1.160.6.101  raeburn  8005:         $output .= '<span class="LC_nobreak"><label>'.
                   8006:                    '<input type="checkbox" name="'.$context.'" '.
                   8007:                    'value="default"'.$defcheck.$onclick.' />'.
                   8008:                    $othertitle.'</label></span>';
1.23      raeburn  8009:     }
1.160.6.101  raeburn  8010:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  8011:     return $output;
1.23      raeburn  8012: }
                   8013: 
                   8014: sub sorted_searchtitles {
                   8015:     my %searchtitles = &Apache::lonlocal::texthash(
                   8016:                          'uname' => 'username',
                   8017:                          'lastname' => 'last name',
                   8018:                          'lastfirst' => 'last name, first name',
                   8019:                      );
                   8020:     my @titleorder = ('uname','lastname','lastfirst');
                   8021:     return (\%searchtitles,\@titleorder);
                   8022: }
                   8023: 
1.25      raeburn  8024: sub sorted_searchtypes {
                   8025:     my %srchtypes_desc = (
                   8026:                            exact    => 'is exact match',
                   8027:                            contains => 'contains ..',
                   8028:                            begins   => 'begins with ..',
                   8029:                          );
                   8030:     my @srchtypeorder = ('exact','begins','contains');
                   8031:     return (\%srchtypes_desc,\@srchtypeorder);
                   8032: }
                   8033: 
1.3       raeburn  8034: sub usertype_update_row {
                   8035:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   8036:     my $datatable;
                   8037:     my $numinrow = 4;
                   8038:     foreach my $type (@{$types}) {
                   8039:         if (defined($usertypes->{$type})) {
                   8040:             $$rownums ++;
                   8041:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   8042:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   8043:                           '</td><td class="LC_left_item"><table>';
                   8044:             for (my $i=0; $i<@{$fields}; $i++) {
                   8045:                 my $rem = $i%($numinrow);
                   8046:                 if ($rem == 0) {
                   8047:                     if ($i > 0) {
                   8048:                         $datatable .= '</tr>';
                   8049:                     }
                   8050:                     $datatable .= '<tr>';
                   8051:                 }
                   8052:                 my $check = ' ';
1.39      raeburn  8053:                 if (ref($settings) eq 'HASH') {
                   8054:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   8055:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   8056:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   8057:                                 $check = ' checked="checked" ';
                   8058:                             }
1.3       raeburn  8059:                         }
                   8060:                     }
                   8061:                 }
                   8062: 
                   8063:                 if ($i == @{$fields}-1) {
                   8064:                     my $colsleft = $numinrow - $rem;
                   8065:                     if ($colsleft > 1) {
                   8066:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   8067:                     } else {
                   8068:                         $datatable .= '<td>';
                   8069:                     }
                   8070:                 } else {
                   8071:                     $datatable .= '<td>';
                   8072:                 }
1.8       raeburn  8073:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   8074:                               '<input type="checkbox" name="updateable_'.$type.
                   8075:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   8076:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  8077:             }
                   8078:             $datatable .= '</tr></table></td></tr>';
                   8079:         }
                   8080:     }
                   8081:     return $datatable;
1.1       raeburn  8082: }
                   8083: 
                   8084: sub modify_login {
1.160.6.24  raeburn  8085:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  8086:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   8087:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   8088:     %title = ( coursecatalog => 'Display course catalog',
                   8089:                adminmail => 'Display administrator E-mail address',
1.160.6.14  raeburn  8090:                helpdesk  => 'Display "Contact Helpdesk" link',
1.160.6.5  raeburn  8091:                newuser => 'Link for visitors to create a user account',
                   8092:                loginheader => 'Log-in box header');
                   8093:     @offon = ('off','on');
1.112     raeburn  8094:     if (ref($domconfig{login}) eq 'HASH') {
                   8095:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   8096:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   8097:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   8098:             }
                   8099:         }
                   8100:     }
1.9       raeburn  8101:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   8102:                                            \%domconfig,\%loginhash);
1.160.6.14  raeburn  8103:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8104:     foreach my $item (@toggles) {
                   8105:         $loginhash{login}{$item} = $env{'form.'.$item};
                   8106:     }
1.41      raeburn  8107:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  8108:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   8109:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   8110:                                          \%loginhash);
                   8111:     }
1.110     raeburn  8112: 
1.149     raeburn  8113:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56  raeburn  8114:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  8115:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  8116:     if (keys(%servers) > 1) {
                   8117:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  8118:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   8119:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   8120:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   8121:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   8122:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   8123:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8124:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8125:                         $changes{'loginvia'}{$lonhost} = 1;
                   8126:                     } else {
                   8127:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   8128:                         $changes{'loginvia'}{$lonhost} = 1;
                   8129:                     }
                   8130:                 } else {
                   8131:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8132:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8133:                         $changes{'loginvia'}{$lonhost} = 1;
                   8134:                     }
                   8135:                 }
                   8136:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   8137:                     foreach my $item (@loginvia_attribs) {
                   8138:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   8139:                     }
                   8140:                 } else {
                   8141:                     foreach my $item (@loginvia_attribs) {
                   8142:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8143:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8144:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   8145:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8146:                                 $new = '/';
                   8147:                             }
                   8148:                         }
                   8149:                         if (($item eq 'custompath') && 
                   8150:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8151:                             $new = '';
                   8152:                         }
                   8153:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   8154:                             $changes{'loginvia'}{$lonhost} = 1;
                   8155:                         }
                   8156:                         if ($item eq 'exempt') {
1.160.6.56  raeburn  8157:                             $new = &check_exempt_addresses($new);
1.128     raeburn  8158:                         }
                   8159:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8160:                     }
                   8161:                 }
1.112     raeburn  8162:             } else {
1.128     raeburn  8163:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8164:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  8165:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  8166:                     foreach my $item (@loginvia_attribs) {
                   8167:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8168:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8169:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8170:                                 $new = '/';
                   8171:                             }
                   8172:                         }
                   8173:                         if (($item eq 'custompath') && 
                   8174:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8175:                             $new = '';
                   8176:                         }
                   8177:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8178:                     }
1.110     raeburn  8179:                 }
                   8180:             }
                   8181:         }
                   8182:     }
1.119     raeburn  8183: 
1.160.6.5  raeburn  8184:     my $servadm = $r->dir_config('lonAdmEMail');
                   8185:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   8186:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8187:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   8188:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   8189:                 if ($lang eq 'nolang') {
                   8190:                     push(@currlangs,$lang);
                   8191:                 } elsif (defined($langchoices{$lang})) {
                   8192:                     push(@currlangs,$lang);
                   8193:                 } else {
                   8194:                     next;
                   8195:                 }
                   8196:             }
                   8197:         }
                   8198:     }
                   8199:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   8200:     if (@currlangs > 0) {
                   8201:         foreach my $lang (@currlangs) {
                   8202:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8203:                 $changes{'helpurl'}{$lang} = 1;
                   8204:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   8205:                 $changes{'helpurl'}{$lang} = 1;
                   8206:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   8207:                 push(@newlangs,$lang);
                   8208:             } else {
                   8209:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8210:             }
                   8211:         }
                   8212:     }
                   8213:     unless (grep(/^nolang$/,@currlangs)) {
                   8214:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   8215:             $changes{'helpurl'}{'nolang'} = 1;
                   8216:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   8217:             push(@newlangs,'nolang');
                   8218:         }
                   8219:     }
                   8220:     if ($env{'form.loginhelpurl_add_lang'}) {
                   8221:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   8222:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   8223:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   8224:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   8225:         }
                   8226:     }
                   8227:     if ((@newlangs > 0) || ($addedfile)) {
                   8228:         my $error;
                   8229:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8230:         if ($configuserok eq 'ok') {
                   8231:             if ($switchserver) {
                   8232:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   8233:             } elsif ($author_ok eq 'ok') {
                   8234:                 my @allnew = @newlangs;
                   8235:                 if ($addedfile ne '') {
                   8236:                     push(@allnew,$addedfile);
                   8237:                 }
                   8238:                 foreach my $lang (@allnew) {
                   8239:                     my $formelem = 'loginhelpurl_'.$lang;
                   8240:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   8241:                         $formelem = 'loginhelpurl_add_file';
                   8242:                     }
                   8243:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8244:                                                                "help/$lang",'','',$newfile{$lang});
                   8245:                     if ($result eq 'ok') {
                   8246:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   8247:                         $changes{'helpurl'}{$lang} = 1;
                   8248:                     } else {
                   8249:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   8250:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   8251:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                   8252:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   8253:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8254:                         }
                   8255:                     }
                   8256:                 }
                   8257:             } else {
                   8258:                 $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);
                   8259:             }
                   8260:         } else {
                   8261:             $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);
                   8262:         }
                   8263:         if ($error) {
                   8264:             &Apache::lonnet::logthis($error);
                   8265:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8266:         }
                   8267:     }
1.160.6.56  raeburn  8268: 
                   8269:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   8270:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8271:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   8272:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   8273:                 if ($domservers{$lonhost}) {
                   8274:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8275:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73  raeburn  8276:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56  raeburn  8277:                     }
                   8278:                 }
                   8279:             }
                   8280:         }
                   8281:     }
                   8282:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   8283:     foreach my $lonhost (sort(keys(%domservers))) {
                   8284:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8285:             $changes{'headtag'}{$lonhost} = 1;
                   8286:         } else {
                   8287:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   8288:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   8289:             }
                   8290:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   8291:                 push(@newhosts,$lonhost);
                   8292:             } elsif ($currheadtagurls{$lonhost}) {
                   8293:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   8294:                 if ($currexempt{$lonhost}) {
                   8295:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
                   8296:                         $changes{'headtag'}{$lonhost} = 1;
                   8297:                     }
                   8298:                 } elsif ($possexempt{$lonhost}) {
                   8299:                     $changes{'headtag'}{$lonhost} = 1;
                   8300:                 }
                   8301:                 if ($possexempt{$lonhost}) {
                   8302:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8303:                 }
                   8304:             }
                   8305:         }
                   8306:     }
                   8307:     if (@newhosts) {
                   8308:         my $error;
                   8309:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8310:         if ($configuserok eq 'ok') {
                   8311:             if ($switchserver) {
                   8312:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   8313:             } elsif ($author_ok eq 'ok') {
                   8314:                 foreach my $lonhost (@newhosts) {
                   8315:                     my $formelem = 'loginheadtag_'.$lonhost;
                   8316:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8317:                                                                           "login/headtag/$lonhost",'','',
                   8318:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   8319:                     if ($result eq 'ok') {
                   8320:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   8321:                         $changes{'headtag'}{$lonhost} = 1;
                   8322:                         if ($possexempt{$lonhost}) {
                   8323:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8324:                         }
                   8325:                     } else {
                   8326:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   8327:                                            $newheadtagurls{$lonhost},$result);
                   8328:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   8329:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   8330:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   8331:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   8332:                         }
                   8333:                     }
                   8334:                 }
                   8335:             } else {
                   8336:                 $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);
                   8337:             }
                   8338:         } else {
                   8339:             $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);
                   8340:         }
                   8341:         if ($error) {
                   8342:             &Apache::lonnet::logthis($error);
                   8343:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8344:         }
                   8345:     }
1.160.6.5  raeburn  8346:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
                   8347: 
                   8348:     my $defaulthelpfile = '/adm/loginproblems.html';
                   8349:     my $defaulttext = &mt('Default in use');
                   8350: 
1.1       raeburn  8351:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   8352:                                              $dom);
                   8353:     if ($putresult eq 'ok') {
1.160.6.14  raeburn  8354:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8355:         my %defaultchecked = (
                   8356:                     'coursecatalog' => 'on',
1.160.6.14  raeburn  8357:                     'helpdesk'      => 'on',
1.42      raeburn  8358:                     'adminmail'     => 'off',
1.43      raeburn  8359:                     'newuser'       => 'off',
1.42      raeburn  8360:         );
1.55      raeburn  8361:         if (ref($domconfig{'login'}) eq 'HASH') {
                   8362:             foreach my $item (@toggles) {
                   8363:                 if ($defaultchecked{$item} eq 'on') { 
                   8364:                     if (($domconfig{'login'}{$item} eq '0') &&
                   8365:                         ($env{'form.'.$item} eq '1')) {
                   8366:                         $changes{$item} = 1;
                   8367:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8368:                               $domconfig{'login'}{$item} eq '1') &&
                   8369:                              ($env{'form.'.$item} eq '0')) {
                   8370:                         $changes{$item} = 1;
                   8371:                     }
                   8372:                 } elsif ($defaultchecked{$item} eq 'off') {
                   8373:                     if (($domconfig{'login'}{$item} eq '1') &&
                   8374:                         ($env{'form.'.$item} eq '0')) {
                   8375:                         $changes{$item} = 1;
                   8376:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8377:                               $domconfig{'login'}{$item} eq '0') &&
                   8378:                              ($env{'form.'.$item} eq '1')) {
                   8379:                         $changes{$item} = 1;
                   8380:                     }
1.42      raeburn  8381:                 }
                   8382:             }
1.41      raeburn  8383:         }
1.6       raeburn  8384:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  8385:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  8386:             if (ref($lastactref) eq 'HASH') {
                   8387:                 $lastactref->{'domainconfig'} = 1;
                   8388:             }
1.1       raeburn  8389:             $resulttext = &mt('Changes made:').'<ul>';
                   8390:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   8391:                 if ($item eq 'loginvia') {
1.112     raeburn  8392:                     if (ref($changes{$item}) eq 'HASH') {
                   8393:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   8394:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  8395:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   8396:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   8397:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   8398:                                     $protocol = 'http' if ($protocol ne 'https');
                   8399:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   8400: 
                   8401:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   8402:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   8403:                                     } else {
                   8404:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   8405:                                     }
                   8406:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   8407:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   8408:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   8409:                                     }
                   8410:                                     $resulttext .= '</li>';
                   8411:                                 } else {
                   8412:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   8413:                                 }
1.112     raeburn  8414:                             } else {
1.128     raeburn  8415:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  8416:                             }
                   8417:                         }
1.128     raeburn  8418:                         $resulttext .= '</ul></li>';
1.112     raeburn  8419:                     }
1.160.6.5  raeburn  8420:                 } elsif ($item eq 'helpurl') {
                   8421:                     if (ref($changes{$item}) eq 'HASH') {
                   8422:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   8423:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8424:                                 my ($chg,$link);
                   8425:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   8426:                                 if ($lang eq 'nolang') {
                   8427:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   8428:                                 } else {
                   8429:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   8430:                                 }
                   8431:                                 $resulttext .= '<li>'.$chg.'</li>';
                   8432:                             } else {
                   8433:                                 my $chg;
                   8434:                                 if ($lang eq 'nolang') {
                   8435:                                     $chg = &mt('custom log-in help file for no preferred language');
                   8436:                                 } else {
                   8437:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   8438:                                 }
                   8439:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   8440:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   8441:                                                       '?inhibitmenu=yes',$chg,600,500).
                   8442:                                                '</li>';
                   8443:                             }
                   8444:                         }
                   8445:                     }
1.160.6.56  raeburn  8446:                 } elsif ($item eq 'headtag') {
                   8447:                     if (ref($changes{$item}) eq 'HASH') {
                   8448:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   8449:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8450:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   8451:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8452:                                 $resulttext .= '<li><a href="'.
                   8453:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   8454:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   8455:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   8456:                                 if ($possexempt{$lonhost}) {
                   8457:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   8458:                                 } else {
                   8459:                                     $resulttext .= &mt('included for any client IP');
                   8460:                                 }
                   8461:                                 $resulttext .= '</li>';
                   8462:                             }
                   8463:                         }
                   8464:                     }
1.160.6.5  raeburn  8465:                 } elsif ($item eq 'captcha') {
                   8466:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8467:                         my $chgtxt;
                   8468:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   8469:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   8470:                         } else {
                   8471:                             my %captchas = &captcha_phrases();
                   8472:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   8473:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   8474:                             } else {
                   8475:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   8476:                             }
                   8477:                         }
                   8478:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8479:                     }
                   8480:                 } elsif ($item eq 'recaptchakeys') {
                   8481:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8482:                         my ($privkey,$pubkey);
                   8483:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   8484:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   8485:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   8486:                         }
                   8487:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   8488:                         if (!$pubkey) {
                   8489:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   8490:                         } else {
                   8491:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   8492:                         }
                   8493:                         if (!$privkey) {
                   8494:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   8495:                         } else {
1.160.6.53  raeburn  8496:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5  raeburn  8497:                         }
                   8498:                         $chgtxt .= '</ul>';
                   8499:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8500:                     }
1.160.6.69  raeburn  8501:                 } elsif ($item eq 'recaptchaversion') {
                   8502:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8503:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
                   8504:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                   8505:                                            '</li>';
                   8506:                         }
                   8507:                     }
1.41      raeburn  8508:                 } else {
                   8509:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   8510:                 }
1.1       raeburn  8511:             }
1.6       raeburn  8512:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  8513:         } else {
                   8514:             $resulttext = &mt('No changes made to log-in page settings');
                   8515:         }
                   8516:     } else {
1.11      albertel 8517:         $resulttext = '<span class="LC_error">'.
                   8518: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8519:     }
1.6       raeburn  8520:     if ($errors) {
1.9       raeburn  8521:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  8522:                        $errors.'</ul>';
                   8523:     }
                   8524:     return $resulttext;
                   8525: }
                   8526: 
1.160.6.56  raeburn  8527: sub check_exempt_addresses {
                   8528:     my ($iplist) = @_;
                   8529:     $iplist =~ s/^\s+//;
                   8530:     $iplist =~ s/\s+$//;
                   8531:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   8532:     my (@okips,$new);
                   8533:     foreach my $ip (@poss_ips) {
                   8534:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   8535:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   8536:                 push(@okips,$ip);
                   8537:             }
                   8538:         }
                   8539:     }
                   8540:     if (@okips > 0) {
                   8541:         $new = join(',',@okips);
                   8542:     } else {
                   8543:         $new = '';
                   8544:     }
                   8545:     return $new;
                   8546: }
                   8547: 
1.6       raeburn  8548: sub color_font_choices {
                   8549:     my %choices =
                   8550:         &Apache::lonlocal::texthash (
                   8551:             img => "Header",
                   8552:             bgs => "Background colors",
                   8553:             links => "Link colors",
1.55      raeburn  8554:             images => "Images",
1.6       raeburn  8555:             font => "Font color",
1.160.6.22  raeburn  8556:             fontmenu => "Font menu",
1.76      raeburn  8557:             pgbg => "Page",
1.6       raeburn  8558:             tabbg => "Header",
                   8559:             sidebg => "Border",
                   8560:             link => "Link",
                   8561:             alink => "Active link",
                   8562:             vlink => "Visited link",
                   8563:         );
                   8564:     return %choices;
                   8565: }
                   8566: 
                   8567: sub modify_rolecolors {
1.160.6.24  raeburn  8568:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  8569:     my ($resulttext,%rolehash);
                   8570:     $rolehash{'rolecolors'} = {};
1.55      raeburn  8571:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   8572:         if ($domconfig{'rolecolors'} eq '') {
                   8573:             $domconfig{'rolecolors'} = {};
                   8574:         }
                   8575:     }
1.9       raeburn  8576:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  8577:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   8578:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   8579:                                              $dom);
                   8580:     if ($putresult eq 'ok') {
                   8581:         if (keys(%changes) > 0) {
1.41      raeburn  8582:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  8583:             if (ref($lastactref) eq 'HASH') {
                   8584:                 $lastactref->{'domainconfig'} = 1;
                   8585:             }
1.6       raeburn  8586:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   8587:                                              $rolehash{'rolecolors'});
                   8588:         } else {
                   8589:             $resulttext = &mt('No changes made to default color schemes');
                   8590:         }
                   8591:     } else {
1.11      albertel 8592:         $resulttext = '<span class="LC_error">'.
                   8593: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  8594:     }
                   8595:     if ($errors) {
                   8596:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   8597:                        $errors.'</ul>';
                   8598:     }
                   8599:     return $resulttext;
                   8600: }
                   8601: 
                   8602: sub modify_colors {
1.9       raeburn  8603:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  8604:     my (%changes,%choices);
1.51      raeburn  8605:     my @bgs;
1.6       raeburn  8606:     my @links = ('link','alink','vlink');
1.41      raeburn  8607:     my @logintext;
1.6       raeburn  8608:     my @images;
                   8609:     my $servadm = $r->dir_config('lonAdmEMail');
                   8610:     my $errors;
1.160.6.22  raeburn  8611:     my %defaults;
1.6       raeburn  8612:     foreach my $role (@{$roles}) {
                   8613:         if ($role eq 'login') {
1.12      raeburn  8614:             %choices = &login_choices();
1.41      raeburn  8615:             @logintext = ('textcol','bgcol');
1.12      raeburn  8616:         } else {
                   8617:             %choices = &color_font_choices();
                   8618:         }
                   8619:         if ($role eq 'login') {
1.41      raeburn  8620:             @images = ('img','logo','domlogo','login');
1.51      raeburn  8621:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  8622:         } else {
                   8623:             @images = ('img');
1.160.6.22  raeburn  8624:             @bgs = ('pgbg','tabbg','sidebg');
                   8625:         }
                   8626:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   8627:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   8628:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   8629:         }
                   8630:         if ($role eq 'login') {
                   8631:             foreach my $item (@logintext) {
1.160.6.39  raeburn  8632:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8633:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8634:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8635:                 }
                   8636:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22  raeburn  8637:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8638:                 }
                   8639:             }
                   8640:         } else {
1.160.6.39  raeburn  8641:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   8642:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   8643:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   8644:             }
                   8645:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22  raeburn  8646:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   8647:             }
1.6       raeburn  8648:         }
1.160.6.22  raeburn  8649:         foreach my $item (@bgs) {
1.160.6.39  raeburn  8650:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8651:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8652:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8653:             }
                   8654:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22  raeburn  8655:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8656:             }
                   8657:         }
                   8658:         foreach my $item (@links) {
1.160.6.39  raeburn  8659:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   8660:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   8661:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   8662:             }
                   8663:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22  raeburn  8664:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   8665:             }
1.6       raeburn  8666:         }
1.46      raeburn  8667:         my ($configuserok,$author_ok,$switchserver) = 
                   8668:             &config_check($dom,$confname,$servadm);
1.9       raeburn  8669:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  8670:         if (ref($domconfig->{$role}) ne 'HASH') {
                   8671:             $domconfig->{$role} = {};
                   8672:         }
1.8       raeburn  8673:         foreach my $img (@images) {
1.70      raeburn  8674:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   8675:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   8676:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   8677:                 } else { 
                   8678:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   8679:                 }
                   8680:             } 
1.18      albertel 8681: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   8682: 		 && !defined($domconfig->{$role}{$img})
                   8683: 		 && !$env{'form.'.$role.'_del_'.$img}
                   8684: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   8685: 		# import the old configured image from the .tab setting
                   8686: 		# if they haven't provided a new one 
                   8687: 		$domconfig->{$role}{$img} = 
                   8688: 		    $env{'form.'.$role.'_import_'.$img};
                   8689: 	    }
1.6       raeburn  8690:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  8691:                 my $error;
1.6       raeburn  8692:                 if ($configuserok eq 'ok') {
1.9       raeburn  8693:                     if ($switchserver) {
1.12      raeburn  8694:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  8695:                     } else {
                   8696:                         if ($author_ok eq 'ok') {
                   8697:                             my ($result,$logourl) = 
                   8698:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   8699:                                            $dom,$confname,$img,$width,$height);
                   8700:                             if ($result eq 'ok') {
                   8701:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  8702:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  8703:                             } else {
1.12      raeburn  8704:                                 $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  8705:                             }
                   8706:                         } else {
1.46      raeburn  8707:                             $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  8708:                         }
                   8709:                     }
                   8710:                 } else {
1.46      raeburn  8711:                     $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  8712:                 }
                   8713:                 if ($error) {
1.8       raeburn  8714:                     &Apache::lonnet::logthis($error);
1.11      albertel 8715:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  8716:                 }
                   8717:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  8718:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   8719:                     my $error;
                   8720:                     if ($configuserok eq 'ok') {
                   8721: # is confname an author?
                   8722:                         if ($switchserver eq '') {
                   8723:                             if ($author_ok eq 'ok') {
                   8724:                                 my ($result,$logourl) = 
                   8725:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   8726:                                             $dom,$confname,$img,$width,$height);
                   8727:                                 if ($result eq 'ok') {
                   8728:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 8729: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  8730:                                 }
                   8731:                             }
                   8732:                         }
                   8733:                     }
1.6       raeburn  8734:                 }
                   8735:             }
                   8736:         }
                   8737:         if (ref($domconfig) eq 'HASH') {
                   8738:             if (ref($domconfig->{$role}) eq 'HASH') {
                   8739:                 foreach my $img (@images) {
                   8740:                     if ($domconfig->{$role}{$img} ne '') {
                   8741:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   8742:                             $confhash->{$role}{$img} = '';
1.12      raeburn  8743:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  8744:                         } else {
1.9       raeburn  8745:                             if ($confhash->{$role}{$img} eq '') {
                   8746:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   8747:                             }
1.6       raeburn  8748:                         }
                   8749:                     } else {
                   8750:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   8751:                             $confhash->{$role}{$img} = '';
1.12      raeburn  8752:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  8753:                         } 
                   8754:                     }
1.70      raeburn  8755:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   8756:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   8757:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   8758:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   8759:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   8760:                             }
                   8761:                         } else {
                   8762:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   8763:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   8764:                             }
                   8765:                         }
                   8766:                     }
                   8767:                 }
1.6       raeburn  8768:                 if ($domconfig->{$role}{'font'} ne '') {
                   8769:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   8770:                         $changes{$role}{'font'} = 1;
                   8771:                     }
                   8772:                 } else {
                   8773:                     if ($confhash->{$role}{'font'}) {
                   8774:                         $changes{$role}{'font'} = 1;
                   8775:                     }
                   8776:                 }
1.107     raeburn  8777:                 if ($role ne 'login') {
                   8778:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   8779:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   8780:                             $changes{$role}{'fontmenu'} = 1;
                   8781:                         }
                   8782:                     } else {
                   8783:                         if ($confhash->{$role}{'fontmenu'}) {
                   8784:                             $changes{$role}{'fontmenu'} = 1;
                   8785:                         }
1.97      tempelho 8786:                     }
                   8787:                 }
1.6       raeburn  8788:                 foreach my $item (@bgs) {
                   8789:                     if ($domconfig->{$role}{$item} ne '') {
                   8790:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8791:                             $changes{$role}{'bgs'}{$item} = 1;
                   8792:                         } 
                   8793:                     } else {
                   8794:                         if ($confhash->{$role}{$item}) {
                   8795:                             $changes{$role}{'bgs'}{$item} = 1;
                   8796:                         }
                   8797:                     }
                   8798:                 }
                   8799:                 foreach my $item (@links) {
                   8800:                     if ($domconfig->{$role}{$item} ne '') {
                   8801:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8802:                             $changes{$role}{'links'}{$item} = 1;
                   8803:                         }
                   8804:                     } else {
                   8805:                         if ($confhash->{$role}{$item}) {
                   8806:                             $changes{$role}{'links'}{$item} = 1;
                   8807:                         }
                   8808:                     }
                   8809:                 }
1.41      raeburn  8810:                 foreach my $item (@logintext) {
                   8811:                     if ($domconfig->{$role}{$item} ne '') {
                   8812:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   8813:                             $changes{$role}{'logintext'}{$item} = 1;
                   8814:                         }
                   8815:                     } else {
                   8816:                         if ($confhash->{$role}{$item}) {
                   8817:                             $changes{$role}{'logintext'}{$item} = 1;
                   8818:                         }
                   8819:                     }
                   8820:                 }
1.6       raeburn  8821:             } else {
                   8822:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  8823:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  8824:             }
                   8825:         } else {
                   8826:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  8827:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  8828:         }
                   8829:     }
                   8830:     return ($errors,%changes);
                   8831: }
                   8832: 
1.46      raeburn  8833: sub config_check {
                   8834:     my ($dom,$confname,$servadm) = @_;
                   8835:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   8836:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   8837:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   8838:                                                    $confname,$servadm);
                   8839:     if ($configuserok eq 'ok') {
                   8840:         $switchserver = &check_switchserver($dom,$confname);
                   8841:         if ($switchserver eq '') {
                   8842:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   8843:         }
                   8844:     }
                   8845:     return ($configuserok,$author_ok,$switchserver);
                   8846: }
                   8847: 
1.6       raeburn  8848: sub default_change_checker {
1.41      raeburn  8849:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  8850:     foreach my $item (@{$links}) {
                   8851:         if ($confhash->{$role}{$item}) {
                   8852:             $changes->{$role}{'links'}{$item} = 1;
                   8853:         }
                   8854:     }
                   8855:     foreach my $item (@{$bgs}) {
                   8856:         if ($confhash->{$role}{$item}) {
                   8857:             $changes->{$role}{'bgs'}{$item} = 1;
                   8858:         }
                   8859:     }
1.41      raeburn  8860:     foreach my $item (@{$logintext}) {
                   8861:         if ($confhash->{$role}{$item}) {
                   8862:             $changes->{$role}{'logintext'}{$item} = 1;
                   8863:         }
                   8864:     }
1.6       raeburn  8865:     foreach my $img (@{$images}) {
                   8866:         if ($env{'form.'.$role.'_del_'.$img}) {
                   8867:             $confhash->{$role}{$img} = '';
1.12      raeburn  8868:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  8869:         }
1.70      raeburn  8870:         if ($role eq 'login') {
                   8871:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   8872:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   8873:             }
                   8874:         }
1.6       raeburn  8875:     }
                   8876:     if ($confhash->{$role}{'font'}) {
                   8877:         $changes->{$role}{'font'} = 1;
                   8878:     }
1.48      raeburn  8879: }
1.6       raeburn  8880: 
                   8881: sub display_colorchgs {
                   8882:     my ($dom,$changes,$roles,$confhash) = @_;
                   8883:     my (%choices,$resulttext);
                   8884:     if (!grep(/^login$/,@{$roles})) {
                   8885:         $resulttext = &mt('Changes made:').'<br />';
                   8886:     }
                   8887:     foreach my $role (@{$roles}) {
                   8888:         if ($role eq 'login') {
                   8889:             %choices = &login_choices();
                   8890:         } else {
                   8891:             %choices = &color_font_choices();
                   8892:         }
                   8893:         if (ref($changes->{$role}) eq 'HASH') {
                   8894:             if ($role ne 'login') {
                   8895:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   8896:             }
                   8897:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   8898:                 if ($role ne 'login') {
                   8899:                     $resulttext .= '<ul>';
                   8900:                 }
                   8901:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   8902:                     if ($role ne 'login') {
                   8903:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   8904:                     }
                   8905:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  8906:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   8907:                             if ($confhash->{$role}{$key}{$item}) {
                   8908:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   8909:                             } else {
                   8910:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   8911:                             }
                   8912:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  8913:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   8914:                         } else {
1.12      raeburn  8915:                             my $newitem = $confhash->{$role}{$item};
                   8916:                             if ($key eq 'images') {
                   8917:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   8918:                             }
                   8919:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  8920:                         }
                   8921:                     }
                   8922:                     if ($role ne 'login') {
                   8923:                         $resulttext .= '</ul></li>';
                   8924:                     }
                   8925:                 } else {
                   8926:                     if ($confhash->{$role}{$key} eq '') {
                   8927:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   8928:                     } else {
                   8929:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   8930:                     }
                   8931:                 }
                   8932:                 if ($role ne 'login') {
                   8933:                     $resulttext .= '</ul>';
                   8934:                 }
                   8935:             }
                   8936:         }
                   8937:     }
1.3       raeburn  8938:     return $resulttext;
1.1       raeburn  8939: }
                   8940: 
1.9       raeburn  8941: sub thumb_dimensions {
                   8942:     return ('200','50');
                   8943: }
                   8944: 
1.16      raeburn  8945: sub check_dimensions {
                   8946:     my ($inputfile) = @_;
                   8947:     my ($fullwidth,$fullheight);
                   8948:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   8949:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   8950:             my $imageinfo = <PIPE>;
                   8951:             if (!close(PIPE)) {
                   8952:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   8953:             }
                   8954:             chomp($imageinfo);
                   8955:             my ($fullsize) = 
1.21      raeburn  8956:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  8957:             if ($fullsize) {
                   8958:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   8959:             }
                   8960:         }
                   8961:     }
                   8962:     return ($fullwidth,$fullheight);
                   8963: }
                   8964: 
1.9       raeburn  8965: sub check_configuser {
                   8966:     my ($uhome,$dom,$confname,$servadm) = @_;
                   8967:     my ($configuserok,%currroles);
                   8968:     if ($uhome eq 'no_host') {
                   8969:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.160.6.98  raeburn  8970:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  8971:         $configuserok = 
                   8972:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   8973:                              $configpass,'','','','','',undef,$servadm);
                   8974:     } else {
                   8975:         $configuserok = 'ok';
                   8976:         %currroles = 
                   8977:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   8978:     }
                   8979:     return ($configuserok,%currroles);
                   8980: }
                   8981: 
                   8982: sub check_authorstatus {
                   8983:     my ($dom,$confname,%currroles) = @_;
                   8984:     my $author_ok;
1.40      raeburn  8985:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  8986:         my $start = time;
                   8987:         my $end = 0;
                   8988:         $author_ok = 
                   8989:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  8990:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  8991:     } else {
                   8992:         $author_ok = 'ok';
                   8993:     }
                   8994:     return $author_ok;
                   8995: }
                   8996: 
                   8997: sub publishlogo {
1.46      raeburn  8998:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  8999:     my ($output,$fname,$logourl);
                   9000:     if ($action eq 'upload') {
                   9001:         $fname=$env{'form.'.$formname.'.filename'};
                   9002:         chop($env{'form.'.$formname});
                   9003:     } else {
                   9004:         ($fname) = ($formname =~ /([^\/]+)$/);
                   9005:     }
1.46      raeburn  9006:     if ($savefileas ne '') {
                   9007:         $fname = $savefileas;
                   9008:     }
1.9       raeburn  9009:     $fname=&Apache::lonnet::clean_filename($fname);
                   9010: # See if there is anything left
                   9011:     unless ($fname) { return ('error: no uploaded file'); }
                   9012:     $fname="$subdir/$fname";
1.160.6.5  raeburn  9013:     my $docroot=$r->dir_config('lonDocRoot');
                   9014:     my $filepath="$docroot/priv";
                   9015:     my $relpath = "$dom/$confname";
1.9       raeburn  9016:     my ($fnamepath,$file,$fetchthumb);
                   9017:     $file=$fname;
                   9018:     if ($fname=~m|/|) {
                   9019:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   9020:     }
1.160.6.26  raeburn  9021:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  9022:     my $count;
1.160.6.5  raeburn  9023:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  9024:         $filepath.="/$parts[$count]";
                   9025:         if ((-e $filepath)!=1) {
                   9026:             mkdir($filepath,02770);
                   9027:         }
                   9028:     }
                   9029:     # Check for bad extension and disallow upload
                   9030:     if ($file=~/\.(\w+)$/ &&
                   9031:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   9032:         $output = 
1.160.6.25  raeburn  9033:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  9034:     } elsif ($file=~/\.(\w+)$/ &&
                   9035:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   9036:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   9037:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18  raeburn  9038:         $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  9039:     } elsif (-d "$filepath/$file") {
1.160.6.18  raeburn  9040:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  9041:     } else {
                   9042:         my $source = $filepath.'/'.$file;
                   9043:         my $logfile;
1.160.6.88  raeburn  9044:         if (!open($logfile,">>",$source.'.log')) {
1.160.6.19  raeburn  9045:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  9046:         }
                   9047:         print $logfile
                   9048: "\n================= Publish ".localtime()." ================\n".
                   9049: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   9050: # Save the file
1.160.6.88  raeburn  9051:         if (!open(FH,">",$source)) {
1.9       raeburn  9052:             &Apache::lonnet::logthis('Failed to create '.$source);
                   9053:             return (&mt('Failed to create file'));
                   9054:         }
                   9055:         if ($action eq 'upload') {
                   9056:             if (!print FH ($env{'form.'.$formname})) {
                   9057:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   9058:                 return (&mt('Failed to write file'));
                   9059:             }
                   9060:         } else {
                   9061:             my $original = &Apache::lonnet::filelocation('',$formname);
                   9062:             if(!copy($original,$source)) {
                   9063:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   9064:                 return (&mt('Failed to write file'));
                   9065:             }
                   9066:         }
                   9067:         close(FH);
                   9068:         chmod(0660, $source); # Permissions to rw-rw---.
                   9069: 
                   9070:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   9071:         my $copyfile=$targetdir.'/'.$file;
                   9072: 
                   9073:         my @parts=split(/\//,$targetdir);
                   9074:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   9075:         for (my $count=5;$count<=$#parts;$count++) {
                   9076:             $path.="/$parts[$count]";
                   9077:             if (!-e $path) {
                   9078:                 print $logfile "\nCreating directory ".$path;
                   9079:                 mkdir($path,02770);
                   9080:             }
                   9081:         }
                   9082:         my $versionresult;
                   9083:         if (-e $copyfile) {
                   9084:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   9085:         } else {
                   9086:             $versionresult = 'ok';
                   9087:         }
                   9088:         if ($versionresult eq 'ok') {
                   9089:             if (copy($source,$copyfile)) {
                   9090:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   9091:                 $output = 'ok';
                   9092:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  9093:                 push(@{$modified_urls},[$copyfile,$source]);
                   9094:                 my $metaoutput = 
                   9095:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   9096:                 unless ($registered_cleanup) {
                   9097:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9098:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9099:                     $registered_cleanup=1;
                   9100:                 }
1.9       raeburn  9101:             } else {
                   9102:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   9103:                 $output = &mt('Failed to copy file to RES space').", $!";
                   9104:             }
                   9105:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   9106:                 my $inputfile = $filepath.'/'.$file;
                   9107:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  9108:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   9109:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   9110:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   9111:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88  raeburn  9112:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   9113:                         system({$args[0]} @args);
1.16      raeburn  9114:                         chmod(0660, $filepath.'/tn-'.$file);
                   9115:                         if (-e $outfile) {
                   9116:                             my $copyfile=$targetdir.'/tn-'.$file;
                   9117:                             if (copy($outfile,$copyfile)) {
                   9118:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  9119:                                 my $thumb_metaoutput = 
                   9120:                                     &write_metadata($dom,$confname,$formname,
                   9121:                                                     $targetdir,'tn-'.$file,$logfile);
                   9122:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   9123:                                 unless ($registered_cleanup) {
                   9124:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9125:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9126:                                     $registered_cleanup=1;
                   9127:                                 }
1.16      raeburn  9128:                             } else {
                   9129:                                 print $logfile "\nUnable to write ".$copyfile.
                   9130:                                                ':'.$!."\n";
                   9131:                             }
                   9132:                         }
1.9       raeburn  9133:                     }
                   9134:                 }
                   9135:             }
                   9136:         } else {
                   9137:             $output = $versionresult;
                   9138:         }
                   9139:     }
                   9140:     return ($output,$logourl);
                   9141: }
                   9142: 
                   9143: sub logo_versioning {
                   9144:     my ($targetdir,$file,$logfile) = @_;
                   9145:     my $target = $targetdir.'/'.$file;
                   9146:     my ($maxversion,$fn,$extn,$output);
                   9147:     $maxversion = 0;
                   9148:     if ($file =~ /^(.+)\.(\w+)$/) {
                   9149:         $fn=$1;
                   9150:         $extn=$2;
                   9151:     }
                   9152:     opendir(DIR,$targetdir);
                   9153:     while (my $filename=readdir(DIR)) {
                   9154:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   9155:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   9156:         }
                   9157:     }
                   9158:     $maxversion++;
                   9159:     print $logfile "\nCreating old version ".$maxversion."\n";
                   9160:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   9161:     if (copy($target,$copyfile)) {
                   9162:         print $logfile "Copied old target to ".$copyfile."\n";
                   9163:         $copyfile=$copyfile.'.meta';
                   9164:         if (copy($target.'.meta',$copyfile)) {
                   9165:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   9166:             $output = 'ok';
                   9167:         } else {
                   9168:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   9169:             $output = &mt('Failed to copy old meta').", $!, ";
                   9170:         }
                   9171:     } else {
                   9172:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   9173:         $output = &mt('Failed to copy old target').", $!, ";
                   9174:     }
                   9175:     return $output;
                   9176: }
                   9177: 
                   9178: sub write_metadata {
                   9179:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   9180:     my (%metadatafields,%metadatakeys,$output);
                   9181:     $metadatafields{'title'}=$formname;
                   9182:     $metadatafields{'creationdate'}=time;
                   9183:     $metadatafields{'lastrevisiondate'}=time;
                   9184:     $metadatafields{'copyright'}='public';
                   9185:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   9186:                                          $env{'user.domain'};
                   9187:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   9188:     $metadatafields{'domain'}=$dom;
                   9189:     {
                   9190:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   9191:         my $mfh;
1.160.6.88  raeburn  9192:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13  raeburn  9193:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  9194:                 unless ($_=~/\./) {
                   9195:                     my $unikey=$_;
                   9196:                     $unikey=~/^([A-Za-z]+)/;
                   9197:                     my $tag=$1;
                   9198:                     $tag=~tr/A-Z/a-z/;
                   9199:                     print $mfh "\n\<$tag";
                   9200:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   9201:                         my $value=$metadatafields{$unikey.'.'.$_};
                   9202:                         $value=~s/\"/\'\'/g;
                   9203:                         print $mfh ' '.$_.'="'.$value.'"';
                   9204:                     }
                   9205:                     print $mfh '>'.
                   9206:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   9207:                             .'</'.$tag.'>';
                   9208:                 }
                   9209:             }
                   9210:             $output = 'ok';
                   9211:             print $logfile "\nWrote metadata";
                   9212:             close($mfh);
                   9213:         } else {
                   9214:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  9215:             $output = &mt('Could not write metadata');
                   9216:         }
                   9217:     }
1.155     raeburn  9218:     return $output;
                   9219: }
                   9220: 
                   9221: sub notifysubscribed {
                   9222:     foreach my $targetsource (@{$modified_urls}){
                   9223:         next unless (ref($targetsource) eq 'ARRAY');
                   9224:         my ($target,$source)=@{$targetsource};
                   9225:         if ($source ne '') {
1.160.6.88  raeburn  9226:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  9227:                 print $logfh "\nCleanup phase: Notifications\n";
                   9228:                 my @subscribed=&subscribed_hosts($target);
                   9229:                 foreach my $subhost (@subscribed) {
                   9230:                     print $logfh "\nNotifying host ".$subhost.':';
                   9231:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   9232:                     print $logfh $reply;
                   9233:                 }
                   9234:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   9235:                 foreach my $subhost (@subscribedmeta) {
                   9236:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   9237:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   9238:                                                         $subhost);
                   9239:                     print $logfh $reply;
                   9240:                 }
                   9241:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  9242:                 close($logfh);
1.155     raeburn  9243:             }
                   9244:         }
                   9245:     }
                   9246:     return OK;
                   9247: }
                   9248: 
                   9249: sub subscribed_hosts {
                   9250:     my ($target) = @_;
                   9251:     my @subscribed;
1.160.6.88  raeburn  9252:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  9253:         while (my $subline=<$fh>) {
                   9254:             if ($subline =~ /^($match_lonid):/) {
                   9255:                 my $host = $1;
                   9256:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   9257:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   9258:                         push(@subscribed,$host);
                   9259:                     }
                   9260:                 }
                   9261:             }
                   9262:         }
                   9263:     }
                   9264:     return @subscribed;
1.9       raeburn  9265: }
                   9266: 
                   9267: sub check_switchserver {
                   9268:     my ($dom,$confname) = @_;
                   9269:     my ($allowed,$switchserver);
                   9270:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   9271:     if ($home eq 'no_host') {
                   9272:         $home = &Apache::lonnet::domain($dom,'primary');
                   9273:     }
                   9274:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 9275:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   9276:     if (!$allowed) {
1.160.6.11  raeburn  9277: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  9278:     }
                   9279:     return $switchserver;
                   9280: }
                   9281: 
1.1       raeburn  9282: sub modify_quotas {
1.160.6.30  raeburn  9283:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  9284:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30  raeburn  9285:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39  raeburn  9286:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   9287:         $validationfieldsref);
1.86      raeburn  9288:     if ($action eq 'quotas') {
                   9289:         $context = 'tools'; 
1.160.6.26  raeburn  9290:     } else {
1.86      raeburn  9291:         $context = $action;
                   9292:     }
                   9293:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  9294:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  9295:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  9296:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   9297:         %titles = &courserequest_titles();
                   9298:         $toolregexp = join('|',@usertools);
                   9299:         %conditions = &courserequest_conditions();
1.160.6.30  raeburn  9300:         $confname = $dom.'-domainconfig';
                   9301:         my $servadm = $r->dir_config('lonAdmEMail');
                   9302:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39  raeburn  9303:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   9304:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5  raeburn  9305:     } elsif ($context eq 'requestauthor') {
                   9306:         @usertools = ('author');
                   9307:         %titles = &authorrequest_titles();
1.86      raeburn  9308:     } else {
1.160.6.4  raeburn  9309:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  9310:         %titles = &tool_titles();
1.86      raeburn  9311:     }
1.160.6.27  raeburn  9312:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  9313:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  9314:     foreach my $key (keys(%env)) {
1.101     raeburn  9315:         if ($context eq 'requestcourses') {
                   9316:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   9317:                 my $item = $1;
                   9318:                 my $type = $2;
                   9319:                 if ($type =~ /^limit_(.+)/) {
                   9320:                     $limithash{$item}{$1} = $env{$key};
                   9321:                 } else {
                   9322:                     $confhash{$item}{$type} = $env{$key};
                   9323:                 }
                   9324:             }
1.160.6.5  raeburn  9325:         } elsif ($context eq 'requestauthor') {
                   9326:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   9327:                 $confhash{$1} = $env{$key};
                   9328:             }
1.101     raeburn  9329:         } else {
1.86      raeburn  9330:             if ($key =~ /^form\.quota_(.+)$/) {
                   9331:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20  raeburn  9332:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   9333:                 $confhash{'authorquota'}{$1} = $env{$key};
                   9334:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  9335:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   9336:             }
1.72      raeburn  9337:         }
                   9338:     }
1.160.6.5  raeburn  9339:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34  raeburn  9340:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  9341:         @approvalnotify = sort(@approvalnotify);
                   9342:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30  raeburn  9343:         my @crstypes = ('official','unofficial','community','textbook');
                   9344:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   9345:         foreach my $type (@hasuniquecode) {
                   9346:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   9347:                 $confhash{'uniquecode'}{$type} = 1;
                   9348:             }
                   9349:         }
1.160.6.46  raeburn  9350:         my (%newbook,%allpos);
1.160.6.30  raeburn  9351:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9352:             foreach my $type ('textbooks','templates') {
                   9353:                 @{$allpos{$type}} = (); 
                   9354:                 my $invalid;
                   9355:                 if ($type eq 'textbooks') {
                   9356:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   9357:                 } else {
                   9358:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   9359:                 }
                   9360:                 if ($env{'form.'.$type.'_addbook'}) {
                   9361:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   9362:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   9363:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   9364:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   9365:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   9366:                         } else {
                   9367:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   9368:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   9369:                             $position =~ s/\D+//g;
                   9370:                             if ($position ne '') {
                   9371:                                 $allpos{$type}[$position] = $newbook{$type};
                   9372:                             }
1.160.6.30  raeburn  9373:                         }
1.160.6.46  raeburn  9374:                     } else {
                   9375:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30  raeburn  9376:                     }
                   9377:                 }
1.160.6.46  raeburn  9378:             } 
1.160.6.30  raeburn  9379:         }
1.102     raeburn  9380:         if (ref($domconfig{$action}) eq 'HASH') {
                   9381:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   9382:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   9383:                     $changes{'notify'}{'approval'} = 1;
                   9384:                 }
                   9385:             } else {
1.144     raeburn  9386:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9387:                     $changes{'notify'}{'approval'} = 1;
                   9388:                 }
                   9389:             }
1.160.6.30  raeburn  9390:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   9391:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9392:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   9393:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   9394:                             $changes{'uniquecode'} = 1;
                   9395:                         }
                   9396:                     }
                   9397:                     unless ($changes{'uniquecode'}) {
                   9398:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   9399:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   9400:                                 $changes{'uniquecode'} = 1;
                   9401:                             }
                   9402:                         }
                   9403:                     }
                   9404:                } else {
                   9405:                    $changes{'uniquecode'} = 1;
                   9406:                }
                   9407:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9408:                 $changes{'uniquecode'} = 1;
                   9409:             }
                   9410:             if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9411:                 foreach my $type ('textbooks','templates') {
                   9412:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9413:                         my %deletions;
                   9414:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   9415:                         if (@todelete) {
                   9416:                             map { $deletions{$_} = 1; } @todelete;
                   9417:                         }
                   9418:                         my %imgdeletions;
                   9419:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   9420:                         if (@todeleteimages) {
                   9421:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   9422:                         }
                   9423:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   9424:                         for (my $i=0; $i<=$maxnum; $i++) {
                   9425:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   9426:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   9427:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   9428:                                 if ($deletions{$key}) {
                   9429:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   9430:                                         #FIXME need to obsolete item in RES space
                   9431:                                     }
                   9432:                                     next;
                   9433:                                 } else {
                   9434:                                     my $newpos = $env{'form.'.$itemid};
                   9435:                                     $newpos =~ s/\D+//g;
1.160.6.47  raeburn  9436:                                     foreach my $item ('subject','title','publisher','author') {
                   9437:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9438:                                                  ($type eq 'templates'));
1.160.6.46  raeburn  9439:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   9440:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   9441:                                             $changes{$type}{$key} = 1;
                   9442:                                         }
                   9443:                                     }
                   9444:                                     $allpos{$type}[$newpos] = $key;
1.160.6.30  raeburn  9445:                                 }
1.160.6.46  raeburn  9446:                                 if ($imgdeletions{$key}) {
                   9447:                                     $changes{$type}{$key} = 1;
                   9448:                                     #FIXME need to obsolete item in RES space
                   9449:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   9450:                                     my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88  raeburn  9451:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9452:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9453:                                     } else {
                   9454:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   9455:                                                                                       $cdom,$cnum,$type,$configuserok,
                   9456:                                                                                       $switchserver,$author_ok);
                   9457:                                         if ($imgurl) {
                   9458:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   9459:                                             $changes{$type}{$key} = 1; 
                   9460:                                         }
                   9461:                                         if ($error) {
                   9462:                                             &Apache::lonnet::logthis($error);
                   9463:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9464:                                         }
1.160.6.46  raeburn  9465:                                     } 
                   9466:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   9467:                                     $confhash{$type}{$key}{'image'} = 
                   9468:                                         $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30  raeburn  9469:                                 }
                   9470:                             }
                   9471:                         }
                   9472:                     }
                   9473:                 }
                   9474:             }
1.102     raeburn  9475:         } else {
1.144     raeburn  9476:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9477:                 $changes{'notify'}{'approval'} = 1;
                   9478:             }
1.160.6.30  raeburn  9479:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
                   9480:                 $changes{'uniquecode'} = 1;
                   9481:             }
                   9482:         }
                   9483:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9484:             foreach my $type ('textbooks','templates') {
                   9485:                 if ($newbook{$type}) {
                   9486:                     $changes{$type}{$newbook{$type}} = 1;
1.160.6.47  raeburn  9487:                     foreach my $item ('subject','title','publisher','author') {
                   9488:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9489:                                  ($type eq 'template'));
1.160.6.46  raeburn  9490:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   9491:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   9492:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   9493:                         }
                   9494:                     }
                   9495:                     if ($type eq 'textbooks') {
                   9496:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   9497:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88  raeburn  9498:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9499:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9500:                             } else {
                   9501:                                 my ($imageurl,$error) =
                   9502:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   9503:                                                             $configuserok,$switchserver,$author_ok);
                   9504:                                 if ($imageurl) {
                   9505:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   9506:                                 }
                   9507:                                 if ($error) {
                   9508:                                     &Apache::lonnet::logthis($error);
                   9509:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9510:                                 }
1.160.6.46  raeburn  9511:                             }
                   9512:                         }
1.160.6.30  raeburn  9513:                     }
                   9514:                 }
1.160.6.46  raeburn  9515:                 if (@{$allpos{$type}} > 0) {
                   9516:                     my $idx = 0;
                   9517:                     foreach my $item (@{$allpos{$type}}) {
                   9518:                         if ($item ne '') {
                   9519:                             $confhash{$type}{$item}{'order'} = $idx;
                   9520:                             if (ref($domconfig{$action}) eq 'HASH') {
                   9521:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9522:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   9523:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   9524:                                             $changes{$type}{$item} = 1;
                   9525:                                         }
1.160.6.30  raeburn  9526:                                     }
                   9527:                                 }
                   9528:                             }
1.160.6.46  raeburn  9529:                             $idx ++;
1.160.6.30  raeburn  9530:                         }
                   9531:                     }
                   9532:                 }
                   9533:             }
1.160.6.39  raeburn  9534:             if (ref($validationitemsref) eq 'ARRAY') {
                   9535:                 foreach my $item (@{$validationitemsref}) {
                   9536:                     if ($item eq 'fields') {
                   9537:                         my @changed;
                   9538:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   9539:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   9540:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   9541:                         }
1.160.6.65  raeburn  9542:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9543:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9544:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   9545:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   9546:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   9547:                                 } else {
                   9548:                                     @changed = @{$confhash{'validation'}{$item}};
                   9549:                                 }
1.160.6.39  raeburn  9550:                             } else {
                   9551:                                 @changed = @{$confhash{'validation'}{$item}};
                   9552:                             }
                   9553:                         } else {
                   9554:                             @changed = @{$confhash{'validation'}{$item}};
                   9555:                         }
                   9556:                         if (@changed) {
                   9557:                             if ($confhash{'validation'}{$item}) {
                   9558:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   9559:                             } else {
                   9560:                                 $changes{'validation'}{$item} = &mt('None');
                   9561:                             }
                   9562:                         }
                   9563:                     } else {
                   9564:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   9565:                         if ($item eq 'markup') {
                   9566:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   9567:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   9568:                             }
                   9569:                         }
1.160.6.65  raeburn  9570:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9571:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9572:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   9573:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9574:                                 }
                   9575:                             } else {
                   9576:                                 if ($confhash{'validation'}{$item} ne '') {
                   9577:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9578:                                 }
1.160.6.39  raeburn  9579:                             }
                   9580:                         } else {
                   9581:                             if ($confhash{'validation'}{$item} ne '') {
                   9582:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9583:                             }
                   9584:                         }
                   9585:                     }
                   9586:                 }
                   9587:             }
                   9588:             if ($env{'form.validationdc'}) {
                   9589:                 my $newval = $env{'form.validationdc'};
1.160.6.77  raeburn  9590:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39  raeburn  9591:                 if (exists($domcoords{$newval})) {
                   9592:                     $confhash{'validation'}{'dc'} = $newval;
                   9593:                 }
                   9594:             }
                   9595:             if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65  raeburn  9596:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9597:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9598:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9599:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9600:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   9601:                                     $changes{'validation'}{'dc'} = &mt('None');
                   9602:                                 } else {
                   9603:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   9604:                                 }
1.160.6.39  raeburn  9605:                             }
1.160.6.65  raeburn  9606:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9607:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39  raeburn  9608:                         }
                   9609:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9610:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   9611:                     }
                   9612:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   9613:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   9614:                 }
1.160.6.65  raeburn  9615:             } else {
                   9616:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9617:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9618:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   9619:                             $changes{'validation'}{'dc'} = &mt('None');
                   9620:                         }
                   9621:                     }
1.160.6.39  raeburn  9622:                 }
                   9623:             }
1.102     raeburn  9624:         }
                   9625:     } else {
1.86      raeburn  9626:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20  raeburn  9627:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  9628:     }
1.72      raeburn  9629:     foreach my $item (@usertools) {
                   9630:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  9631:             my $unset; 
1.101     raeburn  9632:             if ($context eq 'requestcourses') {
1.104     raeburn  9633:                 $unset = '0';
                   9634:                 if ($type eq '_LC_adv') {
                   9635:                     $unset = '';
                   9636:                 }
1.101     raeburn  9637:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   9638:                     $confhash{$item}{$type} .= '=';
                   9639:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   9640:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   9641:                     }
                   9642:                 }
1.160.6.5  raeburn  9643:             } elsif ($context eq 'requestauthor') {
                   9644:                 $unset = '0';
                   9645:                 if ($type eq '_LC_adv') {
                   9646:                     $unset = '';
                   9647:                 }
1.72      raeburn  9648:             } else {
1.101     raeburn  9649:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   9650:                     $confhash{$item}{$type} = 1;
                   9651:                 } else {
                   9652:                     $confhash{$item}{$type} = 0;
                   9653:                 }
1.72      raeburn  9654:             }
1.86      raeburn  9655:             if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5  raeburn  9656:                 if ($action eq 'requestauthor') {
                   9657:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   9658:                         $changes{$type} = 1;
                   9659:                     }
                   9660:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  9661:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   9662:                         $changes{$item}{$type} = 1;
                   9663:                     }
                   9664:                 } else {
                   9665:                     if ($context eq 'requestcourses') {
1.104     raeburn  9666:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  9667:                             $changes{$item}{$type} = 1;
                   9668:                         }
                   9669:                     } else {
                   9670:                         if (!$confhash{$item}{$type}) {
                   9671:                             $changes{$item}{$type} = 1;
                   9672:                         }
                   9673:                     }
                   9674:                 }
                   9675:             } else {
                   9676:                 if ($context eq 'requestcourses') {
1.104     raeburn  9677:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  9678:                         $changes{$item}{$type} = 1;
                   9679:                     }
1.160.6.5  raeburn  9680:                 } elsif ($context eq 'requestauthor') {
                   9681:                     if ($confhash{$type} ne $unset) {
                   9682:                         $changes{$type} = 1;
                   9683:                     }
1.72      raeburn  9684:                 } else {
                   9685:                     if (!$confhash{$item}{$type}) {
                   9686:                         $changes{$item}{$type} = 1;
                   9687:                     }
                   9688:                 }
                   9689:             }
1.1       raeburn  9690:         }
                   9691:     }
1.160.6.5  raeburn  9692:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  9693:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9694:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   9695:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   9696:                     if (exists($confhash{'defaultquota'}{$key})) {
                   9697:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   9698:                             $changes{'defaultquota'}{$key} = 1;
                   9699:                         }
                   9700:                     } else {
                   9701:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  9702:                     }
                   9703:                 }
1.86      raeburn  9704:             } else {
                   9705:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   9706:                     if (exists($confhash{'defaultquota'}{$key})) {
                   9707:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   9708:                             $changes{'defaultquota'}{$key} = 1;
                   9709:                         }
                   9710:                     } else {
                   9711:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  9712:                     }
1.1       raeburn  9713:                 }
                   9714:             }
1.160.6.20  raeburn  9715:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   9716:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   9717:                     if (exists($confhash{'authorquota'}{$key})) {
                   9718:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   9719:                             $changes{'authorquota'}{$key} = 1;
                   9720:                         }
                   9721:                     } else {
                   9722:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   9723:                     }
                   9724:                 }
                   9725:             }
1.1       raeburn  9726:         }
1.86      raeburn  9727:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   9728:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   9729:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9730:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   9731:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   9732:                             $changes{'defaultquota'}{$key} = 1;
                   9733:                         }
                   9734:                     } else {
                   9735:                         if (!exists($domconfig{'quotas'}{$key})) {
                   9736:                             $changes{'defaultquota'}{$key} = 1;
                   9737:                         }
1.72      raeburn  9738:                     }
                   9739:                 } else {
1.86      raeburn  9740:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  9741:                 }
1.1       raeburn  9742:             }
                   9743:         }
1.160.6.20  raeburn  9744:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   9745:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   9746:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   9747:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   9748:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   9749:                             $changes{'authorquota'}{$key} = 1;
                   9750:                         }
                   9751:                     } else {
                   9752:                         $changes{'authorquota'}{$key} = 1;
                   9753:                     }
                   9754:                 } else {
                   9755:                     $changes{'authorquota'}{$key} = 1;
                   9756:                 }
                   9757:             }
                   9758:         }
1.1       raeburn  9759:     }
1.72      raeburn  9760: 
1.160.6.5  raeburn  9761:     if ($context eq 'requestauthor') {
                   9762:         $domdefaults{'requestauthor'} = \%confhash;
                   9763:     } else {
                   9764:         foreach my $key (keys(%confhash)) {
1.160.6.46  raeburn  9765:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30  raeburn  9766:                 $domdefaults{$key} = $confhash{$key};
                   9767:             }
1.160.6.5  raeburn  9768:         }
1.72      raeburn  9769:     }
1.160.6.5  raeburn  9770: 
1.1       raeburn  9771:     my %quotahash = (
1.86      raeburn  9772:                       $action => { %confhash }
1.1       raeburn  9773:                     );
                   9774:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   9775:                                              $dom);
                   9776:     if ($putresult eq 'ok') {
                   9777:         if (keys(%changes) > 0) {
1.72      raeburn  9778:             my $cachetime = 24*60*60;
                   9779:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  9780:             if (ref($lastactref) eq 'HASH') {
                   9781:                 $lastactref->{'domdefaults'} = 1;
                   9782:             }
1.1       raeburn  9783:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5  raeburn  9784:             unless (($context eq 'requestcourses') ||
                   9785:                     ($context eq 'requestauthor')) {
1.86      raeburn  9786:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   9787:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   9788:                     foreach my $type (@{$types},'default') {
                   9789:                         if (defined($changes{'defaultquota'}{$type})) {
                   9790:                             my $typetitle = $usertypes->{$type};
                   9791:                             if ($type eq 'default') {
                   9792:                                 $typetitle = $othertitle;
                   9793:                             }
1.160.6.28  raeburn  9794:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  9795:                         }
                   9796:                     }
1.86      raeburn  9797:                     $resulttext .= '</ul></li>';
1.72      raeburn  9798:                 }
1.160.6.20  raeburn  9799:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34  raeburn  9800:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20  raeburn  9801:                     foreach my $type (@{$types},'default') {
                   9802:                         if (defined($changes{'authorquota'}{$type})) {
                   9803:                             my $typetitle = $usertypes->{$type};
                   9804:                             if ($type eq 'default') {
                   9805:                                 $typetitle = $othertitle;
                   9806:                             }
1.160.6.28  raeburn  9807:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20  raeburn  9808:                         }
                   9809:                     }
                   9810:                     $resulttext .= '</ul></li>';
                   9811:                 }
1.72      raeburn  9812:             }
1.80      raeburn  9813:             my %newenv;
1.72      raeburn  9814:             foreach my $item (@usertools) {
1.160.6.5  raeburn  9815:                 my (%haschgs,%inconf);
                   9816:                 if ($context eq 'requestauthor') {
                   9817:                     %haschgs = %changes;
                   9818:                     %inconf = %confhash;
                   9819:                 } else {
                   9820:                     if (ref($changes{$item}) eq 'HASH') {
                   9821:                         %haschgs = %{$changes{$item}};
                   9822:                     }
                   9823:                     if (ref($confhash{$item}) eq 'HASH') {
                   9824:                         %inconf = %{$confhash{$item}};
                   9825:                     }
                   9826:                 }
                   9827:                 if (keys(%haschgs) > 0) {
1.80      raeburn  9828:                     my $newacc = 
                   9829:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   9830:                                                           $env{'user.domain'},
1.86      raeburn  9831:                                                           $item,'reload',$context);
1.160.6.5  raeburn  9832:                     if (($context eq 'requestcourses') ||
                   9833:                         ($context eq 'requestauthor')) {
1.108     raeburn  9834:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   9835:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  9836:                         }
                   9837:                     } else {
                   9838:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   9839:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   9840:                         }
1.80      raeburn  9841:                     }
1.160.6.5  raeburn  9842:                     unless ($context eq 'requestauthor') {
                   9843:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   9844:                     }
1.72      raeburn  9845:                     foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5  raeburn  9846:                         if ($haschgs{$type}) {
1.72      raeburn  9847:                             my $typetitle = $usertypes->{$type};
                   9848:                             if ($type eq 'default') {
                   9849:                                 $typetitle = $othertitle;
                   9850:                             } elsif ($type eq '_LC_adv') {
                   9851:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   9852:                             }
1.160.6.5  raeburn  9853:                             if ($inconf{$type}) {
1.101     raeburn  9854:                                 if ($context eq 'requestcourses') {
                   9855:                                     my $cond;
1.160.6.5  raeburn  9856:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  9857:                                         if ($1 eq '') {
                   9858:                                             $cond = &mt('(Automatic processing of any request).');
                   9859:                                         } else {
                   9860:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   9861:                                         }
                   9862:                                     } else { 
1.160.6.5  raeburn  9863:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  9864:                                     }
                   9865:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8  raeburn  9866:                                 } elsif ($context eq 'requestauthor') {
                   9867:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   9868:                                                              $titles{$inconf{$type}},$typetitle);
                   9869: 
1.101     raeburn  9870:                                 } else {
                   9871:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   9872:                                 }
1.72      raeburn  9873:                             } else {
1.104     raeburn  9874:                                 if ($type eq '_LC_adv') {
1.160.6.5  raeburn  9875:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  9876:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9877:                                     } else { 
                   9878:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   9879:                                     }
                   9880:                                 } else {
                   9881:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9882:                                 }
1.72      raeburn  9883:                             }
                   9884:                         }
1.26      raeburn  9885:                     }
1.160.6.5  raeburn  9886:                     unless ($context eq 'requestauthor') {
                   9887:                         $resulttext .= '</ul></li>';
                   9888:                     }
1.26      raeburn  9889:                 }
1.1       raeburn  9890:             }
1.160.6.5  raeburn  9891:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  9892:                 if (ref($changes{'notify'}) eq 'HASH') {
                   9893:                     if ($changes{'notify'}{'approval'}) {
                   9894:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   9895:                             if ($confhash{'notify'}{'approval'}) {
                   9896:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   9897:                             } else {
1.160.6.5  raeburn  9898:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  9899:                             }
                   9900:                         }
                   9901:                     }
                   9902:                 }
                   9903:             }
1.160.6.30  raeburn  9904:             if ($action eq 'requestcourses') {
                   9905:                 my @offon = ('off','on');
                   9906:                 if ($changes{'uniquecode'}) {
                   9907:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9908:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   9909:                         $resulttext .= '<li>'.
                   9910:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   9911:                                        '</li>';
                   9912:                     } else {
                   9913:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   9914:                                        '</li>';
                   9915:                     }
                   9916:                 }
1.160.6.46  raeburn  9917:                 foreach my $type ('textbooks','templates') {
                   9918:                     if (ref($changes{$type}) eq 'HASH') {
                   9919:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   9920:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   9921:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   9922:                             my $coursetitle = $coursehash{'description'};
                   9923:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   9924:                             $resulttext .= '<li>';
1.160.6.47  raeburn  9925:                             foreach my $item ('subject','title','publisher','author') {
                   9926:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9927:                                          ($type eq 'templates'));
1.160.6.46  raeburn  9928:                                 my $name = $item.':';
                   9929:                                 $name =~ s/^(\w)/\U$1/;
                   9930:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   9931:                             }
                   9932:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   9933:                             if ($type eq 'textbooks') {
                   9934:                                 if ($confhash{$type}{$key}{'image'}) {
                   9935:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   9936:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   9937:                                                    ' alt="Textbook cover" />').'<br />';
                   9938:                                 }
                   9939:                             }
                   9940:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30  raeburn  9941:                         }
1.160.6.46  raeburn  9942:                         $resulttext .= '</ul></li>';
1.160.6.30  raeburn  9943:                     }
                   9944:                 }
1.160.6.39  raeburn  9945:                 if (ref($changes{'validation'}) eq 'HASH') {
                   9946:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   9947:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   9948:                         foreach my $item (@{$validationitemsref}) {
                   9949:                             if (exists($changes{'validation'}{$item})) {
                   9950:                                 if ($item eq 'markup') {
                   9951:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9952:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   9953:                                 } else {
                   9954:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9955:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   9956:                                 }
                   9957:                             }
                   9958:                         }
                   9959:                         if (exists($changes{'validation'}{'dc'})) {
                   9960:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   9961:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   9962:                         }
                   9963:                     }
                   9964:                 }
1.160.6.30  raeburn  9965:             }
1.1       raeburn  9966:             $resulttext .= '</ul>';
1.80      raeburn  9967:             if (keys(%newenv)) {
                   9968:                 &Apache::lonnet::appenv(\%newenv);
                   9969:             }
1.1       raeburn  9970:         } else {
1.86      raeburn  9971:             if ($context eq 'requestcourses') {
                   9972:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5  raeburn  9973:             } elsif ($context eq 'requestauthor') {
                   9974:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  9975:             } else {
1.90      weissno  9976:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  9977:             }
1.1       raeburn  9978:         }
                   9979:     } else {
1.11      albertel 9980:         $resulttext = '<span class="LC_error">'.
                   9981: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9982:     }
1.160.6.30  raeburn  9983:     if ($errors) {
                   9984:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   9985:                        '<ul>'.$errors.'</ul></p>';
                   9986:     }
1.3       raeburn  9987:     return $resulttext;
1.1       raeburn  9988: }
                   9989: 
1.160.6.30  raeburn  9990: sub process_textbook_image {
1.160.6.46  raeburn  9991:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30  raeburn  9992:     my $filename = $env{'form.'.$caller.'.filename'};
                   9993:     my ($error,$url);
                   9994:     my ($width,$height) = (50,50);
                   9995:     if ($configuserok eq 'ok') {
                   9996:         if ($switchserver) {
                   9997:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   9998:                          $switchserver);
                   9999:         } elsif ($author_ok eq 'ok') {
                   10000:             my ($result,$imageurl) =
                   10001:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88  raeburn  10002:                              "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30  raeburn  10003:             if ($result eq 'ok') {
                   10004:                 $url = $imageurl;
                   10005:             } else {
                   10006:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   10007:             }
                   10008:         } else {
                   10009:             $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);
                   10010:         }
                   10011:     } else {
                   10012:         $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);
                   10013:     }
                   10014:     return ($url,$error);
                   10015: }
                   10016: 
1.3       raeburn  10017: sub modify_autoenroll {
1.160.6.24  raeburn  10018:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  10019:     my ($resulttext,%changes);
                   10020:     my %currautoenroll;
                   10021:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   10022:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   10023:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   10024:         }
                   10025:     }
                   10026:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   10027:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  10028:                   sender => 'Sender for notification messages',
1.160.6.68  raeburn  10029:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   10030:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  10031:     my @offon = ('off','on');
1.17      raeburn  10032:     my $sender_uname = $env{'form.sender_uname'};
                   10033:     my $sender_domain = $env{'form.sender_domain'};
                   10034:     if ($sender_domain eq '') {
                   10035:         $sender_uname = '';
                   10036:     } elsif ($sender_uname eq '') {
                   10037:         $sender_domain = '';
                   10038:     }
1.129     raeburn  10039:     my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68  raeburn  10040:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   10041:     $failsafe =~ s{^\s+|\s+$}{}g;
                   10042:     if ($failsafe =~ /\D/) {
                   10043:         undef($failsafe);
                   10044:     }
1.1       raeburn  10045:     my %autoenrollhash =  (
1.129     raeburn  10046:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   10047:                                        'sender_uname' => $sender_uname,
                   10048:                                        'sender_domain' => $sender_domain,
                   10049:                                        'co-owners' => $coowners,
1.160.6.68  raeburn  10050:                                        'autofailsafe' => $failsafe,
1.1       raeburn  10051:                                 }
                   10052:                      );
1.4       raeburn  10053:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   10054:                                              $dom);
1.1       raeburn  10055:     if ($putresult eq 'ok') {
                   10056:         if (exists($currautoenroll{'run'})) {
                   10057:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   10058:                  $changes{'run'} = 1;
                   10059:              }
                   10060:         } elsif ($autorun) {
                   10061:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  10062:                  $changes{'run'} = 1;
1.1       raeburn  10063:             }
                   10064:         }
1.17      raeburn  10065:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  10066:             $changes{'sender'} = 1;
                   10067:         }
1.17      raeburn  10068:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  10069:             $changes{'sender'} = 1;
                   10070:         }
1.129     raeburn  10071:         if ($currautoenroll{'co-owners'} ne '') {
                   10072:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   10073:                 $changes{'coowners'} = 1;
                   10074:             }
                   10075:         } elsif ($coowners) {
                   10076:             $changes{'coowners'} = 1;
1.160.6.68  raeburn  10077:         }
                   10078:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   10079:             $changes{'autofailsafe'} = 1;
                   10080:         }
1.1       raeburn  10081:         if (keys(%changes) > 0) {
                   10082:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  10083:             if ($changes{'run'}) {
1.1       raeburn  10084:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   10085:             }
                   10086:             if ($changes{'sender'}) {
1.17      raeburn  10087:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   10088:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   10089:                 } else {
                   10090:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   10091:                 }
1.1       raeburn  10092:             }
1.129     raeburn  10093:             if ($changes{'coowners'}) {
                   10094:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   10095:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  10096:                 if (ref($lastactref) eq 'HASH') {
                   10097:                     $lastactref->{'domainconfig'} = 1;
                   10098:                 }
1.129     raeburn  10099:             }
1.160.6.68  raeburn  10100:             if ($changes{'autofailsafe'}) {
                   10101:                 if ($failsafe ne '') {
1.160.6.82  raeburn  10102:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68  raeburn  10103:                 } else {
1.160.6.82  raeburn  10104:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68  raeburn  10105:                 }
                   10106:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   10107:                 if (ref($lastactref) eq 'HASH') {
                   10108:                     $lastactref->{'domdefaults'} = 1;
                   10109:                 }
                   10110:             }
1.1       raeburn  10111:             $resulttext .= '</ul>';
                   10112:         } else {
                   10113:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   10114:         }
                   10115:     } else {
1.11      albertel 10116:         $resulttext = '<span class="LC_error">'.
                   10117: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10118:     }
1.3       raeburn  10119:     return $resulttext;
1.1       raeburn  10120: }
                   10121: 
                   10122: sub modify_autoupdate {
1.3       raeburn  10123:     my ($dom,%domconfig) = @_;
1.1       raeburn  10124:     my ($resulttext,%currautoupdate,%fields,%changes);
                   10125:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   10126:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   10127:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   10128:         }
                   10129:     }
                   10130:     my @offon = ('off','on');
                   10131:     my %title = &Apache::lonlocal::texthash (
                   10132:                    run => 'Auto-update:',
                   10133:                    classlists => 'Updates to user information in classlists?'
                   10134:                 );
1.44      raeburn  10135:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  10136:     my %fieldtitles = &Apache::lonlocal::texthash (
                   10137:                         id => 'Student/Employee ID',
1.20      raeburn  10138:                         permanentemail => 'E-mail address',
1.1       raeburn  10139:                         lastname => 'Last Name',
                   10140:                         firstname => 'First Name',
                   10141:                         middlename => 'Middle Name',
1.132     raeburn  10142:                         generation => 'Generation',
1.1       raeburn  10143:                       );
1.142     raeburn  10144:     $othertitle = &mt('All users');
1.1       raeburn  10145:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  10146:         $othertitle = &mt('Other users');
1.1       raeburn  10147:     }
                   10148:     foreach my $key (keys(%env)) {
                   10149:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  10150:             my ($usertype,$item) = ($1,$2);
                   10151:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   10152:                 if ($usertype eq 'default') {   
                   10153:                     push(@{$fields{$1}},$2);
                   10154:                 } elsif (ref($types) eq 'ARRAY') {
                   10155:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   10156:                         push(@{$fields{$1}},$2);
                   10157:                     }
                   10158:                 }
                   10159:             }
1.1       raeburn  10160:         }
                   10161:     }
1.131     raeburn  10162:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   10163:     @lockablenames = sort(@lockablenames);
                   10164:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   10165:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   10166:         if (@changed) {
                   10167:             $changes{'lockablenames'} = 1;
                   10168:         }
                   10169:     } else {
                   10170:         if (@lockablenames) {
                   10171:             $changes{'lockablenames'} = 1;
                   10172:         }
                   10173:     }
1.1       raeburn  10174:     my %updatehash = (
                   10175:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   10176:                                       classlists => $env{'form.classlists'},
                   10177:                                       fields => {%fields},
1.131     raeburn  10178:                                       lockablenames => \@lockablenames,
1.1       raeburn  10179:                                     }
                   10180:                      );
                   10181:     foreach my $key (keys(%currautoupdate)) {
                   10182:         if (($key eq 'run') || ($key eq 'classlists')) {
                   10183:             if (exists($updatehash{autoupdate}{$key})) {
                   10184:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   10185:                     $changes{$key} = 1;
                   10186:                 }
                   10187:             }
                   10188:         } elsif ($key eq 'fields') {
                   10189:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  10190:                 foreach my $item (@{$types},'default') {
1.1       raeburn  10191:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   10192:                         my $change = 0;
                   10193:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   10194:                             if (!exists($fields{$item})) {
                   10195:                                 $change = 1;
1.132     raeburn  10196:                                 last;
1.1       raeburn  10197:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  10198:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  10199:                                     $change = 1;
1.132     raeburn  10200:                                     last;
1.1       raeburn  10201:                                 }
                   10202:                             }
                   10203:                         }
                   10204:                         if ($change) {
                   10205:                             push(@{$changes{$key}},$item);
                   10206:                         }
1.26      raeburn  10207:                     } 
1.1       raeburn  10208:                 }
                   10209:             }
1.131     raeburn  10210:         } elsif ($key eq 'lockablenames') {
                   10211:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   10212:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   10213:                 if (@changed) {
                   10214:                     $changes{'lockablenames'} = 1;
                   10215:                 }
                   10216:             } else {
                   10217:                 if (@lockablenames) {
                   10218:                     $changes{'lockablenames'} = 1;
                   10219:                 }
                   10220:             }
                   10221:         }
                   10222:     }
                   10223:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   10224:         if (@lockablenames) {
                   10225:             $changes{'lockablenames'} = 1;
1.1       raeburn  10226:         }
                   10227:     }
1.26      raeburn  10228:     foreach my $item (@{$types},'default') {
                   10229:         if (defined($fields{$item})) {
                   10230:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  10231:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   10232:                     my $change = 0;
                   10233:                     if (ref($fields{$item}) eq 'ARRAY') {
                   10234:                         foreach my $type (@{$fields{$item}}) {
                   10235:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   10236:                                 $change = 1;
                   10237:                                 last;
                   10238:                             }
                   10239:                         }
                   10240:                     }
                   10241:                     if ($change) {
                   10242:                         push(@{$changes{'fields'}},$item);
                   10243:                     }
                   10244:                 } else {
1.26      raeburn  10245:                     push(@{$changes{'fields'}},$item);
                   10246:                 }
                   10247:             } else {
                   10248:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  10249:             }
                   10250:         }
                   10251:     }
                   10252:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   10253:                                              $dom);
                   10254:     if ($putresult eq 'ok') {
                   10255:         if (keys(%changes) > 0) {
                   10256:             $resulttext = &mt('Changes made:').'<ul>';
                   10257:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  10258:                 if ($key eq 'lockablenames') {
                   10259:                     $resulttext .= '<li>';
                   10260:                     if (@lockablenames) {
                   10261:                         $usertypes->{'default'} = $othertitle;
                   10262:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   10263:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   10264:                     } else {
                   10265:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   10266:                     }
                   10267:                     $resulttext .= '</li>';
                   10268:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  10269:                     foreach my $item (@{$changes{$key}}) {
                   10270:                         my @newvalues;
                   10271:                         foreach my $type (@{$fields{$item}}) {
                   10272:                             push(@newvalues,$fieldtitles{$type});
                   10273:                         }
1.3       raeburn  10274:                         my $newvaluestr;
                   10275:                         if (@newvalues > 0) {
                   10276:                             $newvaluestr = join(', ',@newvalues);
                   10277:                         } else {
                   10278:                             $newvaluestr = &mt('none');
1.6       raeburn  10279:                         }
1.1       raeburn  10280:                         if ($item eq 'default') {
1.26      raeburn  10281:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  10282:                         } else {
1.26      raeburn  10283:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  10284:                         }
                   10285:                     }
                   10286:                 } else {
                   10287:                     my $newvalue;
                   10288:                     if ($key eq 'run') {
                   10289:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   10290:                     } else {
                   10291:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  10292:                     }
1.1       raeburn  10293:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   10294:                 }
                   10295:             }
                   10296:             $resulttext .= '</ul>';
                   10297:         } else {
1.3       raeburn  10298:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  10299:         }
                   10300:     } else {
1.11      albertel 10301:         $resulttext = '<span class="LC_error">'.
                   10302: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10303:     }
1.3       raeburn  10304:     return $resulttext;
1.1       raeburn  10305: }
                   10306: 
1.125     raeburn  10307: sub modify_autocreate {
                   10308:     my ($dom,%domconfig) = @_;
                   10309:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   10310:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   10311:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   10312:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   10313:         }
                   10314:     }
                   10315:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   10316:                  req => 'Auto-creation of validated requests for official courses',
                   10317:                  xmldc => 'Identity of course creator of courses from XML files',
                   10318:                );
                   10319:     my @types = ('xml','req');
                   10320:     foreach my $item (@types) {
                   10321:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   10322:         $newvals{$item} =~ s/\D//g;
                   10323:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   10324:     }
                   10325:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77  raeburn  10326:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  10327:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   10328:         $newvals{'xmldc'} = '';
                   10329:     } 
                   10330:     %autocreatehash =  (
                   10331:                         autocreate => { xml => $newvals{'xml'},
                   10332:                                         req => $newvals{'req'},
                   10333:                                       }
                   10334:                        );
                   10335:     if ($newvals{'xmldc'} ne '') {
                   10336:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   10337:     }
                   10338:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   10339:                                              $dom);
                   10340:     if ($putresult eq 'ok') {
                   10341:         my @items = @types;
                   10342:         if ($newvals{'xml'}) {
                   10343:             push(@items,'xmldc');
                   10344:         }
                   10345:         foreach my $item (@items) {
                   10346:             if (exists($currautocreate{$item})) {
                   10347:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   10348:                     $changes{$item} = 1;
                   10349:                 }
                   10350:             } elsif ($newvals{$item}) {
                   10351:                 $changes{$item} = 1;
                   10352:             }
                   10353:         }
                   10354:         if (keys(%changes) > 0) {
                   10355:             my @offon = ('off','on'); 
                   10356:             $resulttext = &mt('Changes made:').'<ul>';
                   10357:             foreach my $item (@types) {
                   10358:                 if ($changes{$item}) {
                   10359:                     my $newtxt = $offon[$newvals{$item}];
1.160.6.13  raeburn  10360:                     $resulttext .= '<li>'.
                   10361:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   10362:                                        '<b>','</b>').
                   10363:                                    '</li>';
1.125     raeburn  10364:                 }
                   10365:             }
                   10366:             if ($changes{'xmldc'}) {
                   10367:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   10368:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13  raeburn  10369:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  10370:             }
                   10371:             $resulttext .= '</ul>';
                   10372:         } else {
                   10373:             $resulttext = &mt('No changes made to auto-creation settings');
                   10374:         }
                   10375:     } else {
                   10376:         $resulttext = '<span class="LC_error">'.
                   10377:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10378:     }
                   10379:     return $resulttext;
                   10380: }
                   10381: 
1.23      raeburn  10382: sub modify_directorysrch {
1.160.6.81  raeburn  10383:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  10384:     my ($resulttext,%changes);
                   10385:     my %currdirsrch;
                   10386:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   10387:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   10388:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   10389:         }
                   10390:     }
1.160.6.72  raeburn  10391:     my %title = ( available => 'Institutional directory search available',
                   10392:                   localonly => 'Other domains can search institution',
                   10393:                   lcavailable => 'LON-CAPA directory search available',
                   10394:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  10395:                   searchby => 'Search types',
                   10396:                   searchtypes => 'Search latitude');
                   10397:     my @offon = ('off','on');
1.24      raeburn  10398:     my @otherdoms = ('Yes','No');
1.23      raeburn  10399: 
1.25      raeburn  10400:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  10401:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   10402:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   10403: 
1.44      raeburn  10404:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  10405:     if (keys(%{$usertypes}) == 0) {
                   10406:         @cansearch = ('default');
                   10407:     } else {
                   10408:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   10409:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   10410:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   10411:                     push(@{$changes{'cansearch'}},$type);
                   10412:                 }
1.23      raeburn  10413:             }
1.26      raeburn  10414:             foreach my $type (@cansearch) {
                   10415:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   10416:                     push(@{$changes{'cansearch'}},$type);
                   10417:                 }
1.23      raeburn  10418:             }
1.26      raeburn  10419:         } else {
                   10420:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  10421:         }
                   10422:     }
                   10423: 
                   10424:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   10425:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   10426:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   10427:                 push(@{$changes{'searchby'}},$by);
                   10428:             }
                   10429:         }
                   10430:         foreach my $by (@searchby) {
                   10431:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   10432:                 push(@{$changes{'searchby'}},$by);
                   10433:             }
                   10434:         }
                   10435:     } else {
                   10436:         push(@{$changes{'searchby'}},@searchby);
                   10437:     }
1.25      raeburn  10438: 
                   10439:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   10440:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   10441:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   10442:                 push(@{$changes{'searchtypes'}},$type);
                   10443:             }
                   10444:         }
                   10445:         foreach my $type (@searchtypes) {
                   10446:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   10447:                 push(@{$changes{'searchtypes'}},$type);
                   10448:             }
                   10449:         }
                   10450:     } else {
                   10451:         if (exists($currdirsrch{'searchtypes'})) {
                   10452:             foreach my $type (@searchtypes) {  
                   10453:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   10454:                     push(@{$changes{'searchtypes'}},$type);
                   10455:                 }
                   10456:             }
                   10457:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   10458:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   10459:             }   
                   10460:         } else {
                   10461:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   10462:         }
                   10463:     }
                   10464: 
1.23      raeburn  10465:     my %dirsrch_hash =  (
                   10466:             directorysrch => { available => $env{'form.dirsrch_available'},
                   10467:                                cansearch => \@cansearch,
1.160.6.72  raeburn  10468:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   10469:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   10470:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  10471:                                searchby => \@searchby,
1.25      raeburn  10472:                                searchtypes => \@searchtypes,
1.23      raeburn  10473:                              }
                   10474:             );
                   10475:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   10476:                                              $dom);
                   10477:     if ($putresult eq 'ok') {
                   10478:         if (exists($currdirsrch{'available'})) {
                   10479:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   10480:                  $changes{'available'} = 1;
                   10481:              }
                   10482:         } else {
                   10483:             if ($env{'form.dirsrch_available'} eq '1') {
                   10484:                 $changes{'available'} = 1;
                   10485:             }
                   10486:         }
1.160.6.72  raeburn  10487:         if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78  raeburn  10488:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   10489:                 $changes{'lcavailable'} = 1;
                   10490:             }
1.24      raeburn  10491:         } else {
1.160.6.72  raeburn  10492:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   10493:                 $changes{'lcavailable'} = 1;
                   10494:             }
                   10495:         }
                   10496:         if (exists($currdirsrch{'localonly'})) {
                   10497:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  10498:                 $changes{'localonly'} = 1;
                   10499:             }
1.160.6.72  raeburn  10500:         } else {
                   10501:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
                   10502:                 $changes{'localonly'} = 1;
                   10503:             }
                   10504:         }
                   10505:         if (exists($currdirsrch{'lclocalonly'})) {
                   10506:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   10507:                 $changes{'lclocalonly'} = 1;
                   10508:             }
                   10509:         } else {
                   10510:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   10511:                 $changes{'lclocalonly'} = 1;
                   10512:             }
1.24      raeburn  10513:         }
1.23      raeburn  10514:         if (keys(%changes) > 0) {
                   10515:             $resulttext = &mt('Changes made:').'<ul>';
                   10516:             if ($changes{'available'}) {
                   10517:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   10518:             }
1.160.6.72  raeburn  10519:             if ($changes{'lcavailable'}) {
                   10520:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   10521:             }
1.24      raeburn  10522:             if ($changes{'localonly'}) {
1.160.6.72  raeburn  10523:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
                   10524:             }
                   10525:             if ($changes{'lclocalonly'}) {
                   10526:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24      raeburn  10527:             }
1.23      raeburn  10528:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   10529:                 my $chgtext;
1.26      raeburn  10530:                 if (ref($usertypes) eq 'HASH') {
                   10531:                     if (keys(%{$usertypes}) > 0) {
                   10532:                         foreach my $type (@{$types}) {
                   10533:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   10534:                                 $chgtext .= $usertypes->{$type}.'; ';
                   10535:                             }
                   10536:                         }
                   10537:                         if (grep(/^default$/,@cansearch)) {
                   10538:                             $chgtext .= $othertitle;
                   10539:                         } else {
                   10540:                             $chgtext =~ s/\; $//;
                   10541:                         }
1.160.6.13  raeburn  10542:                         $resulttext .=
                   10543:                             '<li>'.
                   10544:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   10545:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   10546:                             '</li>';
1.23      raeburn  10547:                     }
                   10548:                 }
                   10549:             }
                   10550:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   10551:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   10552:                 my $chgtext;
                   10553:                 foreach my $type (@{$titleorder}) {
                   10554:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   10555:                         if (defined($searchtitles->{$type})) {
                   10556:                             $chgtext .= $searchtitles->{$type}.'; ';
                   10557:                         }
                   10558:                     }
                   10559:                 }
                   10560:                 $chgtext =~ s/\; $//;
                   10561:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   10562:             }
1.25      raeburn  10563:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   10564:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   10565:                 my $chgtext;
                   10566:                 foreach my $type (@{$srchtypeorder}) {
                   10567:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   10568:                         if (defined($srchtypes_desc->{$type})) {
                   10569:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   10570:                         }
                   10571:                     }
                   10572:                 }
                   10573:                 $chgtext =~ s/\; $//;
1.160.6.13  raeburn  10574:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  10575:             }
                   10576:             $resulttext .= '</ul>';
1.160.6.81  raeburn  10577:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   10578:             if (ref($lastactref) eq 'HASH') {
                   10579:                 $lastactref->{'directorysrch'} = 1;
                   10580:             }
1.23      raeburn  10581:         } else {
1.160.6.72  raeburn  10582:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  10583:         }
                   10584:     } else {
                   10585:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  10586:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   10587:     }
                   10588:     return $resulttext;
                   10589: }
                   10590: 
1.28      raeburn  10591: sub modify_contacts {
1.160.6.24  raeburn  10592:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  10593:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   10594:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   10595:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   10596:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   10597:         }
                   10598:     }
1.160.6.78  raeburn  10599:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  10600:     my @contacts = ('supportemail','adminemail');
1.160.6.78  raeburn  10601:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95  raeburn  10602:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107  raeburn  10603:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   10604:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78  raeburn  10605:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  10606:     foreach my $type (@mailings) {
                   10607:         @{$newsetting{$type}} = 
                   10608:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   10609:         foreach my $item (@contacts) {
                   10610:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   10611:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   10612:             } else {
                   10613:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   10614:             }
1.160.6.78  raeburn  10615:         }
1.28      raeburn  10616:         $others{$type} = $env{'form.'.$type.'_others'};
                   10617:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78  raeburn  10618:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10619:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   10620:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78  raeburn  10621:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   10622:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   10623:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   10624:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   10625:             }
1.134     raeburn  10626:         }
1.28      raeburn  10627:     }
                   10628:     foreach my $item (@contacts) {
                   10629:         $to{$item} = $env{'form.'.$item};
                   10630:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   10631:     }
1.160.6.23  raeburn  10632:     foreach my $item (@toggles) {
                   10633:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   10634:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   10635:         }
                   10636:     }
1.160.6.107  raeburn  10637:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   10638:     foreach my $item (@lonstatus) {
                   10639:         if ($item eq 'excluded') {
                   10640:             my (%serverhomes,@excluded);
                   10641:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   10642:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   10643:             if (@possexcluded) {
                   10644:                 foreach my $id (sort(@possexcluded)) {
                   10645:                     if ($serverhomes{$id}) {
                   10646:                         push(@excluded,$id);
                   10647:                     }
                   10648:                 }
                   10649:             }
                   10650:             if (@excluded) {
                   10651:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   10652:             }
                   10653:         } elsif ($item eq 'weights') {
                   10654:             foreach my $type ('E','W','N','U') {
                   10655:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   10656:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   10657:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   10658:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   10659:                             $env{'form.error'.$item.'_'.$type};
                   10660:                     }
                   10661:                 }
                   10662:             }
                   10663:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   10664:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   10665:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   10666:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   10667:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   10668:                 }
                   10669:             }
                   10670:         }
                   10671:     }
1.160.6.78  raeburn  10672:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   10673:         foreach my $field (@{$fields}) {
                   10674:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   10675:                 my $value = $env{'form.helpform_'.$field};
                   10676:                 $value =~ s/^\s+|\s+$//g;
                   10677:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101  raeburn  10678:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78  raeburn  10679:                     if ($field eq 'screenshot') {
                   10680:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   10681:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101  raeburn  10682:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78  raeburn  10683:                         }
                   10684:                     }
                   10685:                 }
                   10686:             }
                   10687:         }
                   10688:     }
1.160.6.101  raeburn  10689:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   10690:     my (@statuses,%usertypeshash,@overrides);
                   10691:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   10692:         @statuses = @{$types};
                   10693:         if (ref($usertypes) eq 'HASH') {
                   10694:             %usertypeshash = %{$usertypes};
                   10695:         }
                   10696:     }
                   10697:     if (@statuses) {
                   10698:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   10699:         foreach my $type (@possoverrides) {
                   10700:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   10701:                 push(@overrides,$type);
                   10702:             }
                   10703:         }
                   10704:         if (@overrides) {
                   10705:             foreach my $type (@overrides) {
                   10706:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   10707:                 foreach my $item (@contacts) {
                   10708:                     if (grep(/^\Q$item\E$/,@standard)) {
                   10709:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   10710:                         $newsetting{'override_'.$type}{$item} = 1;
                   10711:                     } else {
                   10712:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   10713:                         $newsetting{'override_'.$type}{$item} = 0;
                   10714:                     }
                   10715:                 }
                   10716:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   10717:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   10718:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   10719:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   10720:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   10721:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   10722:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   10723:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   10724:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   10725:                 }
                   10726:             }    
                   10727:         }
                   10728:     }
1.28      raeburn  10729:     if (keys(%currsetting) > 0) {
                   10730:         foreach my $item (@contacts) {
                   10731:             if ($to{$item} ne $currsetting{$item}) {
                   10732:                 $changes{$item} = 1;
                   10733:             }
                   10734:         }
                   10735:         foreach my $type (@mailings) {
                   10736:             foreach my $item (@contacts) {
                   10737:                 if (ref($currsetting{$type}) eq 'HASH') {
                   10738:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   10739:                         push(@{$changes{$type}},$item);
                   10740:                     }
                   10741:                 } else {
                   10742:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   10743:                 }
                   10744:             }
                   10745:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   10746:                 push(@{$changes{$type}},'others');
                   10747:             }
1.160.6.78  raeburn  10748:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10749:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   10750:                     push(@{$changes{$type}},'bcc'); 
                   10751:                 }
1.160.6.78  raeburn  10752:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   10753:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   10754:                     push(@{$changes{$type}},'include');
                   10755:                 }
                   10756:             }
                   10757:         }
                   10758:         if (ref($fields) eq 'ARRAY') {
                   10759:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   10760:                 foreach my $field (@{$fields}) {
                   10761:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   10762:                         push(@{$changes{'helpform'}},$field);
                   10763:                     }
                   10764:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10765:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   10766:                             push(@{$changes{'helpform'}},'maxsize');
                   10767:                         }
                   10768:                     }
                   10769:                 }
                   10770:             } else {
                   10771:                 foreach my $field (@{$fields}) {
                   10772:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   10773:                         push(@{$changes{'helpform'}},$field);
                   10774:                     }
                   10775:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10776:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   10777:                             push(@{$changes{'helpform'}},'maxsize');
                   10778:                         }
                   10779:                     }
                   10780:                 }
1.134     raeburn  10781:             }
1.28      raeburn  10782:         }
1.160.6.101  raeburn  10783:         if (@statuses) {
                   10784:             if (ref($currsetting{'overrides'}) eq 'HASH') {
                   10785:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   10786:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   10787:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   10788:                             foreach my $item (@contacts,'bcc','others','include') {
                   10789:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
                   10790:                                     push(@{$changes{'overrides'}},$key);
                   10791:                                     last;
                   10792:                                 }
                   10793:                             }
                   10794:                         } else {
                   10795:                             push(@{$changes{'overrides'}},$key);
                   10796:                         }
                   10797:                     }
                   10798:                 }
                   10799:                 foreach my $key (@overrides) {
                   10800:                     unless (exists($currsetting{'overrides'}{$key})) {
                   10801:                         push(@{$changes{'overrides'}},$key);
                   10802:                     }
                   10803:                 }
                   10804:             } else {
                   10805:                 foreach my $key (@overrides) {
                   10806:                     push(@{$changes{'overrides'}},$key);
                   10807:                 }
                   10808:             }
                   10809:         }
1.160.6.107  raeburn  10810:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   10811:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   10812:                 if ($key eq 'excluded') {
                   10813:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   10814:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   10815:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   10816:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   10817:                             my @diffs =
                   10818:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   10819:                                                                    $currsetting{'lonstatus'}{$key});
                   10820:                             if (@diffs) {
                   10821:                                 push(@{$changes{'lonstatus'}},$key);
                   10822:                             }
                   10823:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   10824:                             push(@{$changes{'lonstatus'}},$key);
                   10825:                         }
                   10826:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   10827:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   10828:                         push(@{$changes{'lonstatus'}},$key);
                   10829:                     }
                   10830:                 } elsif ($key eq 'weights') {
                   10831:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   10832:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   10833:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                   10834:                             foreach my $type ('E','W','N','U') {
                   10835:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   10836:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   10837:                                     push(@{$changes{'lonstatus'}},$key);
                   10838:                                     last;
                   10839:                                 }
                   10840:                             }
                   10841:                         } else {
                   10842:                             foreach my $type ('E','W','N','U') {
                   10843:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   10844:                                     push(@{$changes{'lonstatus'}},$key);
                   10845:                                     last;
                   10846:                                 }
                   10847:                             }
                   10848:                         }
                   10849:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                   10850:                         foreach my $type ('E','W','N','U') {
                   10851:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   10852:                                 push(@{$changes{'lonstatus'}},$key);
                   10853:                                 last;
                   10854:                             }
                   10855:                         }
                   10856:                     }
                   10857:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   10858:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   10859:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   10860:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   10861:                                 push(@{$changes{'lonstatus'}},$key);
                   10862:                             }
                   10863:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   10864:                             push(@{$changes{'lonstatus'}},$key);
                   10865:                         }
                   10866:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   10867:                         push(@{$changes{'lonstatus'}},$key);
                   10868:                     }
                   10869:                 }
                   10870:             }
                   10871:         } else {
                   10872:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   10873:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   10874:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   10875:                         push(@{$changes{'lonstatus'}},$key);
                   10876:                     }
                   10877:                 }
                   10878:             }
                   10879:         }
1.28      raeburn  10880:     } else {
                   10881:         my %default;
                   10882:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   10883:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   10884:         $default{'errormail'} = 'adminemail';
                   10885:         $default{'packagesmail'} = 'adminemail';
                   10886:         $default{'helpdeskmail'} = 'supportemail';
1.160.6.78  raeburn  10887:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  10888:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  10889:         $default{'requestsmail'} = 'adminemail';
1.160.6.15  raeburn  10890:         $default{'updatesmail'} = 'adminemail';
1.160.6.91  raeburn  10891:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  10892:         foreach my $item (@contacts) {
                   10893:            if ($to{$item} ne $default{$item}) {
1.160.6.78  raeburn  10894:                $changes{$item} = 1;
1.160.6.23  raeburn  10895:            }
1.28      raeburn  10896:         }
                   10897:         foreach my $type (@mailings) {
                   10898:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   10899:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   10900:             }
                   10901:             if ($others{$type} ne '') {
                   10902:                 push(@{$changes{$type}},'others');
1.134     raeburn  10903:             }
1.160.6.78  raeburn  10904:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10905:                 if ($bcc{$type} ne '') {
                   10906:                     push(@{$changes{$type}},'bcc');
                   10907:                 }
1.160.6.78  raeburn  10908:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   10909:                     push(@{$changes{$type}},'include');
                   10910:                 }
                   10911:             }
                   10912:         }
                   10913:         if (ref($fields) eq 'ARRAY') {
                   10914:             foreach my $field (@{$fields}) {
                   10915:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   10916:                     push(@{$changes{'helpform'}},$field);
                   10917:                 }
                   10918:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10919:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   10920:                         push(@{$changes{'helpform'}},'maxsize');
                   10921:                     }
                   10922:                 }
1.134     raeburn  10923:             }
1.28      raeburn  10924:         }
1.160.6.107  raeburn  10925:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   10926:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   10927:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   10928:                     push(@{$changes{'lonstatus'}},$key);
                   10929:                 }
                   10930:             }
                   10931:         }
1.28      raeburn  10932:     }
1.160.6.23  raeburn  10933:     foreach my $item (@toggles) {
                   10934:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   10935:             $changes{$item} = 1;
                   10936:         } elsif ((!$env{'form.'.$item}) &&
                   10937:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   10938:             $changes{$item} = 1;
                   10939:         }
                   10940:     }
1.28      raeburn  10941:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   10942:                                              $dom);
                   10943:     if ($putresult eq 'ok') {
                   10944:         if (keys(%changes) > 0) {
1.160.6.24  raeburn  10945:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  10946:             if (ref($lastactref) eq 'HASH') {
                   10947:                 $lastactref->{'domainconfig'} = 1;
                   10948:             }
1.28      raeburn  10949:             my ($titles,$short_titles)  = &contact_titles();
                   10950:             $resulttext = &mt('Changes made:').'<ul>';
                   10951:             foreach my $item (@contacts) {
                   10952:                 if ($changes{$item}) {
                   10953:                     $resulttext .= '<li>'.$titles->{$item}.
                   10954:                                     &mt(' set to: ').
                   10955:                                     '<span class="LC_cusr_emph">'.
                   10956:                                     $to{$item}.'</span></li>';
                   10957:                 }
                   10958:             }
                   10959:             foreach my $type (@mailings) {
                   10960:                 if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78  raeburn  10961:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   10962:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
                   10963:                     } else {
                   10964:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   10965:                     }
1.28      raeburn  10966:                     my @text;
                   10967:                     foreach my $item (@{$newsetting{$type}}) {
                   10968:                         push(@text,$short_titles->{$item});
                   10969:                     }
                   10970:                     if ($others{$type} ne '') {
                   10971:                         push(@text,$others{$type});
                   10972:                     }
1.160.6.78  raeburn  10973:                     if (@text) {
                   10974:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   10975:                                        join(', ',@text).'</span>';
                   10976:                     }
                   10977:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10978:                         if ($bcc{$type} ne '') {
1.160.6.78  raeburn  10979:                             my $bcctext;
                   10980:                             if (@text) {
                   10981:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
                   10982:                             } else {
                   10983:                                 $bcctext = '(Bcc)';
                   10984:                             }
                   10985:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   10986:                         } elsif (!@text) {
                   10987:                             $resulttext .= &mt('No one');
1.134     raeburn  10988:                         }
1.160.6.78  raeburn  10989:                         if ($includestr{$type} ne '') {
                   10990:                             if ($includeloc{$type} eq 'b') {
                   10991:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   10992:                             } elsif ($includeloc{$type} eq 's') {
                   10993:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   10994:                             }
                   10995:                         }
                   10996:                     } elsif (!@text) {
                   10997:                         $resulttext .= &mt('No recipients');
1.134     raeburn  10998:                     }
                   10999:                     $resulttext .= '</li>';
1.28      raeburn  11000:                 }
                   11001:             }
1.160.6.101  raeburn  11002:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   11003:                 my @deletions;
                   11004:                 foreach my $type (@{$changes{'overrides'}}) {
                   11005:                     if ($usertypeshash{$type}) {
                   11006:                         if (grep(/^\Q$type\E/,@overrides)) {
                   11007:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   11008:                                                       $usertypeshash{$type}).'<ul><li>';
                   11009:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   11010:                                 my @text;
                   11011:                                 foreach my $item (@contacts) {
                   11012:                                     if ($newsetting{'override_'.$type}{$item}) {
                   11013:                                         push(@text,$short_titles->{$item});
                   11014:                                     }
                   11015:                                 }
                   11016:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   11017:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   11018:                                 }
                   11019: 
                   11020:                                 if (@text) {
                   11021:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   11022:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   11023:                                 }
                   11024:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   11025:                                     my $bcctext;
                   11026:                                     if (@text) {
                   11027:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   11028:                                     } else {
                   11029:                                         $bcctext = '(Bcc)';
                   11030:                                     }
                   11031:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   11032:                                 } elsif (!@text) {
                   11033:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   11034:                                 }
                   11035:                                 $resulttext .= '</li>';
                   11036:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   11037:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   11038:                                     if ($loc eq 'b') {
                   11039:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   11040:                                     } elsif ($loc eq 's') {
                   11041:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   11042:                                     }
                   11043:                                 }
                   11044:                             }
                   11045:                             $resulttext .= '</li></ul></li>';
                   11046:                         } else {
                   11047:                             push(@deletions,$usertypeshash{$type});
                   11048:                         }
                   11049:                     }
                   11050:                 }
                   11051:                 if (@deletions) {
                   11052:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   11053:                                               join(', ',@deletions)).'</li>';
                   11054:                 }
                   11055:             }
1.160.6.23  raeburn  11056:             my @offon = ('off','on');
1.160.6.107  raeburn  11057:             my $corelink = &core_link_msu();
1.160.6.23  raeburn  11058:             if ($changes{'reporterrors'}) {
                   11059:                 $resulttext .= '<li>'.
                   11060:                                &mt('E-mail error reports to [_1] set to "'.
                   11061:                                    $offon[$env{'form.reporterrors'}].'".',
1.160.6.107  raeburn  11062:                                    $corelink).
1.160.6.23  raeburn  11063:                                '</li>';
                   11064:             }
                   11065:             if ($changes{'reportupdates'}) {
                   11066:                 $resulttext .= '<li>'.
                   11067:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   11068:                                     $offon[$env{'form.reportupdates'}].'".',
1.160.6.107  raeburn  11069:                                     $corelink).
1.160.6.23  raeburn  11070:                                 '</li>';
                   11071:             }
1.160.6.107  raeburn  11072:             if ($changes{'reportstatus'}) {
                   11073:                 $resulttext .= '<li>'.
                   11074:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   11075:                                     $offon[$env{'form.reportstatus'}].'".',
                   11076:                                     $corelink).
                   11077:                                 '</li>';
                   11078:             }
                   11079:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   11080:                 $resulttext .= '<li>'.
                   11081:                                &mt('Nightly status check e-mail settings').':<ul>';
                   11082:                 my (%defval,%use_def,%shown);
                   11083:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   11084:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   11085:                 $defval{'weights'} =
                   11086:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
                   11087:                 $defval{'excluded'} = &mt('None');
                   11088:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   11089:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   11090:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   11091:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   11092:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   11093:                             } elsif ($item eq 'weights') {
                   11094:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
                   11095:                                     foreach my $type ('E','W','N','U') {
                   11096:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   11097:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   11098:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   11099:                                         } else {
                   11100:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   11101:                                         }
                   11102:                                         $shown{$item} .= ', ';
                   11103:                                     }
                   11104:                                     $shown{$item} =~ s/, $//;
                   11105:                                 } else {
                   11106:                                     $shown{$item} = $defval{$item};
                   11107:                                 }
                   11108:                             } elsif ($item eq 'excluded') {
                   11109:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   11110:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   11111:                                 } else {
                   11112:                                     $shown{$item} = $defval{$item};
                   11113:                                 }
                   11114:                             }
                   11115:                         } else {
                   11116:                             $shown{$item} = $defval{$item};
                   11117:                         }
                   11118:                     }
                   11119:                 } else {
                   11120:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   11121:                         $shown{$item} = $defval{$item};
                   11122:                     }
                   11123:                 }
                   11124:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   11125:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   11126:                                           $shown{$item}).'</li>';
                   11127:                 }
                   11128:                 $resulttext .= '</ul></li>';
                   11129:             }
1.160.6.78  raeburn  11130:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   11131:                 my (@optional,@required,@unused,$maxsizechg);
                   11132:                 foreach my $field (@{$changes{'helpform'}}) {
                   11133:                     if ($field eq 'maxsize') {
                   11134:                         $maxsizechg = 1;
                   11135:                         next;
                   11136:                     }
                   11137:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                   11138:                         push(@optional,$field);
                   11139:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   11140:                         push(@unused,$field);
                   11141:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                   11142:                         push(@required,$field);
                   11143:                     }
                   11144:                 }
                   11145:                 if (@optional) {
                   11146:                     $resulttext .= '<li>'.
                   11147:                                    &mt('Help form fields changed to "Optional": [_1].',
                   11148:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   11149:                                    '</li>';
                   11150:                 }
                   11151:                 if (@required) {
                   11152:                     $resulttext .= '<li>'.
                   11153:                                    &mt('Help form fields changed to "Required": [_1].',
                   11154:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   11155:                                    '</li>';
                   11156:                 }
                   11157:                 if (@unused) {
                   11158:                     $resulttext .= '<li>'.
                   11159:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   11160:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   11161:                                    '</li>';
                   11162:                 }
                   11163:                 if ($maxsizechg) {
                   11164:                     $resulttext .= '<li>'.
                   11165:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   11166:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   11167:                                    '</li>';
                   11168:                 }
                   11169:             }
1.28      raeburn  11170:             $resulttext .= '</ul>';
                   11171:         } else {
1.160.6.78  raeburn  11172:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  11173:         }
                   11174:     } else {
                   11175:         $resulttext = '<span class="LC_error">'.
                   11176:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   11177:     }
                   11178:     return $resulttext;
                   11179: }
                   11180: 
1.160.6.98  raeburn  11181: sub modify_passwords {
                   11182:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
                   11183:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   11184:         $updatedefaults,$updateconf);
                   11185:     my $customfn = 'resetpw.html';
                   11186:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   11187:         %current = %{$domconfig{'passwords'}};
                   11188:     }
                   11189:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   11190:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   11191:     if (ref($types) eq 'ARRAY') {
                   11192:         @oktypes = @{$types};
                   11193:     }
                   11194:     push(@oktypes,'default');
                   11195: 
                   11196:     my %titles = &Apache::lonlocal::texthash (
                   11197:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   11198:         intauth_check  => 'Check bcrypt cost if authenticated',
                   11199:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   11200:         permanent      => 'Permanent e-mail address',
                   11201:         critical       => 'Critical notification address',
                   11202:         notify         => 'Notification address',
                   11203:         min            => 'Minimum password length',
                   11204:         max            => 'Maximum password length',
                   11205:         chars          => 'Required characters',
                   11206:         numsaved       => 'Number of previous passwords to save',
                   11207:         reset          => 'Resetting Forgotten Password',
                   11208:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   11209:         rules          => 'Rules for LON-CAPA Passwords',
                   11210:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   11211:         username       => 'Username',
                   11212:         email          => 'E-mail address',
                   11213:     );
                   11214: 
                   11215: #
                   11216: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   11217: #
                   11218:     my (%curr_defaults,%save_defaults);
                   11219:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   11220:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   11221:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   11222:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   11223:             } else {
                   11224:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   11225:             }
                   11226:         }
                   11227:     }
                   11228:     my %staticdefaults = (
                   11229:         'resetlink'      => 2,
                   11230:         'resetcase'      => \@oktypes,
                   11231:         'resetprelink'   => 'both',
                   11232:         'resetemail'     => ['critical','notify','permanent'],
                   11233:         'intauth_cost'   => 10,
                   11234:         'intauth_check'  => 0,
                   11235:         'intauth_switch' => 0,
                   11236:     );
1.160.6.99  raeburn  11237:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  11238:     foreach my $type (@oktypes) {
                   11239:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   11240:     }
                   11241:     my $linklife = $env{'form.passwords_link'};
                   11242:     $linklife =~ s/^\s+|\s+$//g;
                   11243:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   11244:         $newvalues{'resetlink'} = $linklife;
                   11245:         if ($current{'resetlink'}) {
                   11246:             if ($current{'resetlink'} ne $linklife) {
                   11247:                 $changes{'reset'} = 1;
                   11248:             }
1.160.6.102  raeburn  11249:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  11250:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   11251:                 $changes{'reset'} = 1;
                   11252:             }
                   11253:         }
                   11254:     } elsif ($current{'resetlink'}) {
                   11255:         $changes{'reset'} = 1;
                   11256:     }
                   11257:     my @casesens;
                   11258:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   11259:     foreach my $case (sort(@posscase)) {
                   11260:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   11261:             push(@casesens,$case);
                   11262:         }
                   11263:     }
                   11264:     $newvalues{'resetcase'} = \@casesens;
                   11265:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   11266:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   11267:         if (@diffs > 0) {
                   11268:             $changes{'reset'} = 1;
                   11269:         }
1.160.6.102  raeburn  11270:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  11271:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   11272:         if (@diffs > 0) {
                   11273:             $changes{'reset'} = 1;
                   11274:         }
                   11275:     }
                   11276:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   11277:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   11278:         if (exists($current{'resetprelink'})) {
                   11279:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   11280:                 $changes{'reset'} = 1;
                   11281:             }
1.160.6.102  raeburn  11282:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  11283:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   11284:                 $changes{'reset'} = 1;
                   11285:             }
                   11286:         }
                   11287:     } elsif ($current{'resetprelink'}) {
                   11288:         $changes{'reset'} = 1;
                   11289:     }
                   11290:     foreach my $type (@oktypes) {
                   11291:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   11292:         my @postlink;
                   11293:         foreach my $item (sort(@possplink)) {
                   11294:             if ($item =~ /^(email|username)$/) {
                   11295:                 push(@postlink,$item);
                   11296:             }
                   11297:         }
                   11298:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   11299:         unless ($changes{'reset'}) {
                   11300:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   11301:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   11302:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   11303:                     if (@diffs > 0) {
                   11304:                         $changes{'reset'} = 1;
                   11305:                     }
                   11306:                 } else {
                   11307:                     $changes{'reset'} = 1;
                   11308:                 }
1.160.6.102  raeburn  11309:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  11310:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   11311:                 if (@diffs > 0) {
                   11312:                     $changes{'reset'} = 1;
                   11313:                 }
                   11314:             }
                   11315:         }
                   11316:     }
                   11317:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   11318:     my @resetemail;
                   11319:     foreach my $item (sort(@possemailsrc)) {
                   11320:         if ($item =~ /^(permanent|critical|notify)$/) {
                   11321:             push(@resetemail,$item);
                   11322:         }
                   11323:     }
                   11324:     $newvalues{'resetemail'} = \@resetemail;
                   11325:     unless ($changes{'reset'}) {
                   11326:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   11327:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   11328:             if (@diffs > 0) {
                   11329:                 $changes{'reset'} = 1;
                   11330:             }
1.160.6.102  raeburn  11331:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  11332:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   11333:             if (@diffs > 0) {
                   11334:                 $changes{'reset'} = 1;
                   11335:             }
                   11336:         }
                   11337:     }
                   11338:     if ($env{'form.passwords_stdtext'} == 0) {
                   11339:         $newvalues{'resetremove'} = 1;
                   11340:         unless ($current{'resetremove'}) {
                   11341:             $changes{'reset'} = 1;
                   11342:         }
                   11343:     } elsif ($current{'resetremove'}) {
                   11344:         $changes{'reset'} = 1;
                   11345:     }
                   11346:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   11347:         my $servadm = $r->dir_config('lonAdmEMail');
                   11348:         my $servadm = $r->dir_config('lonAdmEMail');
                   11349:         my ($configuserok,$author_ok,$switchserver) =
                   11350:             &config_check($dom,$confname,$servadm);
                   11351:         my $error;
                   11352:         if ($configuserok eq 'ok') {
                   11353:             if ($switchserver) {
                   11354:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   11355:             } else {
                   11356:                 if ($author_ok eq 'ok') {
                   11357:                     my ($result,$customurl) =
                   11358:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   11359:                                      $confname,'customtext/resetpw','','',$customfn);
                   11360:                     if ($result eq 'ok') {
                   11361:                         $newvalues{'resetcustom'} = $customurl;
                   11362:                         $changes{'reset'} = 1;
                   11363:                     } else {
                   11364:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   11365:                     }
                   11366:                 } else {
                   11367:                     $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);
                   11368:                 }
                   11369:             }
                   11370:         } else {
                   11371:             $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);
                   11372:         }
                   11373:         if ($error) {
                   11374:             &Apache::lonnet::logthis($error);
                   11375:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11376:         }
                   11377:     } elsif ($current{'resetcustom'}) {
                   11378:         if ($env{'form.passwords_custom_del'}) {
                   11379:             $changes{'reset'} = 1;
                   11380:         } else {
                   11381:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   11382:         }
                   11383:     }
                   11384:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   11385:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   11386:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   11387:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   11388:             $changes{'intauth'} = 1;
                   11389:         }
                   11390:     } else {
                   11391:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   11392:     }
                   11393:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   11394:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   11395:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   11396:             $changes{'intauth'} = 1;
                   11397:         }
                   11398:     } else {
                   11399:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   11400:     }
                   11401:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   11402:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   11403:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   11404:             $changes{'intauth'} = 1;
                   11405:         }
                   11406:     } else {
                   11407:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   11408:     }
                   11409:     foreach my $item ('cost','check','switch') {
                   11410:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   11411:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   11412:             $updatedefaults = 1;
                   11413:         }
                   11414:     }
                   11415:     foreach my $rule ('min','max','numsaved') {
                   11416:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99  raeburn  11417:         my $ruleok;
                   11418:         if ($rule eq 'min') {
                   11419:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   11420:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   11421:                     $ruleok = 1;
                   11422:                 }
                   11423:             }
                   11424:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   11425:                  ($env{'form.passwords_'.$rule} ne '0')) {
                   11426:             $ruleok = 1;
                   11427:         }
                   11428:         if ($ruleok) {
1.160.6.98  raeburn  11429:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   11430:             if (exists($current{$rule})) {
                   11431:                 if ($newvalues{$rule} ne $current{$rule}) {
                   11432:                     $changes{'rules'} = 1;
                   11433:                 }
                   11434:             } elsif ($rule eq 'min') {
                   11435:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   11436:                     $changes{'rules'} = 1;
                   11437:                 }
1.160.6.104  raeburn  11438:             } else {
                   11439:                 $changes{'rules'} = 1;
1.160.6.98  raeburn  11440:             }
                   11441:         } elsif (exists($current{$rule})) {
                   11442:             $changes{'rules'} = 1;
                   11443:         }
                   11444:     }
                   11445:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   11446:     my @chars;
                   11447:     foreach my $item (sort(@posschars)) {
                   11448:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   11449:             push(@chars,$item);
                   11450:         }
                   11451:     }
                   11452:     $newvalues{'chars'} = \@chars;
                   11453:     unless ($changes{'rules'}) {
                   11454:         if (ref($current{'chars'}) eq 'ARRAY') {
                   11455:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   11456:             if (@diffs > 0) {
                   11457:                 $changes{'rules'} = 1;
                   11458:             }
                   11459:         } else {
                   11460:             if (@chars > 0) {
                   11461:                 $changes{'rules'} = 1;
                   11462:             }
                   11463:         }
                   11464:     }
                   11465:     my %crsownerchg = (
                   11466:                         by => [],
                   11467:                         for => [],
                   11468:                       );
                   11469:     foreach my $item ('by','for') {
                   11470:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   11471:         foreach my $type (sort(@posstypes)) {
                   11472:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   11473:                 push(@{$crsownerchg{$item}},$type);
                   11474:             }
                   11475:         }
                   11476:     }
                   11477:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   11478:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   11479:         foreach my $item ('by','for') {
                   11480:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   11481:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   11482:                 if (@diffs > 0) {
                   11483:                     $changes{'crsownerchg'} = 1;
                   11484:                     last;
                   11485:                 }
                   11486:             }
                   11487:         }
1.160.6.102  raeburn  11488:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98  raeburn  11489:         foreach my $item ('by','for') {
                   11490:             if (@{$crsownerchg{$item}} > 0) {
                   11491:                 $changes{'crsownerchg'} = 1;
                   11492:                 last;
                   11493:             }
                   11494:         }
                   11495:     }
                   11496: 
                   11497:     my %confighash = (
                   11498:                         defaults  => \%save_defaults,
                   11499:                         passwords => \%newvalues,
                   11500:                      );
                   11501:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   11502: 
                   11503:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   11504:     if ($putresult eq 'ok') {
                   11505:         if (keys(%changes) > 0) {
                   11506:             $resulttext = &mt('Changes made: ').'<ul>';
                   11507:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   11508:                 if ($changes{$key}) {
                   11509:                     unless ($key eq 'intauth') {
                   11510:                         $updateconf = 1;
                   11511:                     }
                   11512:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   11513:                     if ($key eq 'reset') {
                   11514:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   11515:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   11516:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   11517:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104  raeburn  11518:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   11519:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   11520:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   11521:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   11522:                             }
1.160.6.98  raeburn  11523:                         } else {
                   11524:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   11525:                         }
                   11526:                         if ($confighash{'passwords'}{'resetlink'}) {
                   11527:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   11528:                         } else {
                   11529:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   11530:                                                   &mt('Will default to 2 hours').'</li>';
                   11531:                         }
                   11532:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   11533:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   11534:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   11535:                             } else {
                   11536:                                 my $casesens;
                   11537:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   11538:                                     if ($type eq 'default') {
                   11539:                                         $casesens .= $othertitle.', ';
                   11540:                                     } elsif ($usertypes->{$type} ne '') {
                   11541:                                         $casesens .= $usertypes->{$type}.', ';
                   11542:                                     }
                   11543:                                 }
                   11544:                                 $casesens =~ s/\Q, \E$//;
                   11545:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   11546:                             }
                   11547:                         } else {
                   11548:                             $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>';
                   11549:                         }
                   11550:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   11551:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   11552:                         } else {
                   11553:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   11554:                         }
                   11555:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   11556:                             my $output;
                   11557:                             if (ref($types) eq 'ARRAY') {
                   11558:                                 foreach my $type (@{$types}) {
                   11559:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   11560:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   11561:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   11562:                                         } else {
                   11563:                                             $output .= $usertypes->{$type}.' -- '.
                   11564:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   11565:                                         }
                   11566:                                     }
                   11567:                                 }
                   11568:                             }
                   11569:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   11570:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   11571:                                     $output .= $othertitle.' -- '.&mt('none');
                   11572:                                 } else {
                   11573:                                     $output .= $othertitle.' -- '.
                   11574:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   11575:                                 }
                   11576:                             }
                   11577:                             if ($output) {
                   11578:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   11579:                             } else {
                   11580:                                 $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>';
                   11581:                             }
                   11582:                         } else {
                   11583:                             $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>';
                   11584:                         }
                   11585:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   11586:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   11587:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   11588:                             } else {
                   11589:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   11590:                             }
                   11591:                         } else {
1.160.6.110  raeburn  11592:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.160.6.98  raeburn  11593:                         }
                   11594:                         if ($confighash{'passwords'}{'resetremove'}) {
                   11595:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   11596:                         } else {
                   11597:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   11598:                         }
                   11599:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   11600:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104  raeburn  11601:                                                                             &mt('custom text'),600,500,undef,undef,
                   11602:                                                                             undef,undef,'background-color:#ffffff');
                   11603:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98  raeburn  11604:                         } else {
                   11605:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   11606:                         }
                   11607:                     } elsif ($key eq 'intauth') {
                   11608:                         foreach my $item ('cost','switch','check') {
                   11609:                             my $value = $save_defaults{$key.'_'.$item};
                   11610:                             if ($item eq 'switch') {
                   11611:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   11612:                                                      0 => 'No',
                   11613:                                                      1 => 'Yes',
                   11614:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   11615:                                                  );
                   11616:                                 if ($value =~ /^(0|1|2)$/) {
                   11617:                                     $value = $optiondesc{$value};
                   11618:                                 } else {
                   11619:                                     $value = &mt('none -- defaults to No');
                   11620:                                 }
                   11621:                             } elsif ($item eq 'check') {
                   11622:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   11623:                                                      0 => 'No',
                   11624:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   11625:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   11626:                                                  );
                   11627:                                 if ($value =~ /^(0|1|2)$/) {
                   11628:                                     $value = $optiondesc{$value};
                   11629:                                 } else {
                   11630:                                     $value = &mt('none -- defaults to No');
                   11631:                                 }
                   11632:                             }
                   11633:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   11634:                         }
                   11635:                     } elsif ($key eq 'rules') {
                   11636:                         foreach my $rule ('min','max','numsaved') {
                   11637:                             if ($confighash{'passwords'}{$rule} eq '') {
                   11638:                                 if ($rule eq 'min') {
                   11639:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99  raeburn  11640:                                                    ' '.&mt('Default of [_1] will be used',
                   11641:                                                            $Apache::lonnet::passwdmin).'</li>';
1.160.6.98  raeburn  11642:                                 } else {
                   11643:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   11644:                                 }
                   11645:                             } else {
                   11646:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   11647:                             }
                   11648:                         }
1.160.6.104  raeburn  11649:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   11650:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   11651:                                 my %rulenames = &Apache::lonlocal::texthash(
                   11652:                                                      uc => 'At least one upper case letter',
                   11653:                                                      lc => 'At least one lower case letter',
                   11654:                                                      num => 'At least one number',
                   11655:                                                      spec => 'At least one non-alphanumeric',
                   11656:                                                    );
                   11657:                                 my $needed = '<ul><li>'.
                   11658:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   11659:                                              '</li></ul>';
                   11660:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   11661:                             } else {
                   11662:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   11663:                             }
                   11664:                         } else {
                   11665:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   11666:                         }
1.160.6.98  raeburn  11667:                     } elsif ($key eq 'crsownerchg') {
                   11668:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   11669:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   11670:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   11671:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   11672:                             } else {
                   11673:                                 my %crsownerstr;
                   11674:                                 foreach my $item ('by','for') {
                   11675:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   11676:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   11677:                                             if ($type eq 'default') {
                   11678:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   11679:                                             } elsif ($usertypes->{$type} ne '') {
                   11680:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   11681:                                             }
                   11682:                                         }
                   11683:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   11684:                                     }
                   11685:                                 }
                   11686:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   11687:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   11688:                             }
                   11689:                         } else {
                   11690:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   11691:                         }
                   11692:                     }
                   11693:                     $resulttext .= '</ul></li>';
                   11694:                 }
                   11695:             }
                   11696:             $resulttext .= '</ul>';
                   11697:         } else {
                   11698:             $resulttext = &mt('No changes made to password settings');
                   11699:         }
                   11700:         my $cachetime = 24*60*60;
                   11701:         if ($updatedefaults) {
                   11702:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   11703:             if (ref($lastactref) eq 'HASH') {
                   11704:                 $lastactref->{'domdefaults'} = 1;
                   11705:             }
                   11706:         }
                   11707:         if ($updateconf) {
                   11708:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   11709:             if (ref($lastactref) eq 'HASH') {
                   11710:                 $lastactref->{'passwdconf'} = 1;
                   11711:             }
                   11712:         }
                   11713:     } else {
                   11714:         $resulttext = '<span class="LC_error">'.
                   11715:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11716:     }
                   11717:     if ($errors) {
                   11718:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   11719:                        $errors.'</ul></p>';
                   11720:     }
                   11721:     return $resulttext;
                   11722: }
                   11723: 
1.28      raeburn  11724: sub modify_usercreation {
1.27      raeburn  11725:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  11726:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  11727:     my $warningmsg;
1.27      raeburn  11728:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   11729:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34  raeburn  11730:             if ($key eq 'cancreate') {
                   11731:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   11732:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93  raeburn  11733:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34  raeburn  11734:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93  raeburn  11735:                         } else {
                   11736:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34  raeburn  11737:                         }
1.50      raeburn  11738:                     }
1.43      raeburn  11739:                 }
1.160.6.34  raeburn  11740:             } elsif ($key eq 'email_rule') {
                   11741:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   11742:             } else {
                   11743:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43      raeburn  11744:             }
                   11745:         }
1.34      raeburn  11746:     }
1.160.6.34  raeburn  11747:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
                   11748:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
                   11749:     my @contexts = ('author','course','requestcrs');
                   11750:     foreach my $item(@contexts) {
                   11751:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  11752:     }
1.34      raeburn  11753:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   11754:         foreach my $item (@contexts) {
1.160.6.34  raeburn  11755:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   11756:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  11757:             }
1.27      raeburn  11758:         }
1.34      raeburn  11759:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   11760:         foreach my $item (@contexts) {
1.43      raeburn  11761:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  11762:                 if ($cancreate{$item} ne 'any') {
                   11763:                     push(@{$changes{'cancreate'}},$item);
                   11764:                 }
                   11765:             } else {
                   11766:                 if ($cancreate{$item} ne 'none') {
                   11767:                     push(@{$changes{'cancreate'}},$item);
                   11768:                 }
1.27      raeburn  11769:             }
                   11770:         }
                   11771:     } else {
1.43      raeburn  11772:         foreach my $item (@contexts)  {
1.34      raeburn  11773:             push(@{$changes{'cancreate'}},$item);
                   11774:         }
1.27      raeburn  11775:     }
1.34      raeburn  11776: 
1.27      raeburn  11777:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   11778:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   11779:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   11780:                 push(@{$changes{'username_rule'}},$type);
                   11781:             }
                   11782:         }
                   11783:         foreach my $type (@username_rule) {
                   11784:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   11785:                 push(@{$changes{'username_rule'}},$type);
                   11786:             }
                   11787:         }
                   11788:     } else {
                   11789:         push(@{$changes{'username_rule'}},@username_rule);
                   11790:     }
                   11791: 
1.32      raeburn  11792:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   11793:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   11794:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   11795:                 push(@{$changes{'id_rule'}},$type);
                   11796:             }
                   11797:         }
                   11798:         foreach my $type (@id_rule) {
                   11799:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   11800:                 push(@{$changes{'id_rule'}},$type);
                   11801:             }
                   11802:         }
                   11803:     } else {
                   11804:         push(@{$changes{'id_rule'}},@id_rule);
                   11805:     }
                   11806: 
1.43      raeburn  11807:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  11808:     my @authtypes = ('int','krb4','krb5','loc');
                   11809:     my %authhash;
1.43      raeburn  11810:     foreach my $item (@authen_contexts) {
1.28      raeburn  11811:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   11812:         foreach my $auth (@authtypes) {
                   11813:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   11814:                 $authhash{$item}{$auth} = 1;
                   11815:             } else {
                   11816:                 $authhash{$item}{$auth} = 0;
                   11817:             }
                   11818:         }
                   11819:     }
                   11820:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  11821:         foreach my $item (@authen_contexts) {
1.28      raeburn  11822:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   11823:                 foreach my $auth (@authtypes) {
                   11824:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   11825:                         push(@{$changes{'authtypes'}},$item);
                   11826:                         last;
                   11827:                     }
                   11828:                 }
                   11829:             }
                   11830:         }
                   11831:     } else {
1.43      raeburn  11832:         foreach my $item (@authen_contexts) {
1.28      raeburn  11833:             push(@{$changes{'authtypes'}},$item);
                   11834:         }
                   11835:     }
                   11836: 
1.160.6.34  raeburn  11837:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   11838:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   11839:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   11840:     $save_usercreate{'id_rule'} = \@id_rule;
                   11841:     $save_usercreate{'username_rule'} = \@username_rule,
                   11842:     $save_usercreate{'authtypes'} = \%authhash;
                   11843: 
1.27      raeburn  11844:     my %usercreation_hash =  (
1.160.6.34  raeburn  11845:         usercreation     => \%save_usercreate,
                   11846:     );
1.27      raeburn  11847: 
                   11848:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   11849:                                              $dom);
1.50      raeburn  11850: 
1.160.6.34  raeburn  11851:     if ($putresult eq 'ok') {
                   11852:         if (keys(%changes) > 0) {
                   11853:             $resulttext = &mt('Changes made:').'<ul>';
                   11854:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   11855:                 my %lt = &usercreation_types();
                   11856:                 foreach my $type (@{$changes{'cancreate'}}) {
                   11857:                     my $chgtext = $lt{$type}.', ';
                   11858:                     if ($cancreate{$type} eq 'none') {
                   11859:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   11860:                     } elsif ($cancreate{$type} eq 'any') {
                   11861:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   11862:                     } elsif ($cancreate{$type} eq 'official') {
                   11863:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   11864:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   11865:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   11866:                     }
                   11867:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   11868:                 }
                   11869:             }
                   11870:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   11871:                 my ($rules,$ruleorder) = 
                   11872:                     &Apache::lonnet::inst_userrules($dom,'username');
                   11873:                 my $chgtext = '<ul>';
                   11874:                 foreach my $type (@username_rule) {
                   11875:                     if (ref($rules->{$type}) eq 'HASH') {
                   11876:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   11877:                     }
                   11878:                 }
                   11879:                 $chgtext .= '</ul>';
                   11880:                 if (@username_rule > 0) {
                   11881:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   11882:                 } else {
                   11883:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   11884:                 }
                   11885:             }
                   11886:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   11887:                 my ($idrules,$idruleorder) = 
                   11888:                     &Apache::lonnet::inst_userrules($dom,'id');
                   11889:                 my $chgtext = '<ul>';
                   11890:                 foreach my $type (@id_rule) {
                   11891:                     if (ref($idrules->{$type}) eq 'HASH') {
                   11892:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   11893:                     }
                   11894:                 }
                   11895:                 $chgtext .= '</ul>';
                   11896:                 if (@id_rule > 0) {
                   11897:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   11898:                 } else {
                   11899:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   11900:                 }
                   11901:             }
                   11902:             my %authname = &authtype_names();
                   11903:             my %context_title = &context_names();
                   11904:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   11905:                 my $chgtext = '<ul>';
                   11906:                 foreach my $type (@{$changes{'authtypes'}}) {
                   11907:                     my @allowed;
                   11908:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   11909:                     foreach my $auth (@authtypes) {
                   11910:                         if ($authhash{$type}{$auth}) {
                   11911:                             push(@allowed,$authname{$auth});
                   11912:                         }
                   11913:                     }
                   11914:                     if (@allowed > 0) {
                   11915:                         $chgtext .= join(', ',@allowed).'</li>';
                   11916:                     } else {
                   11917:                         $chgtext .= &mt('none').'</li>';
                   11918:                     }
                   11919:                 }
                   11920:                 $chgtext .= '</ul>';
                   11921:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   11922:                 $resulttext .= '</li>';
                   11923:             }
                   11924:             $resulttext .= '</ul>';
                   11925:         } else {
                   11926:             $resulttext = &mt('No changes made to user creation settings');
                   11927:         }
                   11928:     } else {
                   11929:         $resulttext = '<span class="LC_error">'.
                   11930:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11931:     }
                   11932:     if ($warningmsg ne '') {
                   11933:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   11934:     }
                   11935:     return $resulttext;
                   11936: }
                   11937: 
                   11938: sub modify_selfcreation {
1.160.6.93  raeburn  11939:     my ($dom,$lastactref,%domconfig) = @_;
                   11940:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   11941:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   11942:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   11943:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   11944:     if (ref($typesref) eq 'ARRAY') {
                   11945:         @types = @{$typesref};
                   11946:     }
                   11947:     if (ref($usertypesref) eq 'HASH') {
                   11948:         %usertypes = %{$usertypesref};
1.160.6.35  raeburn  11949:     }
1.160.6.93  raeburn  11950:     $usertypes{'default'} = $othertitle;
1.160.6.34  raeburn  11951: #
                   11952: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   11953: #
                   11954:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   11955:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   11956:             if ($key eq 'cancreate') {
                   11957:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   11958:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   11959:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93  raeburn  11960:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   11961:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   11962:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   11963:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
                   11964:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34  raeburn  11965:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11966:                         } else {
                   11967:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   11968:                         }
                   11969:                     }
                   11970:                 }
                   11971:             } elsif ($key eq 'email_rule') {
                   11972:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   11973:             } else {
                   11974:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   11975:             }
                   11976:         }
                   11977:     }
                   11978: #
                   11979: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   11980: #
                   11981:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   11982:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   11983:             if ($key eq 'selfcreate') {
                   11984:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   11985:             } else {
                   11986:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   11987:             }
                   11988:         }
                   11989:     }
1.160.6.93  raeburn  11990: #
                   11991: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   11992: #
                   11993:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   11994:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   11995:             if ($key eq 'inststatusguest') {
                   11996:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   11997:             } else {
                   11998:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   11999:             }
                   12000:         }
                   12001:     }
1.160.6.34  raeburn  12002: 
                   12003:     my @contexts = ('selfcreate');
                   12004:     @{$cancreate{'selfcreate'}} = ();
                   12005:     %{$cancreate{'emailusername'}} = ();
1.160.6.93  raeburn  12006:     if (@types) {
                   12007:         @{$cancreate{'statustocreate'}} = ();
                   12008:     }
1.160.6.40  raeburn  12009:     %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44  raeburn  12010:     %{$cancreate{'shibenv'}} = ();
1.160.6.93  raeburn  12011:     %{$cancreate{'emailverified'}} = ();
                   12012:     %{$cancreate{'emailoptions'}} = ();
                   12013:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  12014:     my %selfcreatetypes = (
                   12015:                              sso   => 'users authenticated by institutional single sign on',
                   12016:                              login => 'users authenticated by institutional log-in',
1.160.6.93  raeburn  12017:                              email => 'users verified by e-mail',
1.50      raeburn  12018:                           );
1.160.6.34  raeburn  12019: #
                   12020: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   12021: # is permitted.
                   12022: #
1.160.6.40  raeburn  12023: 
1.160.6.93  raeburn  12024:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40  raeburn  12025: 
1.160.6.93  raeburn  12026:     my (@statuses,%email_rule);
1.160.6.35  raeburn  12027:     foreach my $item ('login','sso','email') {
1.160.6.34  raeburn  12028:         if ($item eq 'email') {
1.160.6.40  raeburn  12029:             if ($env{'form.cancreate_email'}) {
1.160.6.93  raeburn  12030:                 if (@types) {
                   12031:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   12032:                     foreach my $status (@poss_statuses) {
                   12033:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   12034:                             push(@statuses,$status);
                   12035:                         }
                   12036:                     }
                   12037:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   12038:                 } else {
                   12039:                     push(@statuses,'default');
                   12040:                 }
                   12041:                 if (@statuses) {
                   12042:                     my %curr_rule;
                   12043:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   12044:                         foreach my $type (@statuses) {
                   12045:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
                   12046:                         }
                   12047:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   12048:                         foreach my $type (@statuses) {
                   12049:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   12050:                         }
                   12051:                     }
                   12052:                     push(@{$cancreate{'selfcreate'}},'email');
                   12053:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   12054:                     my %curremaildom;
                   12055:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   12056:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   12057:                     }
                   12058:                     foreach my $type (@statuses) {
                   12059:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   12060:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   12061:                         }
                   12062:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   12063:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   12064:                         }
                   12065:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   12066: #
                   12067: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   12068: #
                   12069:                             my $chosen = $1;
                   12070:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   12071:                                 my $emaildom;
                   12072:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   12073:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
                   12074:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   12075:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   12076:                                         if (exists($curremaildom{$type}{$chosen})) {
                   12077:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   12078:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   12079:                                             }
                   12080:                                         } elsif ($emaildom ne '') {
                   12081:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   12082:                                         }
                   12083:                                     } elsif ($emaildom ne '') {
                   12084:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   12085:                                     }
                   12086:                                 }
                   12087:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   12088:                             } elsif ($chosen eq 'custom') {
                   12089:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   12090:                                 $email_rule{$type} = [];
                   12091:                                 if (ref($emailrules) eq 'HASH') {
                   12092:                                     foreach my $rule (@possemail_rules) {
                   12093:                                         if (exists($emailrules->{$rule})) {
                   12094:                                             push(@{$email_rule{$type}},$rule);
                   12095:                                         }
                   12096:                                     }
                   12097:                                 }
                   12098:                                 if (@{$email_rule{$type}}) {
                   12099:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   12100:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   12101:                                         if (@{$curr_rule{$type}} > 0) {
                   12102:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   12103:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   12104:                                                     push(@{$changes{'email_rule'}},$type);
                   12105:                                                 }
                   12106:                                             }
                   12107:                                         }
                   12108:                                         foreach my $type (@{$email_rule{$type}}) {
                   12109:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   12110:                                                 push(@{$changes{'email_rule'}},$type);
                   12111:                                             }
                   12112:                                         }
                   12113:                                     } else {
                   12114:                                         push(@{$changes{'email_rule'}},$type);
                   12115:                                     }
                   12116:                                 }
                   12117:                             } else {
                   12118:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   12119:                             }
                   12120:                         }
                   12121:                     }
                   12122:                     if (@types) {
                   12123:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12124:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   12125:                             if (@changed) {
                   12126:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   12127:                             }
                   12128:                         } else {
                   12129:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12130:                         }
                   12131:                     }
                   12132:                 } else {
                   12133:                     delete($env{'form.cancreate_email'});
                   12134:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12135:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   12136:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12137:                         }
                   12138:                     }
                   12139:                 }
                   12140:             } else {
                   12141:                 $save_inststatus{'inststatusguest'} = [];
                   12142:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12143:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   12144:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40  raeburn  12145:                     }
                   12146:                 }
1.160.6.34  raeburn  12147:             }
                   12148:         } else {
                   12149:             if ($env{'form.cancreate_'.$item}) {
                   12150:                 push(@{$cancreate{'selfcreate'}},$item);
                   12151:             }
                   12152:         }
                   12153:     }
1.160.6.93  raeburn  12154:     my (%userinfo,%savecaptcha);
1.160.6.34  raeburn  12155:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   12156: #
1.160.6.35  raeburn  12157: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   12158: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34  raeburn  12159: #
1.160.6.40  raeburn  12160: 
1.160.6.48  raeburn  12161:     if ($env{'form.cancreate_email'}) {
1.160.6.37  raeburn  12162:         push(@contexts,'emailusername');
1.160.6.93  raeburn  12163:         if (@statuses) {
                   12164:             foreach my $type (@statuses) {
1.160.6.35  raeburn  12165:                 if (ref($infofields) eq 'ARRAY') {
                   12166:                     foreach my $field (@{$infofields}) {
                   12167:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   12168:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   12169:                         }
                   12170:                     }
1.160.6.34  raeburn  12171:                 }
                   12172:             }
                   12173:         }
                   12174: #
                   12175: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93  raeburn  12176: # queued requests for self-creation of account verified by e-mail.
1.160.6.34  raeburn  12177: #
                   12178: 
                   12179:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   12180:         @approvalnotify = sort(@approvalnotify);
                   12181:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   12182:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   12183:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   12184:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   12185:                     push(@{$changes{'cancreate'}},'notify');
                   12186:                 }
                   12187:             } else {
                   12188:                 if ($cancreate{'notify'}{'approval'}) {
                   12189:                     push(@{$changes{'cancreate'}},'notify');
                   12190:                 }
                   12191:             }
                   12192:         } elsif ($cancreate{'notify'}{'approval'}) {
                   12193:             push(@{$changes{'cancreate'}},'notify');
                   12194:         }
                   12195: 
                   12196:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   12197:     }
                   12198: #  
1.160.6.40  raeburn  12199: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34  raeburn  12200: # institutional log-in.
                   12201: #
                   12202:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   12203:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   12204:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   12205:             $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.').' '.
                   12206:                           &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.');
                   12207:         }
                   12208:     }
                   12209:     my @fields = ('lastname','firstname','middlename','generation',
                   12210:                   'permanentemail','id');
1.160.6.44  raeburn  12211:     my @shibfields = (@fields,'inststatus');
1.160.6.34  raeburn  12212:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12213: #
                   12214: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   12215: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   12216: # may self-create accounts 
                   12217: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   12218: # which the user may supply, if institutional data is unavailable.
                   12219: #
                   12220:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93  raeburn  12221:         if (@types) {
                   12222:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   12223:             push(@contexts,'statustocreate');
                   12224:             foreach my $type (@types) {
1.160.6.34  raeburn  12225:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   12226:                 foreach my $field (@fields) {
                   12227:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   12228:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   12229:                     } else {
                   12230:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   12231:                     }
                   12232:                 }
                   12233:             }
                   12234:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93  raeburn  12235:                 foreach my $type (@types) {
1.160.6.34  raeburn  12236:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   12237:                         foreach my $field (@fields) {
                   12238:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   12239:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   12240:                                 push(@{$changes{'selfcreate'}},$type);
                   12241:                                 last;
                   12242:                             }
                   12243:                         }
                   12244:                     }
                   12245:                 }
                   12246:             } else {
1.160.6.93  raeburn  12247:                 foreach my $type (@types) {
1.160.6.34  raeburn  12248:                     push(@{$changes{'selfcreate'}},$type);
                   12249:                 }
                   12250:             }
                   12251:         }
1.160.6.44  raeburn  12252:         foreach my $field (@shibfields) {
                   12253:             if ($env{'form.shibenv_'.$field} ne '') {
                   12254:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   12255:             }
                   12256:         }
                   12257:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   12258:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   12259:                 foreach my $field (@shibfields) {
                   12260:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   12261:                         push(@{$changes{'cancreate'}},'shibenv');
                   12262:                     }
                   12263:                 }
                   12264:             } else {
                   12265:                 foreach my $field (@shibfields) {
                   12266:                     if ($env{'form.shibenv_'.$field}) {
                   12267:                         push(@{$changes{'cancreate'}},'shibenv');
                   12268:                         last;
                   12269:                     }
                   12270:                 }
                   12271:             }
                   12272:         }
1.160.6.34  raeburn  12273:     }
                   12274:     foreach my $item (@contexts) {
                   12275:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   12276:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   12277:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   12278:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   12279:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12280:                             push(@{$changes{'cancreate'}},$item);
                   12281:                         }
                   12282:                     }
                   12283:                 }
                   12284:             }
                   12285:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   12286:                 foreach my $type (@{$cancreate{$item}}) {
                   12287:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   12288:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12289:                             push(@{$changes{'cancreate'}},$item);
                   12290:                         }
                   12291:                     }
                   12292:                 }
                   12293:             }
                   12294:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   12295:             if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93  raeburn  12296:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   12297:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   12298:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   12299:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  12300:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12301:                                     push(@{$changes{'cancreate'}},$item);
                   12302:                                 }
                   12303:                             }
                   12304:                         }
1.160.6.93  raeburn  12305:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12306:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  12307:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12308:                                 push(@{$changes{'cancreate'}},$item);
                   12309:                             }
1.160.6.34  raeburn  12310:                         }
                   12311:                     }
                   12312:                 }
1.160.6.93  raeburn  12313:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   12314:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   12315:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   12316:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   12317:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  12318:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12319:                                         push(@{$changes{'cancreate'}},$item);
                   12320:                                     }
                   12321:                                 }
                   12322:                             } else {
                   12323:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12324:                                     push(@{$changes{'cancreate'}},$item);
                   12325:                                 }
                   12326:                             }
                   12327:                         }
1.160.6.93  raeburn  12328:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12329:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  12330:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12331:                                 push(@{$changes{'cancreate'}},$item);
                   12332:                             }
1.160.6.34  raeburn  12333:                         }
                   12334:                     }
                   12335:                 }
                   12336:             }
                   12337:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   12338:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   12339:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   12340:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12341:                         push(@{$changes{'cancreate'}},$item);
                   12342:                     }
                   12343:                 }
1.160.6.93  raeburn  12344:             }
                   12345:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   12346:             if (ref($cancreate{$item}) eq 'HASH') {
                   12347:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12348:                     push(@{$changes{'cancreate'}},$item);
1.160.6.34  raeburn  12349:                 }
                   12350:             }
                   12351:         } elsif ($item eq 'emailusername') {
1.160.6.35  raeburn  12352:             if (ref($cancreate{$item}) eq 'HASH') {
                   12353:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   12354:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   12355:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   12356:                             if ($cancreate{$item}{$type}{$field}) {
                   12357:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   12358:                                     push(@{$changes{'cancreate'}},$item);
                   12359:                                 }
                   12360:                                 last;
                   12361:                             }
                   12362:                         }
                   12363:                     }
                   12364:                 }
1.160.6.34  raeburn  12365:             }
                   12366:         }
                   12367:     }
                   12368: #
                   12369: # Populate %save_usercreate hash with updates to self-creation configuration.
                   12370: #
                   12371:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   12372:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69  raeburn  12373:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34  raeburn  12374:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   12375:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   12376:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   12377:     }
1.160.6.40  raeburn  12378:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   12379:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   12380:     }
1.160.6.93  raeburn  12381:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   12382:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   12383:     }
                   12384:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   12385:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   12386:     }
                   12387:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   12388:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   12389:     }
1.160.6.34  raeburn  12390:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   12391:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   12392:     }
1.160.6.44  raeburn  12393:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   12394:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   12395:     }
1.160.6.34  raeburn  12396:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93  raeburn  12397:     $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34  raeburn  12398: 
                   12399:     my %userconfig_hash = (
                   12400:             usercreation     => \%save_usercreate,
                   12401:             usermodification => \%save_usermodify,
1.160.6.93  raeburn  12402:             inststatus       => \%save_inststatus,
1.160.6.34  raeburn  12403:     );
1.160.6.93  raeburn  12404: 
1.160.6.34  raeburn  12405:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   12406:                                              $dom);
                   12407: #
1.160.6.93  raeburn  12408: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34  raeburn  12409: #
1.27      raeburn  12410:     if ($putresult eq 'ok') {
                   12411:         if (keys(%changes) > 0) {
                   12412:             $resulttext = &mt('Changes made:').'<ul>';
                   12413:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34  raeburn  12414:                 my %lt = &selfcreation_types();
1.34      raeburn  12415:                 foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93  raeburn  12416:                     my $chgtext = '';
1.45      raeburn  12417:                     if ($type eq 'selfcreate') {
1.50      raeburn  12418:                         if (@{$cancreate{$type}} == 0) {
1.160.6.34  raeburn  12419:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  12420:                         } else {
1.160.6.34  raeburn  12421:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   12422:                                         '<ul>';
1.50      raeburn  12423:                             foreach my $case (@{$cancreate{$type}}) {
                   12424:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   12425:                             }
                   12426:                             $chgtext .= '</ul>';
1.100     raeburn  12427:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   12428:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   12429:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   12430:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93  raeburn  12431:                                             $chgtext .= '<span class="LC_warning">'.
                   12432:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   12433:                                                         '</span><br />';
1.100     raeburn  12434:                                         }
                   12435:                                     }
                   12436:                                 }
1.160.6.93  raeburn  12437:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
                   12438:                                     if (!@statuses) {
                   12439:                                         $chgtext .= '<span class="LC_warning">'.
                   12440:                                                     &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.").
                   12441:                                                     '</span><br />';
                   12442: 
                   12443:                                     }
                   12444:                                 }
1.100     raeburn  12445:                             }
1.43      raeburn  12446:                         }
1.160.6.44  raeburn  12447:                     } elsif ($type eq 'shibenv') {
                   12448:                         if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93  raeburn  12449:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.160.6.44  raeburn  12450:                         } else {
                   12451:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   12452:                                         '<ul>';
                   12453:                             foreach my $field (@shibfields) {
                   12454:                                 next if ($cancreate{$type}{$field} eq '');
                   12455:                                 if ($field eq 'inststatus') {
                   12456:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   12457:                                 } else {
                   12458:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   12459:                                 }
                   12460:                             }
                   12461:                             $chgtext .= '</ul>';
1.160.6.93  raeburn  12462:                         }
1.93      raeburn  12463:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  12464:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   12465:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   12466:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   12467:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  12468:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  12469:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  12470:                                         $chgtext .= '<br />'.
                   12471:                                                     '<span class="LC_warning">'.
                   12472:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   12473:                                                     '</span>';
                   12474:                                     }
1.160.6.93  raeburn  12475:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  12476:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  12477:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   12478:                                     } else {
                   12479:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   12480:                                     }
                   12481:                                     $chgtext .= '<ul>';
                   12482:                                     foreach my $case (@{$cancreate{$type}}) {
                   12483:                                         if ($case eq 'default') {
                   12484:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   12485:                                         } else {
1.160.6.93  raeburn  12486:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  12487:                                         }
                   12488:                                     }
1.100     raeburn  12489:                                     $chgtext .= '</ul>';
                   12490:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93  raeburn  12491:                                         $chgtext .= '<span class="LC_warning">'.
1.160.6.34  raeburn  12492:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   12493:                                                     '</span>';
1.100     raeburn  12494:                                     }
                   12495:                                 }
                   12496:                             } else {
                   12497:                                 if (@{$cancreate{$type}} == 0) {
                   12498:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   12499:                                 } else {
                   12500:                                     $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  12501:                                 }
                   12502:                             }
1.160.6.93  raeburn  12503:                             $chgtext .= '<br />';
1.93      raeburn  12504:                         }
1.160.6.40  raeburn  12505:                     } elsif ($type eq 'selfcreateprocessing') {
                   12506:                         my %choices = &Apache::lonlocal::texthash (
                   12507:                                                                     automatic => 'Automatic approval',
                   12508:                                                                     approval  => 'Queued for approval',
                   12509:                                                                   );
1.160.6.93  raeburn  12510:                         if (@types) {
                   12511:                             if (@statuses) {
                   12512:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
                   12513:                                             '<ul>';
                   12514:                                 foreach my $status (@statuses) {
                   12515:                                     if ($status eq 'default') {
                   12516:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   12517:                                     } else {
                   12518:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   12519:                                     }
                   12520:                                 }
                   12521:                                 $chgtext .= '</ul>';
                   12522:                             }
                   12523:                         } else {
                   12524:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   12525:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   12526:                         }
                   12527:                     } elsif ($type eq 'emailverified') {
                   12528:                         my %options = &Apache::lonlocal::texthash (
                   12529:                                                                     all   => 'Same as e-mail',
                   12530:                                                                     first => 'Omit @domain',
                   12531:                                                                     free  => 'Free to choose',
                   12532:                                                                   );
                   12533:                         if (@types) {
                   12534:                             if (@statuses) {
                   12535:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   12536:                                             '<ul>';
                   12537:                                 foreach my $status (@statuses) {
                   12538:                                     if ($status eq 'default') {
                   12539:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   12540:                                     } else {
                   12541:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   12542:                                     }
                   12543:                                 }
                   12544:                                 $chgtext .= '</ul>';
                   12545:                             }
1.160.6.40  raeburn  12546:                         } else {
1.160.6.93  raeburn  12547:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
                   12548:                                             $options{$cancreate{'emailverified'}{'default'}});
                   12549:                         }
                   12550:                     } elsif ($type eq 'emailoptions') {
                   12551:                         my %options = &Apache::lonlocal::texthash (
                   12552:                                                                     any     => 'Any e-mail',
                   12553:                                                                     inst    => 'Institutional only',
                   12554:                                                                     noninst => 'Non-institutional only',
                   12555:                                                                     custom  => 'Custom restrictions',
                   12556:                                                                   );
                   12557:                         if (@types) {
                   12558:                             if (@statuses) {
                   12559:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   12560:                                             '<ul>';
                   12561:                                 foreach my $status (@statuses) {
                   12562:                                     if ($type eq 'default') {
                   12563:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   12564:                                     } else {
                   12565:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   12566:                                     }
                   12567:                                 }
                   12568:                                 $chgtext .= '</ul>';
                   12569:                             }
                   12570:                         } else {
                   12571:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   12572:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   12573:                             } else {
                   12574:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   12575:                                                 $options{$cancreate{'emailoptions'}{'default'}});
                   12576:                             }
                   12577:                         }
                   12578:                     } elsif ($type eq 'emaildomain') {
                   12579:                         my $output;
                   12580:                         if (@statuses) {
                   12581:                             foreach my $type (@statuses) {
                   12582:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   12583:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   12584:                                         if ($type eq 'default') {
                   12585:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12586:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   12587:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12588:                                             } else {
                   12589:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   12590:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   12591:                                             }
                   12592:                                         } else {
                   12593:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12594:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   12595:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12596:                                             } else {
                   12597:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   12598:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   12599:                                             }
                   12600:                                         }
                   12601:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   12602:                                         if ($type eq 'default') {
                   12603:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12604:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   12605:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12606:                                             } else {
                   12607:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   12608:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   12609:                                             }
                   12610:                                         } else {
                   12611:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   12612:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   12613:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   12614:                                             } else {
                   12615:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   12616:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   12617:                                             }
                   12618:                                         }
                   12619:                                     }
                   12620:                                 }
                   12621:                             }
                   12622:                         }
                   12623:                         if ($output ne '') {
                   12624:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   12625:                                         '<ul>'.$output.'</ul>';
1.160.6.40  raeburn  12626:                         }
1.160.6.5  raeburn  12627:                     } elsif ($type eq 'captcha') {
1.160.6.34  raeburn  12628:                         if ($savecaptcha{$type} eq 'notused') {
1.160.6.5  raeburn  12629:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   12630:                         } else {
                   12631:                             my %captchas = &captcha_phrases();
1.160.6.34  raeburn  12632:                             if ($captchas{$savecaptcha{$type}}) {
                   12633:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5  raeburn  12634:                             } else {
                   12635:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                   12636:                             }
                   12637:                         }
                   12638:                     } elsif ($type eq 'recaptchakeys') {
                   12639:                         my ($privkey,$pubkey);
1.160.6.34  raeburn  12640:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   12641:                             $pubkey = $savecaptcha{$type}{'public'};
                   12642:                             $privkey = $savecaptcha{$type}{'private'};
1.160.6.5  raeburn  12643:                         }
                   12644:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   12645:                         if (!$pubkey) {
                   12646:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   12647:                         } else {
                   12648:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   12649:                         }
                   12650:                         if (!$privkey) {
                   12651:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   12652:                         } else {
                   12653:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   12654:                         }
                   12655:                         $chgtext .= '</ul>';
1.160.6.69  raeburn  12656:                     } elsif ($type eq 'recaptchaversion') {
                   12657:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
                   12658:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                   12659:                         }
1.160.6.34  raeburn  12660:                     } elsif ($type eq 'emailusername') {
                   12661:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93  raeburn  12662:                             if (@statuses) {
                   12663:                                 foreach my $type (@statuses) {
1.160.6.35  raeburn  12664:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   12665:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93  raeburn  12666:                                             $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35  raeburn  12667:                                                     '<ul>';
                   12668:                                             foreach my $field (@{$infofields}) {
                   12669:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   12670:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   12671:                                                 }
                   12672:                                             }
1.160.6.50  raeburn  12673:                                             $chgtext .= '</ul>';
                   12674:                                         } else {
1.160.6.93  raeburn  12675:                                             $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.160.6.35  raeburn  12676:                                         }
                   12677:                                     } else {
1.160.6.93  raeburn  12678:                                         $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.160.6.34  raeburn  12679:                                     }
                   12680:                                 }
                   12681:                             }
                   12682:                         }
                   12683:                     } elsif ($type eq 'notify') {
1.160.6.93  raeburn  12684:                         my $numapprove = 0;
1.160.6.34  raeburn  12685:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   12686:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   12687:                                 if ($cancreate{'notify'}{'approval'}) {
1.160.6.93  raeburn  12688:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   12689:                                     $numapprove ++;
1.160.6.34  raeburn  12690:                                 }
                   12691:                             }
1.43      raeburn  12692:                         }
1.160.6.93  raeburn  12693:                         unless ($numapprove) {
                   12694:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   12695:                         }
1.34      raeburn  12696:                     }
1.160.6.34  raeburn  12697:                     if ($chgtext) {
                   12698:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  12699:                     }
                   12700:                 }
                   12701:             }
1.160.6.93  raeburn  12702:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  12703:                 my ($emailrules,$emailruleorder) =
                   12704:                     &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93  raeburn  12705:                 foreach my $type (@{$changes{'email_rule'}}) {
                   12706:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   12707:                         my $chgtext = '<ul>';
                   12708:                         foreach my $rule (@{$email_rule{$type}}) {
                   12709:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   12710:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   12711:                             }
                   12712:                         }
                   12713:                         $chgtext .= '</ul>';
                   12714:                         my $typename;
                   12715:                         if (@types) {
                   12716:                             if ($type eq 'default') {
                   12717:                                 $typename = $othertitle;
                   12718:                             } else {
                   12719:                                 $typename = $usertypes{$type};
                   12720:                             }
                   12721:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   12722:                         }
                   12723:                         if (@{$email_rule{$type}} > 0) {
                   12724:                             $resulttext .= '<li>'.
                   12725:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   12726:                                                $usertypes{$type}).
                   12727:                                            $chgtext.
                   12728:                                            '</li>';
                   12729:                         } else {
                   12730:                             $resulttext .= '<li>'.
                   12731:                                            &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
                   12732:                                            '</li>'.
                   12733:                                            &mt('(Affiliation: [_1])',$typename);
                   12734:                         }
1.43      raeburn  12735:                     }
                   12736:                 }
1.160.6.93  raeburn  12737:             }
                   12738:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   12739:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12740:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   12741:                         my $chgtext = '<ul>';
                   12742:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   12743:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   12744:                         }
                   12745:                         $chgtext .= '</ul>';
                   12746:                         $resulttext .= '<li>'.
                   12747:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   12748:                                           $chgtext.
                   12749:                                        '</li>';
                   12750:                     } else {
                   12751:                         $resulttext .= '<li>'.
                   12752:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   12753:                                        '</li>';
                   12754:                     }
1.43      raeburn  12755:                 }
                   12756:             }
1.160.6.34  raeburn  12757:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   12758:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   12759:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12760:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   12761:                     my $typename = $type;
1.160.6.93  raeburn  12762:                     if (keys(%usertypes) > 0) {
                   12763:                         if ($usertypes{$type} ne '') {
                   12764:                             $typename = $usertypes{$type};
1.28      raeburn  12765:                         }
                   12766:                     }
1.160.6.34  raeburn  12767:                     my @modifiable;
                   12768:                     $resulttext .= '<li>'.
                   12769:                                     &mt('Self-creation of account by users with status: [_1]',
                   12770:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   12771:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   12772:                     foreach my $field (@fields) {
                   12773:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   12774:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
                   12775:                         }
                   12776:                     }
                   12777:                     if (@modifiable > 0) {
                   12778:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  12779:                     } else {
1.160.6.34  raeburn  12780:                         $resulttext .= &mt('none');
1.43      raeburn  12781:                     }
1.160.6.34  raeburn  12782:                     $resulttext .= '</li>';
1.28      raeburn  12783:                 }
1.160.6.34  raeburn  12784:                 $resulttext .= '</ul></li>';
1.28      raeburn  12785:             }
1.27      raeburn  12786:             $resulttext .= '</ul>';
1.160.6.93  raeburn  12787:             my $cachetime = 24*60*60;
                   12788:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   12789:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12790:             if (ref($lastactref) eq 'HASH') {
                   12791:                 $lastactref->{'domdefaults'} = 1;
                   12792:             }
1.27      raeburn  12793:         } else {
1.160.6.34  raeburn  12794:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  12795:         }
                   12796:     } else {
                   12797:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  12798:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12799:     }
1.43      raeburn  12800:     if ($warningmsg ne '') {
                   12801:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   12802:     }
1.23      raeburn  12803:     return $resulttext;
                   12804: }
                   12805: 
1.160.6.5  raeburn  12806: sub process_captcha {
1.160.6.104  raeburn  12807:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   12808:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5  raeburn  12809:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   12810:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   12811:         $newsettings->{'captcha'} = 'original';
                   12812:     }
1.160.6.104  raeburn  12813:     my %current;
                   12814:     if (ref($currsettings) eq 'HASH') {
                   12815:         %current = %{$currsettings};
                   12816:     }
                   12817:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5  raeburn  12818:         if ($container eq 'cancreate') {
                   12819:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12820:                 push(@{$changes->{'cancreate'}},'captcha');
                   12821:             } elsif (!defined($changes->{'cancreate'})) {
                   12822:                 $changes->{'cancreate'} = ['captcha'];
                   12823:             }
1.160.6.102  raeburn  12824:         } elsif ($container eq 'passwords') {
                   12825:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  12826:         } else {
                   12827:             $changes->{'captcha'} = 1;
                   12828:         }
                   12829:     }
1.160.6.69  raeburn  12830:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5  raeburn  12831:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   12832:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   12833:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52  raeburn  12834:         $newpub =~ s/[^\w\-]//g;
                   12835:         $newpriv =~ s/[^\w\-]//g;
1.160.6.5  raeburn  12836:         $newsettings->{'recaptchakeys'} = {
                   12837:                                              public  => $newpub,
                   12838:                                              private => $newpriv,
                   12839:                                           };
1.160.6.69  raeburn  12840:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   12841:         $newversion =~ s/\D//g;
                   12842:         if ($newversion ne '2') {
                   12843:             $newversion = 1;
                   12844:         }
                   12845:         $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5  raeburn  12846:     }
1.160.6.104  raeburn  12847:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   12848:         $currpub = $current{'recaptchakeys'}{'public'};
                   12849:         $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10  raeburn  12850:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   12851:             $newsettings->{'recaptchakeys'} = {
                   12852:                                                  public  => '',
                   12853:                                                  private => '',
                   12854:                                               }
                   12855:         }
1.160.6.5  raeburn  12856:     }
1.160.6.104  raeburn  12857:     if ($current{'captcha'} eq 'recaptcha') {
                   12858:         $currversion = $current{'recaptchaversion'};
1.160.6.69  raeburn  12859:         if ($currversion ne '2') {
                   12860:             $currversion = 1;
                   12861:         }
                   12862:     }
                   12863:     if ($currversion ne $newversion) {
                   12864:         if ($container eq 'cancreate') {
                   12865:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12866:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   12867:             } elsif (!defined($changes->{'cancreate'})) {
                   12868:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   12869:             }
1.160.6.102  raeburn  12870:         } elsif ($container eq 'passwords') {
                   12871:             $changes->{'reset'} = 1;
1.160.6.69  raeburn  12872:         } else {
                   12873:             $changes->{'recaptchaversion'} = 1;
                   12874:         }
                   12875:     }
1.160.6.5  raeburn  12876:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
                   12877:         if ($container eq 'cancreate') {
                   12878:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   12879:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   12880:             } elsif (!defined($changes->{'cancreate'})) {
                   12881:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   12882:             }
1.160.6.102  raeburn  12883:         } elsif ($container eq 'passwords') {
                   12884:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  12885:         } else {
                   12886:             $changes->{'recaptchakeys'} = 1;
                   12887:         }
                   12888:     }
                   12889:     return;
                   12890: }
                   12891: 
1.33      raeburn  12892: sub modify_usermodification {
                   12893:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  12894:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  12895:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   12896:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34  raeburn  12897:             if ($key eq 'selfcreate') {
                   12898:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   12899:             } else {  
                   12900:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   12901:             }
1.33      raeburn  12902:         }
                   12903:     }
1.160.6.34  raeburn  12904:     my @contexts = ('author','course');
1.33      raeburn  12905:     my %context_title = (
                   12906:                            author => 'In author context',
                   12907:                            course => 'In course context',
                   12908:                         );
                   12909:     my @fields = ('lastname','firstname','middlename','generation',
                   12910:                   'permanentemail','id');
                   12911:     my %roles = (
                   12912:                   author => ['ca','aa'],
                   12913:                   course => ['st','ep','ta','in','cr'],
                   12914:                 );
                   12915:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   12916:     foreach my $context (@contexts) {
                   12917:         foreach my $role (@{$roles{$context}}) {
                   12918:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   12919:             foreach my $item (@fields) {
                   12920:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   12921:                     $modifyhash{$context}{$role}{$item} = 1;
                   12922:                 } else {
                   12923:                     $modifyhash{$context}{$role}{$item} = 0;
                   12924:                 }
                   12925:             }
                   12926:         }
                   12927:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   12928:             foreach my $role (@{$roles{$context}}) {
                   12929:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   12930:                     foreach my $field (@fields) {
                   12931:                         if ($modifyhash{$context}{$role}{$field} ne 
                   12932:                                 $curr_usermodification{$context}{$role}{$field}) {
                   12933:                             push(@{$changes{$context}},$role);
                   12934:                             last;
                   12935:                         }
                   12936:                     }
                   12937:                 }
                   12938:             }
                   12939:         } else {
                   12940:             foreach my $context (@contexts) {
                   12941:                 foreach my $role (@{$roles{$context}}) {
                   12942:                     push(@{$changes{$context}},$role);
                   12943:                 }
                   12944:             }
                   12945:         }
                   12946:     }
                   12947:     my %usermodification_hash =  (
                   12948:                                    usermodification => \%modifyhash,
                   12949:                                  );
                   12950:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   12951:                                              \%usermodification_hash,$dom);
                   12952:     if ($putresult eq 'ok') {
                   12953:         if (keys(%changes) > 0) {
                   12954:             $resulttext = &mt('Changes made: ').'<ul>';
                   12955:             foreach my $context (@contexts) {
                   12956:                 if (ref($changes{$context}) eq 'ARRAY') {
                   12957:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   12958:                     if (ref($changes{$context}) eq 'ARRAY') {
                   12959:                         foreach my $role (@{$changes{$context}}) {
                   12960:                             my $rolename;
1.160.6.34  raeburn  12961:                             if ($role eq 'cr') {
                   12962:                                 $rolename = &mt('Custom');
1.33      raeburn  12963:                             } else {
1.160.6.34  raeburn  12964:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  12965:                             }
                   12966:                             my @modifiable;
1.160.6.34  raeburn  12967:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  12968:                             foreach my $field (@fields) {
                   12969:                                 if ($modifyhash{$context}{$role}{$field}) {
                   12970:                                     push(@modifiable,$fieldtitles{$field});
                   12971:                                 }
                   12972:                             }
                   12973:                             if (@modifiable > 0) {
                   12974:                                 $resulttext .= join(', ',@modifiable);
                   12975:                             } else {
                   12976:                                 $resulttext .= &mt('none'); 
                   12977:                             }
                   12978:                             $resulttext .= '</li>';
                   12979:                         }
                   12980:                         $resulttext .= '</ul></li>';
                   12981:                     }
                   12982:                 }
                   12983:             }
                   12984:             $resulttext .= '</ul>';
                   12985:         } else {
                   12986:             $resulttext = &mt('No changes made to user modification settings');
                   12987:         }
                   12988:     } else {
                   12989:         $resulttext = '<span class="LC_error">'.
                   12990:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12991:     }
                   12992:     return $resulttext;
                   12993: }
                   12994: 
1.43      raeburn  12995: sub modify_defaults {
1.160.6.27  raeburn  12996:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  12997:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27  raeburn  12998:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80  raeburn  12999:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98  raeburn  13000:                  'portal_def');
1.43      raeburn  13001:     my @authtypes = ('internal','krb4','krb5','localauth');
                   13002:     foreach my $item (@items) {
                   13003:         $newvalues{$item} = $env{'form.'.$item};
                   13004:         if ($item eq 'auth_def') {
                   13005:             if ($newvalues{$item} ne '') {
                   13006:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   13007:                     push(@errors,$item);
                   13008:                 }
                   13009:             }
                   13010:         } elsif ($item eq 'lang_def') {
                   13011:             if ($newvalues{$item} ne '') {
                   13012:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   13013:                     my $langcode = $1;
1.103     raeburn  13014:                     if ($langcode ne 'x_chef') {
                   13015:                         if (code2language($langcode) eq '') {
                   13016:                             push(@errors,$item);
                   13017:                         }
1.43      raeburn  13018:                     }
                   13019:                 } else {
                   13020:                     push(@errors,$item);
                   13021:                 }
                   13022:             }
1.54      raeburn  13023:         } elsif ($item eq 'timezone_def') {
                   13024:             if ($newvalues{$item} ne '') {
1.62      raeburn  13025:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  13026:                     push(@errors,$item);   
                   13027:                 }
                   13028:             }
1.68      raeburn  13029:         } elsif ($item eq 'datelocale_def') {
                   13030:             if ($newvalues{$item} ne '') {
                   13031:                 my @datelocale_ids = DateTime::Locale->ids();
                   13032:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   13033:                     push(@errors,$item);
                   13034:                 }
                   13035:             }
1.141     raeburn  13036:         } elsif ($item eq 'portal_def') {
                   13037:             if ($newvalues{$item} ne '') {
                   13038:                 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])\/?$/) {
                   13039:                     push(@errors,$item);
                   13040:                 }
                   13041:             }
1.43      raeburn  13042:         }
                   13043:         if (grep(/^\Q$item\E$/,@errors)) {
                   13044:             $newvalues{$item} = $domdefaults{$item};
                   13045:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   13046:             $changes{$item} = 1;
                   13047:         }
1.72      raeburn  13048:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  13049:     }
1.160.6.98  raeburn  13050:     my %staticdefaults = (
                   13051:                            'intauth_cost'   => 10,
                   13052:                            'intauth_check'  => 0,
                   13053:                            'intauth_switch' => 0,
                   13054:                          );
                   13055:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   13056:         if (exists($domdefaults{$item})) {
                   13057:             $newvalues{$item} = $domdefaults{$item};
                   13058:         } else {
                   13059:             $newvalues{$item} = $staticdefaults{$item};
                   13060:         }
                   13061:     }
1.43      raeburn  13062:     my %defaults_hash = (
1.72      raeburn  13063:                          defaults => \%newvalues,
                   13064:                         );
1.43      raeburn  13065:     my $title = &defaults_titles();
1.160.6.40  raeburn  13066: 
                   13067:     my $currinststatus;
                   13068:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   13069:         $currinststatus = $domconfig{'inststatus'};
                   13070:     } else {
                   13071:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   13072:         $currinststatus = {
                   13073:                              inststatustypes => $usertypes,
                   13074:                              inststatusorder => $types,
                   13075:                              inststatusguest => [],
                   13076:                           };
                   13077:     }
                   13078:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   13079:     my @allpos;
                   13080:     my %alltypes;
1.160.6.93  raeburn  13081:     my @inststatusguest;
                   13082:     if (ref($currinststatus) eq 'HASH') {
                   13083:         if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   13084:             foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   13085:                 unless (grep(/^\Q$type\E$/,@todelete)) {
                   13086:                     push(@inststatusguest,$type);
                   13087:                 }
                   13088:             }
                   13089:         }
                   13090:     }
                   13091:     my ($currtitles,$currorder);
1.160.6.40  raeburn  13092:     if (ref($currinststatus) eq 'HASH') {
                   13093:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   13094:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   13095:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   13096:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   13097:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   13098:                     }
                   13099:                 }
                   13100:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   13101:                     my $position = $env{'form.inststatus_pos_'.$type};
                   13102:                     $position =~ s/\D+//g;
                   13103:                     $allpos[$position] = $type;
                   13104:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   13105:                     $alltypes{$type} =~ s/`//g;
                   13106:                 }
                   13107:             }
                   13108:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   13109:             $currtitles =~ s/,$//;
                   13110:         }
                   13111:     }
                   13112:     if ($env{'form.addinststatus'}) {
                   13113:         my $newtype = $env{'form.addinststatus'};
                   13114:         $newtype =~ s/\W//g;
                   13115:         unless (exists($alltypes{$newtype})) {
                   13116:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   13117:             $alltypes{$newtype} =~ s/`//g; 
                   13118:             my $position = $env{'form.addinststatus_pos'};
                   13119:             $position =~ s/\D+//g;
                   13120:             if ($position ne '') {
                   13121:                 $allpos[$position] = $newtype;
                   13122:             }
                   13123:         }
                   13124:     }
1.160.6.93  raeburn  13125:     my @orderedstatus;
1.160.6.40  raeburn  13126:     foreach my $type (@allpos) {
                   13127:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   13128:             push(@orderedstatus,$type);
                   13129:         }
                   13130:     }
                   13131:     foreach my $type (keys(%alltypes)) {
                   13132:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   13133:             delete($alltypes{$type});
                   13134:         }
                   13135:     }
                   13136:     $defaults_hash{'inststatus'} = {
                   13137:                                      inststatustypes => \%alltypes,
                   13138:                                      inststatusorder => \@orderedstatus,
1.160.6.93  raeburn  13139:                                      inststatusguest => \@inststatusguest,
1.160.6.40  raeburn  13140:                                    };
                   13141:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   13142:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   13143:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   13144:         }
                   13145:     }
                   13146:     if ($currorder ne join(',',@orderedstatus)) {
                   13147:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   13148:     }
                   13149:     my $newtitles;
                   13150:     foreach my $item (@orderedstatus) {
                   13151:         $newtitles .= $alltypes{$item}.',';
                   13152:     }
                   13153:     $newtitles =~ s/,$//;
                   13154:     if ($currtitles ne $newtitles) {
                   13155:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   13156:     }
1.43      raeburn  13157:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   13158:                                              $dom);
                   13159:     if ($putresult eq 'ok') {
                   13160:         if (keys(%changes) > 0) {
                   13161:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27  raeburn  13162:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  13163:             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";
                   13164:             foreach my $item (sort(keys(%changes))) {
1.160.6.40  raeburn  13165:                 if ($item eq 'inststatus') {
                   13166:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93  raeburn  13167:                         if (@orderedstatus) {
1.160.6.40  raeburn  13168:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   13169:                             foreach my $type (@orderedstatus) { 
                   13170:                                 $resulttext .= $alltypes{$type}.', ';
                   13171:                             }
                   13172:                             $resulttext =~ s/, $//;
                   13173:                             $resulttext .= '</li>';
1.160.6.93  raeburn  13174:                         } else {
                   13175:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40  raeburn  13176:                         }
                   13177:                     }
                   13178:                 } else {
                   13179:                     my $value = $env{'form.'.$item};
                   13180:                     if ($value eq '') {
                   13181:                         $value = &mt('none');
                   13182:                     } elsif ($item eq 'auth_def') {
                   13183:                         my %authnames = &authtype_names();
                   13184:                         my %shortauth = (
                   13185:                                           internal   => 'int',
                   13186:                                           krb4       => 'krb4',
                   13187:                                           krb5       => 'krb5',
                   13188:                                           localauth  => 'loc',
                   13189:                         );
                   13190:                         $value = $authnames{$shortauth{$value}};
                   13191:                     }
                   13192:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   13193:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  13194:                 }
                   13195:             }
                   13196:             $resulttext .= '</ul>';
                   13197:             $mailmsgtext .= "\n";
                   13198:             my $cachetime = 24*60*60;
1.72      raeburn  13199:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  13200:             if (ref($lastactref) eq 'HASH') {
                   13201:                 $lastactref->{'domdefaults'} = 1;
                   13202:             }
1.68      raeburn  13203:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23  raeburn  13204:                 my $notify = 1;
                   13205:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   13206:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   13207:                         $notify = 0;
                   13208:                     }
                   13209:                 }
                   13210:                 if ($notify) {
                   13211:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   13212:                                                "LON-CAPA Domain Settings Change - $dom",
                   13213:                                                $mailmsgtext);
                   13214:                 }
1.54      raeburn  13215:             }
1.43      raeburn  13216:         } else {
1.54      raeburn  13217:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  13218:         }
                   13219:     } else {
                   13220:         $resulttext = '<span class="LC_error">'.
                   13221:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13222:     }
                   13223:     if (@errors > 0) {
                   13224:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   13225:         foreach my $item (@errors) {
                   13226:             $resulttext .= ' "'.$title->{$item}.'",';
                   13227:         }
                   13228:         $resulttext =~ s/,$//;
                   13229:     }
                   13230:     return $resulttext;
                   13231: }
                   13232: 
1.46      raeburn  13233: sub modify_scantron {
1.160.6.24  raeburn  13234:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  13235:     my ($resulttext,%confhash,%changes,$errors);
                   13236:     my $custom = 'custom.tab';
                   13237:     my $default = 'default.tab';
                   13238:     my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97  raeburn  13239:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  13240:         &config_check($dom,$confname,$servadm);
                   13241:     if ($env{'form.scantronformat.filename'} ne '') {
                   13242:         my $error;
                   13243:         if ($configuserok eq 'ok') {
                   13244:             if ($switchserver) {
1.130     raeburn  13245:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  13246:             } else {
                   13247:                 if ($author_ok eq 'ok') {
                   13248:                     my ($result,$scantronurl) =
                   13249:                         &publishlogo($r,'upload','scantronformat',$dom,
                   13250:                                      $confname,'scantron','','',$custom);
                   13251:                     if ($result eq 'ok') {
                   13252:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  13253:                         $changes{'scantronformat'} = 1;
1.46      raeburn  13254:                     } else {
                   13255:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   13256:                     }
                   13257:                 } else {
                   13258:                     $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);
                   13259:                 }
                   13260:             }
                   13261:         } else {
                   13262:             $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);
                   13263:         }
                   13264:         if ($error) {
                   13265:             &Apache::lonnet::logthis($error);
                   13266:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   13267:         }
                   13268:     }
1.48      raeburn  13269:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   13270:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   13271:             if ($env{'form.scantronformat_del'}) {
                   13272:                 $confhash{'scantron'}{'scantronformat'} = '';
                   13273:                 $changes{'scantronformat'} = 1;
1.160.6.97  raeburn  13274:             } else {
                   13275:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
                   13276:             }
                   13277:         }
                   13278:     }
                   13279:     my @options = ('hdr','pad','rem');
                   13280:     my @fields = &scantroncsv_fields();
                   13281:     my %titles = &scantronconfig_titles();
                   13282:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
                   13283:     my ($newdat,$currdat,%newcol,%currcol);
                   13284:     if (grep(/^dat$/,@formats)) {
                   13285:         $confhash{'scantron'}{config}{dat} = 1;
                   13286:         $newdat = 1;
                   13287:     } else {
                   13288:         $newdat = 0;
                   13289:     }
                   13290:     if (grep(/^csv$/,@formats)) {
                   13291:         my %bynum;
                   13292:         foreach my $field (@fields) {
                   13293:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   13294:                 my $posscol = $1;
                   13295:                 if (($posscol < 20) && (!$bynum{$posscol})) {
                   13296:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
                   13297:                     $bynum{$posscol} = $field;
                   13298:                     $newcol{$field} = $posscol;
                   13299:                 }
                   13300:             }
                   13301:         }
                   13302:         if (keys(%newcol)) {
                   13303:             foreach my $option (@options) {
                   13304:                 if ($env{'form.scantroncsv_'.$option}) {
                   13305:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   13306:                 }
                   13307:             }
                   13308:         }
                   13309:     }
                   13310:     $currdat = 1;
                   13311:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   13312:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
                   13313:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
                   13314:                 $currdat = 0;
                   13315:             }
                   13316:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   13317:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   13318:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   13319:                 }
                   13320:             }
                   13321:         }
                   13322:     }
                   13323:     if ($currdat != $newdat) {
                   13324:         $changes{'config'} = 1;
                   13325:     } else {
                   13326:         foreach my $field (@fields) {
                   13327:             if ($currcol{$field} ne '') {
                   13328:                 if ($currcol{$field} ne $newcol{$field}) {
                   13329:                     $changes{'config'} = 1;
                   13330:                     last;
                   13331:                 }
                   13332:             } elsif ($newcol{$field} ne '') {
                   13333:                 $changes{'config'} = 1;
                   13334:                 last;
1.46      raeburn  13335:             }
                   13336:         }
                   13337:     }
                   13338:     if (keys(%confhash) > 0) {
                   13339:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   13340:                                                  $dom);
                   13341:         if ($putresult eq 'ok') {
                   13342:             if (keys(%changes) > 0) {
1.48      raeburn  13343:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   13344:                     $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97  raeburn  13345:                     if ($changes{'scantronformat'}) {
                   13346:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   13347:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   13348:                         } else {
                   13349:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   13350:                         }
                   13351:                     }
                   13352:                     if ($changes{'config'}) {
                   13353:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   13354:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   13355:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   13356:                             }
                   13357:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   13358:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   13359:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   13360:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   13361:                                         foreach my $field (@fields) {
                   13362:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   13363:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   13364:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   13365:                                             }
                   13366:                                         }
                   13367:                                         $resulttext .= '</ul></li>';
                   13368:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   13369:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   13370:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   13371:                                                 foreach my $option (@options) {
                   13372:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   13373:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   13374:                                                     }
                   13375:                                                 }
                   13376:                                                 $resulttext .= '</ul></li>';
                   13377:                                             }
                   13378:                                         }
                   13379:                                     }
                   13380:                                 }
                   13381:                             }
                   13382:                         } else {
                   13383:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   13384:                         }
1.46      raeburn  13385:                     }
1.48      raeburn  13386:                     $resulttext .= '</ul>';
                   13387:                 } else {
1.130     raeburn  13388:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  13389:                 }
                   13390:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  13391:                 if (ref($lastactref) eq 'HASH') {
                   13392:                     $lastactref->{'domainconfig'} = 1;
                   13393:                 }
1.46      raeburn  13394:             } else {
1.160.6.97  raeburn  13395:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  13396:             }
                   13397:         } else {
                   13398:             $resulttext = '<span class="LC_error">'.
                   13399:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   13400:         }
                   13401:     } else {
1.160.6.97  raeburn  13402:         $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  13403:     }
                   13404:     if ($errors) {
                   13405:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13406:                        $errors.'</ul>';
                   13407:     }
                   13408:     return $resulttext;
                   13409: }
                   13410: 
1.48      raeburn  13411: sub modify_coursecategories {
1.160.6.43  raeburn  13412:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  13413:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   13414:         $cathash);
1.48      raeburn  13415:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42  raeburn  13416:     my @catitems = ('unauth','auth');
                   13417:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  13418:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  13419:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   13420:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   13421:             $changes{'togglecats'} = 1;
                   13422:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   13423:         }
                   13424:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   13425:             $changes{'categorize'} = 1;
                   13426:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   13427:         }
1.120     raeburn  13428:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   13429:             $changes{'togglecatscomm'} = 1;
                   13430:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   13431:         }
                   13432:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   13433:             $changes{'categorizecomm'} = 1;
                   13434:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   13435:         }
1.160.6.42  raeburn  13436:         foreach my $item (@catitems) {
                   13437:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   13438:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   13439:                     $changes{$item} = 1;
                   13440:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   13441:                 }
                   13442:             }
                   13443:         }
1.57      raeburn  13444:     } else {
                   13445:         $changes{'togglecats'} = 1;
                   13446:         $changes{'categorize'} = 1;
1.124     raeburn  13447:         $changes{'togglecatscomm'} = 1;
                   13448:         $changes{'categorizecomm'} = 1;
1.87      raeburn  13449:         $domconfig{'coursecategories'} = {
                   13450:                                              togglecats => $env{'form.togglecats'},
                   13451:                                              categorize => $env{'form.categorize'},
1.124     raeburn  13452:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   13453:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  13454:                                          };
1.160.6.42  raeburn  13455:         foreach my $item (@catitems) {
                   13456:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   13457:                 $changes{$item} = 1;
                   13458:             }
                   13459:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   13460:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   13461:             }
                   13462:         }
1.57      raeburn  13463:     }
                   13464:     if (ref($cathash) eq 'HASH') {
                   13465:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  13466:             push (@deletecategory,'instcode::0');
                   13467:         }
1.120     raeburn  13468:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   13469:             push(@deletecategory,'communities::0');
                   13470:         }
1.48      raeburn  13471:     }
1.57      raeburn  13472:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   13473:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  13474:         if (@deletecategory > 0) {
                   13475:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  13476:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  13477:             foreach my $item (@deletecategory) {
1.57      raeburn  13478:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   13479:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  13480:                     $deletions{$item} = 1;
1.57      raeburn  13481:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  13482:                 }
                   13483:             }
                   13484:         }
1.57      raeburn  13485:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  13486:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  13487:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  13488:                 $reorderings{$item} = 1;
1.57      raeburn  13489:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  13490:             }
                   13491:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   13492:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   13493:                 my $newdepth = $depth+1;
                   13494:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  13495:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  13496:                 $adds{$newitem} = 1; 
                   13497:             }
                   13498:             if ($env{'form.subcat_'.$item} ne '') {
                   13499:                 my $newcat = $env{'form.subcat_'.$item};
                   13500:                 my $newdepth = $depth+1;
                   13501:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  13502:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  13503:                 $adds{$newitem} = 1;
                   13504:             }
                   13505:         }
                   13506:     }
                   13507:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  13508:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  13509:             my $newitem = 'instcode::0';
1.57      raeburn  13510:             if ($cathash->{$newitem} eq '') {  
                   13511:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  13512:                 $adds{$newitem} = 1;
                   13513:             }
                   13514:         } else {
                   13515:             my $newitem = 'instcode::0';
1.57      raeburn  13516:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  13517:             $adds{$newitem} = 1;
                   13518:         }
                   13519:     }
1.120     raeburn  13520:     if ($env{'form.communities'} eq '1') {
                   13521:         if (ref($cathash) eq 'HASH') {
                   13522:             my $newitem = 'communities::0';
                   13523:             if ($cathash->{$newitem} eq '') {
                   13524:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   13525:                 $adds{$newitem} = 1;
                   13526:             }
                   13527:         } else {
                   13528:             my $newitem = 'communities::0';
                   13529:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   13530:             $adds{$newitem} = 1;
                   13531:         }
                   13532:     }
1.48      raeburn  13533:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  13534:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   13535:             ($env{'form.addcategory_name'} ne 'communities')) {
                   13536:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   13537:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   13538:             $adds{$newitem} = 1;
                   13539:         }
1.48      raeburn  13540:     }
1.57      raeburn  13541:     my $putresult;
1.48      raeburn  13542:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13543:         if (keys(%deletions) > 0) {
                   13544:             foreach my $key (keys(%deletions)) {
                   13545:                 if ($predelallitems{$key} ne '') {
                   13546:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   13547:                 }
                   13548:             }
                   13549:         }
                   13550:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  13551:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  13552:         if (ref($chkcats[0]) eq 'ARRAY') {
                   13553:             my $depth = 0;
                   13554:             my $chg = 0;
                   13555:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   13556:                 my $name = $chkcats[0][$i];
                   13557:                 my $item;
                   13558:                 if ($name eq '') {
                   13559:                     $chg ++;
                   13560:                 } else {
                   13561:                     $item = &escape($name).'::0';
                   13562:                     if ($chg) {
1.57      raeburn  13563:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  13564:                     }
                   13565:                     $depth ++; 
1.57      raeburn  13566:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  13567:                     $depth --;
                   13568:                 }
                   13569:             }
                   13570:         }
1.57      raeburn  13571:     }
                   13572:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13573:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  13574:         if ($putresult eq 'ok') {
1.57      raeburn  13575:             my %title = (
1.120     raeburn  13576:                          togglecats     => 'Show/Hide a course in catalog',
                   13577:                          categorize     => 'Assign a category to a course',
                   13578:                          togglecatscomm => 'Show/Hide a community in catalog',
                   13579:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  13580:                         );
                   13581:             my %level = (
1.120     raeburn  13582:                          dom  => 'set in Domain ("Modify Course/Community")',
                   13583:                          crs  => 'set in Course ("Course Configuration")',
                   13584:                          comm => 'set in Community ("Community Configuration")',
1.160.6.42  raeburn  13585:                          none     => 'No catalog',
                   13586:                          std      => 'Standard catalog',
                   13587:                          domonly  => 'Domain-only catalog',
                   13588:                          codesrch => 'Code search form',
1.57      raeburn  13589:                         );
1.48      raeburn  13590:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  13591:             if ($changes{'togglecats'}) {
                   13592:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   13593:             }
                   13594:             if ($changes{'categorize'}) {
                   13595:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  13596:             }
1.120     raeburn  13597:             if ($changes{'togglecatscomm'}) {
                   13598:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   13599:             }
                   13600:             if ($changes{'categorizecomm'}) {
                   13601:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   13602:             }
1.160.6.42  raeburn  13603:             if ($changes{'unauth'}) {
                   13604:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   13605:             }
                   13606:             if ($changes{'auth'}) {
                   13607:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   13608:             }
1.57      raeburn  13609:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   13610:                 my $cathash;
                   13611:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   13612:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   13613:                 } else {
                   13614:                     $cathash = {};
                   13615:                 } 
                   13616:                 my (@cats,@trails,%allitems);
                   13617:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   13618:                 if (keys(%deletions) > 0) {
                   13619:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   13620:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   13621:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   13622:                     }
                   13623:                     $resulttext .= '</ul></li>';
                   13624:                 }
                   13625:                 if (keys(%reorderings) > 0) {
                   13626:                     my %sort_by_trail;
                   13627:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   13628:                     foreach my $key (keys(%reorderings)) {
                   13629:                         if ($allitems{$key} ne '') {
                   13630:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   13631:                         }
1.48      raeburn  13632:                     }
1.57      raeburn  13633:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   13634:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   13635:                     }
                   13636:                     $resulttext .= '</ul></li>';
1.48      raeburn  13637:                 }
1.57      raeburn  13638:                 if (keys(%adds) > 0) {
                   13639:                     my %sort_by_trail;
                   13640:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   13641:                     foreach my $key (keys(%adds)) {
                   13642:                         if ($allitems{$key} ne '') {
                   13643:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   13644:                         }
                   13645:                     }
                   13646:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   13647:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  13648:                     }
1.57      raeburn  13649:                     $resulttext .= '</ul></li>';
1.48      raeburn  13650:                 }
1.160.6.92  raeburn  13651:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   13652:                 if (ref($lastactref) eq 'HASH') {
                   13653:                     $lastactref->{'cats'} = 1;
                   13654:                 }
1.48      raeburn  13655:             }
                   13656:             $resulttext .= '</ul>';
1.160.6.43  raeburn  13657:             if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50  raeburn  13658:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   13659:                 if ($changes{'auth'}) {
                   13660:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   13661:                 }
                   13662:                 if ($changes{'unauth'}) {
                   13663:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   13664:                 }
                   13665:                 my $cachetime = 24*60*60;
                   13666:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43  raeburn  13667:                 if (ref($lastactref) eq 'HASH') {
1.160.6.50  raeburn  13668:                     $lastactref->{'domdefaults'} = 1;
1.160.6.43  raeburn  13669:                 }
                   13670:             }
1.48      raeburn  13671:         } else {
                   13672:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  13673:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  13674:         }
                   13675:     } else {
1.120     raeburn  13676:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  13677:     }
                   13678:     return $resulttext;
                   13679: }
                   13680: 
1.69      raeburn  13681: sub modify_serverstatuses {
                   13682:     my ($dom,%domconfig) = @_;
                   13683:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   13684:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   13685:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   13686:     }
                   13687:     my @pages = &serverstatus_pages();
                   13688:     foreach my $type (@pages) {
                   13689:         $newserverstatus{$type}{'namedusers'} = '';
                   13690:         $newserverstatus{$type}{'machines'} = '';
                   13691:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   13692:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   13693:             my @okusers;
                   13694:             foreach my $user (@users) {
                   13695:                 my ($uname,$udom) = split(/:/,$user);
                   13696:                 if (($udom =~ /^$match_domain$/) &&   
                   13697:                     (&Apache::lonnet::domain($udom)) &&
                   13698:                     ($uname =~ /^$match_username$/)) {
                   13699:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   13700:                         push(@okusers,$user);
                   13701:                     }
                   13702:                 }
                   13703:             }
                   13704:             if (@okusers > 0) {
                   13705:                  @okusers = sort(@okusers);
                   13706:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   13707:             }
                   13708:         }
                   13709:         if (defined($env{'form.'.$type.'_machines'})) {
                   13710:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   13711:             my @okmachines;
                   13712:             foreach my $ip (@machines) {
                   13713:                 my @parts = split(/\./,$ip);
                   13714:                 next if (@parts < 4);
                   13715:                 my $badip = 0;
                   13716:                 for (my $i=0; $i<4; $i++) {
                   13717:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   13718:                         $badip = 1;
                   13719:                         last;
                   13720:                     }
                   13721:                 }
                   13722:                 if (!$badip) {
                   13723:                     push(@okmachines,$ip);     
                   13724:                 }
                   13725:             }
                   13726:             @okmachines = sort(@okmachines);
                   13727:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   13728:         }
                   13729:     }
                   13730:     my %serverstatushash =  (
                   13731:                                 serverstatuses => \%newserverstatus,
                   13732:                             );
                   13733:     foreach my $type (@pages) {
1.83      raeburn  13734:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  13735:             my (@current,@new);
1.83      raeburn  13736:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  13737:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   13738:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   13739:                 }
                   13740:             }
                   13741:             if ($newserverstatus{$type}{$setting} ne '') {
                   13742:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  13743:             }
                   13744:             if (@current > 0) {
                   13745:                 if (@new > 0) {
                   13746:                     foreach my $item (@current) {
                   13747:                         if (!grep(/^\Q$item\E$/,@new)) {
                   13748:                             $changes{$type}{$setting} = 1;
1.82      raeburn  13749:                             last;
                   13750:                         }
                   13751:                     }
1.84      raeburn  13752:                     foreach my $item (@new) {
                   13753:                         if (!grep(/^\Q$item\E$/,@current)) {
                   13754:                             $changes{$type}{$setting} = 1;
                   13755:                             last;
1.82      raeburn  13756:                         }
                   13757:                     }
                   13758:                 } else {
1.83      raeburn  13759:                     $changes{$type}{$setting} = 1;
1.69      raeburn  13760:                 }
1.83      raeburn  13761:             } elsif (@new > 0) {
                   13762:                 $changes{$type}{$setting} = 1;
1.69      raeburn  13763:             }
                   13764:         }
                   13765:     }
                   13766:     if (keys(%changes) > 0) {
1.81      raeburn  13767:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  13768:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   13769:                                                  \%serverstatushash,$dom);
                   13770:         if ($putresult eq 'ok') {
                   13771:             $resulttext .= &mt('Changes made:').'<ul>';
                   13772:             foreach my $type (@pages) {
1.84      raeburn  13773:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  13774:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  13775:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  13776:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   13777:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   13778:                         } else {
                   13779:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   13780:                         }
1.84      raeburn  13781:                     }
                   13782:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  13783:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   13784:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   13785:                         } else {
                   13786:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   13787:                         }
                   13788: 
                   13789:                     }
                   13790:                     $resulttext .= '</ul></li>';
                   13791:                 }
                   13792:             }
                   13793:             $resulttext .= '</ul>';
                   13794:         } else {
                   13795:             $resulttext = '<span class="LC_error">'.
                   13796:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   13797: 
                   13798:         }
                   13799:     } else {
                   13800:         $resulttext = &mt('No changes made to access to server status pages');
                   13801:     }
                   13802:     return $resulttext;
                   13803: }
                   13804: 
1.118     jms      13805: sub modify_helpsettings {
1.160.6.77  raeburn  13806:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  13807:     my ($resulttext,$errors,%changes,%helphash);
                   13808:     my %defaultchecked = ('submitbugs' => 'on');
                   13809:     my @offon = ('off','on');
1.118     jms      13810:     my @toggles = ('submitbugs');
1.160.6.77  raeburn  13811:     my %current = ('submitbugs' => '',
                   13812:                    'adhoc'      => {},
                   13813:                   );
1.118     jms      13814:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73  raeburn  13815:         %current = %{$domconfig{'helpsettings'}};
                   13816:     }
1.160.6.77  raeburn  13817:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73  raeburn  13818:     foreach my $item (@toggles) {
                   13819:         if ($defaultchecked{$item} eq 'on') { 
                   13820:             if ($current{$item} eq '') {
                   13821:                 if ($env{'form.'.$item} eq '0') {
1.160.6.5  raeburn  13822:                     $changes{$item} = 1;
                   13823:                 }
1.160.6.73  raeburn  13824:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   13825:                 $changes{$item} = 1;
                   13826:             }
                   13827:         } elsif ($defaultchecked{$item} eq 'off') {
                   13828:             if ($current{$item} eq '') {
                   13829:                 if ($env{'form.'.$item} eq '1') {
1.160.6.5  raeburn  13830:                     $changes{$item} = 1;
                   13831:                 }
1.160.6.73  raeburn  13832:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   13833:                 $changes{$item} = 1;
                   13834:             }
                   13835:         }
                   13836:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   13837:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   13838:         }
                   13839:     }
1.160.6.77  raeburn  13840:     my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73  raeburn  13841:     my $confname = $dom.'-domainconfig';
                   13842:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  13843:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   13844:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  13845:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
                   13846:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  13847:     my %lt = &Apache::lonlocal::texthash(
                   13848:                     s      => 'system',
                   13849:                     d      => 'domain',
                   13850:                     order  => 'Display order',
                   13851:                     access => 'Role usage',
1.160.6.79  raeburn  13852:                     all    => 'All with domain helpdesk or helpdesk assistant role',
                   13853:                     dh     => 'All with domain helpdesk role',
                   13854:                     da     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  13855:                     none   => 'None',
                   13856:                     status => 'Determined based on institutional status',
                   13857:                     inc    => 'Include all, but exclude specific personnel',
                   13858:                     exc    => 'Exclude all, but include specific personnel',
                   13859:     );
                   13860:     for (my $num=0; $num<=$maxnum; $num++) {
                   13861:         my ($prefix,$identifier,$rolename,%curr);
                   13862:         if ($num == $maxnum) {
                   13863:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   13864:             $identifier = 'custhelp'.$num;
                   13865:             $prefix = 'helproles_'.$num;
                   13866:             $rolename = $env{'form.custhelpname'.$num};
                   13867:             $rolename=~s/[^A-Za-z0-9]//gs;
                   13868:             next if ($rolename eq '');
                   13869:             next if (exists($existing{'rolesdef_'.$rolename}));
                   13870:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   13871:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   13872:                                                      $newprivs{'c'},$confname,$dom);
                   13873:             if ($result ne 'ok') {
                   13874:                 $errors .= '<li><span class="LC_error">'.
                   13875:                            &mt('An error occurred storing the new custom role: [_1]',
                   13876:                            $result).'</span></li>';
                   13877:                 next;
                   13878:             } else {
                   13879:                 $changedprivs{$rolename} = \%newprivs;
                   13880:                 $newrole = $rolename;
                   13881:             }
                   13882:         } else {
                   13883:             $prefix = 'helproles_'.$num;
                   13884:             $rolename = $env{'form.'.$prefix};
                   13885:             next if ($rolename eq '');
                   13886:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   13887:             $identifier = 'custhelp'.$num;
                   13888:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   13889:             my %currprivs;
                   13890:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
                   13891:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   13892:             foreach my $level ('c','d','s') {
                   13893:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   13894:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   13895:                                                              $newprivs{'c'},$confname,$dom);
                   13896:                     if ($result ne 'ok') {
                   13897:                         $errors .= '<li><span class="LC_error">'.
                   13898:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   13899:                                        $rolename,$result).'</span></li>';
                   13900:                     } else {
                   13901:                         $changedprivs{$rolename} = \%newprivs;
                   13902:                     }
                   13903:                     last;
                   13904:                 }
                   13905:             }
                   13906:             if (ref($current{'adhoc'}) eq 'HASH') {
                   13907:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   13908:                     %curr = %{$current{'adhoc'}{$rolename}};
                   13909:                 }
                   13910:             }
                   13911:         }
                   13912:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   13913:         $newpos =~ s/\D+//g;
                   13914:         $allpos[$newpos] = $rolename;
                   13915:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   13916:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   13917:         if ($curr{'desc'}) {
                   13918:             if ($curr{'desc'} ne $newdesc) {
                   13919:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   13920:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   13921:             }
                   13922:         } elsif ($newdesc ne '') {
                   13923:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   13924:             $newsettings{$rolename}{'desc'} = $newdesc;
                   13925:         }
                   13926:         my $access = $env{'form.'.$prefix.'_access'};
                   13927:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   13928:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   13929:             if ($access eq 'status') {
                   13930:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   13931:                 if (scalar(@statuses) == 0) {
                   13932:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
                   13933:                 } else {
                   13934:                     my (@shownstatus,$numtypes);
                   13935:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   13936:                     if (ref($types) eq 'ARRAY') {
                   13937:                         $numtypes = scalar(@{$types});
                   13938:                         foreach my $type (sort(@statuses)) {
                   13939:                             if ($type eq 'default') {
                   13940:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   13941:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   13942:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   13943:                                 push(@shownstatus,$usertypes->{$type});
                   13944:                             }
1.160.6.73  raeburn  13945:                         }
                   13946:                     }
1.160.6.77  raeburn  13947:                     if (grep(/^default$/,@statuses)) {
                   13948:                         push(@shownstatus,$othertitle);
                   13949:                     }
                   13950:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   13951:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   13952:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   13953:                     } else {
                   13954:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   13955:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   13956:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   13957:                             if (@diffs) {
                   13958:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   13959:                             }
                   13960:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13961:                             $changes{'customrole'}{$rolename}{$access} = 1;
                   13962:                         }
                   13963:                     }
                   13964:                 }
                   13965:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   13966:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   13967:                 my @newspecstaff;
                   13968:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   13969:                 foreach my $person (sort(@personnel)) {
                   13970:                     if ($domhelpdesk{$person}) {
                   13971:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   13972:                     }
                   13973:                 }
                   13974:                 if (ref($curr{$access}) eq 'ARRAY') {
                   13975:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   13976:                     if (@diffs) {
                   13977:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   13978:                     }
                   13979:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13980:                     $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73  raeburn  13981:                 }
1.160.6.77  raeburn  13982:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   13983:                     my ($uname,$udom) = split(/:/,$person);
                   13984:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   13985:                 }
                   13986:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26  raeburn  13987:             }
1.160.6.77  raeburn  13988:         } else {
                   13989:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   13990:         }
                   13991:         unless ($curr{'access'} eq $access) {
                   13992:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   13993:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73  raeburn  13994:         }
                   13995:     }
1.160.6.77  raeburn  13996:     if (@allpos > 0) {
                   13997:         my $idx = 0;
                   13998:         foreach my $rolename (@allpos) {
                   13999:             if ($rolename ne '') {
                   14000:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   14001:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   14002:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   14003:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   14004:                             $changes{'customrole'}{$rolename}{'order'} = 1;
                   14005:                             $newsettings{$rolename}{'order'} = $idx+1;
                   14006:                         }
                   14007:                     }
1.160.6.73  raeburn  14008:                 }
1.160.6.77  raeburn  14009:                 $idx ++;
1.122     jms      14010:             }
                   14011:         }
1.118     jms      14012:     }
1.123     jms      14013:     my $putresult;
                   14014:     if (keys(%changes) > 0) {
1.160.6.5  raeburn  14015:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   14016:         if ($putresult eq 'ok') {
1.160.6.77  raeburn  14017:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   14018:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   14019:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   14020:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   14021:                 }
                   14022:             }
                   14023:             my $cachetime = 24*60*60;
                   14024:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14025:             if (ref($lastactref) eq 'HASH') {
                   14026:                 $lastactref->{'domdefaults'} = 1;
                   14027:             }
                   14028:         } else {
                   14029:             $errors .= '<li><span class="LC_error">'.
                   14030:                        &mt('An error occurred storing the settings: [_1]',
                   14031:                            $putresult).'</span></li>';
                   14032:         }
                   14033:     }
                   14034:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   14035:         $resulttext = &mt('Changes made:').'<ul>';
                   14036:         my (%shownprivs,@levelorder);
                   14037:         @levelorder = ('c','d','s');
                   14038:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5  raeburn  14039:             foreach my $item (sort(keys(%changes))) {
                   14040:                 if ($item eq 'submitbugs') {
                   14041:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   14042:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   14043:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73  raeburn  14044:                 } elsif ($item eq 'customrole') {
                   14045:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77  raeburn  14046:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   14047:                         my %keytext = &Apache::lonlocal::texthash(
                   14048:                                                                    order  => 'Order',
                   14049:                                                                    desc   => 'Role description',
                   14050:                                                                    access => 'Role usage',
1.160.6.83  raeburn  14051:                                                                    status => 'Allowed institutional types',
1.160.6.77  raeburn  14052:                                                                    exc    => 'Allowed personnel',
                   14053:                                                                    inc    => 'Disallowed personnel',
                   14054:                         );
1.160.6.73  raeburn  14055:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77  raeburn  14056:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   14057:                                 if ($role eq $newrole) {
                   14058:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   14059:                                                               $role).'<ul>';
                   14060:                                 } else {
                   14061:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   14062:                                                               $role).'<ul>';
                   14063:                                 }
                   14064:                                 foreach my $key (@keyorder) {
                   14065:                                     if ($changes{'customrole'}{$role}{$key}) {
                   14066:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   14067:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   14068:                                                        '</li>';
                   14069:                                     }
                   14070:                                 }
                   14071:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   14072:                                     $shownprivs{$role} = 1;
                   14073:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   14074:                                     foreach my $level (@levelorder) {
                   14075:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   14076:                                             next if ($item eq '');
                   14077:                                             my ($priv) = split(/\&/,$item,2);
                   14078:                                             if (&Apache::lonnet::plaintext($priv)) {
                   14079:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   14080:                                                 unless ($level eq 'c') {
                   14081:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   14082:                                                 }
                   14083:                                                 $resulttext .= '</li>';
                   14084:                                             }
                   14085:                                         }
                   14086:                                     }
                   14087:                                     $resulttext .= '</ul>';
                   14088:                                 }
                   14089:                                 $resulttext .= '</ul></li>';
                   14090:                             }
1.160.6.73  raeburn  14091:                         }
                   14092:                     }
1.160.6.5  raeburn  14093:                 }
                   14094:             }
                   14095:         }
1.160.6.77  raeburn  14096:         if (keys(%changedprivs)) {
                   14097:             foreach my $role (sort(keys(%changedprivs))) {
                   14098:                 unless ($shownprivs{$role}) {
                   14099:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   14100:                                               $role).'<ul>'.
                   14101:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   14102:                     foreach my $level (@levelorder) {
                   14103:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   14104:                             next if ($item eq '');
                   14105:                             my ($priv) = split(/\&/,$item,2);
                   14106:                             if (&Apache::lonnet::plaintext($priv)) {
                   14107:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   14108:                                 unless ($level eq 'c') {
                   14109:                                     $resulttext .= ' ('.$lt{$level}.')';
                   14110:                                 }
                   14111:                                 $resulttext .= '</li>';
                   14112:                             }
                   14113:                         }
                   14114:                     }
                   14115:                     $resulttext .= '</ul></li></ul></li>';
                   14116:                 }
                   14117:             }
                   14118:         }
                   14119:         $resulttext .= '</ul>';
                   14120:     } else {
                   14121:         $resulttext = &mt('No changes made to help settings');
1.118     jms      14122:     }
                   14123:     if ($errors) {
1.160.6.5  raeburn  14124:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77  raeburn  14125:                                     $errors.'</ul>';
1.118     jms      14126:     }
                   14127:     return $resulttext;
                   14128: }
                   14129: 
1.121     raeburn  14130: sub modify_coursedefaults {
1.160.6.27  raeburn  14131:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  14132:     my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57  raeburn  14133:     my %defaultchecked = (
                   14134:                            'uselcmath'       => 'on',
                   14135:                            'usejsme'         => 'on'
                   14136:                          );
                   14137:     my @toggles = ('uselcmath','usejsme');
1.160.6.21  raeburn  14138:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70  raeburn  14139:                    'uploadquota_community','uploadquota_textbook','mysqltables_official',
                   14140:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30  raeburn  14141:     my @types = ('official','unofficial','community','textbook');
1.160.6.21  raeburn  14142:     my %staticdefaults = (
                   14143:                            anonsurvey_threshold => 10,
                   14144:                            uploadquota          => 500,
1.160.6.57  raeburn  14145:                            postsubmit           => 60,
1.160.6.70  raeburn  14146:                            mysqltables          => 172800,
1.160.6.21  raeburn  14147:                          );
1.160.6.90  raeburn  14148:     my %texoptions = (
                   14149:                         MathJax  => 'MathJax',
                   14150:                         mimetex  => &mt('Convert to Images'),
                   14151:                         tth      => &mt('TeX to HTML'),
                   14152:                      );
1.121     raeburn  14153:     $defaultshash{'coursedefaults'} = {};
                   14154: 
                   14155:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   14156:         if ($domconfig{'coursedefaults'} eq '') {
                   14157:             $domconfig{'coursedefaults'} = {};
                   14158:         }
                   14159:     }
                   14160: 
                   14161:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   14162:         foreach my $item (@toggles) {
                   14163:             if ($defaultchecked{$item} eq 'on') {
                   14164:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   14165:                     ($env{'form.'.$item} eq '0')) {
                   14166:                     $changes{$item} = 1;
1.160.6.16  raeburn  14167:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  14168:                     $changes{$item} = 1;
                   14169:                 }
                   14170:             } elsif ($defaultchecked{$item} eq 'off') {
                   14171:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   14172:                     ($env{'form.'.$item} eq '1')) {
                   14173:                     $changes{$item} = 1;
                   14174:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   14175:                     $changes{$item} = 1;
                   14176:                 }
                   14177:             }
                   14178:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   14179:         }
1.160.6.21  raeburn  14180:         foreach my $item (@numbers) {
                   14181:             my ($currdef,$newdef);
1.160.6.26  raeburn  14182:             $newdef = $env{'form.'.$item};
1.160.6.21  raeburn  14183:             if ($item eq 'anonsurvey_threshold') {
                   14184:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   14185:                 $newdef =~ s/\D//g;
                   14186:                 if ($newdef eq '' || $newdef < 1) {
                   14187:                     $newdef = 1;
                   14188:                 }
                   14189:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   14190:             } else {
1.160.6.70  raeburn  14191:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   14192:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   14193:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21  raeburn  14194:                 }
                   14195:                 $newdef =~ s/[^\w.\-]//g;
1.160.6.70  raeburn  14196:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21  raeburn  14197:             }
                   14198:             if ($currdef ne $newdef) {
                   14199:                 if ($item eq 'anonsurvey_threshold') {
                   14200:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   14201:                         $changes{$item} = 1;
                   14202:                     }
1.160.6.70  raeburn  14203:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   14204:                     my $setting = $1;
                   14205:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   14206:                         $changes{$setting} = 1;
1.160.6.21  raeburn  14207:                     }
                   14208:                 }
1.139     raeburn  14209:             }
                   14210:         }
1.160.6.90  raeburn  14211:         my $texengine;
                   14212:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   14213:             $texengine = $env{'form.texengine'};
                   14214:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   14215:             if ($currdef eq '') {
                   14216:                 unless ($texengine eq $Apache::lonnet::deftex) {
                   14217:                     $changes{'texengine'} = 1;
                   14218:                 }
                   14219:             } elsif ($currdef ne $texengine) {
                   14220:                 $changes{'texengine'} = 1;
                   14221:             }
                   14222:         }
                   14223:         if ($texengine ne '') {
                   14224:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   14225:         }
1.160.6.64  raeburn  14226:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   14227:         my @currclonecode;
                   14228:         if (ref($currclone) eq 'HASH') {
                   14229:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   14230:                 @currclonecode = @{$currclone->{'instcode'}};
                   14231:             }
                   14232:         }
                   14233:         my $newclone;
                   14234:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
                   14235:             $newclone = $env{'form.canclone'};
                   14236:         }
                   14237:         if ($newclone eq 'instcode') {
                   14238:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   14239:             my (%codedefaults,@code_order,@clonecode);
                   14240:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   14241:                                                     \@code_order);
                   14242:             foreach my $item (@code_order) {
                   14243:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   14244:                     push(@clonecode,$item);
                   14245:                 }
                   14246:             }
                   14247:             if (@clonecode) {
                   14248:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   14249:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   14250:                 if (@diffs) {
                   14251:                     $changes{'canclone'} = 1;
                   14252:                 }
                   14253:             } else {
                   14254:                 $newclone eq '';
                   14255:             }
                   14256:         } elsif ($newclone ne '') {
                   14257:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   14258:         }
                   14259:         if ($newclone ne $currclone) {
                   14260:             $changes{'canclone'} = 1;
                   14261:         }
1.160.6.57  raeburn  14262:         my %credits;
                   14263:         foreach my $type (@types) {
                   14264:             unless ($type eq 'community') {
                   14265:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   14266:                 $credits{$type} =~ s/[^\d.]+//g;
                   14267:             }
                   14268:         }
                   14269:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   14270:             ($env{'form.coursecredits'} eq '1')) {
                   14271:             $changes{'coursecredits'} = 1;
                   14272:             foreach my $type (keys(%credits)) {
                   14273:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   14274:             }
                   14275:         } else {
                   14276:             if ($env{'form.coursecredits'} eq '1') {
                   14277:                 foreach my $type (@types) {
                   14278:                     unless ($type eq 'community') {
                   14279:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
                   14280:                             $changes{'coursecredits'} = 1;
                   14281:                         }
                   14282:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   14283:                     }
                   14284:                 }
                   14285:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   14286:                 foreach my $type (@types) {
                   14287:                     unless ($type eq 'community') {
                   14288:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   14289:                             $changes{'coursecredits'} = 1;
                   14290:                             last;
                   14291:                         }
                   14292:                     }
                   14293:                 }
                   14294:             }
                   14295:         }
                   14296:         if ($env{'form.postsubmit'} eq '1') {
                   14297:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   14298:             my %currtimeout;
                   14299:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14300:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   14301:                     $changes{'postsubmit'} = 1;
                   14302:                 }
                   14303:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14304:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   14305:                 }
                   14306:             } else {
                   14307:                 $changes{'postsubmit'} = 1;
                   14308:             }
                   14309:             foreach my $type (@types) {
                   14310:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   14311:                 $timeout =~ s/\D//g;
                   14312:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   14313:                     $timeout = '';
                   14314:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   14315:                     $timeout = '0';
                   14316:                 }
                   14317:                 unless ($timeout eq '') {
                   14318:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   14319:                 }
                   14320:                 if (exists($currtimeout{$type})) {
                   14321:                     if ($timeout ne $currtimeout{$type}) {
                   14322:                         $changes{'postsubmit'} = 1;
                   14323:                     }
                   14324:                 } elsif ($timeout ne '') {
                   14325:                     $changes{'postsubmit'} = 1;
                   14326:                 }
                   14327:             }
                   14328:         } else {
                   14329:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   14330:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14331:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   14332:                     $changes{'postsubmit'} = 1;
                   14333:                 }
                   14334:             } else {
                   14335:                 $changes{'postsubmit'} = 1;
                   14336:             }
1.160.6.16  raeburn  14337:         }
1.121     raeburn  14338:     }
                   14339:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   14340:                                              $dom);
                   14341:     if ($putresult eq 'ok') {
                   14342:         if (keys(%changes) > 0) {
1.160.6.27  raeburn  14343:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57  raeburn  14344:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64  raeburn  14345:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90  raeburn  14346:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   14347:                 foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57  raeburn  14348:                     if ($changes{$item}) {
                   14349:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   14350:                     }
1.160.6.16  raeburn  14351:                 }
                   14352:                 if ($changes{'coursecredits'}) {
                   14353:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  14354:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   14355:                             $domdefaults{$type.'credits'} =
                   14356:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   14357:                         }
                   14358:                     }
                   14359:                 }
                   14360:                 if ($changes{'postsubmit'}) {
                   14361:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14362:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   14363:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14364:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   14365:                                 $domdefaults{$type.'postsubtimeout'} =
                   14366:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   14367:                             }
                   14368:                         }
1.160.6.16  raeburn  14369:                     }
                   14370:                 }
1.160.6.21  raeburn  14371:                 if ($changes{'uploadquota'}) {
                   14372:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   14373:                         foreach my $type (@types) {
                   14374:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   14375:                         }
                   14376:                     }
                   14377:                 }
1.160.6.64  raeburn  14378:                 if ($changes{'canclone'}) {
                   14379:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   14380:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   14381:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   14382:                             if (@clonecodes) {
                   14383:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   14384:                             }
                   14385:                         }
                   14386:                     } else {
                   14387:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   14388:                     }
                   14389:                 }
1.121     raeburn  14390:                 my $cachetime = 24*60*60;
                   14391:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  14392:                 if (ref($lastactref) eq 'HASH') {
                   14393:                     $lastactref->{'domdefaults'} = 1;
                   14394:                 }
1.121     raeburn  14395:             }
                   14396:             $resulttext = &mt('Changes made:').'<ul>';
                   14397:             foreach my $item (sort(keys(%changes))) {
1.160.6.57  raeburn  14398:                 if ($item eq 'uselcmath') {
1.121     raeburn  14399:                     if ($env{'form.'.$item} eq '1') {
1.160.6.57  raeburn  14400:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121     raeburn  14401:                     } else {
1.160.6.57  raeburn  14402:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   14403:                     }
                   14404:                 } elsif ($item eq 'usejsme') {
                   14405:                     if ($env{'form.'.$item} eq '1') {
                   14406:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   14407:                     } else {
                   14408:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121     raeburn  14409:                     }
1.160.6.90  raeburn  14410:                 } elsif ($item eq 'texengine') {
                   14411:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   14412:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   14413:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   14414:                     }
1.139     raeburn  14415:                 } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26  raeburn  14416:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21  raeburn  14417:                 } elsif ($item eq 'uploadquota') {
                   14418:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   14419:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   14420:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   14421:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30  raeburn  14422:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   14423: 
1.160.6.21  raeburn  14424:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   14425:                                        '</ul>'.
                   14426:                                        '</li>';
                   14427:                     } else {
                   14428:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   14429:                     }
1.160.6.70  raeburn  14430:                 } elsif ($item eq 'mysqltables') {
                   14431:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   14432:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   14433:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   14434:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   14435:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   14436:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   14437:                                        '</ul>'.
                   14438:                                        '</li>';
                   14439:                     } else {
                   14440:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   14441:                     }
1.160.6.57  raeburn  14442:                 } elsif ($item eq 'postsubmit') {
                   14443:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   14444:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   14445:                     } else {
                   14446:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   14447:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   14448:                             $resulttext .= &mt('durations:').'<ul>';
                   14449:                             foreach my $type (@types) {
                   14450:                                 $resulttext .= '<li>';
                   14451:                                 my $timeout;
                   14452:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   14453:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   14454:                                 }
                   14455:                                 my $display;
                   14456:                                 if ($timeout eq '0') {
                   14457:                                     $display = &mt('unlimited');
                   14458:                                 } elsif ($timeout eq '') {
                   14459:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   14460:                                 } else {
                   14461:                                     $display = &mt('[quant,_1,second]',$timeout);
                   14462:                                 }
                   14463:                                 if ($type eq 'community') {
                   14464:                                     $resulttext .= &mt('Communities');
                   14465:                                 } elsif ($type eq 'official') {
                   14466:                                     $resulttext .= &mt('Official courses');
                   14467:                                 } elsif ($type eq 'unofficial') {
                   14468:                                     $resulttext .= &mt('Unofficial courses');
                   14469:                                 } elsif ($type eq 'textbook') {
                   14470:                                     $resulttext .= &mt('Textbook courses');
                   14471:                                 }
                   14472:                                 $resulttext .= ' -- '.$display.'</li>';
                   14473:                             }
                   14474:                             $resulttext .= '</ul>';
                   14475:                         }
                   14476:                         $resulttext .= '</li>';
                   14477:                     }
1.160.6.16  raeburn  14478:                 } elsif ($item eq 'coursecredits') {
                   14479:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   14480:                         if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30  raeburn  14481:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   14482:                             ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16  raeburn  14483:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   14484:                         } else {
                   14485:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   14486:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   14487:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30  raeburn  14488:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16  raeburn  14489:                                            '</ul>'.
                   14490:                                            '</li>';
                   14491:                         }
                   14492:                     } else {
                   14493:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   14494:                     }
1.160.6.64  raeburn  14495:                 } elsif ($item eq 'canclone') {
                   14496:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   14497:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   14498:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   14499:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   14500:                         }
                   14501:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   14502:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   14503:                     } else {
                   14504:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
                   14505:                     }
1.140     raeburn  14506:                 }
1.121     raeburn  14507:             }
                   14508:             $resulttext .= '</ul>';
                   14509:         } else {
                   14510:             $resulttext = &mt('No changes made to course defaults');
                   14511:         }
                   14512:     } else {
                   14513:         $resulttext = '<span class="LC_error">'.
                   14514:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14515:     }
                   14516:     return $resulttext;
                   14517: }
                   14518: 
1.160.6.37  raeburn  14519: sub modify_selfenrollment {
                   14520:     my ($dom,$lastactref,%domconfig) = @_;
                   14521:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   14522:     my @types = ('official','unofficial','community','textbook');
                   14523:     my %titles = &tool_titles();
                   14524:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   14525:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   14526:     $ordered{'default'} = ['types','registered','approval','limit'];
                   14527: 
                   14528:     my (%roles,%shown,%toplevel);
                   14529:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   14530: 
                   14531:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   14532:         if ($domconfig{'selfenrollment'} eq '') {
                   14533:             $domconfig{'selfenrollment'} = {};
                   14534:         }
                   14535:     }
                   14536:     %toplevel = (
                   14537:                   admin      => 'Configuration Rights',
                   14538:                   default    => 'Default settings',
                   14539:                   validation => 'Validation of self-enrollment requests',
                   14540:                 );
                   14541:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   14542: 
                   14543:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   14544:         foreach my $item (@{$ordered{'admin'}}) {
                   14545:             foreach my $type (@types) {
                   14546:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   14547:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   14548:                 } else {
                   14549:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   14550:                 }
                   14551:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   14552:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   14553:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   14554:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   14555:                             push(@{$changes{'admin'}{$type}},$item);
                   14556:                         }
                   14557:                     } else {
                   14558:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   14559:                             push(@{$changes{'admin'}{$type}},$item);
                   14560:                         }
                   14561:                     }
                   14562:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   14563:                     push(@{$changes{'admin'}{$type}},$item);
                   14564:                 }
                   14565:             }
                   14566:         }
                   14567:     }
                   14568: 
                   14569:     foreach my $item (@{$ordered{'default'}}) {
                   14570:         foreach my $type (@types) {
                   14571:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   14572:             if ($item eq 'types') {
                   14573:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   14574:                     $value = '';
                   14575:                 }
                   14576:             } elsif ($item eq 'registered') {
                   14577:                 unless ($value eq '1') {
                   14578:                     $value = 0;
                   14579:                 }
                   14580:             } elsif ($item eq 'approval') {
                   14581:                 unless ($value =~ /^[012]$/) {
                   14582:                     $value = 0;
                   14583:                 }
                   14584:             } else {
                   14585:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   14586:                     $value = 'none';
                   14587:                 }
                   14588:             }
                   14589:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   14590:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   14591:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   14592:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   14593:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   14594:                          push(@{$changes{'default'}{$type}},$item);
                   14595:                     }
                   14596:                 } else {
                   14597:                     push(@{$changes{'default'}{$type}},$item);
                   14598:                 }
                   14599:             } else {
                   14600:                 push(@{$changes{'default'}{$type}},$item);
                   14601:             }
                   14602:             if ($item eq 'limit') {
                   14603:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   14604:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   14605:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   14606:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   14607:                     }
                   14608:                 } else {
                   14609:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   14610:                 }
                   14611:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   14612:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   14613:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   14614:                          push(@{$changes{'default'}{$type}},'cap');
                   14615:                     }
                   14616:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   14617:                     push(@{$changes{'default'}{$type}},'cap');
                   14618:                 }
                   14619:             }
                   14620:         }
                   14621:     }
                   14622: 
                   14623:     foreach my $item (@{$itemsref}) {
                   14624:         if ($item eq 'fields') {
                   14625:             my @changed;
                   14626:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   14627:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   14628:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   14629:             }
                   14630:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   14631:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   14632:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   14633:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   14634:                 } else {
                   14635:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   14636:                 }
                   14637:             } else {
                   14638:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   14639:             }
                   14640:             if (@changed) {
                   14641:                 if ($selfenrollhash{'validation'}{$item}) { 
                   14642:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   14643:                 } else {
                   14644:                     $changes{'validation'}{$item} = &mt('None');
                   14645:                 }
                   14646:             }
                   14647:         } else {
                   14648:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   14649:             if ($item eq 'markup') {
                   14650:                if ($env{'form.selfenroll_validation_'.$item}) {
                   14651:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   14652:                }
                   14653:             }
                   14654:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   14655:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   14656:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   14657:                 }
                   14658:             }
                   14659:         }
                   14660:     }
                   14661: 
                   14662:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   14663:                                              $dom);
                   14664:     if ($putresult eq 'ok') {
                   14665:         if (keys(%changes) > 0) {
                   14666:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14667:             $resulttext = &mt('Changes made:').'<ul>';
                   14668:             foreach my $key ('admin','default','validation') {
                   14669:                 if (ref($changes{$key}) eq 'HASH') {
                   14670:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   14671:                     if ($key eq 'validation') {
                   14672:                         foreach my $item (@{$itemsref}) {
                   14673:                             if (exists($changes{$key}{$item})) {
                   14674:                                 if ($item eq 'markup') {
                   14675:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   14676:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   14677:                                 } else {  
                   14678:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   14679:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   14680:                                 }
                   14681:                             }
                   14682:                         }
                   14683:                     } else {
                   14684:                         foreach my $type (@types) {
                   14685:                             if ($type eq 'community') {
                   14686:                                 $roles{'1'} = &mt('Community personnel');
                   14687:                             } else {
                   14688:                                 $roles{'1'} = &mt('Course personnel');
                   14689:                             }
                   14690:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
                   14691:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   14692:                                     if ($key eq 'admin') {
                   14693:                                         my @mgrdc = ();
                   14694:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   14695:                                             foreach my $item (@{$ordered{'admin'}}) {
                   14696:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   14697:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   14698:                                                         push(@mgrdc,$item);
                   14699:                                                     }
                   14700:                                                 }
                   14701:                                             }
                   14702:                                             if (@mgrdc) {
                   14703:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   14704:                                             } else {
                   14705:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   14706:                                             }
                   14707:                                         }
                   14708:                                     } else {
                   14709:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   14710:                                             foreach my $item (@{$ordered{$key}}) {
                   14711:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   14712:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   14713:                                                         $selfenrollhash{$key}{$type}{$item};
                   14714:                                                 }
                   14715:                                             }
                   14716:                                         }
                   14717:                                     }
                   14718:                                 }
                   14719:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   14720:                                 foreach my $item (@{$ordered{$key}}) {
                   14721:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   14722:                                         $resulttext .= '<li>';
                   14723:                                         if ($key eq 'admin') {
                   14724:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   14725:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   14726:                                         } else {
                   14727:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   14728:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   14729:                                         }
                   14730:                                         $resulttext .= '</li>';
                   14731:                                     }
                   14732:                                 }
                   14733:                                 $resulttext .= '</ul></li>';
                   14734:                             }
                   14735:                         }
                   14736:                         $resulttext .= '</ul></li>'; 
                   14737:                     }
                   14738:                 }
1.160.6.93  raeburn  14739:             }
                   14740:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   14741:                 my $cachetime = 24*60*60;
                   14742:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14743:                 if (ref($lastactref) eq 'HASH') {
                   14744:                     $lastactref->{'domdefaults'} = 1;
1.160.6.37  raeburn  14745:                 }
                   14746:             }
                   14747:             $resulttext .= '</ul>';
                   14748:         } else {
                   14749:             $resulttext = &mt('No changes made to self-enrollment settings');
                   14750:         }
                   14751:     } else {
                   14752:         $resulttext = '<span class="LC_error">'.
                   14753:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14754:     }
                   14755:     return $resulttext;
                   14756: }
                   14757: 
1.137     raeburn  14758: sub modify_usersessions {
1.160.6.27  raeburn  14759:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  14760:     my @hostingtypes = ('version','excludedomain','includedomain');
                   14761:     my @offloadtypes = ('primary','default');
                   14762:     my %types = (
                   14763:                   remote => \@hostingtypes,
                   14764:                   hosted => \@hostingtypes,
                   14765:                   spares => \@offloadtypes,
                   14766:                 );
                   14767:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  14768:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  14769:     my (%by_ip,%by_location,@intdoms);
                   14770:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   14771:     my @locations = sort(keys(%by_location));
1.137     raeburn  14772:     my (%defaultshash,%changes);
                   14773:     foreach my $prefix (@prefixes) {
                   14774:         $defaultshash{'usersessions'}{$prefix} = {};
                   14775:     }
1.160.6.27  raeburn  14776:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  14777:     my $resulttext;
1.138     raeburn  14778:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  14779:     foreach my $prefix (@prefixes) {
1.145     raeburn  14780:         next if ($prefix eq 'spares');
                   14781:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  14782:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   14783:             if ($type eq 'version') {
                   14784:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   14785:                 my $okvalue;
                   14786:                 if ($value ne '') {
                   14787:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   14788:                         $okvalue = $value;
                   14789:                     }
                   14790:                 }
                   14791:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14792:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   14793:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   14794:                             if ($inuse == 0) {
                   14795:                                 $changes{$prefix}{$type} = 1;
                   14796:                             } else {
                   14797:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   14798:                                     $changes{$prefix}{$type} = 1;
                   14799:                                 }
                   14800:                                 if ($okvalue ne '') {
                   14801:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14802:                                 } 
                   14803:                             }
                   14804:                         } else {
                   14805:                             if (($inuse == 1) && ($okvalue ne '')) {
                   14806:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14807:                                 $changes{$prefix}{$type} = 1;
                   14808:                             }
                   14809:                         }
                   14810:                     } else {
                   14811:                         if (($inuse == 1) && ($okvalue ne '')) {
                   14812:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14813:                             $changes{$prefix}{$type} = 1;
                   14814:                         }
                   14815:                     }
                   14816:                 } else {
                   14817:                     if (($inuse == 1) && ($okvalue ne '')) {
                   14818:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   14819:                         $changes{$prefix}{$type} = 1;
                   14820:                     }
                   14821:                 }
                   14822:             } else {
                   14823:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   14824:                 my @okvals;
                   14825:                 foreach my $val (@vals) {
1.138     raeburn  14826:                     if ($val =~ /:/) {
                   14827:                         my @items = split(/:/,$val);
                   14828:                         foreach my $item (@items) {
                   14829:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   14830:                                 push(@okvals,$item);
                   14831:                             }
                   14832:                         }
                   14833:                     } else {
                   14834:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   14835:                             push(@okvals,$val);
                   14836:                         }
1.137     raeburn  14837:                     }
                   14838:                 }
                   14839:                 @okvals = sort(@okvals);
                   14840:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14841:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   14842:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   14843:                             if ($inuse == 0) {
                   14844:                                 $changes{$prefix}{$type} = 1; 
                   14845:                             } else {
                   14846:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14847:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   14848:                                 if (@changed > 0) {
                   14849:                                     $changes{$prefix}{$type} = 1;
                   14850:                                 }
                   14851:                             }
                   14852:                         } else {
                   14853:                             if ($inuse == 1) {
                   14854:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14855:                                 $changes{$prefix}{$type} = 1;
                   14856:                             }
                   14857:                         } 
                   14858:                     } else {
                   14859:                         if ($inuse == 1) {
                   14860:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14861:                             $changes{$prefix}{$type} = 1;
                   14862:                         }
                   14863:                     }
                   14864:                 } else {
                   14865:                     if ($inuse == 1) {
                   14866:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   14867:                         $changes{$prefix}{$type} = 1;
                   14868:                     }
                   14869:                 }
                   14870:             }
                   14871:         }
                   14872:     }
1.145     raeburn  14873: 
                   14874:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  14875:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  14876:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   14877:     my $savespares;
                   14878: 
                   14879:     foreach my $lonhost (sort(keys(%servers))) {
                   14880:         my $serverhomeID =
                   14881:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  14882:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  14883:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   14884:         my %spareschg;
                   14885:         foreach my $type (@{$types{'spares'}}) {
                   14886:             my @okspares;
                   14887:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   14888:             foreach my $server (@checked) {
1.152     raeburn  14889:                 if (&Apache::lonnet::hostname($server) ne '') {
                   14890:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   14891:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   14892:                             push(@okspares,$server);
                   14893:                         }
1.145     raeburn  14894:                     }
                   14895:                 }
                   14896:             }
                   14897:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   14898:             my $newspare;
1.152     raeburn  14899:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   14900:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  14901:                     $newspare = $new;
                   14902:                 }
                   14903:             }
1.152     raeburn  14904:             my @spares;
                   14905:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   14906:                 @spares = sort(@okspares,$newspare);
                   14907:             } else {
                   14908:                 @spares = sort(@okspares);
                   14909:             }
                   14910:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  14911:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   14912:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  14913:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  14914:                     if (@diffs > 0) {
                   14915:                         $spareschg{$type} = 1;
                   14916:                     }
                   14917:                 }
                   14918:             }
                   14919:         }
                   14920:         if (keys(%spareschg) > 0) {
                   14921:             $changes{'spares'}{$lonhost} = \%spareschg;
                   14922:         }
                   14923:     }
1.160.6.61  raeburn  14924:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105  raeburn  14925:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61  raeburn  14926:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   14927:     my @okoffload;
                   14928:     if (@offloadnow) {
                   14929:         foreach my $server (@offloadnow) {
                   14930:             if (&Apache::lonnet::hostname($server) ne '') {
                   14931:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   14932:                     push(@okoffload,$server);
                   14933:                 }
                   14934:             }
                   14935:         }
                   14936:         if (@okoffload) {
                   14937:             foreach my $lonhost (@okoffload) {
                   14938:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   14939:             }
                   14940:         }
                   14941:     }
1.160.6.105  raeburn  14942:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   14943:     my @okoffloadoth;
                   14944:     if (@offloadoth) {
                   14945:         foreach my $server (@offloadoth) {
                   14946:             if (&Apache::lonnet::hostname($server) ne '') {
                   14947:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   14948:                     push(@okoffloadoth,$server);
                   14949:                 }
                   14950:             }
                   14951:         }
                   14952:         if (@okoffloadoth) {
                   14953:             foreach my $lonhost (@okoffloadoth) {
                   14954:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   14955:             }
                   14956:         }
                   14957:     }
1.145     raeburn  14958:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   14959:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   14960:             if (ref($changes{'spares'}) eq 'HASH') {
                   14961:                 if (keys(%{$changes{'spares'}}) > 0) {
                   14962:                     $savespares = 1;
                   14963:                 }
                   14964:             }
                   14965:         } else {
                   14966:             $savespares = 1;
                   14967:         }
1.160.6.105  raeburn  14968:         foreach my $offload ('offloadnow','offloadoth') {
                   14969:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   14970:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   14971:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   14972:                         $changes{$offload} = 1;
1.160.6.61  raeburn  14973:                         last;
                   14974:                     }
                   14975:                 }
1.160.6.105  raeburn  14976:                 unless ($changes{$offload}) {
                   14977:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   14978:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   14979:                             $changes{$offload} = 1;
                   14980:                             last;
                   14981:                         }
                   14982:                     }
                   14983:                 }
                   14984:             } else {
                   14985:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   14986:                      $changes{'offloadnow'} = 1;
                   14987:                 }
                   14988:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   14989:                     $changes{'offloadoth'} = 1;
                   14990:                 }
1.160.6.61  raeburn  14991:             }
1.160.6.105  raeburn  14992:         }
                   14993:     } else {
                   14994:         if (@okoffload) {
1.160.6.61  raeburn  14995:             $changes{'offloadnow'} = 1;
                   14996:         }
1.160.6.105  raeburn  14997:         if (@okoffloadoth) {
                   14998:             $changes{'offloadoth'} = 1;
                   14999:         }
1.145     raeburn  15000:     }
1.147     raeburn  15001:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   15002:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  15003:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   15004:                                                  $dom);
                   15005:         if ($putresult eq 'ok') {
                   15006:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   15007:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   15008:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   15009:                 }
                   15010:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   15011:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   15012:                 }
1.160.6.61  raeburn  15013:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   15014:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   15015:                 }
1.160.6.105  raeburn  15016:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   15017:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   15018:                 }
1.137     raeburn  15019:             }
                   15020:             my $cachetime = 24*60*60;
                   15021:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81  raeburn  15022:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27  raeburn  15023:             if (ref($lastactref) eq 'HASH') {
                   15024:                 $lastactref->{'domdefaults'} = 1;
1.160.6.81  raeburn  15025:                 $lastactref->{'usersessions'} = 1;
1.160.6.27  raeburn  15026:             }
1.147     raeburn  15027:             if (keys(%changes) > 0) {
                   15028:                 my %lt = &usersession_titles();
                   15029:                 $resulttext = &mt('Changes made:').'<ul>';
                   15030:                 foreach my $prefix (@prefixes) {
                   15031:                     if (ref($changes{$prefix}) eq 'HASH') {
                   15032:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   15033:                         if ($prefix eq 'spares') {
                   15034:                             if (ref($changes{$prefix}) eq 'HASH') {
                   15035:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   15036:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  15037:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27  raeburn  15038:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   15039:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  15040:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   15041:                                         foreach my $type (@{$types{$prefix}}) {
                   15042:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   15043:                                                 my $offloadto = &mt('None');
                   15044:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   15045:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   15046:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   15047:                                                     }
1.145     raeburn  15048:                                                 }
1.147     raeburn  15049:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  15050:                                             }
1.137     raeburn  15051:                                         }
                   15052:                                     }
1.147     raeburn  15053:                                     $resulttext .= '</li>';
1.137     raeburn  15054:                                 }
                   15055:                             }
1.147     raeburn  15056:                         } else {
                   15057:                             foreach my $type (@{$types{$prefix}}) {
                   15058:                                 if (defined($changes{$prefix}{$type})) {
                   15059:                                     my $newvalue;
                   15060:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   15061:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   15062:                                             if ($type eq 'version') {
                   15063:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   15064:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   15065:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   15066:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   15067:                                                 }
1.145     raeburn  15068:                                             }
                   15069:                                         }
                   15070:                                     }
1.147     raeburn  15071:                                     if ($newvalue eq '') {
                   15072:                                         if ($type eq 'version') {
                   15073:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   15074:                                         } else {
                   15075:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   15076:                                         }
1.145     raeburn  15077:                                     } else {
1.147     raeburn  15078:                                         if ($type eq 'version') {
                   15079:                                             $newvalue .= ' '.&mt('(or later)'); 
                   15080:                                         }
                   15081:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  15082:                                     }
1.137     raeburn  15083:                                 }
                   15084:                             }
                   15085:                         }
1.147     raeburn  15086:                         $resulttext .= '</ul>';
1.137     raeburn  15087:                     }
                   15088:                 }
1.160.6.61  raeburn  15089:                 if ($changes{'offloadnow'}) {
                   15090:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   15091:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105  raeburn  15092:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61  raeburn  15093:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   15094:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   15095:                             }
                   15096:                             $resulttext .= '</ul>';
                   15097:                         } else {
1.160.6.105  raeburn  15098:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   15099:                         }
                   15100:                     } else {
                   15101:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   15102:                     }
                   15103:                 }
                   15104:                 if ($changes{'offloadoth'}) {
                   15105:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   15106:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   15107:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   15108:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   15109:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   15110:                             }
                   15111:                             $resulttext .= '</ul>';
                   15112:                         } else {
                   15113:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61  raeburn  15114:                         }
                   15115:                     } else {
1.160.6.105  raeburn  15116:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61  raeburn  15117:                     }
                   15118:                 }
1.147     raeburn  15119:                 $resulttext .= '</ul>';
                   15120:             } else {
                   15121:                 $resulttext = $nochgmsg;
1.137     raeburn  15122:             }
                   15123:         } else {
                   15124:             $resulttext = '<span class="LC_error">'.
                   15125:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   15126:         }
                   15127:     } else {
1.147     raeburn  15128:         $resulttext = $nochgmsg;
1.137     raeburn  15129:     }
                   15130:     return $resulttext;
                   15131: }
                   15132: 
1.150     raeburn  15133: sub modify_loadbalancing {
                   15134:     my ($dom,%domconfig) = @_;
                   15135:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   15136:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   15137:     my ($othertitle,$usertypes,$types) =
                   15138:         &Apache::loncommon::sorted_inst_types($dom);
                   15139:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55  raeburn  15140:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  15141:     my @sparestypes = ('primary','default');
                   15142:     my %typetitles = &sparestype_titles();
                   15143:     my $resulttext;
1.160.6.94  raeburn  15144:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  15145:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   15146:         %existing = %{$domconfig{'loadbalancing'}};
                   15147:     }
                   15148:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  15149:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  15150:     my ($saveloadbalancing,%defaultshash,%changes);
                   15151:     my ($alltypes,$othertypes,$titles) =
                   15152:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   15153:     my %ruletitles = &offloadtype_text();
                   15154:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   15155:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   15156:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   15157:         if ($balancer eq '') {
                   15158:             next;
                   15159:         }
                   15160:         if (!exists($servers{$balancer})) {
                   15161:             if (exists($currbalancer{$balancer})) {
                   15162:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  15163:             }
1.160.6.7  raeburn  15164:             next;
                   15165:         }
                   15166:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   15167:             push(@{$changes{'delete'}},$balancer);
                   15168:             next;
                   15169:         }
                   15170:         if (!exists($currbalancer{$balancer})) {
                   15171:             push(@{$changes{'add'}},$balancer);
                   15172:         }
                   15173:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   15174:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   15175:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   15176:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   15177:             $saveloadbalancing = 1;
                   15178:         }
                   15179:         foreach my $sparetype (@sparestypes) {
                   15180:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   15181:             my @offloadto;
                   15182:             foreach my $target (@targets) {
                   15183:                 if (($servers{$target}) && ($target ne $balancer)) {
                   15184:                     if ($sparetype eq 'default') {
                   15185:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   15186:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  15187:                         }
                   15188:                     }
1.160.6.7  raeburn  15189:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   15190:                         push(@offloadto,$target);
                   15191:                     }
1.150     raeburn  15192:                 }
                   15193:             }
1.160.6.76  raeburn  15194:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   15195:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   15196:                     push(@offloadto,$balancer);
                   15197:                 }
                   15198:             }
                   15199:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  15200:         }
1.160.6.94  raeburn  15201:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   15202:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   15203:             if (exists($currbalancer{$balancer})) {
                   15204:                 unless ($currcookies{$balancer}) {
                   15205:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   15206:                 }
                   15207:             }
                   15208:         } elsif (exists($currbalancer{$balancer})) {
                   15209:             if ($currcookies{$balancer}) {
                   15210:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   15211:             }
                   15212:         }
1.160.6.7  raeburn  15213:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  15214:             foreach my $sparetype (@sparestypes) {
1.160.6.7  raeburn  15215:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   15216:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  15217:                     if (@targetdiffs > 0) {
1.160.6.7  raeburn  15218:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  15219:                     }
1.160.6.7  raeburn  15220:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15221:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15222:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  15223:                     }
                   15224:                 }
                   15225:             }
                   15226:         } else {
1.160.6.7  raeburn  15227:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   15228:                 foreach my $sparetype (@sparestypes) {
                   15229:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15230:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15231:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   15232:                         }
1.150     raeburn  15233:                     }
                   15234:                 }
1.160.6.7  raeburn  15235:             }
1.150     raeburn  15236:         }
                   15237:         my $ishomedom;
1.160.6.7  raeburn  15238:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   15239:             $ishomedom = 1;
1.150     raeburn  15240:         }
                   15241:         if (ref($alltypes) eq 'ARRAY') {
                   15242:             foreach my $type (@{$alltypes}) {
                   15243:                 my $rule;
1.160.6.7  raeburn  15244:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  15245:                          (!$ishomedom)) {
1.160.6.7  raeburn  15246:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   15247:                 }
                   15248:                 if ($rule eq 'specific') {
1.160.6.55  raeburn  15249:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   15250:                     if (exists($servers{$specifiedhost})) {
                   15251:                         $rule = $specifiedhost;
                   15252:                     }
1.150     raeburn  15253:                 }
1.160.6.7  raeburn  15254:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   15255:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   15256:                     if ($rule ne $currrules{$balancer}{$type}) {
                   15257:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  15258:                     }
                   15259:                 } elsif ($rule ne '') {
1.160.6.7  raeburn  15260:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  15261:                 }
                   15262:             }
                   15263:         }
1.160.6.7  raeburn  15264:     }
                   15265:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   15266:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   15267:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   15268:             $defaultshash{'loadbalancing'} = {};
                   15269:         }
                   15270:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   15271:                                                  \%defaultshash,$dom);
                   15272:         if ($putresult eq 'ok') {
                   15273:             if (keys(%changes) > 0) {
1.160.6.54  raeburn  15274:                 my %toupdate;
1.160.6.7  raeburn  15275:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   15276:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   15277:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54  raeburn  15278:                         $toupdate{$balancer} = 1;
1.150     raeburn  15279:                     }
1.160.6.7  raeburn  15280:                 }
                   15281:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   15282:                     foreach my $balancer (sort(@{$changes{'add'}})) {
                   15283:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54  raeburn  15284:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  15285:                     }
                   15286:                 }
                   15287:                 if (ref($changes{'curr'}) eq 'HASH') {
                   15288:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55  raeburn  15289:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  15290:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   15291:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   15292:                                 my %offloadstr;
                   15293:                                 foreach my $sparetype (@sparestypes) {
                   15294:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15295:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   15296:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   15297:                                         }
                   15298:                                     }
1.150     raeburn  15299:                                 }
1.160.6.7  raeburn  15300:                                 if (keys(%offloadstr) == 0) {
                   15301:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  15302:                                 } else {
1.160.6.7  raeburn  15303:                                     my $showoffload;
                   15304:                                     foreach my $sparetype (@sparestypes) {
                   15305:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   15306:                                         if (defined($offloadstr{$sparetype})) {
                   15307:                                             $showoffload .= $offloadstr{$sparetype};
                   15308:                                         } else {
                   15309:                                             $showoffload .= &mt('None');
                   15310:                                         }
                   15311:                                         $showoffload .= ('&nbsp;'x3);
                   15312:                                     }
                   15313:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  15314:                                 }
                   15315:                             }
                   15316:                         }
1.160.6.7  raeburn  15317:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   15318:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   15319:                                 foreach my $type (@{$alltypes}) {
                   15320:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   15321:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   15322:                                         my $balancetext;
                   15323:                                         if ($rule eq '') {
                   15324:                                             $balancetext =  $ruletitles{'default'};
1.160.6.26  raeburn  15325:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55  raeburn  15326:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                   15327:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54  raeburn  15328:                                                 foreach my $sparetype (@sparestypes) {
                   15329:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   15330:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   15331:                                                     }
                   15332:                                                 }
1.160.6.55  raeburn  15333:                                                 foreach my $item (@{$alltypes}) {
                   15334:                                                     next if ($item =~  /^_LC_ipchange/);
                   15335:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   15336:                                                     if ($hasrule eq 'homeserver') {
                   15337:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   15338:                                                     } else {
                   15339:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   15340:                                                             if ($servers{$hasrule}) {
                   15341:                                                                 $toupdate{$hasrule} = 1;
                   15342:                                                             }
                   15343:                                                         }
                   15344:                                                     }
                   15345:                                                 }
                   15346:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   15347:                                                     $balancetext =  $ruletitles{$rule};
                   15348:                                                 } else {
                   15349:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   15350:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   15351:                                                     if ($receiver) {
                   15352:                                                         $toupdate{$receiver};
                   15353:                                                     }
                   15354:                                                 }
                   15355:                                             } else {
                   15356:                                                 $balancetext =  $ruletitles{$rule};
1.160.6.54  raeburn  15357:                                             }
1.160.6.7  raeburn  15358:                                         } else {
                   15359:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   15360:                                         }
1.160.6.26  raeburn  15361:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  15362:                                     }
                   15363:                                 }
                   15364:                             }
                   15365:                         }
1.160.6.94  raeburn  15366:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
                   15367:                             $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   15368:                                                       $balancer).'</li>';
                   15369:                         }
1.160.6.106  raeburn  15370:                     }
                   15371:                 }
                   15372:                 if (keys(%toupdate)) {
                   15373:                     my %thismachine;
                   15374:                     my $updatedhere;
                   15375:                     my $cachetime = 60*60*24;
                   15376:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   15377:                     foreach my $lonhost (keys(%toupdate)) {
                   15378:                         if ($thismachine{$lonhost}) {
                   15379:                             unless ($updatedhere) {
                   15380:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   15381:                                                               $defaultshash{'loadbalancing'},
                   15382:                                                               $cachetime);
                   15383:                                 $updatedhere = 1;
1.160.6.54  raeburn  15384:                             }
1.160.6.106  raeburn  15385:                         } else {
                   15386:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   15387:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54  raeburn  15388:                         }
1.150     raeburn  15389:                     }
1.160.6.7  raeburn  15390:                 }
                   15391:                 if ($resulttext ne '') {
                   15392:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  15393:                 } else {
                   15394:                     $resulttext = $nochgmsg;
                   15395:                 }
                   15396:             } else {
1.160.6.7  raeburn  15397:                 $resulttext = $nochgmsg;
1.150     raeburn  15398:             }
                   15399:         } else {
1.160.6.7  raeburn  15400:             $resulttext = '<span class="LC_error">'.
                   15401:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  15402:         }
                   15403:     } else {
1.160.6.7  raeburn  15404:         $resulttext = $nochgmsg;
1.150     raeburn  15405:     }
                   15406:     return $resulttext;
                   15407: }
                   15408: 
1.48      raeburn  15409: sub recurse_check {
                   15410:     my ($chkcats,$categories,$depth,$name) = @_;
                   15411:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   15412:         my $chg = 0;
                   15413:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   15414:             my $category = $chkcats->[$depth]{$name}[$j];
                   15415:             my $item;
                   15416:             if ($category eq '') {
                   15417:                 $chg ++;
                   15418:             } else {
                   15419:                 my $deeper = $depth + 1;
                   15420:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   15421:                 if ($chg) {
                   15422:                     $categories->{$item} -= $chg;
                   15423:                 }
                   15424:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   15425:                 $deeper --;
                   15426:             }
                   15427:         }
                   15428:     }
                   15429:     return;
                   15430: }
                   15431: 
                   15432: sub recurse_cat_deletes {
                   15433:     my ($item,$coursecategories,$deletions) = @_;
                   15434:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   15435:     my $subdepth = $depth + 1;
                   15436:     if (ref($coursecategories) eq 'HASH') {
                   15437:         foreach my $subitem (keys(%{$coursecategories})) {
                   15438:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   15439:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   15440:                 delete($coursecategories->{$subitem});
                   15441:                 $deletions->{$subitem} = 1;
                   15442:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26  raeburn  15443:             }
1.48      raeburn  15444:         }
                   15445:     }
                   15446:     return;
                   15447: }
                   15448: 
1.125     raeburn  15449: sub active_dc_picker {
1.160.6.16  raeburn  15450:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77  raeburn  15451:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16  raeburn  15452:     my @domcoord = keys(%domcoords);
                   15453:     if (keys(%currhash)) {
                   15454:         foreach my $dc (keys(%currhash)) {
                   15455:             unless (exists($domcoords{$dc})) {
                   15456:                 push(@domcoord,$dc);
                   15457:             }
                   15458:         }
                   15459:     }
                   15460:     @domcoord = sort(@domcoord);
                   15461:     my $numdcs = scalar(@domcoord);
                   15462:     my $rows = 0;
                   15463:     my $table;
1.125     raeburn  15464:     if ($numdcs > 1) {
1.160.6.16  raeburn  15465:         $table = '<table>';
                   15466:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  15467:             my $rem = $i%($numinrow);
                   15468:             if ($rem == 0) {
                   15469:                 if ($i > 0) {
1.160.6.16  raeburn  15470:                     $table .= '</tr>';
1.125     raeburn  15471:                 }
1.160.6.16  raeburn  15472:                 $table .= '<tr>';
                   15473:                 $rows ++;
1.125     raeburn  15474:             }
1.160.6.16  raeburn  15475:             my $check = '';
                   15476:             if ($inputtype eq 'radio') {
                   15477:                 if (keys(%currhash) == 0) {
                   15478:                     if (!$i) {
                   15479:                         $check = ' checked="checked"';
                   15480:                     }
                   15481:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   15482:                     $check = ' checked="checked"';
                   15483:                 }
                   15484:             } else {
                   15485:                 if (exists($currhash{$domcoord[$i]})) {
                   15486:                     $check = ' checked="checked"';
1.125     raeburn  15487:                 }
                   15488:             }
1.160.6.16  raeburn  15489:             if ($i == @domcoord - 1) {
1.125     raeburn  15490:                 my $colsleft = $numinrow - $rem;
                   15491:                 if ($colsleft > 1) {
1.160.6.16  raeburn  15492:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  15493:                 } else {
1.160.6.16  raeburn  15494:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  15495:                 }
                   15496:             } else {
1.160.6.16  raeburn  15497:                 $table .= '<td class="LC_left_item">';
                   15498:             }
                   15499:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   15500:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   15501:             $table .= '<span class="LC_nobreak"><label>'.
                   15502:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   15503:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   15504:             if ($user ne $dcname.':'.$dcdom) {
1.160.6.32  raeburn  15505:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.125     raeburn  15506:             }
1.160.6.33  raeburn  15507:             $table .= '</label></span></td>';
1.125     raeburn  15508:         }
1.160.6.16  raeburn  15509:         $table .= '</tr></table>';
                   15510:     } elsif ($numdcs == 1) {
1.160.6.32  raeburn  15511:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   15512:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16  raeburn  15513:         if ($inputtype eq 'radio') {
1.160.6.50  raeburn  15514:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31  raeburn  15515:             if ($user ne $dcname.':'.$dcdom) {
                   15516:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   15517:             }
1.160.6.16  raeburn  15518:         } else {
                   15519:             my $check;
                   15520:             if (exists($currhash{$domcoord[0]})) {
                   15521:                 $check = ' checked="checked"';
                   15522:             }
1.160.6.50  raeburn  15523:             $table = '<span class="LC_nobreak"><label>'.
                   15524:                      '<input type="checkbox" name="'.$name.'" '.
                   15525:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31  raeburn  15526:             if ($user ne $dcname.':'.$dcdom) {
                   15527:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   15528:             }
                   15529:             $table .= '</label></span>';
1.160.6.16  raeburn  15530:             $rows ++;
                   15531:         }
1.125     raeburn  15532:     }
1.160.6.16  raeburn  15533:     return ($numdcs,$table,$rows);
1.125     raeburn  15534: }
                   15535: 
1.137     raeburn  15536: sub usersession_titles {
                   15537:     return &Apache::lonlocal::texthash(
                   15538:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   15539:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  15540:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  15541:                version => 'LON-CAPA version requirement',
1.138     raeburn  15542:                excludedomain => 'Allow all, but exclude specific domains',
                   15543:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  15544:                primary => 'Primary (checked first)',
1.154     raeburn  15545:                default => 'Default',
1.137     raeburn  15546:            );
                   15547: }
                   15548: 
1.152     raeburn  15549: sub id_for_thisdom {
                   15550:     my (%servers) = @_;
                   15551:     my %altids;
                   15552:     foreach my $server (keys(%servers)) {
                   15553:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   15554:         if ($serverhome ne $server) {
                   15555:             $altids{$serverhome} = $server;
                   15556:         }
                   15557:     }
                   15558:     return %altids;
                   15559: }
                   15560: 
1.150     raeburn  15561: sub count_servers {
                   15562:     my ($currbalancer,%servers) = @_;
                   15563:     my (@spares,$numspares);
                   15564:     foreach my $lonhost (sort(keys(%servers))) {
                   15565:         next if ($currbalancer eq $lonhost);
                   15566:         push(@spares,$lonhost);
                   15567:     }
                   15568:     if ($currbalancer) {
                   15569:         $numspares = scalar(@spares);
                   15570:     } else {
                   15571:         $numspares = scalar(@spares) - 1;
                   15572:     }
                   15573:     return ($numspares,@spares);
                   15574: }
                   15575: 
                   15576: sub lonbalance_targets_js {
1.160.6.7  raeburn  15577:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  15578:     my $select = &mt('Select');
                   15579:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   15580:     if (ref($servers) eq 'HASH') {
                   15581:         $alltargets = join("','",sort(keys(%{$servers})));
                   15582:         my @homedoms;
                   15583:         foreach my $server (sort(keys(%{$servers}))) {
                   15584:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   15585:                 push(@homedoms,'1');
                   15586:             } else {
                   15587:                 push(@homedoms,'0');
                   15588:             }
                   15589:         }
                   15590:         $allishome = join("','",@homedoms);
                   15591:     }
                   15592:     if (ref($types) eq 'ARRAY') {
                   15593:         if (@{$types} > 0) {
                   15594:             @alltypes = @{$types};
                   15595:         }
                   15596:     }
                   15597:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   15598:     $allinsttypes = join("','",@alltypes);
1.160.6.94  raeburn  15599:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  15600:     if (ref($settings) eq 'HASH') {
                   15601:         %existing = %{$settings};
                   15602:     }
                   15603:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  15604:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  15605:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  15606:     return <<"END";
                   15607: 
                   15608: <script type="text/javascript">
                   15609: // <![CDATA[
                   15610: 
1.160.6.7  raeburn  15611: currBalancers = new Array('$balancers');
                   15612: 
                   15613: function toggleTargets(balnum) {
                   15614:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   15615:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   15616:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   15617:     var prevbalancer = prevhostitem.value;
                   15618:     var baltotal = document.getElementById('loadbalancing_total').value;
                   15619:     prevhostitem.value = balancer;
                   15620:     if (prevbalancer != '') {
                   15621:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   15622:         if (prevIdx != -1) {
                   15623:             currBalancers.splice(prevIdx,1);
                   15624:         }
                   15625:     }
1.150     raeburn  15626:     if (balancer == '') {
1.160.6.7  raeburn  15627:         hideSpares(balnum);
1.150     raeburn  15628:     } else {
1.160.6.7  raeburn  15629:         var currIdx = currBalancers.indexOf(balancer);
                   15630:         if (currIdx == -1) {
                   15631:             currBalancers.push(balancer);
                   15632:         }
1.150     raeburn  15633:         var homedoms = new Array('$allishome');
1.160.6.7  raeburn  15634:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   15635:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  15636:     }
1.160.6.7  raeburn  15637:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  15638:     return;
                   15639: }
                   15640: 
1.160.6.7  raeburn  15641: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  15642:     var alltargets = new Array('$alltargets');
                   15643:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  15644:     var offloadtypes = new Array('primary','default');
                   15645: 
1.160.6.7  raeburn  15646:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   15647:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  15648:  
1.151     raeburn  15649:     for (var i=0; i<offloadtypes.length; i++) {
                   15650:         var count = 0;
                   15651:         for (var j=0; j<alltargets.length; j++) {
                   15652:             if (alltargets[j] != balancer) {
1.160.6.7  raeburn  15653:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   15654:                 item.value = alltargets[j];
                   15655:                 item.style.textAlign='left';
                   15656:                 item.style.textFace='normal';
                   15657:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   15658:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   15659:                     item.disabled = '';
                   15660:                 } else {
                   15661:                     item.disabled = 'disabled';
                   15662:                     item.checked = false;
                   15663:                 }
1.151     raeburn  15664:                 count ++;
                   15665:             }
1.150     raeburn  15666:         }
                   15667:     }
1.151     raeburn  15668:     for (var k=0; k<insttypes.length; k++) {
                   15669:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  15670:             if (ishomedom == 1) {
1.160.6.7  raeburn  15671:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   15672:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  15673:             } else {
1.160.6.7  raeburn  15674:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   15675:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  15676:             }
                   15677:         } else {
1.160.6.7  raeburn  15678:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   15679:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  15680:         }
1.151     raeburn  15681:         if ((insttypes[k] != '_LC_external') && 
                   15682:             ((insttypes[k] != '_LC_internetdom') ||
                   15683:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7  raeburn  15684:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   15685:             item.options.length = 0;
                   15686:             item.options[0] = new Option("","",true,true);
                   15687:             var idx = 0;
1.151     raeburn  15688:             for (var m=0; m<alltargets.length; m++) {
1.160.6.7  raeburn  15689:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   15690:                     idx ++;
                   15691:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  15692:                 }
                   15693:             }
                   15694:         }
                   15695:     }
                   15696:     return;
                   15697: }
                   15698: 
1.160.6.7  raeburn  15699: function hideSpares(balnum) {
1.150     raeburn  15700:     var alltargets = new Array('$alltargets');
                   15701:     var insttypes = new Array('$allinsttypes');
                   15702:     var offloadtypes = new Array('primary','default');
                   15703: 
1.160.6.7  raeburn  15704:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   15705:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  15706: 
                   15707:     var total = alltargets.length - 1;
                   15708:     for (var i=0; i<offloadtypes; i++) {
                   15709:         for (var j=0; j<total; j++) {
1.160.6.7  raeburn  15710:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   15711:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   15712:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  15713:         }
1.150     raeburn  15714:     }
                   15715:     for (var k=0; k<insttypes.length; k++) {
1.160.6.7  raeburn  15716:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   15717:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  15718:         if (insttypes[k] != '_LC_external') {
1.160.6.7  raeburn  15719:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   15720:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  15721:         }
                   15722:     }
                   15723:     return;
                   15724: }
                   15725: 
1.160.6.7  raeburn  15726: function checkOffloads(item,balnum,type) {
1.150     raeburn  15727:     var alltargets = new Array('$alltargets');
                   15728:     var offloadtypes = new Array('primary','default');
                   15729:     if (item.checked) {
                   15730:         var total = alltargets.length - 1;
                   15731:         var other;
                   15732:         if (type == offloadtypes[0]) {
1.151     raeburn  15733:             other = offloadtypes[1];
1.150     raeburn  15734:         } else {
1.151     raeburn  15735:             other = offloadtypes[0];
1.150     raeburn  15736:         }
                   15737:         for (var i=0; i<total; i++) {
1.160.6.7  raeburn  15738:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  15739:             if (server == item.value) {
1.160.6.7  raeburn  15740:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   15741:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  15742:                 }
                   15743:             }
                   15744:         }
                   15745:     }
                   15746:     return;
                   15747: }
                   15748: 
1.160.6.7  raeburn  15749: function singleServerToggle(balnum,type) {
                   15750:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  15751:     if (offloadtoSelIdx == 0) {
1.160.6.7  raeburn  15752:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   15753:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  15754: 
                   15755:     } else {
1.160.6.7  raeburn  15756:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   15757:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  15758:     }
                   15759:     return;
                   15760: }
                   15761: 
1.160.6.7  raeburn  15762: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  15763:     if (type == '_LC_external') {
1.160.6.26  raeburn  15764:         return;
1.150     raeburn  15765:     }
1.160.6.7  raeburn  15766:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  15767:     for (var i=0; i<typesRules.length; i++) {
                   15768:         if (formname.elements[typesRules[i]].checked) {
                   15769:             if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7  raeburn  15770:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   15771:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  15772:             } else {
1.160.6.7  raeburn  15773:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   15774:             }
                   15775:         }
                   15776:     }
                   15777:     return;
                   15778: }
                   15779: 
                   15780: function balancerDeleteChange(balnum) {
                   15781:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   15782:     var baltotal = document.getElementById('loadbalancing_total').value;
                   15783:     var addtarget;
                   15784:     var removetarget;
                   15785:     var action = 'delete';
                   15786:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   15787:         var lonhost = hostitem.value;
                   15788:         var currIdx = currBalancers.indexOf(lonhost);
                   15789:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   15790:             if (currIdx != -1) {
                   15791:                 currBalancers.splice(currIdx,1);
                   15792:             }
                   15793:             addtarget = lonhost;
                   15794:         } else {
                   15795:             if (currIdx == -1) {
                   15796:                 currBalancers.push(lonhost);
                   15797:             }
                   15798:             removetarget = lonhost;
                   15799:             action = 'undelete';
                   15800:         }
                   15801:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   15802:     }
                   15803:     return;
                   15804: }
                   15805: 
                   15806: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   15807:     if (baltotal > 1) {
                   15808:         var offloadtypes = new Array('primary','default');
                   15809:         var alltargets = new Array('$alltargets');
                   15810:         var insttypes = new Array('$allinsttypes');
                   15811:         for (var i=0; i<baltotal; i++) {
                   15812:             if (i != balnum) {
                   15813:                 for (var j=0; j<offloadtypes.length; j++) {
                   15814:                     var total = alltargets.length - 1;
                   15815:                     for (var k=0; k<total; k++) {
                   15816:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   15817:                         var server = serveritem.value;
                   15818:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   15819:                             if (server == addtarget) {
                   15820:                                 serveritem.disabled = '';
                   15821:                             }
                   15822:                         }
                   15823:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   15824:                             if (server == removetarget) {
                   15825:                                 serveritem.disabled = 'disabled';
                   15826:                                 serveritem.checked = false;
                   15827:                             }
                   15828:                         }
                   15829:                     }
                   15830:                 }
                   15831:                 for (var j=0; j<insttypes.length; j++) {
                   15832:                     if (insttypes[j] != '_LC_external') {
                   15833:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   15834:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   15835:                             var currSel = singleserver.selectedIndex;
                   15836:                             var currVal = singleserver.options[currSel].value;
                   15837:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   15838:                                 var numoptions = singleserver.options.length;
                   15839:                                 var needsnew = 1;
                   15840:                                 for (var k=0; k<numoptions; k++) {
                   15841:                                     if (singleserver.options[k] == addtarget) {
                   15842:                                         needsnew = 0;
                   15843:                                         break;
                   15844:                                     }
                   15845:                                 }
                   15846:                                 if (needsnew == 1) {
                   15847:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   15848:                                 }
                   15849:                             }
                   15850:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   15851:                                 singleserver.options.length = 0;
                   15852:                                 if ((currVal) && (currVal != removetarget)) {
                   15853:                                     singleserver.options[0] = new Option("","",false,false);
                   15854:                                 } else {
                   15855:                                     singleserver.options[0] = new Option("","",true,true);
                   15856:                                 }
                   15857:                                 var idx = 0;
                   15858:                                 for (var m=0; m<alltargets.length; m++) {
                   15859:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   15860:                                         idx ++;
                   15861:                                         if (currVal == alltargets[m]) {
                   15862:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   15863:                                         } else {
                   15864:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   15865:                                         }
                   15866:                                     }
                   15867:                                 }
                   15868:                             }
                   15869:                         }
                   15870:                     }
                   15871:                 }
1.150     raeburn  15872:             }
                   15873:         }
                   15874:     }
                   15875:     return;
                   15876: }
                   15877: 
1.152     raeburn  15878: // ]]>
                   15879: </script>
                   15880: 
                   15881: END
                   15882: }
                   15883: 
                   15884: sub new_spares_js {
                   15885:     my @sparestypes = ('primary','default');
                   15886:     my $types = join("','",@sparestypes);
                   15887:     my $select = &mt('Select');
                   15888:     return <<"END";
                   15889: 
                   15890: <script type="text/javascript">
                   15891: // <![CDATA[
                   15892: 
                   15893: function updateNewSpares(formname,lonhost) {
                   15894:     var types = new Array('$types');
                   15895:     var include = new Array();
                   15896:     var exclude = new Array();
                   15897:     for (var i=0; i<types.length; i++) {
                   15898:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   15899:         for (var j=0; j<spareboxes.length; j++) {
                   15900:             if (formname.elements[spareboxes[j]].checked) {
                   15901:                 exclude.push(formname.elements[spareboxes[j]].value);
                   15902:             } else {
                   15903:                 include.push(formname.elements[spareboxes[j]].value);
                   15904:             }
                   15905:         }
                   15906:     }
                   15907:     for (var i=0; i<types.length; i++) {
                   15908:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   15909:         var selIdx = newSpare.selectedIndex;
                   15910:         var currnew = newSpare.options[selIdx].value;
                   15911:         var okSpares = new Array();
                   15912:         for (var j=0; j<newSpare.options.length; j++) {
                   15913:             var possible = newSpare.options[j].value;
                   15914:             if (possible != '') {
                   15915:                 if (exclude.indexOf(possible) == -1) {
                   15916:                     okSpares.push(possible);
                   15917:                 } else {
                   15918:                     if (currnew == possible) {
                   15919:                         selIdx = 0;
                   15920:                     }
                   15921:                 }
                   15922:             }
                   15923:         }
                   15924:         for (var k=0; k<include.length; k++) {
                   15925:             if (okSpares.indexOf(include[k]) == -1) {
                   15926:                 okSpares.push(include[k]);
                   15927:             }
                   15928:         }
                   15929:         okSpares.sort();
                   15930:         newSpare.options.length = 0;
                   15931:         if (selIdx == 0) {
                   15932:             newSpare.options[0] = new Option("$select","",true,true);
                   15933:         } else {
                   15934:             newSpare.options[0] = new Option("$select","",false,false);
                   15935:         }
                   15936:         for (var m=0; m<okSpares.length; m++) {
                   15937:             var idx = m+1;
                   15938:             var selThis = 0;
                   15939:             if (selIdx != 0) {
                   15940:                 if (okSpares[m] == currnew) {
                   15941:                     selThis = 1;
                   15942:                 }
                   15943:             }
                   15944:             if (selThis == 1) {
                   15945:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   15946:             } else {
                   15947:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   15948:             }
                   15949:         }
                   15950:     }
                   15951:     return;
                   15952: }
                   15953: 
                   15954: function checkNewSpares(lonhost,type) {
                   15955:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   15956:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   15957:     if (chosen != '') { 
                   15958:         var othertype;
                   15959:         var othernewSpare;
                   15960:         if (type == 'primary') {
                   15961:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   15962:         }
                   15963:         if (type == 'default') {
                   15964:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   15965:         }
                   15966:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   15967:             othernewSpare.selectedIndex = 0;
                   15968:         }
                   15969:     }
                   15970:     return;
                   15971: }
                   15972: 
                   15973: // ]]>
                   15974: </script>
                   15975: 
                   15976: END
                   15977: 
                   15978: }
                   15979: 
                   15980: sub common_domprefs_js {
                   15981:     return <<"END";
                   15982: 
                   15983: <script type="text/javascript">
                   15984: // <![CDATA[
                   15985: 
1.150     raeburn  15986: function getIndicesByName(formname,item) {
1.152     raeburn  15987:     var group = new Array();
1.150     raeburn  15988:     for (var i=0;i<formname.elements.length;i++) {
                   15989:         if (formname.elements[i].name == item) {
1.152     raeburn  15990:             group.push(formname.elements[i].id);
1.150     raeburn  15991:         }
                   15992:     }
1.152     raeburn  15993:     return group;
1.150     raeburn  15994: }
                   15995: 
                   15996: // ]]>
                   15997: </script>
                   15998: 
                   15999: END
1.152     raeburn  16000: 
1.150     raeburn  16001: }
                   16002: 
1.160.6.5  raeburn  16003: sub recaptcha_js {
                   16004:     my %lt = &captcha_phrases();
                   16005:     return <<"END";
                   16006: 
                   16007: <script type="text/javascript">
                   16008: // <![CDATA[
                   16009: 
                   16010: function updateCaptcha(caller,context) {
                   16011:     var privitem;
                   16012:     var pubitem;
                   16013:     var privtext;
                   16014:     var pubtext;
1.160.6.69  raeburn  16015:     var versionitem;
                   16016:     var versiontext;
1.160.6.5  raeburn  16017:     if (document.getElementById(context+'_recaptchapub')) {
                   16018:         pubitem = document.getElementById(context+'_recaptchapub');
                   16019:     } else {
                   16020:         return;
                   16021:     }
                   16022:     if (document.getElementById(context+'_recaptchapriv')) {
                   16023:         privitem = document.getElementById(context+'_recaptchapriv');
                   16024:     } else {
                   16025:         return;
                   16026:     }
                   16027:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   16028:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   16029:     } else {
                   16030:         return;
                   16031:     }
                   16032:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   16033:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   16034:     } else {
                   16035:         return;
                   16036:     }
1.160.6.69  raeburn  16037:     if (document.getElementById(context+'_recaptchaversion')) {
                   16038:         versionitem = document.getElementById(context+'_recaptchaversion');
                   16039:     } else {
                   16040:         return;
                   16041:     }
                   16042:     if (document.getElementById(context+'_recaptchavertxt')) {
                   16043:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   16044:     } else {
                   16045:         return;
                   16046:     }
1.160.6.5  raeburn  16047:     if (caller.checked) {
                   16048:         if (caller.value == 'recaptcha') {
                   16049:             pubitem.type = 'text';
                   16050:             privitem.type = 'text';
                   16051:             pubitem.size = '40';
                   16052:             privitem.size = '40';
                   16053:             pubtext.innerHTML = "$lt{'pub'}";
                   16054:             privtext.innerHTML = "$lt{'priv'}";
1.160.6.69  raeburn  16055:             versionitem.type = 'text';
                   16056:             versionitem.size = '3';
                   16057:             versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5  raeburn  16058:         } else {
                   16059:             pubitem.type = 'hidden';
                   16060:             privitem.type = 'hidden';
1.160.6.69  raeburn  16061:             versionitem.type = 'hidden';
1.160.6.5  raeburn  16062:             pubtext.innerHTML = '';
                   16063:             privtext.innerHTML = '';
1.160.6.69  raeburn  16064:             versiontext.innerHTML = '';
1.160.6.5  raeburn  16065:         }
                   16066:     }
                   16067:     return;
                   16068: }
                   16069: 
                   16070: // ]]>
                   16071: </script>
                   16072: 
                   16073: END
                   16074: 
                   16075: }
                   16076: 
1.160.6.40  raeburn  16077: sub toggle_display_js {
1.160.6.16  raeburn  16078:     return <<"END";
                   16079: 
                   16080: <script type="text/javascript">
                   16081: // <![CDATA[
                   16082: 
1.160.6.40  raeburn  16083: function toggleDisplay(domForm,caller) {
                   16084:     if (document.getElementById(caller)) {
                   16085:         var divitem = document.getElementById(caller);
                   16086:         var optionsElement = domForm.coursecredits;
1.160.6.64  raeburn  16087:         var checkval = 1;
                   16088:         var dispval = 'block';
1.160.6.93  raeburn  16089:         var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40  raeburn  16090:         if (caller == 'emailoptions') {
                   16091:             optionsElement = domForm.cancreate_email; 
                   16092:         }
1.160.6.57  raeburn  16093:         if (caller == 'studentsubmission') {
                   16094:             optionsElement = domForm.postsubmit;
                   16095:         }
1.160.6.64  raeburn  16096:         if (caller == 'cloneinstcode') {
                   16097:             optionsElement = domForm.canclone;
                   16098:             checkval = 'instcode';
                   16099:         }
1.160.6.93  raeburn  16100:         if (selfcreateRegExp.test(caller)) {
                   16101:             optionsElement = domForm.elements[caller];
                   16102:             checkval = 'other';
                   16103:             dispval = 'inline'
                   16104:         }
1.160.6.40  raeburn  16105:         if (optionsElement.length) {
1.160.6.16  raeburn  16106:             var currval;
1.160.6.40  raeburn  16107:             for (var i=0; i<optionsElement.length; i++) {
                   16108:                 if (optionsElement[i].checked) {
                   16109:                    currval = optionsElement[i].value;
1.160.6.16  raeburn  16110:                 }
                   16111:             }
1.160.6.64  raeburn  16112:             if (currval == checkval) {
                   16113:                 divitem.style.display = dispval;
1.160.6.16  raeburn  16114:             } else {
1.160.6.40  raeburn  16115:                 divitem.style.display = 'none';
1.160.6.16  raeburn  16116:             }
                   16117:         }
                   16118:     }
                   16119:     return;
                   16120: }
                   16121: 
                   16122: // ]]>
                   16123: </script>
                   16124: 
                   16125: END
                   16126: 
                   16127: }
                   16128: 
1.160.6.5  raeburn  16129: sub captcha_phrases {
                   16130:     return &Apache::lonlocal::texthash (
                   16131:                  priv => 'Private key',
                   16132:                  pub  => 'Public key',
                   16133:                  original  => 'original (CAPTCHA)',
                   16134:                  recaptcha => 'successor (ReCAPTCHA)',
                   16135:                  notused   => 'unused',
1.160.6.69  raeburn  16136:                  ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5  raeburn  16137:     );
                   16138: }
                   16139: 
1.160.6.24  raeburn  16140: sub devalidate_remote_domconfs {
1.160.6.27  raeburn  16141:     my ($dom,$cachekeys) = @_;
                   16142:     return unless (ref($cachekeys) eq 'HASH');
1.160.6.24  raeburn  16143:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   16144:     my %thismachine;
                   16145:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98  raeburn  16146:     my @posscached = ('domainconfig','domdefaults','usersessions',
                   16147:                       'directorysrch','passwdconf','cats');
1.160.6.61  raeburn  16148:     if (keys(%servers)) {
1.160.6.24  raeburn  16149:         foreach my $server (keys(%servers)) {
                   16150:             next if ($thismachine{$server});
1.160.6.27  raeburn  16151:             my @cached;
                   16152:             foreach my $name (@posscached) {
                   16153:                 if ($cachekeys->{$name}) {
                   16154:                     push(@cached,&escape($name).':'.&escape($dom));
                   16155:                 }
                   16156:             }
                   16157:             if (@cached) {
                   16158:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   16159:             }
1.160.6.24  raeburn  16160:         }
                   16161:     }
                   16162:     return;
                   16163: }
                   16164: 
1.3       raeburn  16165: 1;

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