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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.160.6.102.2  5(raebur    4:0): # $Id: domainprefs.pm,v 1.160.6.102.2.4 2020/07/18 20:28:24 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.102.2  1(raebur  219:0):                 'requestauthor','selfenrollment','inststatus',
                    220:0):                 'passwords','ltitools'],$dom);
                    221:0):     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    222:0):         my %encconfig =
                    223:0):             &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
                    224:0):         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    225:0):             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
                    226:0):                 if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
                    227:0):                     foreach my $item ('key','secret') {
                    228:0):                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    229:0):                     }
                    230:0):                 }
                    231:0):             }
                    232:0):         }
                    233:0):     }
1.160.6.98  raeburn   234:     my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
1.125     raeburn   235:                        'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34  raeburn   236:                        'usercreation','selfcreation','usermodification','scantron',
1.160.6.5  raeburn   237:                        'requestcourses','requestauthor','coursecategories',
1.160.6.73  raeburn   238:                        'serverstatuses','helpsettings','coursedefaults',
1.160.6.102.2  1(raebur  239:0):                        'ltitools','selfenrollment','usersessions');
1.160.6.7  raeburn   240:     my %existing;
                    241:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    242:         %existing = %{$domconfig{'loadbalancing'}};
                    243:     }
                    244:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   245:         push(@prefs_order,'loadbalancing');
                    246:     }
1.30      raeburn   247:     my %prefs = (
                    248:         'rolecolors' =>
                    249:                    { text => 'Default color schemes',
1.67      raeburn   250:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   251:                      header => [{col1 => 'Student Settings',
                    252:                                  col2 => '',},
                    253:                                 {col1 => 'Coordinator Settings',
                    254:                                  col2 => '',},
                    255:                                 {col1 => 'Author Settings',
                    256:                                  col2 => '',},
                    257:                                 {col1 => 'Administrator Settings',
                    258:                                  col2 => '',}],
1.160.6.37  raeburn   259:                       print => \&print_rolecolors,
                    260:                       modify => \&modify_rolecolors,
1.30      raeburn   261:                     },
1.110     raeburn   262:         'login' =>
1.30      raeburn   263:                     { text => 'Log-in page options',
1.67      raeburn   264:                       help => 'Domain_Configuration_Login_Page',
1.160.6.5  raeburn   265:                       header => [{col1 => 'Log-in Page Items',
                    266:                                   col2 => '',},
                    267:                                  {col1 => 'Log-in Help',
1.160.6.56  raeburn   268:                                   col2 => 'Value'},
                    269:                                  {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   270:                                   col2 => 'Value'}],
1.160.6.37  raeburn   271:                       print => \&print_login,
                    272:                       modify => \&modify_login,
1.30      raeburn   273:                     },
1.43      raeburn   274:         'defaults' => 
1.160.6.40  raeburn   275:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   276:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   277:                       header => [{col1 => 'Setting',
1.160.6.40  raeburn   278:                                   col2 => 'Value'},
                    279:                                  {col1 => 'Institutional user types',
1.160.6.93  raeburn   280:                                   col2 => 'Name displayed'}],
1.160.6.37  raeburn   281:                       print => \&print_defaults,
                    282:                       modify => \&modify_defaults,
1.43      raeburn   283:                     },
1.160.6.98  raeburn   284:         'passwords' =>
                    285:                     { text => 'Passwords (Internal authentication)',
                    286:                       help => 'Domain_Configuration_Passwords',
                    287:                       header => [{col1 => 'Resetting Forgotten Password',
                    288:                                   col2 => 'Settings'},
                    289:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    290:                                   col2 => 'Settings'},
                    291:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    292:                                   col2 => 'Settings'},
                    293:                                  {col1 => 'Course Owner Changing Student Passwords',
                    294:                                   col2 => 'Settings'}],
                    295:                       print => \&print_passwords,
                    296:                       modify => \&modify_passwords,
                    297:                     },
1.30      raeburn   298:         'quotas' => 
1.160.6.20  raeburn   299:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   300:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   301:                       header => [{col1 => 'User affiliation',
1.72      raeburn   302:                                   col2 => 'Available tools',
1.160.6.28  raeburn   303:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37  raeburn   304:                       print => \&print_quotas,
                    305:                       modify => \&modify_quotas,
1.30      raeburn   306:                     },
                    307:         'autoenroll' =>
                    308:                    { text => 'Auto-enrollment settings',
1.67      raeburn   309:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   310:                      header => [{col1 => 'Configuration setting',
                    311:                                  col2 => 'Value(s)'}],
1.160.6.37  raeburn   312:                      print => \&print_autoenroll,
                    313:                      modify => \&modify_autoenroll,
1.30      raeburn   314:                    },
                    315:         'autoupdate' => 
                    316:                    { text => 'Auto-update settings',
1.67      raeburn   317:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   318:                      header => [{col1 => 'Setting',
                    319:                                  col2 => 'Value',},
1.131     raeburn   320:                                 {col1 => 'Setting',
                    321:                                  col2 => 'Affiliation'},
1.43      raeburn   322:                                 {col1 => 'User population',
1.160.6.35  raeburn   323:                                  col2 => 'Updatable user data'}],
1.160.6.37  raeburn   324:                      print => \&print_autoupdate,
                    325:                      modify => \&modify_autoupdate,
1.30      raeburn   326:                   },
1.125     raeburn   327:         'autocreate' => 
                    328:                   { text => 'Auto-course creation settings',
                    329:                      help => 'Domain_Configuration_Auto_Creation',
                    330:                      header => [{col1 => 'Configuration Setting',
                    331:                                  col2 => 'Value',}],
1.160.6.37  raeburn   332:                      print => \&print_autocreate,
                    333:                      modify => \&modify_autocreate,
1.125     raeburn   334:                   },
1.30      raeburn   335:         'directorysrch' => 
1.160.6.72  raeburn   336:                   { text => 'Directory searches',
1.67      raeburn   337:                     help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72  raeburn   338:                     header => [{col1 => 'Institutional Directory Setting',
                    339:                                 col2 => 'Value',},
                    340:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   341:                                 col2 => 'Value',}],
1.160.6.37  raeburn   342:                     print => \&print_directorysrch,
                    343:                     modify => \&modify_directorysrch,
1.30      raeburn   344:                   },
                    345:         'contacts' =>
1.160.6.78  raeburn   346:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   347:                     help => 'Domain_Configuration_Contact_Info',
1.160.6.78  raeburn   348:                     header => [{col1 => 'Default e-mail addresses',
                    349:                                 col2 => 'Value',},
                    350:                                {col1 => 'Recipient(s) for notifications',
                    351:                                 col2 => 'Value',},
                    352:                                {col1 => 'Ask helpdesk form settings',
                    353:                                 col2 => 'Value',},],
1.160.6.37  raeburn   354:                     print => \&print_contacts,
                    355:                     modify => \&modify_contacts,
1.30      raeburn   356:                   },
                    357:         'usercreation' => 
                    358:                   { text => 'User creation',
1.67      raeburn   359:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   360:                     header => [{col1 => 'Format rule type',
                    361:                                 col2 => 'Format rules in force'},
1.34      raeburn   362:                                {col1 => 'User account creation',
                    363:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   364:                                {col1 => 'Context',
1.43      raeburn   365:                                 col2 => 'Assignable authentication types'}],
1.160.6.37  raeburn   366:                     print => \&print_usercreation,
                    367:                     modify => \&modify_usercreation,
1.30      raeburn   368:                   },
1.160.6.34  raeburn   369:         'selfcreation' => 
                    370:                   { text => 'Users self-creating accounts',
                    371:                     help => 'Domain_Configuration_Self_Creation', 
                    372:                     header => [{col1 => 'Self-creation with institutional username',
                    373:                                 col2 => 'Enabled?'},
                    374:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    375:                                 col2 => 'Information user can enter'},
1.160.6.93  raeburn   376:                                {col1 => 'Self-creation with e-mail verification',
1.160.6.34  raeburn   377:                                 col2 => 'Settings'}],
1.160.6.37  raeburn   378:                     print => \&print_selfcreation,
                    379:                     modify => \&modify_selfcreation,
1.160.6.34  raeburn   380:                   },
1.69      raeburn   381:         'usermodification' =>
1.33      raeburn   382:                   { text => 'User modification',
1.67      raeburn   383:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   384:                     header => [{col1 => 'Target user has role',
1.160.6.35  raeburn   385:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   386:                                {col1 => 'Target user has role',
1.160.6.35  raeburn   387:                                 col2 => 'User information updatable in course context'}],
1.160.6.37  raeburn   388:                     print => \&print_usermodification,
                    389:                     modify => \&modify_usermodification,
1.33      raeburn   390:                   },
1.69      raeburn   391:         'scantron' =>
1.160.6.97  raeburn   392:                   { text => 'Bubblesheet format',
1.67      raeburn   393:                     help => 'Domain_Configuration_Scantron_Format',
1.160.6.97  raeburn   394:                     header => [ {col1 => 'Bubblesheet format file',
                    395:                                  col2 => ''},
                    396:                                 {col1 => 'Bubblesheet data upload formats',
                    397:                                  col2 => 'Settings'}],
1.160.6.37  raeburn   398:                     print => \&print_scantron,
                    399:                     modify => \&modify_scantron,
1.46      raeburn   400:                   },
1.86      raeburn   401:         'requestcourses' => 
                    402:                  {text => 'Request creation of courses',
                    403:                   help => 'Domain_Configuration_Request_Courses',
                    404:                   header => [{col1 => 'User affiliation',
1.102     raeburn   405:                               col2 => 'Availability/Processing of requests',},
                    406:                              {col1 => 'Setting',
1.160.6.30  raeburn   407:                               col2 => 'Value'},
                    408:                              {col1 => 'Available textbooks',
1.160.6.39  raeburn   409:                               col2 => ''},
1.160.6.46  raeburn   410:                              {col1 => 'Available templates',
                    411:                               col2 => ''},
1.160.6.39  raeburn   412:                              {col1 => 'Validation (not official courses)',
                    413:                               col2 => 'Value'},],
1.160.6.37  raeburn   414:                   print => \&print_quotas,
                    415:                   modify => \&modify_quotas,
1.86      raeburn   416:                  },
1.160.6.5  raeburn   417:         'requestauthor' =>
1.160.6.34  raeburn   418:                  {text => 'Request Authoring Space',
1.160.6.5  raeburn   419:                   help => 'Domain_Configuration_Request_Author',
                    420:                   header => [{col1 => 'User affiliation',
                    421:                               col2 => 'Availability/Processing of requests',},
                    422:                              {col1 => 'Setting',
                    423:                               col2 => 'Value'}],
1.160.6.37  raeburn   424:                   print => \&print_quotas,
                    425:                   modify => \&modify_quotas,
1.160.6.5  raeburn   426:                  },
1.69      raeburn   427:         'coursecategories' =>
1.120     raeburn   428:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   429:                     help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42  raeburn   430:                     header => [{col1 => 'Catalog type/availability',
                    431:                                 col2 => '',},
                    432:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   433:                                 col2 => '',},
                    434:                                {col1 => 'Categories',
                    435:                                 col2 => '',
                    436:                                }],
1.160.6.37  raeburn   437:                     print => \&print_coursecategories,
                    438:                     modify => \&modify_coursecategories,
1.69      raeburn   439:                   },
                    440:         'serverstatuses' =>
1.77      raeburn   441:                  {text   => 'Access to server status pages',
1.69      raeburn   442:                   help   => 'Domain_Configuration_Server_Status',
                    443:                   header => [{col1 => 'Status Page',
                    444:                               col2 => 'Other named users',
                    445:                               col3 => 'Specific IPs',
                    446:                             }],
1.160.6.37  raeburn   447:                   print => \&print_serverstatuses,
                    448:                   modify => \&modify_serverstatuses,
1.69      raeburn   449:                  },
1.160.6.73  raeburn   450:         'helpsettings' =>
                    451:                  {text   => 'Support settings',
                    452:                   help   => 'Domain_Configuration_Help_Settings',
                    453:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    454:                               col2 => 'Value'},
                    455:                              {col1 => 'Helpdesk Roles',
                    456:                               col2 => 'Settings'},],
                    457:                   print  => \&print_helpsettings,
                    458:                   modify => \&modify_helpsettings,
                    459:                  },
1.160.6.39  raeburn   460:         'coursedefaults' => 
1.160.6.16  raeburn   461:                  {text => 'Course/Community defaults',
                    462:                   help => 'Domain_Configuration_Course_Defaults',
1.160.6.57  raeburn   463:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    464:                               col2 => 'Value',},
                    465:                              {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16  raeburn   466:                               col2 => 'Value',},],
1.160.6.37  raeburn   467:                   print => \&print_coursedefaults,
                    468:                   modify => \&modify_coursedefaults,
                    469:                  },
1.160.6.39  raeburn   470:         'selfenrollment' => 
1.160.6.37  raeburn   471:                  {text   => 'Self-enrollment in Course/Community',
                    472:                   help   => 'Domain_Configuration_Selfenrollment',
                    473:                   header => [{col1 => 'Configuration Rights',
                    474:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    475:                              {col1 => 'Defaults',
                    476:                               col2 => 'Value'},
                    477:                              {col1 => 'Self-enrollment validation (optional)',
                    478:                               col2 => 'Value'},],
                    479:                   print => \&print_selfenrollment,
                    480:                   modify => \&modify_selfenrollment,
1.160.6.16  raeburn   481:                  },
1.141     raeburn   482:         'usersessions' =>
1.145     raeburn   483:                  {text  => 'User session hosting/offloading',
1.137     raeburn   484:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   485:                   header => [{col1 => 'Domain server',
                    486:                               col2 => 'Servers to offload sessions to when busy'},
                    487:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   488:                               col2 => 'Rules'},
                    489:                              {col1 => "Hosting domain's own users elsewhere",
                    490:                               col2 => 'Rules'}],
1.160.6.37  raeburn   491:                   print => \&print_usersessions,
                    492:                   modify => \&modify_usersessions,
1.137     raeburn   493:                  },
1.160.6.78  raeburn   494:         'loadbalancing' =>
1.160.6.7  raeburn   495:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   496:                   help  => 'Domain_Configuration_Load_Balancing',
1.160.6.7  raeburn   497:                   header => [{col1 => 'Balancers',
1.150     raeburn   498:                               col2 => 'Default destinations',
1.160.6.13  raeburn   499:                               col3 => 'User affiliation',
1.150     raeburn   500:                               col4 => 'Overrides'},
                    501:                             ],
1.160.6.37  raeburn   502:                   print => \&print_loadbalancing,
                    503:                   modify => \&modify_loadbalancing,
1.150     raeburn   504:                  },
1.160.6.102.2  1(raebur  505:0):         'ltitools' =>
                    506:0):                  {text => 'External Tools (LTI)',
                    507:0):                   help => 'Domain_Configuration_LTI_Tools',
                    508:0):                   header => [{col1 => 'Setting',
                    509:0):                               col2 => 'Value',}],
                    510:0):                   print => \&print_ltitools,
                    511:0):                   modify => \&modify_ltitools,
                    512:0):                  },
1.3       raeburn   513:     );
1.110     raeburn   514:     if (keys(%servers) > 1) {
                    515:         $prefs{'login'}  = { text   => 'Log-in page options',
                    516:                              help   => 'Domain_Configuration_Login_Page',
                    517:                             header => [{col1 => 'Log-in Service',
                    518:                                         col2 => 'Server Setting',},
                    519:                                        {col1 => 'Log-in Page Items',
1.160.6.5  raeburn   520:                                         col2 => ''},
                    521:                                        {col1 => 'Log-in Help',
1.160.6.56  raeburn   522:                                         col2 => 'Value'},
                    523:                                        {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   524:                                         col2 => 'Value'}],
1.160.6.37  raeburn   525:                             print => \&print_login,
                    526:                             modify => \&modify_login,
1.110     raeburn   527:                            };
                    528:     }
1.160.6.13  raeburn   529: 
1.6       raeburn   530:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   531:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   532:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   533:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   534:       text=>"Settings to display/modify"});
1.9       raeburn   535:     my $confname = $dom.'-domainconfig';
1.160.6.13  raeburn   536: 
1.3       raeburn   537:     if ($phase eq 'process') {
1.160.6.27  raeburn   538:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    539:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33  raeburn   540:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24  raeburn   541:             $r->rflush();
1.160.6.27  raeburn   542:             &devalidate_remote_domconfs($dom,$result);
1.160.6.24  raeburn   543:         }
1.30      raeburn   544:     } elsif ($phase eq 'display') {
1.160.6.16  raeburn   545:         my $js = &recaptcha_js().
1.160.6.40  raeburn   546:                  &toggle_display_js();
1.160.6.7  raeburn   547:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   548:             my ($othertitle,$usertypes,$types) =
                    549:                 &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7  raeburn   550:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    551:                                           $domconfig{'loadbalancing'}).
1.160.6.6  raeburn   552:                    &new_spares_js().
                    553:                    &common_domprefs_js().
                    554:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   555:         }
1.160.6.30  raeburn   556:         if (grep(/^requestcourses$/,@actions)) {
                    557:             my $javascript_validations;
                    558:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    559:             $js .= <<END;
                    560: <script type="text/javascript">
                    561: $javascript_validations
                    562: </script>
                    563: $coursebrowserjs
                    564: END
                    565:         }
1.160.6.93  raeburn   566:         if (grep(/^selfcreation$/,@actions)) {
                    567:             $js .= &selfcreate_javascript();
                    568:         }
1.160.6.78  raeburn   569:         if (grep(/^contacts$/,@actions)) {
                    570:             $js .= &contacts_javascript();
                    571:         }
1.160.6.97  raeburn   572:         if (grep(/^scantron$/,@actions)) {
                    573:             $js .= &scantron_javascript();
                    574:         }
1.150     raeburn   575:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   576:     } else {
1.160.6.11  raeburn   577: # check if domconfig user exists for the domain.
                    578:         my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26  raeburn   579:         my ($configuserok,$author_ok,$switchserver) =
1.160.6.11  raeburn   580:             &config_check($dom,$confname,$servadm);
                    581:         unless ($configuserok eq 'ok') {
                    582:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    583:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    584:                           $confname).
                    585:                       '<br />'
                    586:             );
                    587:             if ($switchserver) {
                    588:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    589:                           '<br />'.
                    590:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    591:                           '<br />'.
                    592:                           &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).
                    593:                           '<br />'.
                    594:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    595:                 );
                    596:             } else {
                    597:                 $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.').
                    598:                           '<br />'.
                    599:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    600:                 );
                    601:             }
                    602:             $r->print(&Apache::loncommon::end_page());
                    603:             return OK;
                    604:         }
1.21      raeburn   605:         if (keys(%domconfig) == 0) {
                    606:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   607:             my @ids=&Apache::lonnet::current_machine_ids();
                    608:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   609:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   610:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   611:                 my $custom_img_count = 0;
                    612:                 foreach my $img (@loginimages) {
                    613:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    614:                         $custom_img_count ++;
                    615:                     }
                    616:                 }
                    617:                 foreach my $role (@roles) {
                    618:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    619:                         $custom_img_count ++;
                    620:                     }
                    621:                 }
                    622:                 if ($custom_img_count > 0) {
1.94      raeburn   623:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   624:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   625:                     $r->print(
                    626:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    627:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    628:     &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 />'.
                    629:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    630:                     if ($switch_server) {
1.30      raeburn   631:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   632:                     }
1.91      raeburn   633:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   634:                     return OK;
                    635:                 }
                    636:             }
                    637:         }
1.91      raeburn   638:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   639:     }
                    640:     return OK;
                    641: }
                    642: 
                    643: sub process_changes {
1.160.6.24  raeburn   644:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   645:     my %domconfig;
                    646:     if (ref($values) eq 'HASH') {
                    647:         %domconfig = %{$values};
                    648:     }
1.3       raeburn   649:     my $output;
                    650:     if ($action eq 'login') {
1.160.6.24  raeburn   651:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   652:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   653:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24  raeburn   654:                                      $lastactref,%domconfig);
1.3       raeburn   655:     } elsif ($action eq 'quotas') {
1.160.6.30  raeburn   656:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   657:     } elsif ($action eq 'autoenroll') {
1.160.6.24  raeburn   658:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   659:     } elsif ($action eq 'autoupdate') {
                    660:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   661:     } elsif ($action eq 'autocreate') {
                    662:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   663:     } elsif ($action eq 'directorysrch') {
1.160.6.81  raeburn   664:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   665:     } elsif ($action eq 'usercreation') {
1.28      raeburn   666:         $output = &modify_usercreation($dom,%domconfig);
1.160.6.34  raeburn   667:     } elsif ($action eq 'selfcreation') {
1.160.6.93  raeburn   668:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   669:     } elsif ($action eq 'usermodification') {
                    670:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   671:     } elsif ($action eq 'contacts') {
1.160.6.24  raeburn   672:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   673:     } elsif ($action eq 'defaults') {
1.160.6.27  raeburn   674:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   675:     } elsif ($action eq 'scantron') {
1.160.6.24  raeburn   676:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   677:     } elsif ($action eq 'coursecategories') {
1.160.6.43  raeburn   678:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   679:     } elsif ($action eq 'serverstatuses') {
                    680:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   681:     } elsif ($action eq 'requestcourses') {
1.160.6.30  raeburn   682:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5  raeburn   683:     } elsif ($action eq 'requestauthor') {
1.160.6.30  raeburn   684:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73  raeburn   685:     } elsif ($action eq 'helpsettings') {
1.160.6.77  raeburn   686:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16  raeburn   687:     } elsif ($action eq 'coursedefaults') {
1.160.6.27  raeburn   688:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37  raeburn   689:     } elsif ($action eq 'selfenrollment') {
                    690:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   691:     } elsif ($action eq 'usersessions') {
1.160.6.27  raeburn   692:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   693:     } elsif ($action eq 'loadbalancing') {
                    694:         $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.98  raeburn   695:     } elsif ($action eq 'passwords') {
                    696:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.102.2  1(raebur  697:0):     } elsif ($action eq 'ltitools') {
                    698:0):         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   699:     }
                    700:     return $output;
                    701: }
                    702: 
                    703: sub print_config_box {
1.9       raeburn   704:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   705:     my $rowtotal = 0;
1.49      raeburn   706:     my $output;
                    707:     if ($action eq 'coursecategories') {
                    708:         $output = &coursecategories_javascript($settings);
1.160.6.40  raeburn   709:     } elsif ($action eq 'defaults') {
                    710:         $output = &defaults_javascript($settings); 
1.160.6.98  raeburn   711:     } elsif ($action eq 'passwords') {
                    712:         $output = &passwords_javascript();
1.160.6.73  raeburn   713:     } elsif ($action eq 'helpsettings') {
                    714:         my (%privs,%levelscurrent);
                    715:         my %full=();
                    716:         my %levels=(
                    717:                      course => {},
                    718:                      domain => {},
                    719:                      system => {},
                    720:                    );
                    721:         my $context = 'domain';
                    722:         my $crstype = 'Course';
                    723:         my $formname = 'display';
                    724:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    725:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    726:         $output =
                    727:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
                    728:                                                       \@templateroles);
1.160.6.102.2  5(raebur  729:0):     } elsif ($action eq 'ltitools') {
                    730:0):         $output .= &ltitools_javascript($settings);
1.91      raeburn   731:     }
1.160.6.40  raeburn   732:     $output .=
1.30      raeburn   733:          '<table class="LC_nested_outer">
1.3       raeburn   734:           <tr>
1.66      raeburn   735:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    736:            &mt($item->{text}).'&nbsp;'.
                    737:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    738:           '</tr>';
1.30      raeburn   739:     $rowtotal ++;
1.110     raeburn   740:     my $numheaders = 1;
                    741:     if (ref($item->{'header'}) eq 'ARRAY') {
                    742:         $numheaders = scalar(@{$item->{'header'}});
                    743:     }
                    744:     if ($numheaders > 1) {
1.64      raeburn   745:         my $colspan = '';
1.145     raeburn   746:         my $rightcolspan = '';
1.160.6.102.2  3(raebur  747:0):         my $leftnobr = '';
1.160.6.42  raeburn   748:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72  raeburn   749:             ($action eq 'directorysrch') ||
1.160.6.56  raeburn   750:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   751:             $colspan = ' colspan="2"';
                    752:         }
1.145     raeburn   753:         if ($action eq 'usersessions') {
                    754:             $rightcolspan = ' colspan="3"'; 
                    755:         }
1.160.6.102.2  3(raebur  756:0):         if ($action eq 'passwords') {
                    757:0):             $leftnobr = ' LC_nobreak';
                    758:0):         }
1.30      raeburn   759:         $output .= '
1.3       raeburn   760:           <tr>
                    761:            <td>
                    762:             <table class="LC_nested">
                    763:              <tr class="LC_info_row">
1.160.6.102.2  3(raebur  764:0):               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   765:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   766:              </tr>';
1.69      raeburn   767:         $rowtotal ++;
1.160.6.37  raeburn   768:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57  raeburn   769:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   770:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78  raeburn   771:             ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37  raeburn   772:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98  raeburn   773:         } elsif ($action eq 'passwords') {
                    774:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   775:         } elsif ($action eq 'coursecategories') {
1.160.6.37  raeburn   776:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97  raeburn   777:         } elsif ($action eq 'scantron') {
                    778:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   779:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   780:             if ($numheaders == 4) {
1.160.6.5  raeburn   781:                 $colspan = ' colspan="2"';
                    782:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    783:             } else {
                    784:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    785:             }
1.160.6.37  raeburn   786:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn   787:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       788:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   789:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2  raeburn   790:         }
1.30      raeburn   791:         $output .= '
1.6       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.37  raeburn   799:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    800:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   801:              </tr>';
                    802:             $rowtotal ++;
1.160.6.37  raeburn   803:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    804:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78  raeburn   805:             ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.98  raeburn   806:             ($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.42  raeburn   807:             if ($action eq 'coursecategories') {
                    808:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    809:                 $colspan = ' colspan="2"';
1.160.6.98  raeburn   810:             } elsif ($action eq 'passwords') {
                    811:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42  raeburn   812:             } else {
                    813:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    814:             }
                    815:             $output .= '
1.63      raeburn   816:            </table>
                    817:           </td>
                    818:          </tr>
                    819:          <tr>
                    820:            <td>
                    821:             <table class="LC_nested">
                    822:              <tr class="LC_info_row">
1.160.6.102.2  3(raebur  823:0):               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34  raeburn   824:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42  raeburn   825:              </tr>'."\n";
                    826:             if ($action eq 'coursecategories') {
                    827:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.98  raeburn   828:             } elsif ($action eq 'passwords') {
                    829:                 $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal).'
                    830:              </tr>
                    831:             </table>
                    832:            </td>
                    833:           </tr>
                    834:           <tr>
                    835:            <td>
                    836:             <table class="LC_nested">
                    837:              <tr class="LC_info_row">
                    838:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    839:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n".
                    840:               $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal).'
                    841:             </table>
                    842:           </td>
                    843:          </tr>
                    844:          <tr>';
1.160.6.42  raeburn   845:             } else {
                    846:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    847:             }
1.63      raeburn   848:             $rowtotal ++;
1.160.6.57  raeburn   849:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   850:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    851:                  ($action eq 'helpsettings')) {
1.160.6.37  raeburn   852:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97  raeburn   853:         } elsif ($action eq 'scantron') {
                    854:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   855:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   856:             if ($numheaders == 4) {
1.160.6.5  raeburn   857:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    858:            </table>
                    859:           </td>
                    860:          </tr>
                    861:          <tr>
                    862:            <td>
                    863:             <table class="LC_nested">
                    864:              <tr class="LC_info_row">
                    865:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30  raeburn   866:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5  raeburn   867:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    868:                 $rowtotal ++;
                    869:             } else {
                    870:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    871:             }
1.160.6.56  raeburn   872:             $output .= '
                    873:            </table>
                    874:           </td>
                    875:          </tr>
                    876:          <tr>
                    877:            <td>
                    878:             <table class="LC_nested">
                    879:              <tr class="LC_info_row">';
                    880:             if ($numheaders == 4) {
                    881:                 $output .= '
                    882:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    883:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    884:              </tr>';
                    885:             } else {
                    886:                 $output .= '
                    887:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    888:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    889:              </tr>';
                    890:             }
                    891:             $rowtotal ++;
                    892:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   893:         } elsif ($action eq 'requestcourses') {
1.160.6.50  raeburn   894:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    895:             $rowtotal ++;
                    896:             $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30  raeburn   897:            </table>
                    898:           </td>
                    899:          </tr>
                    900:          <tr>
                    901:            <td>
                    902:             <table class="LC_nested">
                    903:              <tr class="LC_info_row">
                    904:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    905:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46  raeburn   906:                        &textbookcourses_javascript($settings).
                    907:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    908:             </table>
                    909:            </td>
                    910:           </tr>
                    911:          <tr>
                    912:            <td>
                    913:             <table class="LC_nested">
                    914:              <tr class="LC_info_row">
                    915:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    916:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    917:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39  raeburn   918:             </table>
                    919:            </td>
                    920:           </tr>
                    921:           <tr>
                    922:            <td>
                    923:             <table class="LC_nested">
                    924:              <tr class="LC_info_row">
1.160.6.46  raeburn   925:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    926:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39  raeburn   927:              </tr>'.
                    928:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5  raeburn   929:         } elsif ($action eq 'requestauthor') {
                    930:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50  raeburn   931:             $rowtotal ++;
1.122     jms       932:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   933:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   934:            </table>
                    935:           </td>
                    936:          </tr>
                    937:          <tr>
                    938:            <td>
                    939:             <table class="LC_nested">
                    940:              <tr class="LC_info_row">
1.69      raeburn   941:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    942:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    943:               <td class="LC_right_item" valign="top">'.
                    944:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   945:              </tr>'.
1.30      raeburn   946:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   947:            </table>
                    948:           </td>
                    949:          </tr>
                    950:          <tr>
                    951:            <td>
                    952:             <table class="LC_nested">
                    953:              <tr class="LC_info_row">
1.59      bisitz    954:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    955:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   956:              </tr>'.
1.30      raeburn   957:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    958:             $rowtotal += 2;
1.6       raeburn   959:         }
1.3       raeburn   960:     } else {
1.30      raeburn   961:         $output .= '
1.3       raeburn   962:           <tr>
                    963:            <td>
                    964:             <table class="LC_nested">
1.30      raeburn   965:              <tr class="LC_info_row">';
1.160.6.72  raeburn   966:         if ($action eq 'login') {
1.30      raeburn   967:             $output .= '  
1.59      bisitz    968:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   969:         } elsif ($action eq 'serverstatuses') {
                    970:             $output .= '
                    971:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    972:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    973: 
1.6       raeburn   974:         } else {
1.30      raeburn   975:             $output .= '
1.69      raeburn   976:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    977:         }
1.72      raeburn   978:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    979:             $output .= '<td class="LC_left_item" valign="top">'.
                    980:                        &mt($item->{'header'}->[0]->{'col2'});
                    981:             if ($action eq 'serverstatuses') {
                    982:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    983:             } 
1.69      raeburn   984:         } else {
                    985:             $output .= '<td class="LC_right_item" valign="top">'.
                    986:                        &mt($item->{'header'}->[0]->{'col2'});
                    987:         }
                    988:         $output .= '</td>';
                    989:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   990:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    991:                 $output .= '<td class="LC_left_item" valign="top">'.
                    992:                             &mt($item->{'header'}->[0]->{'col3'});
                    993:             } else {
                    994:                 $output .= '<td class="LC_right_item" valign="top">'.
                    995:                            &mt($item->{'header'}->[0]->{'col3'});
                    996:             }
1.69      raeburn   997:             if ($action eq 'serverstatuses') {
                    998:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    999:             }
                   1000:             $output .= '</td>';
1.6       raeburn  1001:         }
1.150     raeburn  1002:         if ($item->{'header'}->[0]->{'col4'}) {
                   1003:             $output .= '<td class="LC_right_item" valign="top">'.
                   1004:                        &mt($item->{'header'}->[0]->{'col4'});
                   1005:         }
1.69      raeburn  1006:         $output .= '</tr>';
1.48      raeburn  1007:         $rowtotal ++;
1.160.6.5  raeburn  1008:         if ($action eq 'quotas') {
1.86      raeburn  1009:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72  raeburn  1010:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.160.6.102.2  1(raebur 1011:0):                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
                   1012:0):                  ($action eq 'ltitools')) {
1.160.6.37  raeburn  1013:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1014:         }
1.3       raeburn  1015:     }
1.30      raeburn  1016:     $output .= '
1.3       raeburn  1017:    </table>
                   1018:   </td>
                   1019:  </tr>
1.30      raeburn  1020: </table><br />';
                   1021:     return ($output,$rowtotal);
1.1       raeburn  1022: }
                   1023: 
1.3       raeburn  1024: sub print_login {
1.160.6.5  raeburn  1025:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn  1026:     my ($css_class,$datatable);
1.6       raeburn  1027:     my %choices = &login_choices();
1.110     raeburn  1028: 
1.160.6.5  raeburn  1029:     if ($caller eq 'service') {
1.149     raeburn  1030:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1031:         my $choice = $choices{'disallowlogin'};
                   1032:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1033:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn  1034:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1035:                       '<th>'.$choices{'server'}.'</th>'.
                   1036:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1037:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1038:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1039:         my %disallowed;
                   1040:         if (ref($settings) eq 'HASH') {
                   1041:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1042:                %disallowed = %{$settings->{'loginvia'}};
                   1043:             }
                   1044:         }
                   1045:         foreach my $lonhost (sort(keys(%servers))) {
                   1046:             my $direct = 'selected="selected"';
1.128     raeburn  1047:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1048:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1049:                     $direct = '';
                   1050:                 }
1.110     raeburn  1051:             }
1.115     raeburn  1052:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1053:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1054:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1055:                           '</option>';
1.160.6.13  raeburn  1056:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1057:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1058:                 my $selected = '';
1.128     raeburn  1059:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1060:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1061:                         $selected = 'selected="selected"';
                   1062:                     }
1.110     raeburn  1063:                 }
                   1064:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1065:                               $servers{$hostid}.'</option>';
                   1066:             }
1.128     raeburn  1067:             $datatable .= '</select></td>'.
                   1068:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1069:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1070:                 my $pathname = $path;
                   1071:                 if ($path eq 'custom') {
                   1072:                     $pathname = &mt('Custom Path').' ->';
                   1073:                 }
                   1074:                 my $selected = '';
                   1075:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1076:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1077:                         $selected = 'selected="selected"';
                   1078:                     }
                   1079:                 } elsif ($path eq '') {
                   1080:                     $selected = 'selected="selected"';
                   1081:                 }
                   1082:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1083:             }
                   1084:             $datatable .= '</select></td>';
                   1085:             my ($custom,$exempt);
                   1086:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1087:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1088:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1089:             }
                   1090:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1091:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1092:                           '</tr>';
1.110     raeburn  1093:         }
                   1094:         $datatable .= '</table></td></tr>';
                   1095:         return $datatable;
1.160.6.5  raeburn  1096:     } elsif ($caller eq 'page') {
                   1097:         my %defaultchecked = ( 
                   1098:                                'coursecatalog' => 'on',
1.160.6.14  raeburn  1099:                                'helpdesk'      => 'on',
1.160.6.5  raeburn  1100:                                'adminmail'     => 'off',
                   1101:                                'newuser'       => 'off',
                   1102:                              );
1.160.6.14  raeburn  1103:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5  raeburn  1104:         my (%checkedon,%checkedoff);
1.42      raeburn  1105:         foreach my $item (@toggles) {
1.160.6.5  raeburn  1106:             if ($defaultchecked{$item} eq 'on') { 
                   1107:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1108:                 $checkedoff{$item} = ' ';
1.160.6.5  raeburn  1109:             } elsif ($defaultchecked{$item} eq 'off') {
                   1110:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1111:                 $checkedon{$item} = ' ';
                   1112:             }
1.1       raeburn  1113:         }
1.160.6.5  raeburn  1114:         my @images = ('img','logo','domlogo','login');
                   1115:         my @logintext = ('textcol','bgcol');
                   1116:         my @bgs = ('pgbg','mainbg','sidebg');
                   1117:         my @links = ('link','alink','vlink');
                   1118:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1119:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1120:         my (%is_custom,%designs);
                   1121:         my %defaults = (
                   1122:                        font => $defaultdesign{'login.font'},
                   1123:                        );
1.6       raeburn  1124:         foreach my $item (@images) {
1.160.6.5  raeburn  1125:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1126:             $defaults{'showlogo'}{$item} = 1;
                   1127:         }
                   1128:         foreach my $item (@bgs) {
                   1129:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1130:         }
1.41      raeburn  1131:         foreach my $item (@logintext) {
1.160.6.5  raeburn  1132:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1133:         }
1.160.6.5  raeburn  1134:         foreach my $item (@links) {
                   1135:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1136:         }
1.160.6.5  raeburn  1137:         if (ref($settings) eq 'HASH') {
                   1138:             foreach my $item (@toggles) {
                   1139:                 if ($settings->{$item} eq '1') {
                   1140:                     $checkedon{$item} =  ' checked="checked" ';
                   1141:                     $checkedoff{$item} = ' ';
                   1142:                 } elsif ($settings->{$item} eq '0') {
                   1143:                     $checkedoff{$item} =  ' checked="checked" ';
                   1144:                     $checkedon{$item} = ' ';
                   1145:                 }
1.6       raeburn  1146:             }
1.160.6.5  raeburn  1147:             foreach my $item (@images) {
                   1148:                 if (defined($settings->{$item})) {
                   1149:                     $designs{$item} = $settings->{$item};
                   1150:                     $is_custom{$item} = 1;
                   1151:                 }
                   1152:                 if (defined($settings->{'showlogo'}{$item})) {
                   1153:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1154:                 }
                   1155:             }
                   1156:             foreach my $item (@logintext) {
                   1157:                 if ($settings->{$item} ne '') {
                   1158:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1159:                     $is_custom{$item} = 1;
                   1160:                 }
                   1161:             }
                   1162:             if ($settings->{'font'} ne '') {
                   1163:                 $designs{'font'} = $settings->{'font'};
                   1164:                 $is_custom{'font'} = 1;
                   1165:             }
                   1166:             foreach my $item (@bgs) {
                   1167:                 if ($settings->{$item} ne '') {
                   1168:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1169:                     $is_custom{$item} = 1;
                   1170:                 }
                   1171:             }
                   1172:             foreach my $item (@links) {
                   1173:                 if ($settings->{$item} ne '') {
                   1174:                     $designs{'links'}{$item} = $settings->{$item};
                   1175:                     $is_custom{$item} = 1;
                   1176:                 }
                   1177:             }
                   1178:         } else {
                   1179:             if ($designhash{$dom.'.login.font'} ne '') {
                   1180:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1181:                 $is_custom{'font'} = 1;
                   1182:             }
                   1183:             foreach my $item (@images) {
                   1184:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1185:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1186:                     $is_custom{$item} = 1;
                   1187:                 }
                   1188:             }
                   1189:             foreach my $item (@bgs) {
                   1190:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1191:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1192:                     $is_custom{$item} = 1;
                   1193:                 }
                   1194:             }
                   1195:             foreach my $item (@links) {
                   1196:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1197:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1198:                     $is_custom{$item} = 1;
                   1199:                 }
1.6       raeburn  1200:             }
                   1201:         }
1.160.6.5  raeburn  1202:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1203:                                                       logo => 'Institution Logo',
                   1204:                                                       domlogo => 'Domain Logo',
                   1205:                                                       login => 'Login box');
                   1206:         my $itemcount = 1;
                   1207:         foreach my $item (@toggles) {
                   1208:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1209:             $datatable .=  
                   1210:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1211:                 '</td><td>'.
                   1212:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1213:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1214:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1215:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1216:                 '</tr>';
                   1217:             $itemcount ++;
1.6       raeburn  1218:         }
1.160.6.5  raeburn  1219:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1220:         $datatable .= '</tr></table></td></tr>';
                   1221:     } elsif ($caller eq 'help') {
                   1222:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1223:         my $switchserver = &check_switchserver($dom,$confname);
                   1224:         my $itemcount = 1;
                   1225:         $defaulturl = '/adm/loginproblems.html';
                   1226:         $defaulttype = 'default';
                   1227:         %lt = &Apache::lonlocal::texthash (
                   1228:                      del     => 'Delete?',
                   1229:                      rep     => 'Replace:',
                   1230:                      upl     => 'Upload:',
                   1231:                      default => 'Default',
                   1232:                      custom  => 'Custom',
                   1233:                                              );
                   1234:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1235:         my @currlangs;
                   1236:         if (ref($settings) eq 'HASH') {
                   1237:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1238:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1239:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1240:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1241:                     $type{$key} = 'custom';
                   1242:                     unless ($key eq 'nolang') {
                   1243:                         push(@currlangs,$key);
                   1244:                     }
                   1245:                 }
                   1246:             } elsif ($settings->{'helpurl'} ne '') {
                   1247:                 $type{'nolang'} = 'custom';
                   1248:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1249:             }
                   1250:         }
1.160.6.5  raeburn  1251:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1252:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1253:             $datatable .= '<tr'.$css_class.'>';
                   1254:             if ($url{$lang} eq '') {
                   1255:                 $url{$lang} = $defaulturl;
                   1256:             }
                   1257:             if ($type{$lang} eq '') {
                   1258:                 $type{$lang} = $defaulttype;
                   1259:             }
                   1260:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1261:             if ($lang eq 'nolang') {
                   1262:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1263:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1264:             } else {
                   1265:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1266:                                   $langchoices{$lang},
                   1267:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1268:             }
                   1269:             $datatable .= '</span></td>'."\n".
                   1270:                           '<td class="LC_left_item">';
                   1271:             if ($type{$lang} eq 'custom') {
                   1272:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1273:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1274:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1275:             } else {
                   1276:                 $datatable .= $lt{'upl'};
                   1277:             }
                   1278:             $datatable .='<br />';
                   1279:             if ($switchserver) {
                   1280:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1281:             } else {
                   1282:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1283:             }
1.160.6.5  raeburn  1284:             $datatable .= '</td></tr>';
                   1285:             $itemcount ++;
1.6       raeburn  1286:         }
1.160.6.5  raeburn  1287:         my @addlangs;
                   1288:         foreach my $lang (sort(keys(%langchoices))) {
                   1289:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1290:             push(@addlangs,$lang);
                   1291:         }
                   1292:         if (@addlangs > 0) {
                   1293:             my %toadd;
                   1294:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1295:             $toadd{''} = &mt('Select');
                   1296:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1297:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1298:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1299:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1300:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1301:             if ($switchserver) {
                   1302:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1303:             } else {
                   1304:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1305:             }
1.160.6.5  raeburn  1306:             $datatable .= '</td></tr>';
                   1307:             $itemcount ++;
1.6       raeburn  1308:         }
1.160.6.5  raeburn  1309:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56  raeburn  1310:     } elsif ($caller eq 'headtag') {
                   1311:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1312:         my $choice = $choices{'headtag'};
                   1313:         $css_class = ' class="LC_odd_row"';
                   1314:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1315:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1316:                       '<th>'.$choices{'current'}.'</th>'.
                   1317:                       '<th>'.$choices{'action'}.'</th>'.
                   1318:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1319:         my (%currurls,%currexempt);
                   1320:         if (ref($settings) eq 'HASH') {
                   1321:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1322:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1323:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1324:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1325:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1326:                     }
                   1327:                 }
                   1328:             }
                   1329:         }
                   1330:         my %lt = &Apache::lonlocal::texthash(
                   1331:                                                del  => 'Delete?',
                   1332:                                                rep  => 'Replace:',
                   1333:                                                upl  => 'Upload:',
                   1334:                                                curr => 'View contents',
                   1335:                                                none => 'None',
                   1336:         );
                   1337:         my $switchserver = &check_switchserver($dom,$confname);
                   1338:         foreach my $lonhost (sort(keys(%domservers))) {
                   1339:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1340:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1341:             if ($currurls{$lonhost}) {
                   1342:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1343:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1344:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1345:                               '">'.$lt{'curr'}.'</a></td>'.
                   1346:                               '<td><span class="LC_nobreak"><label>'.
                   1347:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1348:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1349:             } else {
                   1350:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1351:             }
                   1352:             $datatable .='<br />';
                   1353:             if ($switchserver) {
                   1354:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1355:             } else {
                   1356:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1357:             }
1.160.6.87  raeburn  1358:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56  raeburn  1359:         }
                   1360:         $datatable .= '</table></td></tr>';
1.1       raeburn  1361:     }
1.6       raeburn  1362:     return $datatable;
                   1363: }
                   1364: 
                   1365: sub login_choices {
                   1366:     my %choices =
                   1367:         &Apache::lonlocal::texthash (
1.116     bisitz   1368:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1369:             adminmail     => "Display Administrator's E-mail Address?",
1.160.6.14  raeburn  1370:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1371:             disallowlogin => "Login page requests redirected",
                   1372:             hostid        => "Server",
1.128     raeburn  1373:             server        => "Redirect to:",
                   1374:             serverpath    => "Path",
                   1375:             custompath    => "Custom", 
                   1376:             exempt        => "Exempt IP(s)",
1.110     raeburn  1377:             directlogin   => "No redirect",
                   1378:             newuser       => "Link to create a user account",
                   1379:             img           => "Header",
                   1380:             logo          => "Main Logo",
                   1381:             domlogo       => "Domain Logo",
                   1382:             login         => "Log-in Header", 
                   1383:             textcol       => "Text color",
                   1384:             bgcol         => "Box color",
                   1385:             bgs           => "Background colors",
                   1386:             links         => "Link colors",
                   1387:             font          => "Font color",
                   1388:             pgbg          => "Header",
                   1389:             mainbg        => "Page",
                   1390:             sidebg        => "Login box",
                   1391:             link          => "Link",
                   1392:             alink         => "Active link",
                   1393:             vlink         => "Visited link",
1.160.6.56  raeburn  1394:             headtag       => "Custom markup",
                   1395:             action        => "Action",
                   1396:             current       => "Current",
1.6       raeburn  1397:         );
                   1398:     return %choices;
                   1399: }
                   1400: 
                   1401: sub print_rolecolors {
1.30      raeburn  1402:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1403:     my %choices = &color_font_choices();
                   1404:     my @bgs = ('pgbg','tabbg','sidebg');
                   1405:     my @links = ('link','alink','vlink');
                   1406:     my @images = ('img');
                   1407:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1408:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1409:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1410:     my (%is_custom,%designs);
1.160.6.22  raeburn  1411:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1412:     if (ref($settings) eq 'HASH') {
                   1413:         if (ref($settings->{$role}) eq 'HASH') {
                   1414:             if ($settings->{$role}->{'img'} ne '') {
                   1415:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1416:                 $is_custom{'img'} = 1;
                   1417:             }
                   1418:             if ($settings->{$role}->{'font'} ne '') {
                   1419:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1420:                 $is_custom{'font'} = 1;
                   1421:             }
1.97      tempelho 1422:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1423:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1424:                 $is_custom{'fontmenu'} = 1;
                   1425:             }
1.6       raeburn  1426:             foreach my $item (@bgs) {
                   1427:                 if ($settings->{$role}->{$item} ne '') {
                   1428:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1429:                     $is_custom{$item} = 1;
                   1430:                 }
                   1431:             }
                   1432:             foreach my $item (@links) {
                   1433:                 if ($settings->{$role}->{$item} ne '') {
                   1434:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1435:                     $is_custom{$item} = 1;
                   1436:                 }
                   1437:             }
                   1438:         }
                   1439:     } else {
                   1440:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1441:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1442:             $is_custom{'img'} = 1;
                   1443:         }
1.97      tempelho 1444:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1445:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1446:             $is_custom{'fontmenu'} = 1; 
                   1447:         }
1.6       raeburn  1448:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1449:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1450:             $is_custom{'font'} = 1;
                   1451:         }
                   1452:         foreach my $item (@bgs) {
                   1453:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1454:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1455:                 $is_custom{$item} = 1;
                   1456:             
                   1457:             }
                   1458:         }
                   1459:         foreach my $item (@links) {
                   1460:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1461:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1462:                 $is_custom{$item} = 1;
                   1463:             }
                   1464:         }
                   1465:     }
                   1466:     my $itemcount = 1;
1.30      raeburn  1467:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1468:     $datatable .= '</tr></table></td></tr>';
                   1469:     return $datatable;
                   1470: }
                   1471: 
1.160.6.22  raeburn  1472: sub role_defaults {
                   1473:     my ($role,$bgs,$links,$images,$logintext) = @_;
                   1474:     my %defaults;
                   1475:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
                   1476:         return %defaults;
                   1477:     }
                   1478:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1479:     if ($role eq 'login') {
                   1480:         %defaults = (
                   1481:                        font => $defaultdesign{$role.'.font'},
                   1482:                     );
                   1483:         if (ref($logintext) eq 'ARRAY') {
                   1484:             foreach my $item (@{$logintext}) {
                   1485:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1486:             }
                   1487:         }
                   1488:         foreach my $item (@{$images}) {
                   1489:             $defaults{'showlogo'}{$item} = 1;
                   1490:         }
                   1491:     } else {
                   1492:         %defaults = (
                   1493:                        img => $defaultdesign{$role.'.img'},
                   1494:                        font => $defaultdesign{$role.'.font'},
                   1495:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1496:                     );
                   1497:     }
                   1498:     foreach my $item (@{$bgs}) {
                   1499:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1500:     }
                   1501:     foreach my $item (@{$links}) {
                   1502:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1503:     }
                   1504:     foreach my $item (@{$images}) {
                   1505:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1506:     }
                   1507:     return %defaults;
                   1508: }
                   1509: 
1.6       raeburn  1510: sub display_color_options {
1.9       raeburn  1511:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1512:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1513:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1514:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1515:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1516:         '<td>'.$choices->{'font'}.'</td>';
                   1517:     if (!$is_custom->{'font'}) {
1.160.6.87  raeburn  1518:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1519:     } else {
                   1520:         $datatable .= '<td>&nbsp;</td>';
                   1521:     }
1.160.6.9  raeburn  1522:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1523: 
1.8       raeburn  1524:     $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1525:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1526:                   ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1527:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1528:     unless ($role eq 'login') { 
                   1529:         $datatable .= '<tr'.$css_class.'>'.
                   1530:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1531:         if (!$is_custom->{'fontmenu'}) {
1.160.6.87  raeburn  1532:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1533:         } else {
                   1534:             $datatable .= '<td>&nbsp;</td>';
                   1535:         }
1.160.6.22  raeburn  1536: 	$current_color = $designs->{'fontmenu'} ?
                   1537: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1538:         $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1539:                       '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22  raeburn  1540: 		      .$role.'_fontmenu"'.
1.160.6.9  raeburn  1541:                       ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1542:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1543:     }
1.9       raeburn  1544:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1545:     foreach my $img (@{$images}) {
1.18      albertel 1546: 	$itemcount ++;
1.6       raeburn  1547:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1548:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1549:                       '<td>'.$choices->{$img};
1.41      raeburn  1550:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1551:         if ($role eq 'login') {
                   1552:             if ($img eq 'login') {
                   1553:                 $login_hdr_pick =
1.135     bisitz   1554:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1555:                 $logincolors =
                   1556:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22  raeburn  1557:                                        $designs,$defaults);
1.70      raeburn  1558:             } elsif ($img ne 'domlogo') {
                   1559:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1560:             }
                   1561:         }
                   1562:         $datatable .= '</td>';
1.6       raeburn  1563:         if ($designs->{$img} ne '') {
                   1564:             $imgfile = $designs->{$img};
1.18      albertel 1565: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1566:         } else {
                   1567:             $imgfile = $defaults->{$img};
                   1568:         }
                   1569:         if ($imgfile) {
1.9       raeburn  1570:             my ($showfile,$fullsize);
                   1571:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1572:                 my $urldir = $1;
                   1573:                 my $filename = $2;
                   1574:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1575:                 if (@info) {
                   1576:                     my $thumbfile = 'tn-'.$filename;
                   1577:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1578:                     if (@thumb) {
                   1579:                         $showfile = $urldir.'/'.$thumbfile;
                   1580:                     } else {
                   1581:                         $showfile = $imgfile;
                   1582:                     }
                   1583:                 } else {
                   1584:                     $showfile = '';
                   1585:                 }
                   1586:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1587:                 $showfile = $imgfile;
1.6       raeburn  1588:                 my $imgdir = $1;
                   1589:                 my $filename = $2;
1.159     raeburn  1590:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1591:                     $showfile = "/$imgdir/tn-".$filename;
                   1592:                 } else {
1.159     raeburn  1593:                     my $input = $londocroot.$imgfile;
                   1594:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1595:                     if (!-e $output) {
1.9       raeburn  1596:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1597:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1598:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1599:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1600:                                 my $size = $width.'x'.$height;
1.160.6.88  raeburn  1601:                                 my @args = ('convert','-sample',$size,$input,$output);
                   1602:                                 system({$args[0]} @args);
1.159     raeburn  1603:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1604:                             }
                   1605:                         }
1.6       raeburn  1606:                     }
                   1607:                 }
1.16      raeburn  1608:             }
1.6       raeburn  1609:             if ($showfile) {
1.40      raeburn  1610:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1611:                     if ($showfile =~ m{^/res/}) {
                   1612:                         my $local_showfile =
                   1613:                             &Apache::lonnet::filelocation('',$showfile);
                   1614:                         &Apache::lonnet::repcopy($local_showfile);
                   1615:                     }
                   1616:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1617:                 }
                   1618:                 if ($imgfile) {
                   1619:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1620:                         if ($imgfile =~ m{^/res/}) {
                   1621:                             my $local_imgfile =
                   1622:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1623:                             &Apache::lonnet::repcopy($local_imgfile);
                   1624:                         }
                   1625:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1626:                     } else {
                   1627:                         $fullsize = $imgfile;
                   1628:                     }
                   1629:                 }
1.41      raeburn  1630:                 $datatable .= '<td>';
                   1631:                 if ($img eq 'login') {
1.135     bisitz   1632:                     $datatable .= $login_hdr_pick;
                   1633:                 } 
1.41      raeburn  1634:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1635:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1636:             } else {
1.160.6.22  raeburn  1637:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1638:                               &mt('Upload:').'<br />';
1.6       raeburn  1639:             }
                   1640:         } else {
1.160.6.22  raeburn  1641:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1642:                           &mt('Upload:').'<br />';
1.6       raeburn  1643:         }
1.9       raeburn  1644:         if ($switchserver) {
                   1645:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1646:         } else {
1.135     bisitz   1647:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1648:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1649:             }
1.9       raeburn  1650:         }
                   1651:         $datatable .= '</td></tr>';
1.6       raeburn  1652:     }
                   1653:     $itemcount ++;
                   1654:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1655:     $datatable .= '<tr'.$css_class.'>'.
                   1656:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1657:     my $bgs_def;
                   1658:     foreach my $item (@{$bgs}) {
                   1659:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1660:             $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  1661:         }
                   1662:     }
                   1663:     if ($bgs_def) {
1.8       raeburn  1664:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1665:     } else {
                   1666:         $datatable .= '<td>&nbsp;</td>';
                   1667:     }
                   1668:     $datatable .= '<td class="LC_right_item">'.
                   1669:                   '<table border="0"><tr>';
1.160.6.13  raeburn  1670: 
1.6       raeburn  1671:     foreach my $item (@{$bgs}) {
1.160.6.22  raeburn  1672:         $datatable .= '<td align="center">'.$choices->{$item};
                   1673: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1674:         if ($designs->{'bgs'}{$item}) {
1.160.6.9  raeburn  1675:             $datatable .= '&nbsp;';
1.6       raeburn  1676:         }
1.160.6.9  raeburn  1677:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1678:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1679:     }
                   1680:     $datatable .= '</tr></table></td></tr>';
                   1681:     $itemcount ++;
                   1682:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1683:     $datatable .= '<tr'.$css_class.'>'.
                   1684:                   '<td>'.$choices->{'links'}.'</td>';
                   1685:     my $links_def;
                   1686:     foreach my $item (@{$links}) {
                   1687:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  1688:             $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  1689:         }
                   1690:     }
                   1691:     if ($links_def) {
1.8       raeburn  1692:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1693:     } else {
                   1694:         $datatable .= '<td>&nbsp;</td>';
                   1695:     }
                   1696:     $datatable .= '<td class="LC_right_item">'.
                   1697:                   '<table border="0"><tr>';
                   1698:     foreach my $item (@{$links}) {
1.160.6.39  raeburn  1699: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22  raeburn  1700:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1701:         if ($designs->{'links'}{$item}) {
1.160.6.9  raeburn  1702:             $datatable.='&nbsp;';
1.6       raeburn  1703:         }
1.160.6.9  raeburn  1704:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1705:                       '" /></td>';
                   1706:     }
1.30      raeburn  1707:     $$rowtotal += $itemcount;
1.3       raeburn  1708:     return $datatable;
                   1709: }
                   1710: 
1.70      raeburn  1711: sub logo_display_options {
                   1712:     my ($img,$defaults,$designs) = @_;
                   1713:     my $checkedon;
                   1714:     if (ref($defaults) eq 'HASH') {
                   1715:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1716:             if ($defaults->{'showlogo'}{$img}) {
                   1717:                 $checkedon = 'checked="checked" ';     
                   1718:             }
                   1719:         } 
                   1720:     }
                   1721:     if (ref($designs) eq 'HASH') {
                   1722:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1723:             if (defined($designs->{'showlogo'}{$img})) {
                   1724:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1725:                     $checkedon = '';
                   1726:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1727:                     $checkedon = 'checked="checked" ';
                   1728:                 }
                   1729:             }
                   1730:         }
                   1731:     }
                   1732:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1733:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1734:            &mt('show').'</label>'."\n";
                   1735: }
                   1736: 
1.41      raeburn  1737: sub login_header_options  {
1.135     bisitz   1738:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1739:     my $output = '';
1.41      raeburn  1740:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1741:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1742:         if (!$is_custom->{'textcol'}) {
                   1743:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1744:                        '&nbsp;&nbsp;&nbsp;';
                   1745:         }
                   1746:         if (!$is_custom->{'bgcol'}) {
                   1747:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1748:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1749:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1750:         }
                   1751:         $output .= '<br />';
                   1752:     }
                   1753:     $output .='<br />';
                   1754:     return $output;
                   1755: }
                   1756: 
                   1757: sub login_text_colors {
1.160.6.22  raeburn  1758:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1759:     my $color_menu = '<table border="0"><tr>';
                   1760:     foreach my $item (@{$logintext}) {
1.160.6.22  raeburn  1761:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1762:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1763:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1764:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1765:     }
                   1766:     $color_menu .= '</tr></table><br />';
                   1767:     return $color_menu;
                   1768: }
                   1769: 
                   1770: sub image_changes {
                   1771:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1772:     my $output;
1.135     bisitz   1773:     if ($img eq 'login') {
1.160.6.87  raeburn  1774:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   1775:     } elsif (!$is_custom) {
1.70      raeburn  1776:         if ($img ne 'domlogo') {
1.160.6.87  raeburn  1777:             $output = &mt('Default image:').'<br />';
1.41      raeburn  1778:         } else {
1.160.6.87  raeburn  1779:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  1780:         }
                   1781:     }
1.160.6.87  raeburn  1782:     if ($img ne 'login') {
1.135     bisitz   1783:         if ($img_import) {
                   1784:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1785:         }
                   1786:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1787:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1788:         if ($is_custom) {
                   1789:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1790:                        '<input type="checkbox" name="'.
                   1791:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1792:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1793:         } else {
1.160.6.22  raeburn  1794:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1795:         }
1.41      raeburn  1796:     }
                   1797:     return $output;
                   1798: }
                   1799: 
1.3       raeburn  1800: sub print_quotas {
1.86      raeburn  1801:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1802:     my $context;
                   1803:     if ($action eq 'quotas') {
                   1804:         $context = 'tools';
                   1805:     } else {
                   1806:         $context = $action;
                   1807:     }
1.160.6.20  raeburn  1808:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1809:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1810:     my $typecount = 0;
1.101     raeburn  1811:     my ($css_class,%titles);
1.86      raeburn  1812:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  1813:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  1814:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1815:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1816:         %titles = &courserequest_titles();
1.160.6.5  raeburn  1817:     } elsif ($context eq 'requestauthor') {
                   1818:         @usertools = ('author');
                   1819:         @options = ('norequest','approval','automatic');
                   1820:         %titles = &authorrequest_titles();
1.86      raeburn  1821:     } else {
1.160.6.4  raeburn  1822:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1823:         %titles = &tool_titles();
1.86      raeburn  1824:     }
1.26      raeburn  1825:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1826:         foreach my $type (@{$types}) {
1.160.6.20  raeburn  1827:             my ($currdefquota,$currauthorquota);
1.160.6.5  raeburn  1828:             unless (($context eq 'requestcourses') ||
                   1829:                     ($context eq 'requestauthor')) {
1.86      raeburn  1830:                 if (ref($settings) eq 'HASH') {
                   1831:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20  raeburn  1832:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1833:                     } else {
                   1834:                         $currdefquota = $settings->{$type};
                   1835:                     }
1.160.6.20  raeburn  1836:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1837:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1838:                     }
1.78      raeburn  1839:                 }
1.72      raeburn  1840:             }
1.3       raeburn  1841:             if (defined($usertypes->{$type})) {
                   1842:                 $typecount ++;
                   1843:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1844:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1845:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1846:                               '<td class="LC_left_item">';
1.101     raeburn  1847:                 if ($context eq 'requestcourses') {
                   1848:                     $datatable .= '<table><tr>';
                   1849:                 }
                   1850:                 my %cell;  
1.72      raeburn  1851:                 foreach my $item (@usertools) {
1.101     raeburn  1852:                     if ($context eq 'requestcourses') {
                   1853:                         my ($curroption,$currlimit);
                   1854:                         if (ref($settings) eq 'HASH') {
                   1855:                             if (ref($settings->{$item}) eq 'HASH') {
                   1856:                                 $curroption = $settings->{$item}->{$type};
                   1857:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1858:                                     $currlimit = $1; 
                   1859:                                 }
                   1860:                             }
                   1861:                         }
                   1862:                         if (!$curroption) {
                   1863:                             $curroption = 'norequest';
                   1864:                         }
                   1865:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1866:                         foreach my $option (@options) {
                   1867:                             my $val = $option;
                   1868:                             if ($option eq 'norequest') {
                   1869:                                 $val = 0;  
                   1870:                             }
                   1871:                             if ($option eq 'validate') {
                   1872:                                 my $canvalidate = 0;
                   1873:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1874:                                     if ($validations{$item}{$type}) {
                   1875:                                         $canvalidate = 1;
                   1876:                                     }
                   1877:                                 }
                   1878:                                 next if (!$canvalidate);
                   1879:                             }
                   1880:                             my $checked = '';
                   1881:                             if ($option eq $curroption) {
                   1882:                                 $checked = ' checked="checked"';
                   1883:                             } elsif ($option eq 'autolimit') {
                   1884:                                 if ($curroption =~ /^autolimit/) {
                   1885:                                     $checked = ' checked="checked"';
                   1886:                                 }                       
                   1887:                             } 
                   1888:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1889:                                   '<input type="radio" name="crsreq_'.$item.
                   1890:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1891:                                   $titles{$option}.'</label>';
1.101     raeburn  1892:                             if ($option eq 'autolimit') {
1.127     raeburn  1893:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1894:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1895:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1896:                             }
1.127     raeburn  1897:                             $cell{$item} .= '</span> ';
1.103     raeburn  1898:                             if ($option eq 'autolimit') {
1.127     raeburn  1899:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1900:                             }
1.101     raeburn  1901:                         }
1.160.6.5  raeburn  1902:                     } elsif ($context eq 'requestauthor') {
                   1903:                         my $curroption;
                   1904:                         if (ref($settings) eq 'HASH') {
                   1905:                             $curroption = $settings->{$type};
                   1906:                         }
                   1907:                         if (!$curroption) {
                   1908:                             $curroption = 'norequest';
                   1909:                         }
                   1910:                         foreach my $option (@options) {
                   1911:                             my $val = $option;
                   1912:                             if ($option eq 'norequest') {
                   1913:                                 $val = 0;
                   1914:                             }
                   1915:                             my $checked = '';
                   1916:                             if ($option eq $curroption) {
                   1917:                                 $checked = ' checked="checked"';
                   1918:                             }
                   1919:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1920:                                   '<input type="radio" name="authorreq_'.$type.
                   1921:                                   '" value="'.$val.'"'.$checked.' />'.
                   1922:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1923:                         }
1.101     raeburn  1924:                     } else {
                   1925:                         my $checked = 'checked="checked" ';
                   1926:                         if (ref($settings) eq 'HASH') {
                   1927:                             if (ref($settings->{$item}) eq 'HASH') {
                   1928:                                 if ($settings->{$item}->{$type} == 0) {
                   1929:                                     $checked = '';
                   1930:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1931:                                     $checked =  'checked="checked" ';
                   1932:                                 }
1.78      raeburn  1933:                             }
1.72      raeburn  1934:                         }
1.101     raeburn  1935:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1936:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1937:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1938:                                       '</label></span>&nbsp; ';
1.72      raeburn  1939:                     }
1.101     raeburn  1940:                 }
                   1941:                 if ($context eq 'requestcourses') {
                   1942:                     $datatable .= '</tr><tr>';
                   1943:                     foreach my $item (@usertools) {
1.106     raeburn  1944:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1945:                     }
                   1946:                     $datatable .= '</tr></table>';
1.72      raeburn  1947:                 }
1.86      raeburn  1948:                 $datatable .= '</td>';
1.160.6.5  raeburn  1949:                 unless (($context eq 'requestcourses') ||
                   1950:                         ($context eq 'requestauthor')) {
1.86      raeburn  1951:                     $datatable .= 
1.160.6.20  raeburn  1952:                               '<td class="LC_right_item">'.
                   1953:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1954:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1955:                               '" value="'.$currdefquota.
1.160.6.20  raeburn  1956:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1957:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1958:                               '<input type="text" name="authorquota_'.$type.
                   1959:                               '" value="'.$currauthorquota.
                   1960:                               '" size="5" /></span></td>';
1.86      raeburn  1961:                 }
                   1962:                 $datatable .= '</tr>';
1.3       raeburn  1963:             }
                   1964:         }
                   1965:     }
1.160.6.5  raeburn  1966:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1967:         $defaultquota = '20';
1.160.6.20  raeburn  1968:         $authorquota = '500';
1.86      raeburn  1969:         if (ref($settings) eq 'HASH') {
                   1970:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1971:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1972:             } elsif (defined($settings->{'default'})) {
                   1973:                 $defaultquota = $settings->{'default'};
                   1974:             }
1.160.6.20  raeburn  1975:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1976:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1977:             }
1.3       raeburn  1978:         }
                   1979:     }
                   1980:     $typecount ++;
                   1981:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1982:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1983:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1984:                   '<td class="LC_left_item">';
1.101     raeburn  1985:     if ($context eq 'requestcourses') {
                   1986:         $datatable .= '<table><tr>';
                   1987:     }
                   1988:     my %defcell;
1.72      raeburn  1989:     foreach my $item (@usertools) {
1.101     raeburn  1990:         if ($context eq 'requestcourses') {
                   1991:             my ($curroption,$currlimit);
                   1992:             if (ref($settings) eq 'HASH') {
                   1993:                 if (ref($settings->{$item}) eq 'HASH') {
                   1994:                     $curroption = $settings->{$item}->{'default'};
                   1995:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1996:                         $currlimit = $1;
                   1997:                     }
                   1998:                 }
                   1999:             }
                   2000:             if (!$curroption) {
                   2001:                 $curroption = 'norequest';
                   2002:             }
                   2003:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2004:             foreach my $option (@options) {
                   2005:                 my $val = $option;
                   2006:                 if ($option eq 'norequest') {
                   2007:                     $val = 0;
                   2008:                 }
                   2009:                 if ($option eq 'validate') {
                   2010:                     my $canvalidate = 0;
                   2011:                     if (ref($validations{$item}) eq 'HASH') {
                   2012:                         if ($validations{$item}{'default'}) {
                   2013:                             $canvalidate = 1;
                   2014:                         }
                   2015:                     }
                   2016:                     next if (!$canvalidate);
                   2017:                 }
                   2018:                 my $checked = '';
                   2019:                 if ($option eq $curroption) {
                   2020:                     $checked = ' checked="checked"';
                   2021:                 } elsif ($option eq 'autolimit') {
                   2022:                     if ($curroption =~ /^autolimit/) {
                   2023:                         $checked = ' checked="checked"';
                   2024:                     }
                   2025:                 }
                   2026:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2027:                                   '<input type="radio" name="crsreq_'.$item.
                   2028:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2029:                                   $titles{$option}.'</label>';
                   2030:                 if ($option eq 'autolimit') {
1.127     raeburn  2031:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2032:                                        $item.'_limit_default" size="1" '.
                   2033:                                        'value="'.$currlimit.'" />';
                   2034:                 }
1.127     raeburn  2035:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2036:                 if ($option eq 'autolimit') {
1.127     raeburn  2037:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2038:                 }
1.101     raeburn  2039:             }
1.160.6.5  raeburn  2040:         } elsif ($context eq 'requestauthor') {
                   2041:             my $curroption;
                   2042:             if (ref($settings) eq 'HASH') {
1.160.6.8  raeburn  2043:                 $curroption = $settings->{'default'};
1.160.6.5  raeburn  2044:             }
                   2045:             if (!$curroption) {
                   2046:                 $curroption = 'norequest';
                   2047:             }
                   2048:             foreach my $option (@options) {
                   2049:                 my $val = $option;
                   2050:                 if ($option eq 'norequest') {
                   2051:                     $val = 0;
                   2052:                 }
                   2053:                 my $checked = '';
                   2054:                 if ($option eq $curroption) {
                   2055:                     $checked = ' checked="checked"';
                   2056:                 }
                   2057:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2058:                               '<input type="radio" name="authorreq_default"'.
                   2059:                               ' value="'.$val.'"'.$checked.' />'.
                   2060:                               $titles{$option}.'</label></span>&nbsp; ';
                   2061:             }
1.101     raeburn  2062:         } else {
                   2063:             my $checked = 'checked="checked" ';
                   2064:             if (ref($settings) eq 'HASH') {
                   2065:                 if (ref($settings->{$item}) eq 'HASH') {
                   2066:                     if ($settings->{$item}->{'default'} == 0) {
                   2067:                         $checked = '';
                   2068:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2069:                         $checked = 'checked="checked" ';
                   2070:                     }
1.78      raeburn  2071:                 }
1.72      raeburn  2072:             }
1.101     raeburn  2073:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2074:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2075:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2076:                           '</label></span>&nbsp; ';
                   2077:         }
                   2078:     }
                   2079:     if ($context eq 'requestcourses') {
                   2080:         $datatable .= '</tr><tr>';
                   2081:         foreach my $item (@usertools) {
1.106     raeburn  2082:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2083:         }
1.101     raeburn  2084:         $datatable .= '</tr></table>';
1.72      raeburn  2085:     }
1.86      raeburn  2086:     $datatable .= '</td>';
1.160.6.5  raeburn  2087:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20  raeburn  2088:         $datatable .= '<td class="LC_right_item">'.
                   2089:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2090:                       '<input type="text" name="defaultquota" value="'.
1.160.6.20  raeburn  2091:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2092:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2093:                       '<input type="text" name="authorquota" value="'.
                   2094:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2095:     }
                   2096:     $datatable .= '</tr>';
1.72      raeburn  2097:     $typecount ++;
                   2098:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2099:     $datatable .= '<tr'.$css_class.'>'.
1.160.6.20  raeburn  2100:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2101:     if ($context eq 'requestcourses') {
1.109     raeburn  2102:         $datatable .= &mt('(overrides affiliation, if set)').
                   2103:                       '</td>'.
                   2104:                       '<td class="LC_left_item">'.
                   2105:                       '<table><tr>';
1.101     raeburn  2106:     } else {
1.109     raeburn  2107:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2108:                       '</td>'.
                   2109:                       '<td class="LC_left_item" colspan="2">'.
                   2110:                       '<br />';
1.101     raeburn  2111:     }
                   2112:     my %advcell;
1.72      raeburn  2113:     foreach my $item (@usertools) {
1.101     raeburn  2114:         if ($context eq 'requestcourses') {
                   2115:             my ($curroption,$currlimit);
                   2116:             if (ref($settings) eq 'HASH') {
                   2117:                 if (ref($settings->{$item}) eq 'HASH') {
                   2118:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2119:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2120:                         $currlimit = $1;
                   2121:                     }
                   2122:                 }
                   2123:             }
                   2124:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2125:             my $checked = '';
                   2126:             if ($curroption eq '') {
                   2127:                 $checked = ' checked="checked"';
                   2128:             }
                   2129:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2130:                                '<input type="radio" name="crsreq_'.$item.
                   2131:                                '__LC_adv" value=""'.$checked.' />'.
                   2132:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2133:             foreach my $option (@options) {
                   2134:                 my $val = $option;
                   2135:                 if ($option eq 'norequest') {
                   2136:                     $val = 0;
                   2137:                 }
                   2138:                 if ($option eq 'validate') {
                   2139:                     my $canvalidate = 0;
                   2140:                     if (ref($validations{$item}) eq 'HASH') {
                   2141:                         if ($validations{$item}{'_LC_adv'}) {
                   2142:                             $canvalidate = 1;
                   2143:                         }
                   2144:                     }
                   2145:                     next if (!$canvalidate);
                   2146:                 }
                   2147:                 my $checked = '';
1.104     raeburn  2148:                 if ($val eq $curroption) {
1.101     raeburn  2149:                     $checked = ' checked="checked"';
                   2150:                 } elsif ($option eq 'autolimit') {
                   2151:                     if ($curroption =~ /^autolimit/) {
                   2152:                         $checked = ' checked="checked"';
                   2153:                     }
                   2154:                 }
                   2155:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2156:                                   '<input type="radio" name="crsreq_'.$item.
                   2157:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2158:                                   $titles{$option}.'</label>';
                   2159:                 if ($option eq 'autolimit') {
1.127     raeburn  2160:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2161:                                        $item.'_limit__LC_adv" size="1" '.
                   2162:                                        'value="'.$currlimit.'" />';
                   2163:                 }
1.127     raeburn  2164:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2165:                 if ($option eq 'autolimit') {
1.127     raeburn  2166:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2167:                 }
1.101     raeburn  2168:             }
1.160.6.5  raeburn  2169:         } elsif ($context eq 'requestauthor') {
                   2170:             my $curroption;
                   2171:             if (ref($settings) eq 'HASH') {
                   2172:                 $curroption = $settings->{'_LC_adv'};
                   2173:             }
                   2174:             my $checked = '';
                   2175:             if ($curroption eq '') {
                   2176:                 $checked = ' checked="checked"';
                   2177:             }
                   2178:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2179:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2180:                           ' value=""'.$checked.' />'.
                   2181:                           &mt('No override set').'</label></span>&nbsp; ';
                   2182:             foreach my $option (@options) {
                   2183:                 my $val = $option;
                   2184:                 if ($option eq 'norequest') {
                   2185:                     $val = 0;
                   2186:                 }
                   2187:                 my $checked = '';
                   2188:                 if ($val eq $curroption) {
                   2189:                     $checked = ' checked="checked"';
                   2190:                 }
                   2191:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8  raeburn  2192:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2193:                               ' value="'.$val.'"'.$checked.' />'.
1.160.6.5  raeburn  2194:                               $titles{$option}.'</label></span>&nbsp; ';
                   2195:             }
1.101     raeburn  2196:         } else {
                   2197:             my $checked = 'checked="checked" ';
                   2198:             if (ref($settings) eq 'HASH') {
                   2199:                 if (ref($settings->{$item}) eq 'HASH') {
                   2200:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2201:                         $checked = '';
                   2202:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2203:                         $checked = 'checked="checked" ';
                   2204:                     }
1.79      raeburn  2205:                 }
1.72      raeburn  2206:             }
1.101     raeburn  2207:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2208:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2209:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2210:                           '</label></span>&nbsp; ';
                   2211:         }
                   2212:     }
                   2213:     if ($context eq 'requestcourses') {
                   2214:         $datatable .= '</tr><tr>';
                   2215:         foreach my $item (@usertools) {
1.106     raeburn  2216:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2217:         }
1.101     raeburn  2218:         $datatable .= '</tr></table>';
1.72      raeburn  2219:     }
1.98      raeburn  2220:     $datatable .= '</td></tr>';
1.30      raeburn  2221:     $$rowtotal += $typecount;
1.3       raeburn  2222:     return $datatable;
                   2223: }
                   2224: 
1.160.6.5  raeburn  2225: sub print_requestmail {
1.160.6.93  raeburn  2226:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25  raeburn  2227:     my ($now,$datatable,%currapp);
1.102     raeburn  2228:     $now = time;
                   2229:     if (ref($settings) eq 'HASH') {
                   2230:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2231:             if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34  raeburn  2232:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2233:             }
                   2234:         }
                   2235:     }
1.160.6.16  raeburn  2236:     my $numinrow = 2;
1.160.6.34  raeburn  2237:     my $css_class;
1.160.6.93  raeburn  2238:     if ($$rowtotal%2) {
                   2239:         $css_class = 'LC_odd_row';
                   2240:     }
                   2241:     if ($customcss) {
                   2242:         $css_class .= " $customcss";
                   2243:     }
                   2244:     $css_class =~ s/^\s+//;
                   2245:     if ($css_class) {
                   2246:         $css_class = ' class="'.$css_class.'"';
                   2247:     }
                   2248:     if ($rowstyle) {
                   2249:         $css_class .= ' style="'.$rowstyle.'"';
                   2250:     }
1.160.6.5  raeburn  2251:     my $text;
                   2252:     if ($action eq 'requestcourses') {
                   2253:         $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34  raeburn  2254:     } elsif ($action eq 'requestauthor') {
                   2255:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5  raeburn  2256:     } else {
1.160.6.34  raeburn  2257:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5  raeburn  2258:     }
1.160.6.34  raeburn  2259:     $datatable = '<tr'.$css_class.'>'.
1.160.6.5  raeburn  2260:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2261:                  ' <td class="LC_left_item">';
1.160.6.16  raeburn  2262:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34  raeburn  2263:                                                  $action.'notifyapproval',%currapp);
1.160.6.16  raeburn  2264:     if ($numdc > 0) {
                   2265:         $datatable .= $table;
1.102     raeburn  2266:     } else {
                   2267:         $datatable .= &mt('There are no active Domain Coordinators');
                   2268:     }
                   2269:     $datatable .='</td></tr>';
                   2270:     return $datatable;
                   2271: }
                   2272: 
1.160.6.30  raeburn  2273: sub print_studentcode {
                   2274:     my ($settings,$rowtotal) = @_;
                   2275:     my $rownum = 0; 
                   2276:     my ($output,%current);
                   2277:     my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51  raeburn  2278:     if (ref($settings) eq 'HASH') {
                   2279:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2280:             foreach my $type (@crstypes) {
                   2281:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2282:             }
1.160.6.30  raeburn  2283:         }
                   2284:     }
                   2285:     $output .= '<tr>'.
                   2286:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2287:                '<td class="LC_left_item">';
                   2288:     foreach my $type (@crstypes) {
                   2289:         my $check = ' ';
                   2290:         if ($current{$type}) {
                   2291:             $check = ' checked="checked" ';
                   2292:         }
                   2293:         $output .= '<span class="LC_nobreak"><label>'.
                   2294:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2295:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2296:     }
                   2297:     $output .= '</td></tr>';
                   2298:     $$rowtotal ++;
                   2299:     return $output;
                   2300: }
                   2301: 
                   2302: sub print_textbookcourses {
1.160.6.46  raeburn  2303:     my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30  raeburn  2304:     my $rownum = 0;
                   2305:     my $css_class;
                   2306:     my $itemcount = 1;
                   2307:     my $maxnum = 0;
                   2308:     my $bookshash;
                   2309:     if (ref($settings) eq 'HASH') {
1.160.6.46  raeburn  2310:         $bookshash = $settings->{$type};
1.160.6.30  raeburn  2311:     }
                   2312:     my %ordered;
                   2313:     if (ref($bookshash) eq 'HASH') {
                   2314:         foreach my $item (keys(%{$bookshash})) {
                   2315:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2316:                 my $num = $bookshash->{$item}{'order'};
                   2317:                 $ordered{$num} = $item;
                   2318:             }
                   2319:         }
                   2320:     }
                   2321:     my $confname = $dom.'-domainconfig';
                   2322:     my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46  raeburn  2323:     my $maxnum = scalar(keys(%ordered));
                   2324:     my $datatable;
1.160.6.30  raeburn  2325:     if (keys(%ordered)) {
                   2326:         my @items = sort { $a <=> $b } keys(%ordered);
                   2327:         for (my $i=0; $i<@items; $i++) {
                   2328:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2329:             my $key = $ordered{$items[$i]};
                   2330:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2331:             my $coursetitle = $coursehash{'description'};
1.160.6.47  raeburn  2332:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30  raeburn  2333:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2334:                 $subject = $bookshash->{$key}->{'subject'};
                   2335:                 $title = $bookshash->{$key}->{'title'};
1.160.6.46  raeburn  2336:                 if ($type eq 'textbooks') {
1.160.6.47  raeburn  2337:                     $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46  raeburn  2338:                     $author = $bookshash->{$key}->{'author'};
                   2339:                     $image = $bookshash->{$key}->{'image'};
                   2340:                     if ($image ne '') {
                   2341:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2342:                         my $imagethumb = "$path/tn-".$imagefile;
                   2343:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2344:                     }
1.160.6.30  raeburn  2345:                 }
                   2346:             }
1.160.6.46  raeburn  2347:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30  raeburn  2348:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46  raeburn  2349:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30  raeburn  2350:             for (my $k=0; $k<=$maxnum; $k++) {
                   2351:                 my $vpos = $k+1;
                   2352:                 my $selstr;
                   2353:                 if ($k == $i) {
                   2354:                     $selstr = ' selected="selected" ';
                   2355:                 }
                   2356:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2357:             }
                   2358:             $datatable .= '</select>'.('&nbsp;'x2).
1.160.6.46  raeburn  2359:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30  raeburn  2360:                 &mt('Delete?').'</label></span></td>'.
                   2361:                 '<td colspan="2">'.
1.160.6.46  raeburn  2362:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30  raeburn  2363:                 ('&nbsp;'x2).
1.160.6.46  raeburn  2364:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2365:             if ($type eq 'textbooks') {
                   2366:                 $datatable .= ('&nbsp;'x2).
1.160.6.47  raeburn  2367:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2368:                               ('&nbsp;'x2).
1.160.6.46  raeburn  2369:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2370:                               ('&nbsp;'x2).
                   2371:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2372:                 if ($image) {
                   2373:                     $datatable .= '<span class="LC_nobreak">'.
                   2374:                                   $imgsrc.
                   2375:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2376:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2377:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2378:                 }
                   2379:                 if ($switchserver) {
                   2380:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2381:                 } else {
                   2382:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2383:                 }
1.160.6.30  raeburn  2384:             }
1.160.6.46  raeburn  2385:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30  raeburn  2386:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2387:                           $coursetitle.'</span></td></tr>'."\n";
                   2388:             $itemcount ++;
                   2389:         }
                   2390:     }
                   2391:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46  raeburn  2392:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30  raeburn  2393:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46  raeburn  2394:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2395:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30  raeburn  2396:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2397:         my $vpos = $k+1;
                   2398:         my $selstr;
                   2399:         if ($k == $maxnum) {
                   2400:             $selstr = ' selected="selected" ';
                   2401:         }
                   2402:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2403:     }
                   2404:     $datatable .= '</select>&nbsp;'."\n".
1.160.6.87  raeburn  2405:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30  raeburn  2406:                   '<td colspan="2">'.
1.160.6.46  raeburn  2407:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30  raeburn  2408:                   ('&nbsp;'x2).
1.160.6.46  raeburn  2409:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2410:                   ('&nbsp;'x2);
                   2411:     if ($type eq 'textbooks') {
1.160.6.47  raeburn  2412:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2413:                       ('&nbsp;'x2).
                   2414:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46  raeburn  2415:                       ('&nbsp;'x2).
                   2416:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2417:         if ($switchserver) {
                   2418:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2419:         } else {
                   2420:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2421:         }
1.160.6.87  raeburn  2422:         $datatable .= '</span>'."\n";
1.160.6.30  raeburn  2423:     }
1.160.6.87  raeburn  2424:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.160.6.46  raeburn  2425:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2426:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30  raeburn  2427:                   &Apache::loncommon::selectcourse_link
1.160.6.87  raeburn  2428:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30  raeburn  2429:                   '</span></td>'."\n".
                   2430:                   '</tr>'."\n";
                   2431:     $itemcount ++;
                   2432:     return $datatable;
                   2433: }
                   2434: 
                   2435: sub textbookcourses_javascript {
1.160.6.46  raeburn  2436:     my ($settings) = @_;
                   2437:     return unless(ref($settings) eq 'HASH');
                   2438:     my (%ordered,%total,%jstext);
                   2439:     foreach my $type ('textbooks','templates') {
                   2440:         $total{$type} = 0;
                   2441:         if (ref($settings->{$type}) eq 'HASH') {
                   2442:             foreach my $item (keys(%{$settings->{$type}})) {
                   2443:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2444:                     my $num = $settings->{$type}->{$item}{'order'};
                   2445:                     $ordered{$type}{$num} = $item;
                   2446:                 }
                   2447:             }
                   2448:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2449:         }
                   2450:         my @jsarray = ();
                   2451:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2452:             push(@jsarray,$ordered{$type}{$item});
                   2453:         }
                   2454:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30  raeburn  2455:     }
                   2456:     return <<"ENDSCRIPT";
                   2457: <script type="text/javascript">
                   2458: // <![CDATA[
1.160.6.46  raeburn  2459: function reorderBooks(form,item,caller) {
1.160.6.30  raeburn  2460:     var changedVal;
1.160.6.46  raeburn  2461: $jstext{'textbooks'};
                   2462: $jstext{'templates'};
                   2463:     var newpos;
                   2464:     var maxh;
                   2465:     if (caller == 'textbooks') {  
                   2466:         newpos = 'textbooks_addbook_pos';
                   2467:         maxh = 1 + $total{'textbooks'};
                   2468:     } else {
                   2469:         newpos = 'templates_addbook_pos';
                   2470:         maxh = 1 + $total{'templates'};
                   2471:     }
1.160.6.30  raeburn  2472:     var current = new Array;
                   2473:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2474:     if (item == newpos) {
                   2475:         changedVal = newitemVal;
                   2476:     } else {
                   2477:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2478:         current[newitemVal] = newpos;
                   2479:     }
1.160.6.46  raeburn  2480:     if (caller == 'textbooks') {
                   2481:         for (var i=0; i<textbooks.length; i++) {
                   2482:             var elementName = 'textbooks_'+textbooks[i];
                   2483:             if (elementName != item) {
                   2484:                 if (form.elements[elementName]) {
                   2485:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2486:                     current[currVal] = elementName;
                   2487:                 }
                   2488:             }
                   2489:         }
                   2490:     }
                   2491:     if (caller == 'templates') {
                   2492:         for (var i=0; i<templates.length; i++) {
                   2493:             var elementName = 'templates_'+templates[i];
                   2494:             if (elementName != item) {
                   2495:                 if (form.elements[elementName]) {
                   2496:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2497:                     current[currVal] = elementName;
                   2498:                 }
1.160.6.30  raeburn  2499:             }
                   2500:         }
                   2501:     }
                   2502:     var oldVal;
                   2503:     for (var j=0; j<maxh; j++) {
                   2504:         if (current[j] == undefined) {
                   2505:             oldVal = j;
                   2506:         }
                   2507:     }
                   2508:     if (oldVal < changedVal) {
                   2509:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2510:            var elementName = current[k];
                   2511:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2512:         }
                   2513:     } else {
                   2514:         for (var k=changedVal; k<oldVal; k++) {
                   2515:             var elementName = current[k];
                   2516:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2517:         }
                   2518:     }
                   2519:     return;
                   2520: }
                   2521: 
                   2522: // ]]>
                   2523: </script>
                   2524: 
                   2525: ENDSCRIPT
                   2526: }
                   2527: 
1.160.6.102.2  1(raebur 2528:0): sub ltitools_javascript {
                   2529:0):     my ($settings) = @_;
          5(raebur 2530:0):     my $togglejs = &ltitools_toggle_js();
                   2531:0):     unless (ref($settings) eq 'HASH') {
                   2532:0):         return $togglejs;
                   2533:0):     }
          1(raebur 2534:0):     my (%ordered,$total,%jstext);
                   2535:0):     $total = 0;
                   2536:0):     foreach my $item (keys(%{$settings})) {
                   2537:0):         if (ref($settings->{$item}) eq 'HASH') {
                   2538:0):             my $num = $settings->{$item}{'order'};
                   2539:0):             $ordered{$num} = $item;
                   2540:0):         }
                   2541:0):     }
                   2542:0):     $total = scalar(keys(%{$settings}));
                   2543:0):     my @jsarray = ();
                   2544:0):     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2545:0):         push(@jsarray,$ordered{$item});
                   2546:0):     }
                   2547:0):     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2548:0):     return <<"ENDSCRIPT";
                   2549:0): <script type="text/javascript">
                   2550:0): // <![CDATA[
          5(raebur 2551:0): function reorderLTITools(form,item) {
          1(raebur 2552:0):     var changedVal;
                   2553:0): $jstext
                   2554:0):     var newpos = 'ltitools_add_pos';
                   2555:0):     var maxh = 1 + $total;
                   2556:0):     var current = new Array;
                   2557:0):     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2558:0):     if (item == newpos) {
                   2559:0):         changedVal = newitemVal;
                   2560:0):     } else {
                   2561:0):         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2562:0):         current[newitemVal] = newpos;
                   2563:0):     }
                   2564:0):     for (var i=0; i<ltitools.length; i++) {
                   2565:0):         var elementName = 'ltitools_'+ltitools[i];
                   2566:0):         if (elementName != item) {
                   2567:0):             if (form.elements[elementName]) {
                   2568:0):                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2569:0):                 current[currVal] = elementName;
                   2570:0):             }
                   2571:0):         }
                   2572:0):     }
                   2573:0):     var oldVal;
                   2574:0):     for (var j=0; j<maxh; j++) {
                   2575:0):         if (current[j] == undefined) {
                   2576:0):             oldVal = j;
                   2577:0):         }
                   2578:0):     }
                   2579:0):     if (oldVal < changedVal) {
                   2580:0):         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2581:0):            var elementName = current[k];
                   2582:0):            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2583:0):         }
                   2584:0):     } else {
                   2585:0):         for (var k=changedVal; k<oldVal; k++) {
                   2586:0):             var elementName = current[k];
                   2587:0):             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2588:0):         }
                   2589:0):     }
                   2590:0):     return;
                   2591:0): }
                   2592:0): 
                   2593:0): // ]]>
                   2594:0): </script>
                   2595:0): 
          5(raebur 2596:0): $togglejs
                   2597:0): 
                   2598:0): ENDSCRIPT
                   2599:0): }
                   2600:0): 
                   2601:0): sub ltitools_toggle_js {
                   2602:0):     return <<"ENDSCRIPT";
                   2603:0): <script type="text/javascript">
                   2604:0): // <![CDATA[
                   2605:0): 
                   2606:0): function toggleLTITools(form,setting,item) {
                   2607:0):     var radioname = '';
                   2608:0):     var divid = '';
                   2609:0):     if (setting == 'user') {
                   2610:0):         divid = 'ltitools_'+setting+'_div_'+item;
                   2611:0):         var checkid = 'ltitools_'+setting+'_field_'+item;
                   2612:0):         if (document.getElementById(divid)) {
                   2613:0):             if (document.getElementById(checkid)) {
                   2614:0):                 if (document.getElementById(checkid).checked) {
                   2615:0):                     document.getElementById(divid).style.display = 'inline-block';
                   2616:0):                 } else {
                   2617:0):                     document.getElementById(divid).style.display = 'none';
                   2618:0):                 }
                   2619:0):             }
                   2620:0):         }
                   2621:0):     }
                   2622:0):     return;
                   2623:0): }
                   2624:0): // ]]>
                   2625:0): </script>
                   2626:0): 
          1(raebur 2627:0): ENDSCRIPT
                   2628:0): }
                   2629:0): 
1.3       raeburn  2630: sub print_autoenroll {
1.30      raeburn  2631:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2632:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68  raeburn  2633:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2634:     if (ref($settings) eq 'HASH') {
                   2635:         if (exists($settings->{'run'})) {
                   2636:             if ($settings->{'run'} eq '0') {
                   2637:                 $runoff = ' checked="checked" ';
                   2638:                 $runon = ' ';
                   2639:             } else {
                   2640:                 $runon = ' checked="checked" ';
                   2641:                 $runoff = ' ';
                   2642:             }
                   2643:         } else {
                   2644:             if ($autorun) {
                   2645:                 $runon = ' checked="checked" ';
                   2646:                 $runoff = ' ';
                   2647:             } else {
                   2648:                 $runoff = ' checked="checked" ';
                   2649:                 $runon = ' ';
                   2650:             }
                   2651:         }
1.129     raeburn  2652:         if (exists($settings->{'co-owners'})) {
                   2653:             if ($settings->{'co-owners'} eq '0') {
                   2654:                 $coownersoff = ' checked="checked" ';
                   2655:                 $coownerson = ' ';
                   2656:             } else {
                   2657:                 $coownerson = ' checked="checked" ';
                   2658:                 $coownersoff = ' ';
                   2659:             }
                   2660:         } else {
                   2661:             $coownersoff = ' checked="checked" ';
                   2662:             $coownerson = ' ';
                   2663:         }
1.3       raeburn  2664:         if (exists($settings->{'sender_domain'})) {
                   2665:             $defdom = $settings->{'sender_domain'};
                   2666:         }
1.160.6.68  raeburn  2667:         if (exists($settings->{'autofailsafe'})) {
                   2668:             $failsafe = $settings->{'autofailsafe'};
                   2669:         }
1.14      raeburn  2670:     } else {
                   2671:         if ($autorun) {
                   2672:             $runon = ' checked="checked" ';
                   2673:             $runoff = ' ';
                   2674:         } else {
                   2675:             $runoff = ' checked="checked" ';
                   2676:             $runon = ' ';
                   2677:         }
1.3       raeburn  2678:     }
                   2679:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2680:     my $notif_sender;
                   2681:     if (ref($settings) eq 'HASH') {
                   2682:         $notif_sender = $settings->{'sender_uname'};
                   2683:     }
1.3       raeburn  2684:     my $datatable='<tr class="LC_odd_row">'.
                   2685:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2686:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2687:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2688:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2689:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2690:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2691:                   '</tr><tr>'.
                   2692:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2693:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2694:                   &mt('username').':&nbsp;'.
                   2695:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2696:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2697:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2698:                   '<tr class="LC_odd_row">'.
                   2699:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2700:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2701:                   '<input type="radio" name="autoassign_coowners"'.
                   2702:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2703:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2704:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68  raeburn  2705:                   '</tr><tr>'.
                   2706:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2707:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2708:                   '<input type="text" name="autoenroll_failsafe"'.
1.160.6.87  raeburn  2709:                   ' value="'.$failsafe.'" size="4" /></span></td></tr>';
1.160.6.68  raeburn  2710:     $$rowtotal += 4;
1.3       raeburn  2711:     return $datatable;
                   2712: }
                   2713: 
                   2714: sub print_autoupdate {
1.30      raeburn  2715:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2716:     my $datatable;
                   2717:     if ($position eq 'top') {
                   2718:         my $updateon = ' ';
                   2719:         my $updateoff = ' checked="checked" ';
                   2720:         my $classlistson = ' ';
                   2721:         my $classlistsoff = ' checked="checked" ';
                   2722:         if (ref($settings) eq 'HASH') {
                   2723:             if ($settings->{'run'} eq '1') {
                   2724:                 $updateon = $updateoff;
                   2725:                 $updateoff = ' ';
                   2726:             }
                   2727:             if ($settings->{'classlists'} eq '1') {
                   2728:                 $classlistson = $classlistsoff;
                   2729:                 $classlistsoff = ' ';
                   2730:             }
                   2731:         }
                   2732:         my %title = (
                   2733:                    run => 'Auto-update active?',
                   2734:                    classlists => 'Update information in classlists?',
                   2735:                     );
                   2736:         $datatable = '<tr class="LC_odd_row">'. 
                   2737:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2738:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2739:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2740:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2741:                   '<label><input type="radio" name="autoupdate_run"'.
                   2742:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2743:                   '</tr><tr>'.
                   2744:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2745:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2746:                   '<label><input type="radio" name="classlists"'.
                   2747:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2748:                   '<label><input type="radio" name="classlists"'.
                   2749:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2750:                   '</tr>';
1.30      raeburn  2751:         $$rowtotal += 2;
1.131     raeburn  2752:     } elsif ($position eq 'middle') {
                   2753:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2754:         my $numinrow = 3;
                   2755:         my $locknamesettings;
                   2756:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2757:                                      $dom,$numinrow,$othertitle,
1.160.6.93  raeburn  2758:                                     'lockablenames',$rowtotal);
1.131     raeburn  2759:         $$rowtotal ++;
1.3       raeburn  2760:     } else {
1.44      raeburn  2761:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2762:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2763:                       'permanentemail','id');
1.33      raeburn  2764:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2765:         my $numrows = 0;
1.26      raeburn  2766:         if (ref($types) eq 'ARRAY') {
                   2767:             if (@{$types} > 0) {
                   2768:                 $datatable = 
                   2769:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2770:                                          \@fields,$types,\$numrows);
1.30      raeburn  2771:                     $$rowtotal += @{$types}; 
1.26      raeburn  2772:             }
1.3       raeburn  2773:         }
                   2774:         $datatable .= 
                   2775:             &usertype_update_row($settings,{'default' => $othertitle},
                   2776:                                  \%fieldtitles,\@fields,['default'],
                   2777:                                  \$numrows);
1.30      raeburn  2778:         $$rowtotal ++;     
1.3       raeburn  2779:     }
                   2780:     return $datatable;
                   2781: }
                   2782: 
1.125     raeburn  2783: sub print_autocreate {
                   2784:     my ($dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  2785:     my (%createon,%createoff,%currhash);
1.125     raeburn  2786:     my @types = ('xml','req');
                   2787:     if (ref($settings) eq 'HASH') {
                   2788:         foreach my $item (@types) {
                   2789:             $createoff{$item} = ' checked="checked" ';
                   2790:             $createon{$item} = ' ';
                   2791:             if (exists($settings->{$item})) {
                   2792:                 if ($settings->{$item}) {
                   2793:                     $createon{$item} = ' checked="checked" ';
                   2794:                     $createoff{$item} = ' ';
                   2795:                 }
                   2796:             }
                   2797:         }
1.160.6.16  raeburn  2798:         if ($settings->{'xmldc'} ne '') {
                   2799:             $currhash{$settings->{'xmldc'}} = 1;
                   2800:         }
1.125     raeburn  2801:     } else {
                   2802:         foreach my $item (@types) {
                   2803:             $createoff{$item} = ' checked="checked" ';
                   2804:             $createon{$item} = ' ';
                   2805:         }
                   2806:     }
                   2807:     $$rowtotal += 2;
1.160.6.16  raeburn  2808:     my $numinrow = 2;
1.125     raeburn  2809:     my $datatable='<tr class="LC_odd_row">'.
                   2810:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2811:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2812:                   '<input type="radio" name="autocreate_xml"'.
                   2813:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2814:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2815:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2816:                   '</td></tr><tr>'.
                   2817:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2818:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2819:                   '<input type="radio" name="autocreate_req"'.
                   2820:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2821:                   '<label><input type="radio" name="autocreate_req"'.
                   2822:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16  raeburn  2823:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2824:                                                    'autocreate_xmldc',%currhash);
1.160.6.50  raeburn  2825:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2826:     if ($numdc > 1) {
1.160.6.50  raeburn  2827:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2828:                       '</td><td class="LC_left_item">';
1.125     raeburn  2829:     } else {
1.160.6.50  raeburn  2830:         $datatable .= &mt('Course creation processed as:').
                   2831:                       '</td><td class="LC_right_item">';
1.125     raeburn  2832:     }
1.160.6.50  raeburn  2833:     $datatable .= $dctable.'</td></tr>';
1.160.6.16  raeburn  2834:     $$rowtotal += $rows;
1.125     raeburn  2835:     return $datatable;
                   2836: }
                   2837: 
1.23      raeburn  2838: sub print_directorysrch {
1.160.6.72  raeburn  2839:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2840:     my $datatable;
                   2841:     if ($position eq 'top') {
                   2842:         my $instsrchon = ' ';
                   2843:         my $instsrchoff = ' checked="checked" ';
                   2844:         my ($exacton,$containson,$beginson);
                   2845:         my $instlocalon = ' ';
                   2846:         my $instlocaloff = ' checked="checked" ';
                   2847:         if (ref($settings) eq 'HASH') {
                   2848:             if ($settings->{'available'} eq '1') {
                   2849:                 $instsrchon = $instsrchoff;
                   2850:                 $instsrchoff = ' ';
                   2851:             }
                   2852:             if ($settings->{'localonly'} eq '1') {
                   2853:                 $instlocalon = $instlocaloff;
                   2854:                 $instlocaloff = ' ';
                   2855:             }
                   2856:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2857:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2858:                     if ($type eq 'exact') {
                   2859:                         $exacton = ' checked="checked" ';
                   2860:                     } elsif ($type eq 'contains') {
                   2861:                         $containson = ' checked="checked" ';
                   2862:                     } elsif ($type eq 'begins') {
                   2863:                         $beginson = ' checked="checked" ';
                   2864:                     }
                   2865:                 }
                   2866:             } else {
                   2867:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2868:                     $exacton = ' checked="checked" ';
                   2869:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2870:                     $containson = ' checked="checked" ';
                   2871:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2872:                     $exacton = ' checked="checked" ';
                   2873:                     $containson = ' checked="checked" ';
                   2874:                 }
                   2875:             }
1.23      raeburn  2876:         }
1.160.6.72  raeburn  2877:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2878:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2879: 
1.160.6.72  raeburn  2880:         my $numinrow = 4;
                   2881:         my $cansrchrow = 0;
                   2882:         $datatable='<tr class="LC_odd_row">'.
                   2883:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2884:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2885:                    '<input type="radio" name="dirsrch_available"'.
                   2886:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2887:                    '<label><input type="radio" name="dirsrch_available"'.
                   2888:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2889:                    '</tr><tr>'.
                   2890:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2891:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2892:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2893:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2894:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2895:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2896:                    '</tr>';
                   2897:         $$rowtotal += 2;
                   2898:         if (ref($usertypes) eq 'HASH') {
                   2899:             if (keys(%{$usertypes}) > 0) {
                   2900:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93  raeburn  2901:                                              $numinrow,$othertitle,'cansearch',
                   2902:                                              $rowtotal);
1.160.6.72  raeburn  2903:                 $cansrchrow = 1;
                   2904:             }
1.26      raeburn  2905:         }
1.160.6.72  raeburn  2906:         if ($cansrchrow) {
                   2907:             $$rowtotal ++;
                   2908:             $datatable .= '<tr>';
                   2909:         } else {
                   2910:             $datatable .= '<tr class="LC_odd_row">';
                   2911:         }
                   2912:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2913:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2914:         foreach my $title (@{$titleorder}) {
                   2915:             if (defined($searchtitles->{$title})) {
                   2916:                 my $check = ' ';
                   2917:                 if (ref($settings) eq 'HASH') {
                   2918:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2919:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2920:                             $check = ' checked="checked" ';
                   2921:                         }
1.39      raeburn  2922:                     }
1.25      raeburn  2923:                 }
1.160.6.72  raeburn  2924:                 $datatable .= '<td class="LC_left_item">'.
                   2925:                               '<span class="LC_nobreak"><label>'.
                   2926:                               '<input type="checkbox" name="searchby" '.
                   2927:                               'value="'.$title.'"'.$check.'/>'.
                   2928:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2929:             }
                   2930:         }
1.160.6.72  raeburn  2931:         $datatable .= '</tr></table></td></tr>';
                   2932:         $$rowtotal ++;
                   2933:         if ($cansrchrow) {
                   2934:             $datatable .= '<tr class="LC_odd_row">';
                   2935:         } else {
                   2936:             $datatable .= '<tr>';
                   2937:         }
                   2938:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2939:                       '<td class="LC_left_item" colspan="2">'.
                   2940:                       '<span class="LC_nobreak"><label>'.
                   2941:                       '<input type="checkbox" name="searchtypes" '.
                   2942:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2943:                       '</label>&nbsp;'.
                   2944:                       '<label><input type="checkbox" name="searchtypes" '.
                   2945:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2946:                       '</label>&nbsp;'.
                   2947:                       '<label><input type="checkbox" name="searchtypes" '.
                   2948:                       $containson.' value="contains" />'.&mt('Contains').
                   2949:                       '</label></span></td></tr>';
                   2950:         $$rowtotal ++;
1.26      raeburn  2951:     } else {
1.160.6.72  raeburn  2952:         my $domsrchon = ' checked="checked" ';
                   2953:         my $domsrchoff = ' ';
                   2954:         my $domlocalon = ' ';
                   2955:         my $domlocaloff = ' checked="checked" ';
                   2956:         if (ref($settings) eq 'HASH') {
                   2957:             if ($settings->{'lclocalonly'} eq '1') {
                   2958:                 $domlocalon = $domlocaloff;
                   2959:                 $domlocaloff = ' ';
                   2960:             }
                   2961:             if ($settings->{'lcavailable'} eq '0') {
                   2962:                 $domsrchoff = $domsrchon;
                   2963:                 $domsrchon = ' ';
                   2964:             }
                   2965:         }
                   2966:         $datatable='<tr class="LC_odd_row">'.
                   2967:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2968:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2969:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2970:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2971:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2972:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2973:                       '</tr><tr>'.
                   2974:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   2975:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2976:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   2977:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2978:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   2979:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2980:                       '</tr>';
                   2981:         $$rowtotal += 2;
1.26      raeburn  2982:     }
1.25      raeburn  2983:     return $datatable;
                   2984: }
                   2985: 
1.28      raeburn  2986: sub print_contacts {
1.160.6.78  raeburn  2987:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  2988:     my $datatable;
                   2989:     my @contacts = ('adminemail','supportemail');
1.160.6.78  raeburn  2990:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
                   2991:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
                   2992:     if ($position eq 'top') {
                   2993:         if (ref($settings) eq 'HASH') {
                   2994:             foreach my $item (@contacts) {
                   2995:                 if (exists($settings->{$item})) {
                   2996:                     $to{$item} = $settings->{$item};
                   2997:                 }
1.28      raeburn  2998:             }
                   2999:         }
1.160.6.78  raeburn  3000:     } elsif ($position eq 'middle') {
                   3001:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91  raeburn  3002:                      'updatesmail','idconflictsmail','hostipmail');
1.28      raeburn  3003:         foreach my $type (@mailings) {
1.160.6.78  raeburn  3004:             $otheremails{$type} = '';
                   3005:         }
                   3006:     } else {
                   3007:         @mailings = ('helpdeskmail','otherdomsmail');
                   3008:         foreach my $type (@mailings) {
                   3009:             $otheremails{$type} = '';
                   3010:         }
                   3011:         $bccemails{'helpdeskmail'} = '';
                   3012:         $bccemails{'otherdomsmail'} = '';
                   3013:         $includestr{'helpdeskmail'} = '';
                   3014:         $includestr{'otherdomsmail'} = '';
                   3015:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   3016:     }
                   3017:     if (ref($settings) eq 'HASH') {
                   3018:         unless ($position eq 'top') {
                   3019:             foreach my $type (@mailings) {
                   3020:                 if (exists($settings->{$type})) {
                   3021:                     if (ref($settings->{$type}) eq 'HASH') {
                   3022:                         foreach my $item (@contacts) {
                   3023:                             if ($settings->{$type}{$item}) {
                   3024:                                 $checked{$type}{$item} = ' checked="checked" ';
                   3025:                             }
1.28      raeburn  3026:                         }
1.160.6.78  raeburn  3027:                         $otheremails{$type} = $settings->{$type}{'others'};
                   3028:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3029:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   3030:                             if ($settings->{$type}{'include'} ne '') {
                   3031:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3032:                                 $includestr{$type} = &unescape($includestr{$type});
                   3033:                             }
                   3034:                         }
                   3035:                     }
                   3036:                 } elsif ($type eq 'lonstatusmail') {
                   3037:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3038:                 }
                   3039:             }
                   3040:         }
                   3041:         if ($position eq 'bottom') {
                   3042:             foreach my $type (@mailings) {
                   3043:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   3044:                 if ($settings->{$type}{'include'} ne '') {
                   3045:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3046:                     $includestr{$type} = &unescape($includestr{$type});
                   3047:                 }
                   3048:             }
                   3049:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   3050:                 if (ref($fields) eq 'ARRAY') {
                   3051:                     foreach my $field (@{$fields}) {
                   3052:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  3053:                     }
1.160.6.78  raeburn  3054:                 }
                   3055:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   3056:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   3057:                 } else {
                   3058:                     $maxsize = '1.0';
                   3059:                 }
                   3060:             } else {
                   3061:                 if (ref($fields) eq 'ARRAY') {
                   3062:                     foreach my $field (@{$fields}) {
                   3063:                         $currfield{$field} = 'yes';
1.134     raeburn  3064:                     }
1.28      raeburn  3065:                 }
1.160.6.78  raeburn  3066:                 $maxsize = '1.0';
1.28      raeburn  3067:             }
                   3068:         }
                   3069:     } else {
1.160.6.78  raeburn  3070:         if ($position eq 'top') {
                   3071:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   3072:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   3073:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   3074:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   3075:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3076:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   3077:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   3078:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91  raeburn  3079:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78  raeburn  3080:         } elsif ($position eq 'bottom') {
                   3081:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   3082:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   3083:             if (ref($fields) eq 'ARRAY') {
                   3084:                 foreach my $field (@{$fields}) {
                   3085:                     $currfield{$field} = 'yes';
                   3086:                 }
                   3087:             }
                   3088:             $maxsize = '1.0';
                   3089:         }
1.28      raeburn  3090:     }
                   3091:     my ($titles,$short_titles) = &contact_titles();
                   3092:     my $rownum = 0;
                   3093:     my $css_class;
1.160.6.78  raeburn  3094:     if ($position eq 'top') {
                   3095:         foreach my $item (@contacts) {
                   3096:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3097:             $datatable .= '<tr'.$css_class.'>'. 
                   3098:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3099:                           '</span></td><td class="LC_right_item">'.
                   3100:                           '<input type="text" name="'.$item.'" value="'.
                   3101:                           $to{$item}.'" /></td></tr>';
                   3102:             $rownum ++;
                   3103:         }
1.160.6.101  raeburn  3104:     } elsif ($position eq 'bottom') {
                   3105:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3106:         $datatable .= '<tr'.$css_class.'>'.
                   3107:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   3108:                       &mt('(e-mail, subject, and description always shown)').
                   3109:                       '</td><td class="LC_left_item">';
                   3110:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3111:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3112:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3113:             foreach my $field (@{$fields}) {
                   3114:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3115:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3116:                     $datatable .= ' '.&mt('(logged-in users)');
                   3117:                 }
                   3118:                 $datatable .='</td><td>';
                   3119:                 my $clickaction;
                   3120:                 if ($field eq 'screenshot') {
                   3121:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3122:                 }
                   3123:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3124:                     foreach my $option (@{$possoptions->{$field}}) {
                   3125:                         my $checked;
                   3126:                         if ($currfield{$field} eq $option) {
                   3127:                             $checked = ' checked="checked"';
                   3128:                         }
                   3129:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3130:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3131:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3132:                                       '</label></span>'.('&nbsp;'x2);
                   3133:                     }
                   3134:                 }
                   3135:                 if ($field eq 'screenshot') {
                   3136:                     my $display;
                   3137:                     if ($currfield{$field} eq 'no') {
                   3138:                         $display = ' style="display:none"';
                   3139:                     }
                   3140:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
                   3141:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3142:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3143:                 }
                   3144:                 $datatable .= '</td></tr>';
                   3145:             }
                   3146:             $datatable .= '</table>';
                   3147:         }
                   3148:         $datatable .= '</td></tr>'."\n";
                   3149:         $rownum ++;
                   3150:     }
                   3151:     unless ($position eq 'top') {
1.160.6.78  raeburn  3152:         foreach my $type (@mailings) {
                   3153:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3154:             $datatable .= '<tr'.$css_class.'>'.
                   3155:                           '<td><span class="LC_nobreak">'.
                   3156:                           $titles->{$type}.': </span></td>'.
                   3157:                           '<td class="LC_left_item">';
                   3158:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3159:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3160:             }
                   3161:             $datatable .= '<span class="LC_nobreak">';
                   3162:             foreach my $item (@contacts) {
                   3163:                 $datatable .= '<label>'.
                   3164:                               '<input type="checkbox" name="'.$type.'"'.
                   3165:                               $checked{$type}{$item}.
                   3166:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3167:                               '</label>&nbsp;';
                   3168:             }
                   3169:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3170:                           '<input type="text" name="'.$type.'_others" '.
                   3171:                           'value="'.$otheremails{$type}.'"  />';
                   3172:             my %locchecked;
                   3173:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3174:                 foreach my $loc ('s','b') {
                   3175:                     if ($includeloc{$type} eq $loc) {
                   3176:                         $locchecked{$loc} = ' checked="checked"';
                   3177:                         last;
                   3178:                     }
                   3179:                 }
                   3180:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3181:                               '<input type="text" name="'.$type.'_bcc" '.
                   3182:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3183:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3184:                               &mt('Text automatically added to e-mail:').' '.
1.160.6.87  raeburn  3185:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78  raeburn  3186:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3187:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3188:                               ('&nbsp;'x2).
                   3189:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3190:                               '</span></fieldset>';
                   3191:             }
                   3192:             $datatable .= '</td></tr>'."\n";
                   3193:             $rownum ++;
                   3194:         }
1.28      raeburn  3195:     }
1.160.6.78  raeburn  3196:     if ($position eq 'middle') {
                   3197:         my %choices;
                   3198:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   3199:                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3200:                                        &mt('LON-CAPA core group - MSU'),600,500));
                   3201:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   3202:                                         &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3203:                                         &mt('LON-CAPA core group - MSU'),600,500));
                   3204:         my @toggles = ('reporterrors','reportupdates');
                   3205:         my %defaultchecked = ('reporterrors'  => 'on',
                   3206:                               'reportupdates' => 'on');
                   3207:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3208:                                                    \%choices,$rownum);
                   3209:         $datatable .= $reports;
                   3210:     } elsif ($position eq 'bottom') {
1.160.6.101  raeburn  3211:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3212:         my (@posstypes,%usertypeshash);
                   3213:         if (ref($types) eq 'ARRAY') {
                   3214:             @posstypes = @{$types};
                   3215:         }
                   3216:         if (@posstypes) {
                   3217:             if (ref($usertypes) eq 'HASH') {
                   3218:                 %usertypeshash = %{$usertypes};
                   3219:             }
                   3220:             my @overridden;
                   3221:             my $numinrow = 4;
                   3222:             if (ref($settings) eq 'HASH') {
                   3223:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   3224:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   3225:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   3226:                             push(@overridden,$key);
                   3227:                             foreach my $item (@contacts) {
                   3228:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   3229:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   3230:                                 }
                   3231:                             }
                   3232:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   3233:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   3234:                             $includeloc{'override_'.$key} = '';
                   3235:                             $includestr{'override_'.$key} = '';
                   3236:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   3237:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
                   3238:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   3239:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   3240:                             }
1.160.6.78  raeburn  3241:                         }
                   3242:                     }
                   3243:                 }
1.160.6.101  raeburn  3244:             }
                   3245:             my $customclass = 'LC_helpdesk_override';
                   3246:             my $optionsprefix = 'LC_options_helpdesk_';
                   3247: 
                   3248:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   3249: 
                   3250:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   3251:                                          $numinrow,$othertitle,'overrides',
                   3252:                                          \$rownum,$onclicktypes,$customclass);
                   3253:             $rownum ++;
                   3254:             $usertypeshash{'default'} = $othertitle;
                   3255:             foreach my $status (@posstypes) {
                   3256:                 my $css_class;
                   3257:                 if ($rownum%2) {
                   3258:                     $css_class = 'LC_odd_row ';
                   3259:                 }
                   3260:                 $css_class .= $customclass;
                   3261:                 my $rowid = $optionsprefix.$status;
                   3262:                 my $hidden = 1;
                   3263:                 my $currstyle = 'display:none';
                   3264:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   3265:                     $currstyle = 'display:table-row';
                   3266:                     $hidden = 0;
                   3267:                 }
                   3268:                 my $key = 'override_'.$status;
                   3269:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   3270:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   3271:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   3272:                                                   \@contacts,$short_titles);
                   3273:                 unless ($hidden) {
                   3274:                     $rownum ++;
1.160.6.78  raeburn  3275:                 }
                   3276:             }
1.134     raeburn  3277:         }
1.28      raeburn  3278:     }
1.30      raeburn  3279:     $$rowtotal += $rownum;
1.28      raeburn  3280:     return $datatable;
                   3281: }
                   3282: 
1.160.6.101  raeburn  3283: sub overridden_helpdesk {
                   3284:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   3285:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   3286:     my $class = 'LC_left_item';
                   3287:     if ($css_class) {
                   3288:         $css_class = ' class="'.$css_class.'"';
                   3289:     }
                   3290:     if ($rowid) {
                   3291:         $rowid = ' id="'.$rowid.'"';
                   3292:     }
                   3293:     if ($rowstyle) {
                   3294:         $rowstyle = ' style="'.$rowstyle.'"';
                   3295:     }
                   3296:     my ($output,$description);
                   3297:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   3298:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   3299:               "<td>$description</td>\n".
                   3300:               '<td class="'.$class.'" colspan="2">'.
                   3301:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   3302:               '<span class="LC_nobreak">';
                   3303:     if (ref($contacts) eq 'ARRAY') {
                   3304:         foreach my $item (@{$contacts}) {
                   3305:             my $check;
                   3306:             if (ref($checked) eq 'HASH') {
                   3307:                $check = $checked->{$item};
                   3308:             }
                   3309:             my $title;
                   3310:             if (ref($short_titles) eq 'HASH') {
                   3311:                 $title = $short_titles->{$item};
                   3312:             }
                   3313:             $output .= '<label>'.
                   3314:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   3315:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   3316:         }
                   3317:     }
                   3318:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3319:                '<input type="text" name="override_'.$type.'_others" '.
                   3320:                'value="'.$otheremails.'"  />';
                   3321:     my %locchecked;
                   3322:     foreach my $loc ('s','b') {
                   3323:         if ($includeloc eq $loc) {
                   3324:             $locchecked{$loc} = ' checked="checked"';
                   3325:             last;
                   3326:         }
                   3327:     }
                   3328:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3329:                '<input type="text" name="override_'.$type.'_bcc" '.
                   3330:                'value="'.$bccemails.'"  /></fieldset>'.
                   3331:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3332:                &mt('Text automatically added to e-mail:').' '.
                   3333:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
                   3334:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3335:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3336:                ('&nbsp;'x2).
                   3337:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3338:                '</span></fieldset>'.
                   3339:                '</td></tr>'."\n";
                   3340:     return $output;
                   3341: }
                   3342: 
1.160.6.78  raeburn  3343: sub contacts_javascript {
                   3344:     return <<"ENDSCRIPT";
                   3345: 
                   3346: <script type="text/javascript">
                   3347: // <![CDATA[
                   3348: 
                   3349: function screenshotSize(field) {
                   3350:     if (document.getElementById('help_screenshotsize')) {
                   3351:         if (field.value == 'no') {
                   3352:             document.getElementById('help_screenshotsize').style.display="none";
                   3353:         } else {
                   3354:             document.getElementById('help_screenshotsize').style.display="";
                   3355:         }
                   3356:     }
                   3357:     return;
                   3358: }
                   3359: 
1.160.6.101  raeburn  3360: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   3361:     if (form.elements[checkbox].length != undefined) {
                   3362:         var count = 0;
                   3363:         if (docount) {
                   3364:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   3365:                 if (form.elements[checkbox][i].checked) {
                   3366:                     count ++;
                   3367:                 }
                   3368:             }
                   3369:         }
                   3370:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   3371:             var type = form.elements[checkbox][i].value;
                   3372:             if (document.getElementById(prefix+type)) {
                   3373:                 if (form.elements[checkbox][i].checked) {
                   3374:                     document.getElementById(prefix+type).style.display = 'table-row';
                   3375:                     if (count % 2 == 1) {
                   3376:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   3377:                     } else {
                   3378:                         document.getElementById(prefix+type).className = target;
                   3379:                     }
                   3380:                     count ++;
                   3381:                 } else {
                   3382:                     document.getElementById(prefix+type).style.display = 'none';
                   3383:                 }
                   3384:             }
                   3385:         }
                   3386:     }
                   3387:     return;
                   3388: }
                   3389: 
1.160.6.78  raeburn  3390: // ]]>
                   3391: </script>
                   3392: 
                   3393: ENDSCRIPT
                   3394: }
                   3395: 
1.118     jms      3396: sub print_helpsettings {
1.160.6.73  raeburn  3397:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3398:     my $confname = $dom.'-domainconfig';
1.160.6.77  raeburn  3399:     my $formname = 'display';
1.160.6.5  raeburn  3400:     my ($datatable,$itemcount);
1.160.6.73  raeburn  3401:     if ($position eq 'top') {
                   3402:         $itemcount = 1;
                   3403:         my (%choices,%defaultchecked,@toggles);
                   3404:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3405:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3406:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3407:         %defaultchecked = ('submitbugs' => 'on');
                   3408:         @toggles = ('submitbugs');
                   3409:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3410:                                                      \%choices,$itemcount);
                   3411:         $$rowtotal ++;
                   3412:     } else {
                   3413:         my $css_class;
                   3414:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  3415:         my (%customroles,%ordered,%current);
1.160.6.84  raeburn  3416:         if (ref($settings) eq 'HASH') {
                   3417:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3418:                 %current = %{$settings->{'adhoc'}};
                   3419:             }
1.160.6.77  raeburn  3420:         }
                   3421:         my $count = 0;
                   3422:         foreach my $key (sort(keys(%existing))) {
1.160.6.73  raeburn  3423:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3424:                 my $rolename = $1;
1.160.6.77  raeburn  3425:                 my (%privs,$order);
1.160.6.73  raeburn  3426:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3427:                 $customroles{$rolename} = \%privs;
1.160.6.77  raeburn  3428:                 if (ref($current{$rolename}) eq 'HASH') {
                   3429:                     $order = $current{$rolename}{'order'};
                   3430:                 }
                   3431:                 if ($order eq '') {
                   3432:                     $order = $count;
                   3433:                 }
                   3434:                 $ordered{$order} = $rolename;
                   3435:                 $count++;
1.160.6.73  raeburn  3436:             }
                   3437:         }
1.160.6.77  raeburn  3438:         my $maxnum = scalar(keys(%ordered));
                   3439:         my @roles_by_num = ();
                   3440:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3441:             push(@roles_by_num,$item);
                   3442:         }
                   3443:         my $context = 'domprefs';
                   3444:         my $crstype = 'Course';
                   3445:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  3446:         my @accesstypes = ('all','dh','da','none');
1.160.6.77  raeburn  3447:         my ($numstatustypes,@jsarray);
                   3448:         if (ref($types) eq 'ARRAY') {
                   3449:             if (@{$types} > 0) {
                   3450:                 $numstatustypes = scalar(@{$types});
                   3451:                 push(@accesstypes,'status');
                   3452:                 @jsarray = ('bystatus');
                   3453:             }
                   3454:         }
1.160.6.86  raeburn  3455:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  3456:         if (keys(%domhelpdesk)) {
                   3457:             push(@accesstypes,('inc','exc'));
                   3458:             push(@jsarray,('notinc','notexc'));
                   3459:         }
                   3460:         my $hiddenstr = join("','",@jsarray);
                   3461:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73  raeburn  3462:         my $context = 'domprefs';
                   3463:         my $crstype = 'Course';
1.160.6.77  raeburn  3464:         my $prefix = 'helproles_';
                   3465:         my $add_class = 'LC_hidden';
                   3466:         foreach my $num (@roles_by_num) {
                   3467:             my $role = $ordered{$num};
                   3468:             my ($desc,$access,@statuses);
                   3469:             if (ref($current{$role}) eq 'HASH') {
                   3470:                 $desc = $current{$role}{'desc'};
                   3471:                 $access = $current{$role}{'access'};
                   3472:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3473:                     @statuses = @{$current{$role}{'insttypes'}};
                   3474:                 }
                   3475:             }
                   3476:             if ($desc eq '') {
                   3477:                 $desc = $role;
                   3478:             }
                   3479:             my $identifier = 'custhelp'.$num;
1.160.6.73  raeburn  3480:             my %full=();
                   3481:             my %levels= (
                   3482:                          course => {},
                   3483:                          domain => {},
                   3484:                          system => {},
                   3485:                         );
                   3486:             my %levelscurrent=(
                   3487:                                course => {},
                   3488:                                domain => {},
                   3489:                                system => {},
                   3490:                               );
                   3491:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3492:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3493:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77  raeburn  3494:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
                   3495:             $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                   3496:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   3497:             for (my $k=0; $k<=$maxnum; $k++) {
                   3498:                 my $vpos = $k+1;
                   3499:                 my $selstr;
                   3500:                 if ($k == $num) {
                   3501:                     $selstr = ' selected="selected" ';
                   3502:                 }
                   3503:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3504:             }
                   3505:             $datatable .= '</select>'.('&nbsp;'x2).
                   3506:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   3507:                           '</td>'.
                   3508:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3509:                           &mt('Name shown to users:').
                   3510:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   3511:                           '</fieldset>'.
                   3512:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   3513:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   3514:                           '<fieldset>'.
                   3515:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73  raeburn  3516:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77  raeburn  3517:                                                                    \%levelscurrent,$identifier,
                   3518:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   3519:                           '</fieldset></td>';
1.160.6.73  raeburn  3520:             $itemcount ++;
                   3521:         }
                   3522:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3523:         my $newcust = 'custhelp'.$count;
                   3524:         my (%privs,%levelscurrent);
                   3525:         my %full=();
                   3526:         my %levels= (
                   3527:                      course => {},
                   3528:                      domain => {},
                   3529:                      system => {},
                   3530:                     );
                   3531:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3532:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77  raeburn  3533:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
                   3534:         $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                   3535:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   3536:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   3537:         for (my $k=0; $k<$maxnum+1; $k++) {
                   3538:             my $vpos = $k+1;
                   3539:             my $selstr;
                   3540:             if ($k == $maxnum) {
                   3541:                 $selstr = ' selected="selected" ';
                   3542:             }
                   3543:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3544:         }
                   3545:         $datatable .= '</select>&nbsp;'."\n".
1.160.6.73  raeburn  3546:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3547:                       '</label></span></td>'.
1.160.6.77  raeburn  3548:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3549:                       '<span class="LC_nobreak">'.
                   3550:                       &mt('Internal name:').
                   3551:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   3552:                       '</span>'.('&nbsp;'x4).
                   3553:                       '<span class="LC_nobreak">'.
                   3554:                       &mt('Name shown to users:').
                   3555:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   3556:                       '</span></fieldset>'.
                   3557:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   3558:                                              $usertypes,$types,\%domhelpdesk).
                   3559:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73  raeburn  3560:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3561:                                                                 \@templateroles,$newcust).
                   3562:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3563:                                                                \%levelscurrent,$newcust).
1.160.6.87  raeburn  3564:                       '</fieldset>'.
                   3565:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   3566:                       '</td></tr>';
1.160.6.73  raeburn  3567:         $count ++;
                   3568:         $$rowtotal += $count;
                   3569:     }
1.160.6.5  raeburn  3570:     return $datatable;
1.121     raeburn  3571: }
                   3572: 
1.160.6.77  raeburn  3573: sub adhocbutton {
                   3574:     my ($prefix,$num,$field,$visibility) = @_;
                   3575:     my %lt = &Apache::lonlocal::texthash(
                   3576:                                           show => 'Show details',
                   3577:                                           hide => 'Hide details',
                   3578:                                         );
                   3579:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   3580:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   3581:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   3582:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   3583: }
                   3584: 
                   3585: sub helpsettings_javascript {
                   3586:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   3587:     return unless(ref($roles_by_num) eq 'ARRAY');
                   3588:     my %html_js_lt = &Apache::lonlocal::texthash(
                   3589:                                           show => 'Show details',
                   3590:                                           hide => 'Hide details',
                   3591:                                         );
                   3592:     &html_escape(\%html_js_lt);
                   3593:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   3594:     return <<"ENDSCRIPT";
                   3595: <script type="text/javascript">
                   3596: // <![CDATA[
                   3597: 
                   3598: function reorderHelpRoles(form,item) {
                   3599:     var changedVal;
                   3600: $jstext
                   3601:     var newpos = 'helproles_${total}_pos';
                   3602:     var maxh = 1 + $total;
                   3603:     var current = new Array();
                   3604:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3605:     if (item == newpos) {
                   3606:         changedVal = newitemVal;
                   3607:     } else {
                   3608:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3609:         current[newitemVal] = newpos;
                   3610:     }
                   3611:     for (var i=0; i<helproles.length; i++) {
                   3612:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   3613:         if (elementName != item) {
                   3614:             if (form.elements[elementName]) {
                   3615:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3616:                 current[currVal] = elementName;
                   3617:             }
                   3618:         }
                   3619:     }
                   3620:     var oldVal;
                   3621:     for (var j=0; j<maxh; j++) {
                   3622:         if (current[j] == undefined) {
                   3623:             oldVal = j;
                   3624:         }
                   3625:     }
                   3626:     if (oldVal < changedVal) {
                   3627:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3628:            var elementName = current[k];
                   3629:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3630:         }
                   3631:     } else {
                   3632:         for (var k=changedVal; k<oldVal; k++) {
                   3633:             var elementName = current[k];
                   3634:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3635:         }
                   3636:     }
                   3637:     return;
                   3638: }
                   3639: 
                   3640: function helpdeskAccess(num) {
                   3641:     var curraccess = null;
                   3642:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   3643:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   3644:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   3645:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   3646:             }
                   3647:         }
                   3648:     }
                   3649:     var shown = Array();
                   3650:     var hidden = Array();
                   3651:     if (curraccess == 'none') {
                   3652:         hidden = Array('$hiddenstr');
                   3653:     } else {
                   3654:         if (curraccess == 'status') {
                   3655:             shown = Array('bystatus');
                   3656:             hidden = Array('notinc','notexc');
                   3657:         } else {
                   3658:             if (curraccess == 'exc') {
                   3659:                 shown = Array('notexc');
                   3660:                 hidden = Array('notinc','bystatus');
                   3661:             }
                   3662:             if (curraccess == 'inc') {
                   3663:                 shown = Array('notinc');
                   3664:                 hidden = Array('notexc','bystatus');
                   3665:             }
1.160.6.79  raeburn  3666:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77  raeburn  3667:                 hidden = Array('notinc','notexc','bystatus');
                   3668:             }
                   3669:         }
                   3670:     }
                   3671:     if (hidden.length > 0) {
                   3672:         for (var i=0; i<hidden.length; i++) {
                   3673:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   3674:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   3675:             }
                   3676:         }
                   3677:     }
                   3678:     if (shown.length > 0) {
                   3679:         for (var i=0; i<shown.length; i++) {
                   3680:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   3681:                 if (shown[i] == 'privs') {
                   3682:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   3683:                 } else {
                   3684:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   3685:                 }
                   3686:             }
                   3687:         }
                   3688:     }
                   3689:     return;
                   3690: }
                   3691: 
                   3692: function toggleHelpdeskItem(num,field) {
                   3693:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   3694:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
                   3695:             document.getElementById('helproles_'+num+'_'+field).className =
                   3696:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   3697:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3698:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   3699:             }
                   3700:         } else {
                   3701:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   3702:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3703:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   3704:             }
                   3705:         }
                   3706:     }
                   3707:     return;
                   3708: }
                   3709: 
                   3710: // ]]>
                   3711: </script>
                   3712: 
                   3713: ENDSCRIPT
                   3714: }
                   3715: 
                   3716: sub helpdeskroles_access {
                   3717:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   3718:         $usertypes,$types,$domhelpdesk) = @_;
                   3719:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   3720:     my %lt = &Apache::lonlocal::texthash(
                   3721:                     'rou'    => 'Role usage',
                   3722:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.160.6.79  raeburn  3723:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   3724:                     'dh'     => 'All with domain helpdesk role',
                   3725:                     'da'     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  3726:                     'none'   => 'None',
                   3727:                     'status' => 'Determined based on institutional status',
                   3728:                     'inc'    => 'Include all, but exclude specific personnel',
                   3729:                     'exc'    => 'Exclude all, but include specific personnel',
                   3730:                   );
                   3731:     my %usecheck = (
                   3732:                      all => ' checked="checked"',
                   3733:                    );
                   3734:     my %displaydiv = (
                   3735:                       status => 'none',
                   3736:                       inc    => 'none',
                   3737:                       exc    => 'none',
                   3738:                       priv   => 'block',
                   3739:                      );
                   3740:     my $output;
                   3741:     if (ref($current) eq 'HASH') {
                   3742:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   3743:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   3744:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   3745:                 delete($usecheck{'all'});
                   3746:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   3747:                     my $access = $1;
                   3748:                     $displaydiv{$access} = 'inline';
                   3749:                 } elsif ($current->{access} eq 'none') {
                   3750:                     $displaydiv{'priv'} = 'none';
                   3751:                 }
                   3752:             }
                   3753:         }
                   3754:     }
                   3755:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   3756:               '<p>'.$lt{'whi'}.'</p>';
                   3757:     foreach my $access (@{$accesstypes}) {
                   3758:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   3759:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   3760:                    $lt{$access}.'</label>';
                   3761:         if ($access eq 'status') {
                   3762:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   3763:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   3764:                                                                  $othertitle,$usertypes,$types).
                   3765:                        '</div>';
                   3766:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   3767:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   3768:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3769:                        '</div>';
                   3770:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   3771:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   3772:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3773:                        '</div>';
                   3774:         }
                   3775:         $output .= '</p>';
                   3776:     }
                   3777:     $output .= '</fieldset>';
                   3778:     return $output;
                   3779: }
                   3780: 
1.121     raeburn  3781: sub radiobutton_prefs {
1.160.6.16  raeburn  3782:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57  raeburn  3783:         $additional,$align) = @_;
1.121     raeburn  3784:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3785:                    (ref($choices) eq 'HASH'));
                   3786: 
                   3787:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   3788: 
                   3789:     foreach my $item (@{$toggles}) {
                   3790:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3791:             $checkedon{$item} = ' checked="checked" ';
                   3792:             $checkedoff{$item} = ' ';
1.121     raeburn  3793:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3794:             $checkedoff{$item} = ' checked="checked" ';
                   3795:             $checkedon{$item} = ' ';
                   3796:         }
                   3797:     }
                   3798:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3799:         foreach my $item (@{$toggles}) {
1.118     jms      3800:             if ($settings->{$item} eq '1') {
                   3801:                 $checkedon{$item} =  ' checked="checked" ';
                   3802:                 $checkedoff{$item} = ' ';
                   3803:             } elsif ($settings->{$item} eq '0') {
                   3804:                 $checkedoff{$item} =  ' checked="checked" ';
                   3805:                 $checkedon{$item} = ' ';
                   3806:             }
                   3807:         }
1.121     raeburn  3808:     }
1.160.6.16  raeburn  3809:     if ($onclick) {
                   3810:         $onclick = ' onclick="'.$onclick.'"';
                   3811:     }
1.121     raeburn  3812:     foreach my $item (@{$toggles}) {
1.118     jms      3813:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3814:         $datatable .=
1.160.6.16  raeburn  3815:             '<tr'.$css_class.'><td valign="top">'.
                   3816:             '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57  raeburn  3817:             '</span></td>';
                   3818:         if ($align eq 'left') {
                   3819:             $datatable .= '<td class="LC_left_item">';
                   3820:         } else {
                   3821:             $datatable .= '<td class="LC_right_item">';
                   3822:         }
                   3823:         $datatable .=
                   3824:             '<span class="LC_nobreak">'.
1.118     jms      3825:             '<label><input type="radio" name="'.
1.160.6.16  raeburn  3826:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3827:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.160.6.16  raeburn  3828:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3829:             '</span>'.$additional.
                   3830:             '</td>'.
1.118     jms      3831:             '</tr>';
                   3832:         $itemcount ++;
1.121     raeburn  3833:     }
                   3834:     return ($datatable,$itemcount);
                   3835: }
                   3836: 
1.160.6.102.2  1(raebur 3837:0): sub print_ltitools {
                   3838:0):     my ($dom,$settings,$rowtotal) = @_;
                   3839:0):     my $rownum = 0;
                   3840:0):     my $css_class;
                   3841:0):     my $itemcount = 1;
                   3842:0):     my $maxnum = 0;
                   3843:0):     my %ordered;
                   3844:0):     if (ref($settings) eq 'HASH') {
                   3845:0):         foreach my $item (keys(%{$settings})) {
                   3846:0):             if (ref($settings->{$item}) eq 'HASH') {
                   3847:0):                 my $num = $settings->{$item}{'order'};
                   3848:0):                 $ordered{$num} = $item;
                   3849:0):             }
                   3850:0):         }
                   3851:0):     }
                   3852:0):     my $confname = $dom.'-domainconfig';
                   3853:0):     my $switchserver = &check_switchserver($dom,$confname);
                   3854:0):     my $maxnum = scalar(keys(%ordered));
          5(raebur 3855:0):     my $datatable;
          1(raebur 3856:0):     my %lt = &ltitools_names();
                   3857:0):     my @courseroles = ('cc','in','ta','ep','st');
                   3858:0):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
          5(raebur 3859:0):     my @fields = ('fullname','firstname','lastname','email','roles','user');
          1(raebur 3860:0):     if (keys(%ordered)) {
                   3861:0):         my @items = sort { $a <=> $b } keys(%ordered);
                   3862:0):         for (my $i=0; $i<@items; $i++) {
                   3863:0):             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3864:0):             my $item = $ordered{$items[$i]};
          5(raebur 3865:0):             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
          1(raebur 3866:0):             if (ref($settings->{$item}) eq 'HASH') {
                   3867:0):                 $title = $settings->{$item}->{'title'};
                   3868:0):                 $url = $settings->{$item}->{'url'};
                   3869:0):                 $key = $settings->{$item}->{'key'};
                   3870:0):                 $secret = $settings->{$item}->{'secret'};
          5(raebur 3871:0):                 $lifetime = $settings->{$item}->{'lifetime'};
          1(raebur 3872:0):                 my $image = $settings->{$item}->{'image'};
                   3873:0):                 if ($image ne '') {
                   3874:0):                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   3875:0):                 }
          5(raebur 3876:0):                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   3877:0):                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   3878:0):                 } else {
                   3879:0):                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   3880:0):                 }
          1(raebur 3881:0):             }
          5(raebur 3882:0):             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
          1(raebur 3883:0):             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3884:0):                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   3885:0):             for (my $k=0; $k<=$maxnum; $k++) {
                   3886:0):                 my $vpos = $k+1;
                   3887:0):                 my $selstr;
                   3888:0):                 if ($k == $i) {
                   3889:0):                     $selstr = ' selected="selected" ';
                   3890:0):                 }
                   3891:0):                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3892:0):             }
                   3893:0):             $datatable .= '</select>'.('&nbsp;'x2).
                   3894:0):                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   3895:0):                 &mt('Delete?').'</label></span></td>'.
                   3896:0):                 '<td colspan="2">'.
                   3897:0):                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
          5(raebur 3898:0):                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
          1(raebur 3899:0):                 ('&nbsp;'x2).
                   3900:0):                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   3901:0):                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   3902:0):                 ('&nbsp;'x2).
                   3903:0):                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   3904:0):                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
          5(raebur 3905:0):                 ('&nbsp;'x2).
                   3906:0):                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   3907:0):                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   3908:0):                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
          1(raebur 3909:0):                 '<br /><br />'.
          5(raebur 3910:0):                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
          1(raebur 3911:0):                 ' value="'.$url.'" /></span>'.
                   3912:0):                 ('&nbsp;'x2).
          5(raebur 3913:0):                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
          1(raebur 3914:0):                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   3915:0):                 ('&nbsp;'x2).
          5(raebur 3916:0):                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   3917:0):                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   3918:0):                 ('&nbsp;'x2).
          1(raebur 3919:0):                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   3920:0):                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   3921:0):                 '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   3922:0):                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   3923:0):                 '</fieldset>'.
                   3924:0):                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3925:0):                 '<span class="LC_nobreak">'.&mt('Display target:');
                   3926:0):             my %currdisp;
                   3927:0):             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   3928:0):                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   3929:0):                     $currdisp{'window'} = ' checked="checked"';
                   3930:0):                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   3931:0):                     $currdisp{'tab'} = ' checked="checked"';
                   3932:0):                 } else {
                   3933:0):                     $currdisp{'iframe'} = ' checked="checked"';
                   3934:0):                 }
                   3935:0):                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   3936:0):                     $currdisp{'width'} = $1;
                   3937:0):                 }
                   3938:0):                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   3939:0):                      $currdisp{'height'} = $1;
                   3940:0):                 }
                   3941:0):                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   3942:0):                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
                   3943:0):             } else {
                   3944:0):                 $currdisp{'iframe'} = ' checked="checked"';
                   3945:0):             }
                   3946:0):             foreach my $disp ('iframe','tab','window') {
                   3947:0):                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   3948:0):                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3949:0):             }
                   3950:0):             $datatable .= ('&nbsp;'x4);
                   3951:0):             foreach my $dimen ('width','height') {
                   3952:0):                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3953:0):                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   3954:0):                               ('&nbsp;'x2);
                   3955:0):             }
          5(raebur 3956:0):             $datatable .= '</span><br />'.
          1(raebur 3957:0):                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
          5(raebur 3958:0):                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
          1(raebur 3959:0):                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   3960:0):                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
          5(raebur 3961:0):                           '</textarea></div><div style=""></div>'.
                   3962:0):                           '<div style="padding:0;clear:both;margin:0;border:0"></div>';
                   3963:0):             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
          1(raebur 3964:0):             if ($imgsrc) {
                   3965:0):                 $datatable .= $imgsrc.
                   3966:0):                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   3967:0):                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   3968:0):                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   3969:0):             } else {
                   3970:0):                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3971:0):             }
                   3972:0):             if ($switchserver) {
                   3973:0):                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3974:0):             } else {
                   3975:0):                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   3976:0):             }
                   3977:0):             $datatable .= '</span></fieldset>';
          5(raebur 3978:0):             my (%checkedfields,%rolemaps,$userincdom);
          1(raebur 3979:0):             if (ref($settings->{$item}) eq 'HASH') {
                   3980:0):                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   3981:0):                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   3982:0):                 }
          5(raebur 3983:0):                 $userincdom = $settings->{$item}->{'incdom'};
          1(raebur 3984:0):                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   3985:0):                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   3986:0):                     $checkedfields{'roles'} = 1;
                   3987:0):                 }
                   3988:0):             }
                   3989:0):             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3990:0):                           '<span class="LC_nobreak">';
          5(raebur 3991:0):             my $userfieldstyle = 'display:none;';
                   3992:0):             my $seluserdom = '';
                   3993:0):             my $unseluserdom = ' selected="selected"';
          1(raebur 3994:0):             foreach my $field (@fields) {
          5(raebur 3995:0):                 my ($checked,$onclick,$id,$spacer);
          1(raebur 3996:0):                 if ($checkedfields{$field}) {
                   3997:0):                     $checked = ' checked="checked"';
                   3998:0):                 }
          5(raebur 3999:0):                 if ($field eq 'user') {
                   4000:0):                     $id = ' id="ltitools_user_field_'.$i.'"';
                   4001:0):                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   4002:0):                     if ($checked) {
                   4003:0):                         $userfieldstyle = 'display:inline-block';
                   4004:0):                         if ($userincdom) {
                   4005:0):                             $seluserdom = $unseluserdom;
                   4006:0):                             $unseluserdom = '';
                   4007:0):                         }
                   4008:0):                     }
                   4009:0):                 } else {
                   4010:0):                     $spacer = ('&nbsp;' x2);
                   4011:0):                 }
          1(raebur 4012:0):                 $datatable .= '<label>'.
          5(raebur 4013:0):                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   4014:0):                               $lt{$field}.'</label>'.$spacer;
          1(raebur 4015:0):             }
          5(raebur 4016:0):             $datatable .= '</span>';
                   4017:0):             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   4018:0):                           '<span class="LC_nobreak"> : '.
                   4019:0):                           '<select name="ltitools_userincdom_'.$i.'">'.
                   4020:0):                           '<option value="">'.&mt('Select').'</option>'.
                   4021:0):                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   4022:0):                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   4023:0):                           '</select></span></div>';
                   4024:0):             $datatable .= '</fieldset>'.
          1(raebur 4025:0):                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   4026:0):             foreach my $role (@courseroles) {
                   4027:0):                 my ($selected,$selectnone);
                   4028:0):                 if (!$rolemaps{$role}) {
                   4029:0):                     $selectnone = ' selected="selected"';
                   4030:0):                 }
                   4031:0):                 $datatable .= '<td align="center">'.
                   4032:0):                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4033:0):                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   4034:0):                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   4035:0):                 foreach my $ltirole (@ltiroles) {
                   4036:0):                     unless ($selectnone) {
                   4037:0):                         if ($rolemaps{$role} eq $ltirole) {
                   4038:0):                             $selected = ' selected="selected"';
                   4039:0):                         } else {
                   4040:0):                             $selected = '';
                   4041:0):                         }
                   4042:0):                     }
                   4043:0):                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   4044:0):                 }
                   4045:0):                 $datatable .= '</select></td>';
                   4046:0):             }
                   4047:0):             $datatable .= '</tr></table></fieldset>';
                   4048:0):             my %courseconfig;
                   4049:0):             if (ref($settings->{$item}) eq 'HASH') {
                   4050:0):                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   4051:0):                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   4052:0):                 }
                   4053:0):             }
                   4054:0):             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
          5(raebur 4055:0):             foreach my $item ('label','title','target','linktext','explanation','append') {
          1(raebur 4056:0):                 my $checked;
                   4057:0):                 if ($courseconfig{$item}) {
                   4058:0):                     $checked = ' checked="checked"';
                   4059:0):                 }
                   4060:0):                 $datatable .= '<label>'.
                   4061:0):                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   4062:0):                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   4063:0):             }
                   4064:0):             $datatable .= '</span></fieldset>'.
                   4065:0):                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4066:0):                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   4067:0):             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   4068:0):                 my %custom = %{$settings->{$item}->{'custom'}};
                   4069:0):                 if (keys(%custom) > 0) {
                   4070:0):                     foreach my $key (sort(keys(%custom))) {
                   4071:0):                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4072:0):                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   4073:0):                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   4074:0):                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   4075:0):                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   4076:0):                     }
                   4077:0):                 }
                   4078:0):             }
                   4079:0):             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   4080:0):                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   4081:0):                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   4082:0):                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   4083:0):             $datatable .= '</table></fieldset></td></tr>'."\n";
                   4084:0):             $itemcount ++;
                   4085:0):         }
                   4086:0):     }
                   4087:0):     $css_class = $itemcount%2?' class="LC_odd_row"':'';
          5(raebur 4088:0):     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
          1(raebur 4089:0):     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   4090:0):                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   4091:0):                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   4092:0):     for (my $k=0; $k<$maxnum+1; $k++) {
                   4093:0):         my $vpos = $k+1;
                   4094:0):         my $selstr;
                   4095:0):         if ($k == $maxnum) {
                   4096:0):             $selstr = ' selected="selected" ';
                   4097:0):         }
                   4098:0):         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4099:0):     }
                   4100:0):     $datatable .= '</select>&nbsp;'."\n".
          5(raebur 4101:0):                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
          1(raebur 4102:0):                   '<td colspan="2">'.
                   4103:0):                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
          5(raebur 4104:0):                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
          1(raebur 4105:0):                   ('&nbsp;'x2).
                   4106:0):                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   4107:0):                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   4108:0):                   ('&nbsp;'x2).
                   4109:0):                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   4110:0):                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
          5(raebur 4111:0):                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   4112:0):                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   4113:0):                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
          1(raebur 4114:0):                   '<br />'.
          5(raebur 4115:0):                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
          1(raebur 4116:0):                   ('&nbsp;'x2).
                   4117:0):                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   4118:0):                   ('&nbsp;'x2).
          5(raebur 4119:0):                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   4120:0):                   ('&nbsp;'x2).
          1(raebur 4121:0):                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   4122:0):                   '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
                   4123:0):                   '</fieldset>'.
                   4124:0):                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4125:0):                   '<span class="LC_nobreak">'.&mt('Display target:');
                   4126:0):     my %defaultdisp;
                   4127:0):     $defaultdisp{'iframe'} = ' checked="checked"';
                   4128:0):     foreach my $disp ('iframe','tab','window') {
                   4129:0):         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   4130:0):                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4131:0):     }
                   4132:0):     $datatable .= ('&nbsp;'x4);
                   4133:0):     foreach my $dimen ('width','height') {
                   4134:0):         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4135:0):                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   4136:0):                       ('&nbsp;'x2);
                   4137:0):     }
          5(raebur 4138:0):     $datatable .= '</span><br />'.
          1(raebur 4139:0):                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
          5(raebur 4140:0):                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
          1(raebur 4141:0):                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
          5(raebur 4142:0):                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
                   4143:0):                   '</div><div style=""></div>'.
                   4144:0):                   '<div style="padding:0;clear:both;margin:0;border:0"></div>';
                   4145:0):     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
          1(raebur 4146:0):                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4147:0):     if ($switchserver) {
                   4148:0):         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4149:0):     } else {
                   4150:0):         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   4151:0):     }
                   4152:0):     $datatable .= '</span></fieldset>'.
                   4153:0):                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4154:0):                   '<span class="LC_nobreak">';
                   4155:0):     foreach my $field (@fields) {
          5(raebur 4156:0):         my ($id,$onclick,$spacer);
                   4157:0):         if ($field eq 'user') {
                   4158:0):             $id = ' id="ltitools_user_field_add"';
                   4159:0):             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   4160:0):         } else {
                   4161:0):             $spacer = ('&nbsp;' x2);
                   4162:0):         }
          1(raebur 4163:0):         $datatable .= '<label>'.
          5(raebur 4164:0):                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   4165:0):                       $lt{$field}.'</label>'.$spacer;
          1(raebur 4166:0):     }
          5(raebur 4167:0):     $datatable .= '</span>'.
                   4168:0):                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   4169:0):                   '<span class="LC_nobreak"> : '.
                   4170:0):                   '<select name="ltitools_userincdom_add">'.
                   4171:0):                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   4172:0):                   '<option value="0">'.&mt('username').'</option>'.
                   4173:0):                   '<option value="1">'.&mt('username:domain').'</option>'.
                   4174:0):                   '</select></span></div></fieldset>';
                   4175:0):     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
          1(raebur 4176:0):     foreach my $role (@courseroles) {
                   4177:0):         my ($checked,$checkednone);
                   4178:0):         $datatable .= '<td align="center">'.
                   4179:0):                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   4180:0):                       '<select name="ltitools_add_roles_'.$role.'">'.
                   4181:0):                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   4182:0):         foreach my $ltirole (@ltiroles) {
                   4183:0):             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   4184:0):         }
                   4185:0):         $datatable .= '</select></td>';
                   4186:0):     }
                   4187:0):     $datatable .= '</tr></table></fieldset>'.
                   4188:0):                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
          5(raebur 4189:0):     foreach my $item ('label','title','target','linktext','explanation','append') {
          1(raebur 4190:0):         $datatable .= '<label>'.
                   4191:0):                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   4192:0):                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   4193:0):     }
                   4194:0):     $datatable .= '</span></fieldset>'.
                   4195:0):                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   4196:0):                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   4197:0):                   '<tr><td><span class="LC_nobreak">'.
                   4198:0):                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   4199:0):                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   4200:0):                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
          5(raebur 4201:0):                   '</table></fieldset>'."\n".
          1(raebur 4202:0):                   '</td>'."\n".
                   4203:0):                   '</tr>'."\n";
                   4204:0):     $itemcount ++;
                   4205:0):     return $datatable;
                   4206:0): }
                   4207:0): 
                   4208:0): sub ltitools_names {
                   4209:0):     my %lt = &Apache::lonlocal::texthash(
                   4210:0):                                           'title'          => 'Title',
                   4211:0):                                           'version'        => 'Version',
                   4212:0):                                           'msgtype'        => 'Message Type',
          5(raebur 4213:0):                                           'sigmethod'      => 'Signature Method',
          1(raebur 4214:0):                                           'url'            => 'URL',
                   4215:0):                                           'key'            => 'Key',
          5(raebur 4216:0):                                           'lifetime'       => 'Nonce lifetime (s)',
          1(raebur 4217:0):                                           'secret'         => 'Secret',
                   4218:0):                                           'icon'           => 'Icon',
          5(raebur 4219:0):                                           'user'           => 'User',
          1(raebur 4220:0):                                           'fullname'       => 'Full Name',
                   4221:0):                                           'firstname'      => 'First Name',
                   4222:0):                                           'lastname'       => 'Last Name',
                   4223:0):                                           'email'          => 'E-mail',
                   4224:0):                                           'roles'          => 'Role',
                   4225:0):                                           'window'         => 'Window',
                   4226:0):                                           'tab'            => 'Tab',
                   4227:0):                                           'iframe'         => 'iFrame',
                   4228:0):                                           'height'         => 'Height',
                   4229:0):                                           'width'          => 'Width',
                   4230:0):                                           'linktext'       => 'Default Link Text',
                   4231:0):                                           'explanation'    => 'Default Explanation',
                   4232:0):                                           'crstarget'      => 'Display target',
                   4233:0):                                           'crslabel'       => 'Course label',
                   4234:0):                                           'crstitle'       => 'Course title',
                   4235:0):                                           'crslinktext'    => 'Link Text',
                   4236:0):                                           'crsexplanation' => 'Explanation',
          5(raebur 4237:0):                                           'crsappend'      => 'Provider URL',
          1(raebur 4238:0):                                         );
                   4239:0): 
                   4240:0):     return %lt;
                   4241:0): }
                   4242:0): 
1.121     raeburn  4243: sub print_coursedefaults {
1.139     raeburn  4244:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  4245:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  4246:     my $itemcount = 1;
1.160.6.16  raeburn  4247:     my %choices =  &Apache::lonlocal::texthash (
1.160.6.21  raeburn  4248:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16  raeburn  4249:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   4250:         coursecredits        => 'Credits can be specified for courses',
1.160.6.57  raeburn  4251:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   4252:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.90  raeburn  4253:         texengine            => 'Default method to display mathematics',
1.160.6.57  raeburn  4254:         postsubmit           => 'Disable submit button/keypress following student submission',
1.160.6.64  raeburn  4255:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70  raeburn  4256:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16  raeburn  4257:     );
1.160.6.21  raeburn  4258:     my %staticdefaults = (
                   4259:                            anonsurvey_threshold => 10,
                   4260:                            uploadquota          => 500,
1.160.6.57  raeburn  4261:                            postsubmit           => 60,
1.160.6.70  raeburn  4262:                            mysqltables          => 172800,
1.160.6.21  raeburn  4263:                          );
1.139     raeburn  4264:     if ($position eq 'top') {
1.160.6.57  raeburn  4265:         %defaultchecked = (
                   4266:                             'uselcmath'       => 'on',
                   4267:                             'usejsme'         => 'on',
1.160.6.64  raeburn  4268:                             'canclone'        => 'none',
1.160.6.57  raeburn  4269:                           );
                   4270:         @toggles = ('uselcmath','usejsme');
1.160.6.90  raeburn  4271:         my $deftex = $Apache::lonnet::deftex;
                   4272:         if (ref($settings) eq 'HASH') {
                   4273:             if ($settings->{'texengine'}) {
                   4274:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   4275:                     $deftex = $settings->{'texengine'};
                   4276:                 }
                   4277:             }
                   4278:         }
                   4279:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4280:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   4281:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   4282:                        '</span></td><td class="LC_right_item">'.
                   4283:                        '<select name="texengine">'."\n";
                   4284:         my %texoptions = (
                   4285:                             MathJax  => 'MathJax',
                   4286:                             mimetex  => &mt('Convert to Images'),
                   4287:                             tth      => &mt('TeX to HTML'),
                   4288:                          );
                   4289:         foreach my $renderer ('MathJax','mimetex','tth') {
                   4290:             my $selected = '';
                   4291:             if ($renderer eq $deftex) {
                   4292:                 $selected = ' selected="selected"';
                   4293:             }
                   4294:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   4295:         }
                   4296:         $mathdisp .= '</select></td></tr>'."\n";
                   4297:         $itemcount ++;
1.139     raeburn  4298:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  4299:                                                      \%choices,$itemcount);
1.160.6.90  raeburn  4300:         $datatable = $mathdisp.$datatable;
1.160.6.64  raeburn  4301:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4302:         $datatable .=
                   4303:             '<tr'.$css_class.'><td valign="top">'.
                   4304:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   4305:             '</span></td><td class="LC_left_item">';
                   4306:         my $currcanclone = 'none';
                   4307:         my $onclick;
                   4308:         my @cloneoptions = ('none','domain');
                   4309:         my %clonetitles = (
                   4310:                              none     => 'No additional course requesters',
                   4311:                              domain   => "Any course requester in course's domain",
                   4312:                              instcode => 'Course requests for official courses ...',
                   4313:                           );
                   4314:         my (%codedefaults,@code_order,@posscodes);
                   4315:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   4316:                                                     \@code_order) eq 'ok') {
                   4317:             if (@code_order > 0) {
                   4318:                 push(@cloneoptions,'instcode');
                   4319:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   4320:             }
                   4321:         }
                   4322:         if (ref($settings) eq 'HASH') {
                   4323:             if ($settings->{'canclone'}) {
                   4324:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   4325:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   4326:                         if (@code_order > 0) {
                   4327:                             $currcanclone = 'instcode';
                   4328:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   4329:                         }
                   4330:                     }
                   4331:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   4332:                     $currcanclone = $settings->{'canclone'};
                   4333:                 }
                   4334:             }
                   4335:         }
                   4336:         foreach my $option (@cloneoptions) {
                   4337:             my ($checked,$additional);
                   4338:             if ($currcanclone eq $option) {
                   4339:                 $checked = ' checked="checked"';
                   4340:             }
                   4341:             if ($option eq 'instcode') {
                   4342:                 if (@code_order) {
                   4343:                     my $show = 'none';
                   4344:                     if ($checked) {
                   4345:                         $show = 'block';
                   4346:                     }
                   4347:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   4348:                                   &mt('Institutional codes for new and cloned course have identical:').
                   4349:                                   '<br />';
                   4350:                     foreach my $item (@code_order) {
                   4351:                         my $codechk;
                   4352:                         if ($checked) {
                   4353:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   4354:                                 $codechk = ' checked="checked"';
                   4355:                             }
                   4356:                         }
                   4357:                         $additional .= '<label>'.
                   4358:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   4359:                                        $item.'</label>';
                   4360:                     }
                   4361:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   4362:                 }
                   4363:             }
                   4364:             $datatable .=
                   4365:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   4366:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   4367:                 '</label>&nbsp;'.$additional.'</span><br />';
                   4368:         }
                   4369:         $datatable .= '</td>'.
                   4370:                       '</tr>';
                   4371:         $itemcount ++;
1.139     raeburn  4372:     } else {
                   4373:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71  raeburn  4374:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16  raeburn  4375:         my $currusecredits = 0;
1.160.6.57  raeburn  4376:         my $postsubmitclient = 1;
1.160.6.30  raeburn  4377:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  4378:         if (ref($settings) eq 'HASH') {
                   4379:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21  raeburn  4380:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   4381:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   4382:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   4383:                 }
                   4384:             }
1.160.6.16  raeburn  4385:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  4386:                 foreach my $type (@types) {
                   4387:                     next if ($type eq 'community');
                   4388:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   4389:                     if ($defcredits{$type} ne '') {
                   4390:                         $currusecredits = 1;
                   4391:                     }
                   4392:                 }
                   4393:             }
                   4394:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   4395:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   4396:                     $postsubmitclient = 0;
                   4397:                     foreach my $type (@types) {
                   4398:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4399:                     }
                   4400:                 } else {
                   4401:                     foreach my $type (@types) {
                   4402:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   4403:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   4404:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
                   4405:                             } else {
                   4406:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4407:                             }
                   4408:                         } else {
                   4409:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4410:                         }
                   4411:                     }
                   4412:                 }
                   4413:             } else {
                   4414:                 foreach my $type (@types) {
                   4415:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16  raeburn  4416:                 }
                   4417:             }
1.160.6.70  raeburn  4418:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   4419:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   4420:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   4421:                 }
                   4422:             } else {
                   4423:                 foreach my $type (@types) {
                   4424:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   4425:                 }
                   4426:             }
1.160.6.58  raeburn  4427:         } else {
                   4428:             foreach my $type (@types) {
                   4429:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4430:             }
1.139     raeburn  4431:         }
                   4432:         if (!$currdefresponder) {
1.160.6.21  raeburn  4433:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  4434:         } elsif ($currdefresponder < 1) {
                   4435:             $currdefresponder = 1;
                   4436:         }
1.160.6.21  raeburn  4437:         foreach my $type (@types) {
                   4438:             if ($curruploadquota{$type} eq '') {
                   4439:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   4440:             }
                   4441:         }
1.139     raeburn  4442:         $datatable .=
1.160.6.16  raeburn  4443:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4444:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  4445:                 '</span></td>'.
                   4446:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4447:                 '<input type="text" name="anonsurvey_threshold"'.
                   4448:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37  raeburn  4449:                 '</td></tr>'."\n";
                   4450:         $itemcount ++;
                   4451:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4452:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4453:                       $choices{'uploadquota'}.
                   4454:                       '</span></td>'.
                   4455:                       '<td align="right" class="LC_right_item">'.
                   4456:                       '<table><tr>';
1.160.6.21  raeburn  4457:         foreach my $type (@types) {
                   4458:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4459:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   4460:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   4461:         }
                   4462:         $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37  raeburn  4463:         $itemcount ++;
1.160.6.40  raeburn  4464:         my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16  raeburn  4465:         my $display = 'none';
                   4466:         if ($currusecredits) {
                   4467:             $display = 'block';
                   4468:         }
                   4469:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57  raeburn  4470:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   4471:         foreach my $type (@types) {
                   4472:             next if ($type eq 'community');
                   4473:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4474:                            '<input type="text" name="'.$type.'_credits"'.
                   4475:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
                   4476:         }
                   4477:         $additional .= '</tr></table></div>'."\n";
1.160.6.16  raeburn  4478:         %defaultchecked = ('coursecredits' => 'off');
                   4479:         @toggles = ('coursecredits');
                   4480:         my $current = {
                   4481:                         'coursecredits' => $currusecredits,
                   4482:                       };
                   4483:         (my $table,$itemcount) =
                   4484:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  4485:                                \%choices,$itemcount,$onclick,$additional,'left');
                   4486:         $datatable .= $table;
                   4487:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   4488:         my $display = 'none';
                   4489:         if ($postsubmitclient) {
                   4490:             $display = 'block';
                   4491:         }
                   4492:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59  raeburn  4493:                       &mt('Number of seconds submit is disabled').'<br />'.
                   4494:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   4495:                       '<table><tr>';
1.160.6.57  raeburn  4496:         foreach my $type (@types) {
                   4497:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4498:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   4499:                            $deftimeout{$type}.'" size="5" /></td>';
                   4500:         }
                   4501:         $additional .= '</tr></table></div>'."\n";
                   4502:         %defaultchecked = ('postsubmit' => 'on');
                   4503:         @toggles = ('postsubmit');
1.160.6.70  raeburn  4504:         $current = {
                   4505:                        'postsubmit' => $postsubmitclient,
                   4506:                    };
1.160.6.57  raeburn  4507:         ($table,$itemcount) =
                   4508:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   4509:                                \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16  raeburn  4510:         $datatable .= $table;
1.160.6.70  raeburn  4511:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4512:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4513:                       $choices{'mysqltables'}.
                   4514:                       '</span></td>'.
                   4515:                       '<td align="right" class="LC_right_item">'.
                   4516:                       '<table><tr>';
                   4517:         foreach my $type (@types) {
                   4518:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4519:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81  raeburn  4520:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70  raeburn  4521:         }
                   4522:         $datatable .= '</tr></table></td></tr>'."\n";
                   4523:         $itemcount ++;
                   4524: 
1.160.6.37  raeburn  4525:     }
                   4526:     $$rowtotal += $itemcount;
                   4527:     return $datatable;
                   4528: }
                   4529: 
                   4530: sub print_selfenrollment {
                   4531:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4532:     my ($css_class,$datatable);
                   4533:     my $itemcount = 1;
                   4534:     my @types = ('official','unofficial','community','textbook');
                   4535:     if (($position eq 'top') || ($position eq 'middle')) {
                   4536:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   4537:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   4538:         my @rows;
                   4539:         my $key;
                   4540:         if ($position eq 'top') {
                   4541:             $key = 'admin'; 
                   4542:             if (ref($rowsref) eq 'ARRAY') {
                   4543:                 @rows = @{$rowsref};
                   4544:             }
                   4545:         } elsif ($position eq 'middle') {
                   4546:             $key = 'default';
                   4547:             @rows = ('types','registered','approval','limit');
                   4548:         }
                   4549:         foreach my $row (@rows) {
                   4550:             if (defined($titlesref->{$row})) {
                   4551:                 $itemcount ++;
                   4552:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4553:                 $datatable .= '<tr'.$css_class.'>'.
                   4554:                               '<td>'.$titlesref->{$row}.'</td>'.
                   4555:                               '<td class="LC_left_item">'.
                   4556:                               '<table><tr>';
                   4557:                 my (%current,%currentcap);
                   4558:                 if (ref($settings) eq 'HASH') {
                   4559:                     if (ref($settings->{$key}) eq 'HASH') {
                   4560:                         foreach my $type (@types) {
                   4561:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4562:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   4563:                             }
                   4564:                             if (($row eq 'limit') && ($key eq 'default')) {
                   4565:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4566:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   4567:                                 }
                   4568:                             }
                   4569:                         }
                   4570:                     }
                   4571:                 }
                   4572:                 my %roles = (
                   4573:                              '0' => &Apache::lonnet::plaintext('dc'),
                   4574:                             ); 
                   4575:             
                   4576:                 foreach my $type (@types) {
                   4577:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   4578:                         $datatable .= '<th>'.&mt($type).'</th>';
                   4579:                     }
                   4580:                 }
                   4581:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   4582:                     $datatable .= '</tr><tr>';
                   4583:                 }
                   4584:                 foreach my $type (@types) {
                   4585:                     if ($type eq 'community') {
                   4586:                         $roles{'1'} = &mt('Community personnel');
                   4587:                     } else {
                   4588:                         $roles{'1'} = &mt('Course personnel');
                   4589:                     }
                   4590:                     $datatable .= '<td style="vertical-align: top">';
                   4591:                     if ($position eq 'top') {
                   4592:                         my %checked;
                   4593:                         if ($current{$type} eq '0') {
                   4594:                             $checked{'0'} = ' checked="checked"';
                   4595:                         } else {
                   4596:                             $checked{'1'} = ' checked="checked"';
                   4597:                         }
                   4598:                         foreach my $role ('1','0') {
                   4599:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   4600:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   4601:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   4602:                                           $roles{$role}.'</label></span> ';
                   4603:                         }
                   4604:                     } else {
                   4605:                         if ($row eq 'types') {
                   4606:                             my %checked;
                   4607:                             if ($current{$type} =~ /^(all|dom)$/) {
                   4608:                                 $checked{$1} = ' checked="checked"';
                   4609:                             } else {
                   4610:                                 $checked{''} = ' checked="checked"';
                   4611:                             }
                   4612:                             foreach my $val ('','dom','all') {
                   4613:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4614:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4615:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4616:                             }
                   4617:                         } elsif ($row eq 'registered') {
                   4618:                             my %checked;
                   4619:                             if ($current{$type} eq '1') {
                   4620:                                 $checked{'1'} = ' checked="checked"';
                   4621:                             } else {
                   4622:                                 $checked{'0'} = ' checked="checked"';
                   4623:                             }
                   4624:                             foreach my $val ('0','1') {
                   4625:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4626:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4627:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4628:                             }
                   4629:                         } elsif ($row eq 'approval') {
                   4630:                             my %checked;
                   4631:                             if ($current{$type} =~ /^([12])$/) {
                   4632:                                 $checked{$1} = ' checked="checked"';
                   4633:                             } else {
                   4634:                                 $checked{'0'} = ' checked="checked"';
                   4635:                             }
                   4636:                             for my $val (0..2) {
                   4637:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4638:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4639:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4640:                             }
                   4641:                         } elsif ($row eq 'limit') {
                   4642:                             my %checked;
                   4643:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   4644:                                 $checked{$1} = ' checked="checked"';
                   4645:                             } else {
                   4646:                                 $checked{'none'} = ' checked="checked"';
                   4647:                             }
                   4648:                             my $cap;
                   4649:                             if ($currentcap{$type} =~ /^\d+$/) {
                   4650:                                 $cap = $currentcap{$type};
                   4651:                             }
                   4652:                             foreach my $val ('none','allstudents','selfenrolled') {
                   4653:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4654:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4655:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4656:                             }
                   4657:                             $datatable .= '<br />'.
                   4658:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   4659:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   4660:                                           '</span>'; 
                   4661:                         }
                   4662:                     }
                   4663:                     $datatable .= '</td>';
                   4664:                 }
                   4665:                 $datatable .= '</tr>';
                   4666:             }
                   4667:             $datatable .= '</table></td></tr>';
                   4668:         }
                   4669:     } elsif ($position eq 'bottom') {
1.160.6.39  raeburn  4670:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   4671:     }
                   4672:     $$rowtotal += $itemcount;
                   4673:     return $datatable;
                   4674: }
                   4675: 
                   4676: sub print_validation_rows {
                   4677:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   4678:     my ($itemsref,$namesref,$fieldsref);
                   4679:     if ($caller eq 'selfenroll') { 
                   4680:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   4681:     } elsif ($caller eq 'requestcourses') {
                   4682:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   4683:     }
                   4684:     my %currvalidation;
                   4685:     if (ref($settings) eq 'HASH') {
                   4686:         if (ref($settings->{'validation'}) eq 'HASH') {
                   4687:             %currvalidation = %{$settings->{'validation'}};
1.160.6.37  raeburn  4688:         }
1.160.6.39  raeburn  4689:     }
                   4690:     my $datatable;
                   4691:     my $itemcount = 0;
                   4692:     foreach my $item (@{$itemsref}) {
                   4693:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4694:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4695:                       $namesref->{$item}.
                   4696:                       '</span></td>'.
                   4697:                       '<td class="LC_left_item">';
                   4698:         if (($item eq 'url') || ($item eq 'button')) {
                   4699:             $datatable .= '<span class="LC_nobreak">'.
                   4700:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   4701:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   4702:         } elsif ($item eq 'fields') {
                   4703:             my @currfields;
                   4704:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   4705:                 @currfields = @{$currvalidation{$item}};
                   4706:             }
                   4707:             foreach my $field (@{$fieldsref}) {
                   4708:                 my $check = '';
                   4709:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   4710:                     $check = ' checked="checked"';
                   4711:                 }
                   4712:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4713:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   4714:                               ' value="'.$field.'"'.$check.' />'.$field.
                   4715:                               '</label></span> ';
                   4716:             }
                   4717:         } elsif ($item eq 'markup') {
1.160.6.87  raeburn  4718:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39  raeburn  4719:                            $currvalidation{$item}.
1.160.6.37  raeburn  4720:                               '</textarea>';
1.160.6.39  raeburn  4721:         }
                   4722:         $datatable .= '</td></tr>'."\n";
                   4723:         if (ref($rowtotal)) {
1.160.6.37  raeburn  4724:             $itemcount ++;
                   4725:         }
1.139     raeburn  4726:     }
1.160.6.39  raeburn  4727:     if ($caller eq 'requestcourses') {
                   4728:         my %currhash;
1.160.6.51  raeburn  4729:         if (ref($settings) eq 'HASH') {
                   4730:             if (ref($settings->{'validation'}) eq 'HASH') {
                   4731:                 if ($settings->{'validation'}{'dc'} ne '') {
                   4732:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   4733:                 }
1.160.6.39  raeburn  4734:             }
                   4735:         }
                   4736:         my $numinrow = 2;
                   4737:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4738:                                                        'validationdc',%currhash);
1.160.6.50  raeburn  4739:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87  raeburn  4740:         $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39  raeburn  4741:         if ($numdc > 1) {
1.160.6.50  raeburn  4742:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39  raeburn  4743:         } else {
1.160.6.50  raeburn  4744:             $datatable .=  &mt('Course creation processed as: ');
1.160.6.39  raeburn  4745:         }
1.160.6.50  raeburn  4746:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39  raeburn  4747:         $itemcount ++;
                   4748:     }
                   4749:     if (ref($rowtotal)) {
                   4750:         $$rowtotal += $itemcount;
                   4751:     }
1.121     raeburn  4752:     return $datatable;
1.118     jms      4753: }
                   4754: 
1.160.6.98  raeburn  4755: sub print_passwords {
                   4756:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   4757:     my ($datatable,$css_class);
                   4758:     my $itemcount = 0;
                   4759:     my %titles = &Apache::lonlocal::texthash (
                   4760:         captcha        => '"Forgot Password" CAPTCHA validation',
                   4761:         link           => 'Reset link expiration (hours)',
                   4762:         case           => 'Case-sensitive usernames/e-mail',
                   4763:         prelink        => 'Information required (form 1)',
                   4764:         postlink       => 'Information required (form 2)',
                   4765:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   4766:         customtext     => 'Domain specific text (HTML)',
                   4767:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   4768:         intauth_check  => 'Check bcrypt cost if authenticated',
                   4769:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   4770:         permanent      => 'Permanent e-mail address',
                   4771:         critical       => 'Critical notification address',
                   4772:         notify         => 'Notification address',
                   4773:         min            => 'Minimum password length',
                   4774:         max            => 'Maximum password length',
                   4775:         chars          => 'Required characters',
                   4776:         numsaved       => 'Number of previous passwords to save and disallow reuse',
                   4777:     );
                   4778:     if ($position eq 'top') {
                   4779:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4780:         my $shownlinklife = 2;
                   4781:         my $prelink = 'both';
                   4782:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   4783:         if (ref($settings) eq 'HASH') {
                   4784:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   4785:                 $shownlinklife = $settings->{resetlink};
                   4786:             }
                   4787:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   4788:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   4789:             }
                   4790:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   4791:                 $prelink = $settings->{resetprelink};
                   4792:             }
                   4793:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   4794:                 %postlink = %{$settings->{resetpostlink}};
                   4795:             }
                   4796:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   4797:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   4798:             }
                   4799:             if ($settings->{resetremove}) {
                   4800:                 $nostdtext = 1;
                   4801:             }
                   4802:             if ($settings->{resetcustom}) {
                   4803:                 $customurl = $settings->{resetcustom};
                   4804:             }
                   4805:         } else {
                   4806:             if (ref($types) eq 'ARRAY') {
                   4807:                 foreach my $item (@{$types}) {
                   4808:                     $casesens{$item} = 1;
                   4809:                     $postlink{$item} = ['username','email'];
                   4810:                 }
                   4811:             }
                   4812:             $casesens{'default'} = 1;
                   4813:             $postlink{'default'} = ['username','email'];
                   4814:             $prelink = 'both';
                   4815:             %emailsrc = (
                   4816:                           permanent => 1,
                   4817:                           critical  => 1,
                   4818:                           notify    => 1,
                   4819:             );
                   4820:         }
                   4821:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   4822:         $itemcount ++;
                   4823:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4824:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   4825:                       '<td class="LC_left_item">'.
                   4826:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   4827:                       'name="passwords_link" size="3" /></td></tr>';
                   4828:         $itemcount ++;
                   4829:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4830:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   4831:                       '<td class="LC_left_item">';
                   4832:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   4833:             foreach my $item (@{$types}) {
                   4834:                 my $checkedcase;
                   4835:                 if ($casesens{$item}) {
                   4836:                     $checkedcase = ' checked="checked"';
                   4837:                 }
                   4838:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4839:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   4840:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.102.2  3(raebur 4841:0):                               '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  4842:             }
                   4843:         }
                   4844:         my $checkedcase;
                   4845:         if ($casesens{'default'}) {
                   4846:             $checkedcase = ' checked="checked"';
                   4847:         }
                   4848:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   4849:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   4850:                       $othertitle.'</label></span></td>';
                   4851:         $itemcount ++;
                   4852:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4853:         my %checkedpre = (
                   4854:                              both => ' checked="checked"',
                   4855:                              either => '',
                   4856:                          );
                   4857:         if ($prelink eq 'either') {
                   4858:             $checkedpre{either} = ' checked="checked"';
                   4859:             $checkedpre{both} = '';
                   4860:         }
                   4861:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   4862:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4863:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   4864:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   4865:                       '<span class="LC_nobreak"><label>'.
                   4866:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   4867:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   4868:         $itemcount ++;
                   4869:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4870:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   4871:                       '<td class="LC_left_item">';
                   4872:         my %postlinked;
                   4873:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   4874:             foreach my $item (@{$types}) {
                   4875:                 undef(%postlinked);
                   4876:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   4877:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   4878:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   4879:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   4880:                 }
                   4881:                 foreach my $field ('email','username') {
                   4882:                     my $checked;
                   4883:                     if ($postlinked{$field}) {
                   4884:                         $checked = ' checked="checked"';
                   4885:                     }
                   4886:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   4887:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   4888:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   4889:                                   '<span>&nbsp;&nbsp; ';
                   4890:                 }
                   4891:                 $datatable .= '</fieldset>';
                   4892:             }
                   4893:         }
                   4894:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   4895:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   4896:         }
                   4897:         $datatable .= '<fieldset style="display: inline-block;">'.
                   4898:                       '<legend>'.$othertitle.'</legend>';
                   4899:         foreach my $field ('email','username') {
                   4900:             my $checked;
                   4901:             if ($postlinked{$field}) {
                   4902:                 $checked = ' checked="checked"';
                   4903:             }
                   4904:             $datatable .= '<span class="LC_nobreak"><label>'.
                   4905:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   4906:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   4907:                           '<span>&nbsp;&nbsp; ';
                   4908:         }
                   4909:         $datatable .= '</fieldset></td></tr>';
                   4910:         $itemcount ++;
                   4911:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4912:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   4913:                       '<td class="LC_left_item">';
                   4914:         foreach my $type ('permanent','critical','notify') {
                   4915:             my $checkedemail;
                   4916:             if ($emailsrc{$type}) {
                   4917:                 $checkedemail = ' checked="checked"';
                   4918:             }
                   4919:             $datatable .= '<span class="LC_nobreak"><label>'.
                   4920:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   4921:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   4922:                           '<span>&nbsp;&nbsp; ';
                   4923:         }
                   4924:         $datatable .= '</td></tr>';
                   4925:         $itemcount ++;
                   4926:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4927:         my $switchserver = &check_switchserver($dom,$confname);
                   4928:         my ($showstd,$noshowstd);
                   4929:         if ($nostdtext) {
                   4930:             $noshowstd = ' checked="checked"';
                   4931:         } else {
                   4932:             $showstd = ' checked="checked"';
                   4933:         }
                   4934:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   4935:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4936:                       &mt('Retain standard text:').
                   4937:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   4938:                       &mt('Yes').'</label>'.'&nbsp;'.
                   4939:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   4940:                       &mt('No').'</label></span><br />'.
                   4941:                       '<span class="LC_fontsize_small">'.
                   4942:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   4943:                       &mt('Include custom text:');
                   4944:         if ($customurl) {
1.160.6.102.2  3(raebur 4945:0):             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98  raeburn  4946:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   4947:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   4948:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   4949:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   4950:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   4951:         }
                   4952:         if ($switchserver) {
                   4953:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   4954:         } else {
                   4955:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   4956:                          '<input type="file" name="passwords_customfile" /></span>';
                   4957:         }
                   4958:         $datatable .= '</td></tr>';
                   4959:     } elsif ($position eq 'middle') {
                   4960:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   4961:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   4962:         my %defaults;
                   4963:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   4964:             %defaults = %{$domconf{'defaults'}};
                   4965:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   4966:                 $defaults{'intauth_cost'} = 10;
                   4967:             }
                   4968:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   4969:                 $defaults{'intauth_check'} = 0;
                   4970:             }
                   4971:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   4972:                 $defaults{'intauth_switch'} = 0;
                   4973:             }
                   4974:         } else {
                   4975:             %defaults = (
                   4976:                           'intauth_cost'   => 10,
                   4977:                           'intauth_check'  => 0,
                   4978:                           'intauth_switch' => 0,
                   4979:                         );
                   4980:         }
                   4981:         foreach my $item (@items) {
                   4982:             if ($itemcount%2) {
                   4983:                 $css_class = '';
                   4984:             } else {
                   4985:                 $css_class = ' class="LC_odd_row" ';
                   4986:             }
                   4987:             $datatable .= '<tr'.$css_class.'>'.
                   4988:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   4989:                           '</span></td><td class="LC_left_item" colspan="3">';
                   4990:             if ($item eq 'intauth_switch') {
                   4991:                 my @options = (0,1,2);
                   4992:                 my %optiondesc = &Apache::lonlocal::texthash (
                   4993:                                    0 => 'No',
                   4994:                                    1 => 'Yes',
                   4995:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   4996:                                  );
                   4997:                 $datatable .= '<table width="100%">';
                   4998:                 foreach my $option (@options) {
                   4999:                     my $checked = ' ';
                   5000:                     if ($defaults{$item} eq $option) {
                   5001:                         $checked = ' checked="checked"';
                   5002:                     }
                   5003:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5004:                                   '<label><input type="radio" name="'.$item.
                   5005:                                   '" value="'.$option.'"'.$checked.' />'.
                   5006:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   5007:                 }
                   5008:                 $datatable .= '</table>';
                   5009:             } elsif ($item eq 'intauth_check') {
                   5010:                 my @options = (0,1,2);
                   5011:                 my %optiondesc = &Apache::lonlocal::texthash (
                   5012:                                    0 => 'No',
                   5013:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   5014:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   5015:                                  );
                   5016:                 $datatable .= '<table width="100%">';
                   5017:                 foreach my $option (@options) {
                   5018:                     my $checked = ' ';
                   5019:                     my $onclick;
                   5020:                     if ($defaults{$item} eq $option) {
                   5021:                         $checked = ' checked="checked"';
                   5022:                     }
                   5023:                     if ($option == 2) {
                   5024:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   5025:                     }
                   5026:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5027:                                   '<label><input type="radio" name="'.$item.
                   5028:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   5029:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   5030:                 }
                   5031:                 $datatable .= '</table>';
                   5032:             } else {
                   5033:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5034:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   5035:             }
                   5036:             $datatable .= '</td></tr>';
                   5037:             $itemcount ++;
                   5038:         }
                   5039:     } elsif ($position eq 'lower') {
                   5040:         my ($min,$max,%chars,$numsaved);
1.160.6.99  raeburn  5041:         $min = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  5042:         if (ref($settings) eq 'HASH') {
                   5043:             if ($settings->{min}) {
                   5044:                 $min = $settings->{min};
                   5045:             }
                   5046:             if ($settings->{max}) {
                   5047:                 $max = $settings->{max};
                   5048:             }
                   5049:             if (ref($settings->{chars}) eq 'ARRAY') {
                   5050:                 map { $chars{$_} = 1; } (@{$settings->{chars}});
                   5051:             }
                   5052:             if ($settings->{numsaved}) {
                   5053:                 $numsaved = $settings->{numsaved};
                   5054:             }
                   5055:         }
                   5056:         my %rulenames = &Apache::lonlocal::texthash(
                   5057:                                                      uc => 'At least one upper case letter',
                   5058:                                                      lc => 'At least one lower case letter',
                   5059:                                                      num => 'At least one number',
                   5060:                                                      spec => 'At least one non-alphanumeric',
                   5061:                                                    );
                   5062:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5063:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   5064:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99  raeburn  5065:                       '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                   5066:                       'onblur="javascript:warnIntPass(this);" />'.
                   5067:                       '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
1.160.6.98  raeburn  5068:                       '</span></td></tr>';
                   5069:         $itemcount ++;
                   5070:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5071:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   5072:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.99  raeburn  5073:                       '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                   5074:                       'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98  raeburn  5075:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   5076:                       '</span></td></tr>';
                   5077:         $itemcount ++;
                   5078:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5079:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   5080:                       '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   5081:                       '</span></td>';
                   5082:         my $numinrow = 2;
                   5083:         my @possrules = ('uc','lc','num','spec');
                   5084:         $datatable .= '<td class="LC_left_item"><table>';
                   5085:         for (my $i=0; $i<@possrules; $i++) {
                   5086:             my ($rem,$checked);
                   5087:             if ($chars{$possrules[$i]}) {
                   5088:                 $checked = ' checked="checked"';
                   5089:             }
                   5090:             $rem = $i%($numinrow);
                   5091:             if ($rem == 0) {
                   5092:                 if ($i > 0) {
                   5093:                     $datatable .= '</tr>';
                   5094:                 }
                   5095:                 $datatable .= '<tr>';
                   5096:             }
                   5097:             $datatable .= '<td><span class="LC_nobreak"><label>'.
                   5098:                           '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   5099:                           $rulenames{$possrules[$i]}.'</label></span></td>';
                   5100:         }
                   5101:         my $rem = @possrules%($numinrow);
                   5102:         my $colsleft = $numinrow - $rem;
                   5103:         if ($colsleft > 1 ) {
                   5104:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5105:                           '&nbsp;</td>';
                   5106:         } elsif ($colsleft == 1) {
                   5107:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   5108:         }
                   5109:         $datatable .='</table></td></tr>';
                   5110:         $itemcount ++;
                   5111:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5112:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   5113:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.100  raeburn  5114:                       '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
1.160.6.99  raeburn  5115:                       'onblur="javascript:warnIntPass(this);" />'.
1.160.6.98  raeburn  5116:                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   5117:                       '</span></td></tr>';
                   5118:     } else {
                   5119:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5120:         my %ownerchg = (
                   5121:                           by  => {},
                   5122:                           for => {},
                   5123:                        );
                   5124:         my %ownertitles = &Apache::lonlocal::texthash (
                   5125:                             by  => 'Course owner status(es) allowed',
                   5126:                             for => 'Student status(es) allowed',
                   5127:                           );
                   5128:         if (ref($settings) eq 'HASH') {
                   5129:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   5130:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   5131:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   5132:                 }
                   5133:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   5134:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   5135:                 }
                   5136:             }
                   5137:         }
                   5138:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5139:         $datatable .= '<tr '.$css_class.'>'.
                   5140:                       '<td>'.
                   5141:                       &mt('Requirements').'<ul>'.
                   5142:                       '<li>'.&mt("Course 'type' is not a Community").'</li>'.
                   5143:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   5144:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
                   5145:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
                   5146:                       '</ul>'.
                   5147:                       '</td>'.
                   5148:                       '<td class="LC_left_item">';
                   5149:         foreach my $item ('by','for') {
                   5150:             $datatable .= '<fieldset style="display: inline-block;">'.
                   5151:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   5152:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   5153:                 foreach my $type (@{$types}) {
                   5154:                     my $checked;
                   5155:                     if ($ownerchg{$item}{$type}) {
                   5156:                         $checked = ' checked="checked"';
                   5157:                     }
                   5158:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   5159:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   5160:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.102.2  3(raebur 5161:0):                                   '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  5162:                 }
                   5163:             }
                   5164:             my $checked;
                   5165:             if ($ownerchg{$item}{'default'}) {
                   5166:                 $checked = ' checked="checked"';
                   5167:             }
                   5168:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   5169:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   5170:                           $othertitle.'</label></span></fieldset>';
                   5171:         }
                   5172:         $datatable .= '</td></tr>';
                   5173:     }
                   5174:     return $datatable;
                   5175: }
                   5176: 
1.137     raeburn  5177: sub print_usersessions {
                   5178:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5179:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  5180:     my (%by_ip,%by_location,@intdoms);
                   5181:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  5182: 
                   5183:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  5184:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  5185:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  5186:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  5187:     my $itemcount = 1;
                   5188:     if ($position eq 'top') {
1.152     raeburn  5189:         if (keys(%serverhomes) > 1) {
1.145     raeburn  5190:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.160.6.102.2  4(raebur 5191:0):             my ($curroffloadnow,$curroffloadoth);
1.160.6.61  raeburn  5192:             if (ref($settings) eq 'HASH') {
                   5193:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   5194:                     $curroffloadnow = $settings->{'offloadnow'};
                   5195:                 }
1.160.6.102.2  4(raebur 5196:0):                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   5197:0):                     $curroffloadoth = $settings->{'offloadoth'};
                   5198:0):                 }
1.160.6.61  raeburn  5199:             }
1.160.6.102.2  4(raebur 5200:0):             my $other_insts = scalar(keys(%by_location));
                   5201:0):             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   5202:0):                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  5203:         } else {
1.140     raeburn  5204:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  5205:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  5206:         }
1.137     raeburn  5207:     } else {
1.145     raeburn  5208:         if (keys(%by_location) == 0) {
                   5209:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  5210:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  5211:         } else {
                   5212:             my %lt = &usersession_titles();
                   5213:             my $numinrow = 5;
                   5214:             my $prefix;
                   5215:             my @types;
                   5216:             if ($position eq 'bottom') {
                   5217:                 $prefix = 'remote';
                   5218:                 @types = ('version','excludedomain','includedomain');
                   5219:             } else {
                   5220:                 $prefix = 'hosted';
                   5221:                 @types = ('excludedomain','includedomain');
                   5222:             }
                   5223:             my (%current,%checkedon,%checkedoff);
                   5224:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   5225:             my @locations = sort(keys(%by_location));
                   5226:             foreach my $type (@types) {
                   5227:                 $checkedon{$type} = '';
                   5228:                 $checkedoff{$type} = ' checked="checked"';
                   5229:             }
                   5230:             if (ref($settings) eq 'HASH') {
                   5231:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   5232:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   5233:                         $current{$key} = $settings->{$prefix}{$key};
                   5234:                         if ($key eq 'version') {
                   5235:                             if ($current{$key} ne '') {
                   5236:                                 $checkedon{$key} = ' checked="checked"';
                   5237:                                 $checkedoff{$key} = '';
                   5238:                             }
                   5239:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   5240:                             $checkedon{$key} = ' checked="checked"';
                   5241:                             $checkedoff{$key} = '';
                   5242:                         }
1.137     raeburn  5243:                     }
                   5244:                 }
                   5245:             }
1.145     raeburn  5246:             foreach my $type (@types) {
                   5247:                 next if ($type ne 'version' && !@locations);
                   5248:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5249:                 $datatable .= '<tr'.$css_class.'>
                   5250:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   5251:                                <span class="LC_nobreak">&nbsp;
                   5252:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   5253:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   5254:                 if ($type eq 'version') {
                   5255:                     my $selector = '<select name="'.$prefix.'_version">';
                   5256:                     foreach my $version (@lcversions) {
                   5257:                         my $selected = '';
                   5258:                         if ($current{'version'} eq $version) {
                   5259:                             $selected = ' selected="selected"';
                   5260:                         }
                   5261:                         $selector .= ' <option value="'.$version.'"'.
                   5262:                                      $selected.'>'.$version.'</option>';
                   5263:                     }
                   5264:                     $selector .= '</select> ';
                   5265:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   5266:                 } else {
                   5267:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   5268:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   5269:                                  ' />'.('&nbsp;'x2).
                   5270:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   5271:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   5272:                                  "\n".
                   5273:                                  '</div><div><table>';
                   5274:                     my $rem;
                   5275:                     for (my $i=0; $i<@locations; $i++) {
                   5276:                         my ($showloc,$value,$checkedtype);
                   5277:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   5278:                             my $ip = $by_location{$locations[$i]}->[0];
                   5279:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   5280:                                  $value = join(':',@{$by_ip{$ip}});
                   5281:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   5282:                                 if (ref($current{$type}) eq 'ARRAY') {
                   5283:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   5284:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   5285:                                             $checkedtype = ' checked="checked"';
                   5286:                                             last;
                   5287:                                         }
                   5288:                                     }
1.138     raeburn  5289:                                 }
                   5290:                             }
                   5291:                         }
1.145     raeburn  5292:                         $rem = $i%($numinrow);
                   5293:                         if ($rem == 0) {
                   5294:                             if ($i > 0) {
                   5295:                                 $datatable .= '</tr>';
                   5296:                             }
                   5297:                             $datatable .= '<tr>';
                   5298:                         }
                   5299:                         $datatable .= '<td class="LC_left_item">'.
                   5300:                                       '<span class="LC_nobreak"><label>'.
                   5301:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   5302:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   5303:                                       '</label></span></td>';
1.137     raeburn  5304:                     }
1.145     raeburn  5305:                     $rem = @locations%($numinrow);
                   5306:                     my $colsleft = $numinrow - $rem;
                   5307:                     if ($colsleft > 1 ) {
                   5308:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5309:                                       '&nbsp;</td>';
                   5310:                     } elsif ($colsleft == 1) {
                   5311:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  5312:                     }
1.145     raeburn  5313:                     $datatable .= '</tr></table>';
1.137     raeburn  5314:                 }
1.145     raeburn  5315:                 $datatable .= '</td></tr>';
                   5316:                 $itemcount ++;
1.137     raeburn  5317:             }
                   5318:         }
                   5319:     }
                   5320:     $$rowtotal += $itemcount;
                   5321:     return $datatable;
                   5322: }
                   5323: 
1.138     raeburn  5324: sub build_location_hashes {
                   5325:     my ($intdoms,$by_ip,$by_location) = @_;
                   5326:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   5327:                   (ref($by_location) eq 'HASH')); 
                   5328:     my %iphost = &Apache::lonnet::get_iphost();
                   5329:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   5330:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   5331:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   5332:         foreach my $id (@{$iphost{$primary_ip}}) {
                   5333:             my $intdom = &Apache::lonnet::internet_dom($id);
                   5334:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   5335:                 push(@{$intdoms},$intdom);
                   5336:             }
                   5337:         }
                   5338:     }
                   5339:     foreach my $ip (keys(%iphost)) {
                   5340:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   5341:             foreach my $id (@{$iphost{$ip}}) {
                   5342:                 my $location = &Apache::lonnet::internet_dom($id);
                   5343:                 if ($location) {
                   5344:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   5345:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   5346:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   5347:                             push(@{$by_ip->{$ip}},$location);
                   5348:                         }
                   5349:                     } else {
                   5350:                         $by_ip->{$ip} = [$location];
                   5351:                     }
                   5352:                 }
                   5353:             }
                   5354:         }
                   5355:     }
                   5356:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   5357:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   5358:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   5359:             my $first = $by_ip->{$ip}->[0];
                   5360:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   5361:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   5362:                     push(@{$by_location->{$first}},$ip);
                   5363:                 }
                   5364:             } else {
                   5365:                 $by_location->{$first} = [$ip];
                   5366:             }
                   5367:         }
                   5368:     }
                   5369:     return;
                   5370: }
                   5371: 
1.145     raeburn  5372: sub current_offloads_to {
                   5373:     my ($dom,$settings,$servers) = @_;
                   5374:     my (%spareid,%otherdomconfigs);
1.152     raeburn  5375:     if (ref($servers) eq 'HASH') {
1.145     raeburn  5376:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   5377:             my $gotspares;
1.152     raeburn  5378:             if (ref($settings) eq 'HASH') {
                   5379:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   5380:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   5381:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   5382:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   5383:                         $gotspares = 1;
                   5384:                     }
1.145     raeburn  5385:                 }
                   5386:             }
                   5387:             unless ($gotspares) {
                   5388:                 my $gotspares;
                   5389:                 my $serverhomeID =
                   5390:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   5391:                 my $serverhomedom =
                   5392:                     &Apache::lonnet::host_domain($serverhomeID);
                   5393:                 if ($serverhomedom ne $dom) {
                   5394:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   5395:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   5396:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   5397:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   5398:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   5399:                                 $gotspares = 1;
                   5400:                             }
                   5401:                         }
                   5402:                     } else {
                   5403:                         $otherdomconfigs{$serverhomedom} =
                   5404:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   5405:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   5406:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   5407:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   5408:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   5409:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   5410:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   5411:                                         $gotspares = 1;
                   5412:                                     }
                   5413:                                 }
                   5414:                             }
                   5415:                         }
                   5416:                     }
                   5417:                 }
                   5418:             }
                   5419:             unless ($gotspares) {
                   5420:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   5421:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   5422:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   5423:                } else {
                   5424:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   5425:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   5426:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   5427:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   5428:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   5429:                     } else {
1.150     raeburn  5430:                         my %what = (
                   5431:                              spareid => 1,
                   5432:                         );
                   5433:                         my ($result,$returnhash) = 
                   5434:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   5435:                         if ($result eq 'ok') { 
                   5436:                             if (ref($returnhash) eq 'HASH') {
                   5437:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   5438:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   5439:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   5440:                                 }
                   5441:                             }
1.145     raeburn  5442:                         }
                   5443:                     }
                   5444:                 }
                   5445:             }
                   5446:         }
                   5447:     }
                   5448:     return %spareid;
                   5449: }
                   5450: 
                   5451: sub spares_row {
1.160.6.102.2  4(raebur 5452:0):     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   5453:0):         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  5454:     my $css_class;
                   5455:     my $numinrow = 4;
                   5456:     my $itemcount = 1;
                   5457:     my $datatable;
1.152     raeburn  5458:     my %typetitles = &sparestype_titles();
                   5459:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  5460:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  5461:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   5462:             my ($othercontrol,$serverdom);
                   5463:             if ($serverhome ne $server) {
                   5464:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   5465:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5466:             } else {
                   5467:                 $serverdom = &Apache::lonnet::host_domain($server);
                   5468:                 if ($serverdom ne $dom) {
                   5469:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   5470:                 }
                   5471:             }
                   5472:             next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.102.2  4(raebur 5473:0):             my ($checkednow,$checkedoth);
1.160.6.61  raeburn  5474:             if (ref($curroffloadnow) eq 'HASH') {
                   5475:                 if ($curroffloadnow->{$server}) {
                   5476:                     $checkednow = ' checked="checked"';
                   5477:                 }
                   5478:             }
1.160.6.102.2  4(raebur 5479:0):             if (ref($curroffloadoth) eq 'HASH') {
                   5480:0):                 if ($curroffloadoth->{$server}) {
                   5481:0):                     $checkedoth = ' checked="checked"';
                   5482:0):                 }
                   5483:0):             }
1.145     raeburn  5484:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5485:             $datatable .= '<tr'.$css_class.'>
                   5486:                            <td rowspan="2">
1.160.6.13  raeburn  5487:                             <span class="LC_nobreak">'.
                   5488:                           &mt('[_1] when busy, offloads to:'
1.160.6.61  raeburn  5489:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   5490:                           '<span class="LC_nobreak">'."\n".
                   5491:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.102.2  4(raebur 5492:0):                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13  raeburn  5493:                           "\n";
1.160.6.102.2  4(raebur 5494:0):             if ($other_insts) {
                   5495:0):                 $datatable .= '<br />'.
                   5496:0):                               '<span class="LC_nobreak">'."\n".
                   5497:0):                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   5498:0):                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   5499:0):                           "\n";
                   5500:0):             }
1.145     raeburn  5501:             my (%current,%canselect);
1.152     raeburn  5502:             my @choices = 
                   5503:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   5504:             foreach my $type ('primary','default') {
                   5505:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  5506:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   5507:                         my @spares = @{$spareid->{$server}{$type}};
                   5508:                         if (@spares > 0) {
1.152     raeburn  5509:                             if ($othercontrol) {
                   5510:                                 $current{$type} = join(', ',@spares);
                   5511:                             } else {
                   5512:                                 $current{$type} .= '<table>';
                   5513:                                 my $numspares = scalar(@spares);
                   5514:                                 for (my $i=0;  $i<@spares; $i++) {
                   5515:                                     my $rem = $i%($numinrow);
                   5516:                                     if ($rem == 0) {
                   5517:                                         if ($i > 0) {
                   5518:                                             $current{$type} .= '</tr>';
                   5519:                                         }
                   5520:                                         $current{$type} .= '<tr>';
1.145     raeburn  5521:                                     }
1.152     raeburn  5522:                                     $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;'.
                   5523:                                                        $spareid->{$server}{$type}[$i].
                   5524:                                                        '</label></td>'."\n";
                   5525:                                 }
                   5526:                                 my $rem = @spares%($numinrow);
                   5527:                                 my $colsleft = $numinrow - $rem;
                   5528:                                 if ($colsleft > 1 ) {
                   5529:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   5530:                                                        '" class="LC_left_item">'.
                   5531:                                                        '&nbsp;</td>';
                   5532:                                 } elsif ($colsleft == 1) {
                   5533:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  5534:                                 }
1.152     raeburn  5535:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  5536:                             }
1.145     raeburn  5537:                         }
                   5538:                     }
                   5539:                     if ($current{$type} eq '') {
                   5540:                         $current{$type} = &mt('None specified');
                   5541:                     }
1.152     raeburn  5542:                     if ($othercontrol) {
                   5543:                         if ($type eq 'primary') {
                   5544:                             $canselect{$type} = $othercontrol;
                   5545:                         }
                   5546:                     } else {
                   5547:                         $canselect{$type} = 
                   5548:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   5549:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   5550:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   5551:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   5552:                         if (@choices > 0) {
                   5553:                             foreach my $lonhost (@choices) {
                   5554:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   5555:                             }
                   5556:                         }
                   5557:                         $canselect{$type} .= '</select>'."\n";
                   5558:                     }
                   5559:                 } else {
                   5560:                     $current{$type} = &mt('Could not be determined');
                   5561:                     if ($type eq 'primary') {
                   5562:                         $canselect{$type} =  $othercontrol;
                   5563:                     }
1.145     raeburn  5564:                 }
1.152     raeburn  5565:                 if ($type eq 'default') {
                   5566:                     $datatable .= '<tr'.$css_class.'>';
                   5567:                 }
                   5568:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   5569:                               '<td>'.$current{$type}.'</td>'."\n".
                   5570:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  5571:             }
                   5572:             $itemcount ++;
                   5573:         }
                   5574:     }
                   5575:     $$rowtotal += $itemcount;
                   5576:     return $datatable;
                   5577: }
                   5578: 
1.152     raeburn  5579: sub possible_newspares {
                   5580:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   5581:     my $serverhostname = &Apache::lonnet::hostname($server);
                   5582:     my %excluded;
                   5583:     if ($serverhostname ne '') {
                   5584:         %excluded = (
                   5585:                        $serverhostname => 1,
                   5586:                     );
                   5587:     }
                   5588:     if (ref($currspares) eq 'HASH') {
                   5589:         foreach my $type (keys(%{$currspares})) {
                   5590:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   5591:                 if (@{$currspares->{$type}} > 0) {
                   5592:                     foreach my $curr (@{$currspares->{$type}}) {
                   5593:                         my $hostname = &Apache::lonnet::hostname($curr);
                   5594:                         $excluded{$hostname} = 1;
                   5595:                     }
                   5596:                 }
                   5597:             }
                   5598:         }
                   5599:     }
                   5600:     my @choices;
                   5601:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   5602:         if (keys(%{$serverhomes}) > 1) {
                   5603:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   5604:                 unless ($excluded{$name}) {
                   5605:                     if (exists($altids->{$serverhomes->{$name}})) {
                   5606:                         push(@choices,$altids->{$serverhomes->{$name}});
                   5607:                     } else {
                   5608:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  5609:                     }
                   5610:                 }
                   5611:             }
                   5612:         }
                   5613:     }
1.152     raeburn  5614:     return sort(@choices);
1.145     raeburn  5615: }
                   5616: 
1.150     raeburn  5617: sub print_loadbalancing {
                   5618:     my ($dom,$settings,$rowtotal) = @_;
                   5619:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   5620:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   5621:     my $numinrow = 1;
                   5622:     my $datatable;
                   5623:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94  raeburn  5624:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  5625:     if (ref($settings) eq 'HASH') {
                   5626:         %existing = %{$settings};
                   5627:     }
                   5628:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   5629:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  5630:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  5631:     } else {
                   5632:         return;
                   5633:     }
                   5634:     my ($othertitle,$usertypes,$types) =
                   5635:         &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26  raeburn  5636:     my $rownum = 8;
1.150     raeburn  5637:     if (ref($types) eq 'ARRAY') {
                   5638:         $rownum += scalar(@{$types});
                   5639:     }
1.160.6.7  raeburn  5640:     my @css_class = ('LC_odd_row','LC_even_row');
                   5641:     my $balnum = 0;
                   5642:     my $islast;
                   5643:     my (@toshow,$disabledtext);
                   5644:     if (keys(%currbalancer) > 0) {
                   5645:         @toshow = sort(keys(%currbalancer));
                   5646:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   5647:             push(@toshow,'');
                   5648:         }
                   5649:     } else {
                   5650:         @toshow = ('');
                   5651:         $disabledtext = &mt('No existing load balancer');
                   5652:     }
                   5653:     foreach my $lonhost (@toshow) {
                   5654:         if ($balnum == scalar(@toshow)-1) {
                   5655:             $islast = 1;
                   5656:         } else {
                   5657:             $islast = 0;
                   5658:         }
                   5659:         my $cssidx = $balnum%2;
                   5660:         my $targets_div_style = 'display: none';
                   5661:         my $disabled_div_style = 'display: block';
                   5662:         my $homedom_div_style = 'display: none';
                   5663:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   5664:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   5665:                       '<p>';
                   5666:         if ($lonhost eq '') {
                   5667:             $datatable .= '<span class="LC_nobreak">';
                   5668:             if (keys(%currbalancer) > 0) {
                   5669:                 $datatable .= &mt('Add balancer:');
                   5670:             } else {
                   5671:                 $datatable .= &mt('Enable balancer:');
                   5672:             }
                   5673:             $datatable .= '&nbsp;'.
                   5674:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   5675:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   5676:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   5677:                           '<option value="" selected="selected">'.&mt('None').
                   5678:                           '</option>'."\n";
                   5679:             foreach my $server (sort(keys(%servers))) {
                   5680:                 next if ($currbalancer{$server});
                   5681:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   5682:             }
                   5683:             $datatable .=
                   5684:                 '</select>'."\n".
                   5685:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   5686:         } else {
                   5687:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   5688:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   5689:                            &mt('Stop balancing').'</label>'.
                   5690:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   5691:             $targets_div_style = 'display: block';
                   5692:             $disabled_div_style = 'display: none';
                   5693:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   5694:                 $homedom_div_style = 'display: block';
                   5695:             }
                   5696:         }
                   5697:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   5698:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   5699:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   5700:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   5701:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   5702:         my @sparestypes = ('primary','default');
                   5703:         my %typetitles = &sparestype_titles();
1.160.6.76  raeburn  5704:         my %hostherechecked = (
                   5705:                                   no => ' checked="checked"',
                   5706:                               );
1.160.6.94  raeburn  5707:         my %balcookiechecked = (
                   5708:                                   no => ' checked="checked"',
                   5709:                                );
1.160.6.7  raeburn  5710:         foreach my $sparetype (@sparestypes) {
                   5711:             my $targettable;
                   5712:             for (my $i=0; $i<$numspares; $i++) {
                   5713:                 my $checked;
                   5714:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5715:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5716:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5717:                             $checked = ' checked="checked"';
                   5718:                         }
                   5719:                     }
                   5720:                 }
                   5721:                 my ($chkboxval,$disabled);
                   5722:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   5723:                     $chkboxval = $spares[$i];
                   5724:                 }
                   5725:                 if (exists($currbalancer{$spares[$i]})) {
                   5726:                     $disabled = ' disabled="disabled"';
                   5727:                 }
                   5728:                 $targettable .=
1.160.6.55  raeburn  5729:                     '<td><span class="LC_nobreak"><label>'.
                   5730:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7  raeburn  5731:                     $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  5732:                     '</span></label></span></td>';
1.160.6.7  raeburn  5733:                 my $rem = $i%($numinrow);
                   5734:                 if ($rem == 0) {
                   5735:                     if (($i > 0) && ($i < $numspares-1)) {
                   5736:                         $targettable .= '</tr>';
                   5737:                     }
                   5738:                     if ($i < $numspares-1) {
                   5739:                         $targettable .= '<tr>';
1.150     raeburn  5740:                     }
                   5741:                 }
                   5742:             }
1.160.6.7  raeburn  5743:             if ($targettable ne '') {
                   5744:                 my $rem = $numspares%($numinrow);
                   5745:                 my $colsleft = $numinrow - $rem;
                   5746:                 if ($colsleft > 1 ) {
                   5747:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5748:                                     '&nbsp;</td>';
                   5749:                 } elsif ($colsleft == 1) {
                   5750:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   5751:                 }
                   5752:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   5753:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   5754:             }
1.160.6.76  raeburn  5755:             $hostherechecked{$sparetype} = '';
                   5756:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   5757:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   5758:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   5759:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   5760:                         $hostherechecked{'no'} = '';
                   5761:                     }
                   5762:                 }
                   5763:             }
                   5764:         }
1.160.6.94  raeburn  5765:         if ($currcookies{$lonhost}) {
                   5766:             %balcookiechecked = (
                   5767:                                     yes => ' checked="checked"',
                   5768:                                 );
                   5769:         }
1.160.6.76  raeburn  5770:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   5771:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   5772:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   5773:         foreach my $sparetype (@sparestypes) {
                   5774:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   5775:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   5776:                           '</i></label><br />';
1.160.6.7  raeburn  5777:         }
1.160.6.94  raeburn  5778:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   5779:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   5780:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   5781:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   5782:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   5783:                       '</div></td></tr>'.
1.160.6.7  raeburn  5784:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   5785:                                            $othertitle,$usertypes,$types,\%servers,
                   5786:                                            \%currbalancer,$lonhost,
                   5787:                                            $targets_div_style,$homedom_div_style,
                   5788:                                            $css_class[$cssidx],$balnum,$islast);
                   5789:         $$rowtotal += $rownum;
                   5790:         $balnum ++;
                   5791:     }
                   5792:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   5793:     return $datatable;
                   5794: }
                   5795: 
                   5796: sub get_loadbalancers_config {
1.160.6.94  raeburn  5797:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7  raeburn  5798:     return unless ((ref($servers) eq 'HASH') &&
                   5799:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94  raeburn  5800:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   5801:                    (ref($currcookies) eq 'HASH'));
1.160.6.7  raeburn  5802:     if (keys(%{$existing}) > 0) {
                   5803:         my $oldlonhost;
                   5804:         foreach my $key (sort(keys(%{$existing}))) {
                   5805:             if ($key eq 'lonhost') {
                   5806:                 $oldlonhost = $existing->{'lonhost'};
                   5807:                 $currbalancer->{$oldlonhost} = 1;
                   5808:             } elsif ($key eq 'targets') {
                   5809:                 if ($oldlonhost) {
                   5810:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   5811:                 }
                   5812:             } elsif ($key eq 'rules') {
                   5813:                 if ($oldlonhost) {
                   5814:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   5815:                 }
                   5816:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   5817:                 $currbalancer->{$key} = 1;
                   5818:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   5819:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94  raeburn  5820:                 if ($existing->{$key}{'cookie'}) {
                   5821:                     $currcookies->{$key} = 1;
                   5822:                 }
1.150     raeburn  5823:             }
                   5824:         }
1.160.6.7  raeburn  5825:     } else {
                   5826:         my ($balancerref,$targetsref) =
                   5827:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   5828:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   5829:             foreach my $server (sort(keys(%{$balancerref}))) {
                   5830:                 $currbalancer->{$server} = 1;
                   5831:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  5832:             }
                   5833:         }
                   5834:     }
1.160.6.7  raeburn  5835:     return;
1.150     raeburn  5836: }
                   5837: 
                   5838: sub loadbalancing_rules {
                   5839:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7  raeburn  5840:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   5841:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  5842:     my $output;
1.160.6.7  raeburn  5843:     my $num = 0;
                   5844:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  5845:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   5846:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   5847:         foreach my $type (@{$alltypes}) {
1.160.6.7  raeburn  5848:             $num ++;
1.150     raeburn  5849:             my $current;
                   5850:             if (ref($currrules) eq 'HASH') {
                   5851:                 $current = $currrules->{$type};
                   5852:             }
1.160.6.55  raeburn  5853:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7  raeburn  5854:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  5855:                     $current = '';
                   5856:                 }
                   5857:             }
                   5858:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7  raeburn  5859:                                              $servers,$currbalancer,$lonhost,$dom,
                   5860:                                              $targets_div_style,$homedom_div_style,
                   5861:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  5862:         }
                   5863:     }
                   5864:     return $output;
                   5865: }
                   5866: 
                   5867: sub loadbalancing_titles {
                   5868:     my ($dom,$intdom,$usertypes,$types) = @_;
                   5869:     my %othertypes = (
                   5870:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   5871:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   5872:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   5873:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.160.6.26  raeburn  5874:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   5875:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  5876:                      );
1.160.6.26  raeburn  5877:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89  raeburn  5878:     my @available;
1.150     raeburn  5879:     if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  5880:         @available = @{$types};
1.150     raeburn  5881:     }
1.160.6.89  raeburn  5882:     unless (grep(/^default$/,@available)) {
                   5883:         push(@available,'default');
                   5884:     }
                   5885:     unshift(@alltypes,@available);
1.150     raeburn  5886:     my %titles;
                   5887:     foreach my $type (@alltypes) {
                   5888:         if ($type =~ /^_LC_/) {
                   5889:             $titles{$type} = $othertypes{$type};
                   5890:         } elsif ($type eq 'default') {
                   5891:             $titles{$type} = &mt('All users from [_1]',$dom);
                   5892:             if (ref($types) eq 'ARRAY') {
                   5893:                 if (@{$types} > 0) {
                   5894:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   5895:                 }
                   5896:             }
                   5897:         } elsif (ref($usertypes) eq 'HASH') {
                   5898:             $titles{$type} = $usertypes->{$type};
                   5899:         }
                   5900:     }
                   5901:     return (\@alltypes,\%othertypes,\%titles);
                   5902: }
                   5903: 
                   5904: sub loadbalance_rule_row {
1.160.6.7  raeburn  5905:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   5906:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26  raeburn  5907:     my @rulenames;
1.150     raeburn  5908:     my %ruletitles = &offloadtype_text();
1.160.6.26  raeburn  5909:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55  raeburn  5910:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  5911:     } else {
1.160.6.26  raeburn  5912:         @rulenames = ('default','homeserver');
                   5913:         if ($type eq '_LC_external') {
                   5914:             push(@rulenames,'externalbalancer');
                   5915:         } else {
                   5916:             push(@rulenames,'specific');
                   5917:         }
                   5918:         push(@rulenames,'none');
1.150     raeburn  5919:     }
                   5920:     my $style = $targets_div_style;
1.160.6.55  raeburn  5921:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  5922:         $style = $homedom_div_style;
                   5923:     }
1.160.6.7  raeburn  5924:     my $space;
                   5925:     if ($islast && $num == 1) {
                   5926:         $space = '<div display="inline-block">&nbsp;</div>';
                   5927:     }
                   5928:     my $output =
                   5929:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   5930:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   5931:         '<td valaign="top">'.$space.
                   5932:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  5933:     for (my $i=0; $i<@rulenames; $i++) {
                   5934:         my $rule = $rulenames[$i];
                   5935:         my ($checked,$extra);
                   5936:         if ($rulenames[$i] eq 'default') {
                   5937:             $rule = '';
                   5938:         }
                   5939:         if ($rulenames[$i] eq 'specific') {
                   5940:             if (ref($servers) eq 'HASH') {
                   5941:                 my $default;
                   5942:                 if (($current ne '') && (exists($servers->{$current}))) {
                   5943:                     $checked = ' checked="checked"';
                   5944:                 }
                   5945:                 unless ($checked) {
                   5946:                     $default = ' selected="selected"';
                   5947:                 }
1.160.6.7  raeburn  5948:                 $extra =
                   5949:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5950:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5951:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   5952:                     '<option value=""'.$default.'></option>'."\n";
                   5953:                 foreach my $server (sort(keys(%{$servers}))) {
                   5954:                     if (ref($currbalancer) eq 'HASH') {
                   5955:                         next if (exists($currbalancer->{$server}));
                   5956:                     }
1.150     raeburn  5957:                     my $selected;
1.160.6.7  raeburn  5958:                     if ($server eq $current) {
1.150     raeburn  5959:                         $selected = ' selected="selected"';
                   5960:                     }
1.160.6.7  raeburn  5961:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  5962:                 }
                   5963:                 $extra .= '</select>';
                   5964:             }
                   5965:         } elsif ($rule eq $current) {
                   5966:             $checked = ' checked="checked"';
                   5967:         }
                   5968:         $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7  raeburn  5969:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   5970:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   5971:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55  raeburn  5972:                    ')"'.$checked.' />&nbsp;';
1.160.6.56  raeburn  5973:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55  raeburn  5974:             $output .= $ruletitles{'particular'};
                   5975:         } else {
                   5976:             $output .= $ruletitles{$rulenames[$i]};
                   5977:         }
                   5978:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  5979:     }
                   5980:     $output .= '</div></td></tr>'."\n";
                   5981:     return $output;
                   5982: }
                   5983: 
                   5984: sub offloadtype_text {
                   5985:     my %ruletitles = &Apache::lonlocal::texthash (
                   5986:            'default'          => 'Offloads to default destinations',
                   5987:            'homeserver'       => "Offloads to user's home server",
                   5988:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   5989:            'specific'         => 'Offloads to specific server',
1.160.6.3  raeburn  5990:            'none'             => 'No offload',
1.160.6.26  raeburn  5991:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   5992:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.160.6.55  raeburn  5993:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  5994:     );
                   5995:     return %ruletitles;
                   5996: }
                   5997: 
                   5998: sub sparestype_titles {
                   5999:     my %typestitles = &Apache::lonlocal::texthash (
                   6000:                           'primary' => 'primary',
                   6001:                           'default' => 'default',
                   6002:                       );
                   6003:     return %typestitles;
                   6004: }
                   6005: 
1.28      raeburn  6006: sub contact_titles {
                   6007:     my %titles = &Apache::lonlocal::texthash (
1.160.6.78  raeburn  6008:                    'supportemail'    => 'Support E-mail address',
                   6009:                    'adminemail'      => 'Default Server Admin E-mail address',
                   6010:                    'errormail'       => 'Error reports to be e-mailed to',
                   6011:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.160.6.101  raeburn  6012:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   6013:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78  raeburn  6014:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   6015:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   6016:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23  raeburn  6017:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91  raeburn  6018:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.28      raeburn  6019:                  );
                   6020:     my %short_titles = &Apache::lonlocal::texthash (
                   6021:                            adminemail   => 'Admin E-mail address',
                   6022:                            supportemail => 'Support E-mail',
                   6023:                        );   
                   6024:     return (\%titles,\%short_titles);
                   6025: }
                   6026: 
1.160.6.78  raeburn  6027: sub helpform_fields {
                   6028:     my %titles =  &Apache::lonlocal::texthash (
                   6029:                        'username'   => 'Name',
                   6030:                        'user'       => 'Username/domain',
                   6031:                        'phone'      => 'Phone',
                   6032:                        'cc'         => 'Cc e-mail',
                   6033:                        'course'     => 'Course Details',
                   6034:                        'section'    => 'Sections',
                   6035:                        'screenshot' => 'File upload',
                   6036:     );
                   6037:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   6038:     my %possoptions = (
                   6039:                         username     => ['yes','no','req'],
                   6040:                         phone        => ['yes','no','req'],
                   6041:                         user         => ['yes','no'],
                   6042:                         cc           => ['yes','no'],
                   6043:                         course       => ['yes','no'],
                   6044:                         section      => ['yes','no'],
                   6045:                         screenshot   => ['yes','no'],
                   6046:                       );
                   6047:     my %fieldoptions = &Apache::lonlocal::texthash (
                   6048:                          'yes'  => 'Optional',
                   6049:                          'req'  => 'Required',
                   6050:                          'no'   => "Not shown",
                   6051:     );
                   6052:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   6053: }
                   6054: 
1.72      raeburn  6055: sub tool_titles {
                   6056:     my %titles = &Apache::lonlocal::texthash (
1.160.6.4  raeburn  6057:                      aboutme    => 'Personal web page',
1.86      raeburn  6058:                      blog       => 'Blog',
1.160.6.4  raeburn  6059:                      webdav     => 'WebDAV',
1.86      raeburn  6060:                      portfolio  => 'Portfolio',
1.88      bisitz   6061:                      official   => 'Official courses (with institutional codes)',
                   6062:                      unofficial => 'Unofficial courses',
1.98      raeburn  6063:                      community  => 'Communities',
1.160.6.30  raeburn  6064:                      textbook   => 'Textbook courses',
1.86      raeburn  6065:                  );
1.72      raeburn  6066:     return %titles;
                   6067: }
                   6068: 
1.101     raeburn  6069: sub courserequest_titles {
                   6070:     my %titles = &Apache::lonlocal::texthash (
                   6071:                                    official   => 'Official',
                   6072:                                    unofficial => 'Unofficial',
                   6073:                                    community  => 'Communities',
1.160.6.30  raeburn  6074:                                    textbook   => 'Textbook',
1.101     raeburn  6075:                                    norequest  => 'Not allowed',
1.104     raeburn  6076:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  6077:                                    validate   => 'With validation',
                   6078:                                    autolimit  => 'Numerical limit',
1.103     raeburn  6079:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  6080:                  );
                   6081:     return %titles;
                   6082: }
                   6083: 
1.160.6.5  raeburn  6084: sub authorrequest_titles {
                   6085:     my %titles = &Apache::lonlocal::texthash (
                   6086:                                    norequest  => 'Not allowed',
                   6087:                                    approval   => 'Approval by Dom. Coord.',
                   6088:                                    automatic  => 'Automatic approval',
                   6089:                  );
                   6090:     return %titles;
                   6091: }
                   6092: 
1.101     raeburn  6093: sub courserequest_conditions {
                   6094:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  6095:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17  raeburn  6096:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  6097:                  );
                   6098:     return %conditions;
                   6099: }
                   6100: 
                   6101: 
1.27      raeburn  6102: sub print_usercreation {
1.30      raeburn  6103:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  6104:     my $numinrow = 4;
1.28      raeburn  6105:     my $datatable;
                   6106:     if ($position eq 'top') {
1.30      raeburn  6107:         $$rowtotal ++;
1.34      raeburn  6108:         my $rowcount = 0;
1.32      raeburn  6109:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  6110:         if (ref($rules) eq 'HASH') {
                   6111:             if (keys(%{$rules}) > 0) {
1.32      raeburn  6112:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   6113:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  6114:                 $$rowtotal ++;
1.32      raeburn  6115:                 $rowcount ++;
                   6116:             }
                   6117:         }
                   6118:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   6119:         if (ref($idrules) eq 'HASH') {
                   6120:             if (keys(%{$idrules}) > 0) {
                   6121:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   6122:                                                 $idruleorder,$numinrow,$rowcount);
                   6123:                 $$rowtotal ++;
                   6124:                 $rowcount ++;
1.28      raeburn  6125:             }
                   6126:         }
1.39      raeburn  6127:         if ($rowcount == 0) {
                   6128:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   6129:             $$rowtotal ++;
                   6130:             $rowcount ++;
                   6131:         }
1.34      raeburn  6132:     } elsif ($position eq 'middle') {
1.160.6.34  raeburn  6133:         my @creators = ('author','course','requestcrs');
1.37      raeburn  6134:         my ($rules,$ruleorder) =
                   6135:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  6136:         my %lt = &usercreation_types();
                   6137:         my %checked;
                   6138:         if (ref($settings) eq 'HASH') {
                   6139:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   6140:                 foreach my $item (@creators) {
                   6141:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   6142:                 }
                   6143:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   6144:                 foreach my $item (@creators) {
                   6145:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   6146:                         $checked{$item} = 'none';
                   6147:                     }
                   6148:                 }
                   6149:             }
                   6150:         }
                   6151:         my $rownum = 0;
                   6152:         foreach my $item (@creators) {
                   6153:             $rownum ++;
1.160.6.34  raeburn  6154:             if ($checked{$item} eq '') {
                   6155:                 $checked{$item} = 'any';
1.34      raeburn  6156:             }
                   6157:             my $css_class;
                   6158:             if ($rownum%2) {
                   6159:                 $css_class = '';
                   6160:             } else {
                   6161:                 $css_class = ' class="LC_odd_row" ';
                   6162:             }
                   6163:             $datatable .= '<tr'.$css_class.'>'.
                   6164:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   6165:                          '</span></td><td align="right">';
1.160.6.34  raeburn  6166:             my @options = ('any');
                   6167:             if (ref($rules) eq 'HASH') {
                   6168:                 if (keys(%{$rules}) > 0) {
                   6169:                     push(@options,('official','unofficial'));
1.37      raeburn  6170:                 }
                   6171:             }
1.160.6.34  raeburn  6172:             push(@options,'none');
1.37      raeburn  6173:             foreach my $option (@options) {
1.50      raeburn  6174:                 my $type = 'radio';
1.34      raeburn  6175:                 my $check = ' ';
1.160.6.34  raeburn  6176:                 if ($checked{$item} eq $option) {
                   6177:                     $check = ' checked="checked" ';
1.34      raeburn  6178:                 } 
                   6179:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  6180:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  6181:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   6182:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   6183:             }
                   6184:             $datatable .= '</td></tr>';
                   6185:         }
1.28      raeburn  6186:     } else {
                   6187:         my @contexts = ('author','course','domain');
                   6188:         my @authtypes = ('int','krb4','krb5','loc');
                   6189:         my %checked;
                   6190:         if (ref($settings) eq 'HASH') {
                   6191:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   6192:                 foreach my $item (@contexts) {
                   6193:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   6194:                         foreach my $auth (@authtypes) {
                   6195:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   6196:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   6197:                             }
                   6198:                         }
                   6199:                     }
                   6200:                 }
1.27      raeburn  6201:             }
1.35      raeburn  6202:         } else {
                   6203:             foreach my $item (@contexts) {
1.36      raeburn  6204:                 foreach my $auth (@authtypes) {
1.35      raeburn  6205:                     $checked{$item}{$auth} = ' checked="checked" ';
                   6206:                 }
                   6207:             }
1.27      raeburn  6208:         }
1.28      raeburn  6209:         my %title = &context_names();
                   6210:         my %authname = &authtype_names();
                   6211:         my $rownum = 0;
                   6212:         my $css_class; 
                   6213:         foreach my $item (@contexts) {
                   6214:             if ($rownum%2) {
                   6215:                 $css_class = '';
                   6216:             } else {
                   6217:                 $css_class = ' class="LC_odd_row" ';
                   6218:             }
1.30      raeburn  6219:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  6220:                             '<td>'.$title{$item}.
                   6221:                             '</td><td class="LC_left_item">'.
                   6222:                             '<span class="LC_nobreak">';
                   6223:             foreach my $auth (@authtypes) {
                   6224:                 $datatable .= '<label>'. 
                   6225:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   6226:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   6227:                               $authname{$auth}.'</label>&nbsp;';
                   6228:             }
                   6229:             $datatable .= '</span></td></tr>';
                   6230:             $rownum ++;
1.27      raeburn  6231:         }
1.30      raeburn  6232:         $$rowtotal += $rownum;
1.27      raeburn  6233:     }
                   6234:     return $datatable;
                   6235: }
                   6236: 
1.160.6.34  raeburn  6237: sub print_selfcreation {
                   6238:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93  raeburn  6239:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   6240:         $emaildomain,$datatable);
1.160.6.34  raeburn  6241:     if (ref($settings) eq 'HASH') {
                   6242:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   6243:             $createsettings = $settings->{'cancreate'};
1.160.6.40  raeburn  6244:             if (ref($createsettings) eq 'HASH') {
                   6245:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   6246:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   6247:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   6248:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   6249:                         @selfcreate = ('email','login','sso');
                   6250:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   6251:                         @selfcreate = ($createsettings->{'selfcreate'});
                   6252:                     }
                   6253:                 }
                   6254:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   6255:                     $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34  raeburn  6256:                 }
1.160.6.93  raeburn  6257:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   6258:                     $emailoptions = $createsettings->{'emailoptions'};
                   6259:                 }
                   6260:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   6261:                     $emailverified = $createsettings->{'emailverified'};
                   6262:                 }
                   6263:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   6264:                     $emaildomain = $createsettings->{'emaildomain'};
                   6265:                 }
1.160.6.34  raeburn  6266:             }
                   6267:         }
                   6268:     }
                   6269:     my %radiohash;
                   6270:     my $numinrow = 4;
                   6271:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89  raeburn  6272:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34  raeburn  6273:     if ($position eq 'top') {
                   6274:         my %choices = &Apache::lonlocal::texthash (
                   6275:                                                       cancreate_login      => 'Institutional Login',
                   6276:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   6277:                                                   );
                   6278:         my @toggles = sort(keys(%choices));
                   6279:         my %defaultchecked = (
                   6280:                                'cancreate_login' => 'off',
                   6281:                                'cancreate_sso'   => 'off',
                   6282:                              );
1.160.6.35  raeburn  6283:         my ($onclick,$itemcount);
1.160.6.34  raeburn  6284:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   6285:                                                      \%choices,$itemcount,$onclick);
1.160.6.35  raeburn  6286:         $$rowtotal += $itemcount;
1.160.6.34  raeburn  6287: 
                   6288:         if (ref($usertypes) eq 'HASH') {
                   6289:             if (keys(%{$usertypes}) > 0) {
                   6290:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   6291:                                              $dom,$numinrow,$othertitle,
1.160.6.89  raeburn  6292:                                              'statustocreate',$rowtotal);
1.160.6.34  raeburn  6293:                 $$rowtotal ++;
                   6294:             }
                   6295:         }
1.160.6.44  raeburn  6296:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   6297:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6298:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   6299:         my $rem;
                   6300:         my $numperrow = 2;
                   6301:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   6302:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.45  raeburn  6303:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44  raeburn  6304:                      '<td class="LC_left_item">'."\n".
1.160.6.87  raeburn  6305:                      '<table>'."\n";
1.160.6.44  raeburn  6306:         for (my $i=0; $i<@fields; $i++) {
                   6307:             $rem = $i%($numperrow);
                   6308:             if ($rem == 0) {
                   6309:                 if ($i > 0) {
                   6310:                     $datatable .= '</tr>';
                   6311:                 }
                   6312:                 $datatable .= '<tr>';
                   6313:             }
                   6314:             my $currval;
1.160.6.51  raeburn  6315:             if (ref($createsettings) eq 'HASH') {
                   6316:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   6317:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   6318:                 }
1.160.6.44  raeburn  6319:             }
                   6320:             $datatable .= '<td class="LC_left_item">'.
                   6321:                           '<span class="LC_nobreak">'.
                   6322:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   6323:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   6324:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   6325:         }
                   6326:         my $colsleft = $numperrow - $rem;
                   6327:         if ($colsleft > 1 ) {
                   6328:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6329:                          '&nbsp;</td>';
                   6330:         } elsif ($colsleft == 1) {
                   6331:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   6332:         }
                   6333:         $datatable .= '</tr></table></td></tr>';
                   6334:         $$rowtotal ++;
1.160.6.34  raeburn  6335:     } elsif ($position eq 'middle') {
                   6336:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89  raeburn  6337:         my @posstypes;
1.160.6.34  raeburn  6338:         if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  6339:             @posstypes = @{$types};
                   6340:         }
                   6341:         unless (grep(/^default$/,@posstypes)) {
                   6342:             push(@posstypes,'default');
                   6343:         }
                   6344:         my %usertypeshash;
                   6345:         if (ref($usertypes) eq 'HASH') {
                   6346:             %usertypeshash = %{$usertypes};
                   6347:         }
                   6348:         $usertypeshash{'default'} = $othertitle;
                   6349:         foreach my $status (@posstypes) {
                   6350:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   6351:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   6352:             $$rowtotal ++;
1.160.6.34  raeburn  6353:         }
                   6354:     } else {
1.160.6.40  raeburn  6355:         my %choices = &Apache::lonlocal::texthash (
1.160.6.93  raeburn  6356:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40  raeburn  6357:                                                   );
                   6358:         my @toggles = sort(keys(%choices));
                   6359:         my %defaultchecked = (
                   6360:                                'cancreate_email' => 'off',
                   6361:                              );
1.160.6.93  raeburn  6362:         my $customclass = 'LC_selfcreate_email';
                   6363:         my $classprefix = 'LC_canmodify_emailusername_';
                   6364:         my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40  raeburn  6365:         my $display = 'none';
1.160.6.93  raeburn  6366:         my $rowstyle = 'display:none';
1.160.6.40  raeburn  6367:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   6368:             $display = 'block';
1.160.6.93  raeburn  6369:             $rowstyle = 'display:table-row';
1.160.6.40  raeburn  6370:         }
1.160.6.93  raeburn  6371:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   6372:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   6373:                                                      \%choices,$$rowtotal,$onclick);
                   6374:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   6375:                                          $rowstyle);
                   6376:         $$rowtotal ++;
                   6377:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   6378:                                       $rowstyle);
                   6379:         $$rowtotal ++;
                   6380:         my (@ordered,@posstypes,%usertypeshash);
1.160.6.40  raeburn  6381:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93  raeburn  6382:         my ($emailrules,$emailruleorder) =
                   6383:             &Apache::lonnet::inst_userrules($dom,'email');
                   6384:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   6385:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   6386:         if (ref($types) eq 'ARRAY') {
                   6387:             @posstypes = @{$types};
                   6388:         }
                   6389:         if (@posstypes) {
                   6390:             unless (grep(/^default$/,@posstypes)) {
                   6391:                 push(@posstypes,'default');
1.160.6.89  raeburn  6392:             }
                   6393:             if (ref($usertypes) eq 'HASH') {
                   6394:                 %usertypeshash = %{$usertypes};
                   6395:             }
1.160.6.93  raeburn  6396:             my $currassign;
                   6397:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   6398:                 $currassign = {
                   6399:                                   selfassign => $domdefaults{'inststatusguest'},
                   6400:                               };
                   6401:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   6402:             } else {
                   6403:                 $currassign = { selfassign => [] };
                   6404:             }
                   6405:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   6406:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   6407:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   6408:                                          $numinrow,$othertitle,'selfassign',
                   6409:                                          $rowtotal,$onclicktypes,$customclass,
                   6410:                                          $rowstyle);
                   6411:             $$rowtotal ++;
1.160.6.89  raeburn  6412:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  6413:             foreach my $status (@posstypes) {
                   6414:                 my $css_class;
                   6415:                 if ($$rowtotal%2) {
                   6416:                     $css_class = 'LC_odd_row ';
                   6417:                 }
                   6418:                 $css_class .= $customclass;
                   6419:                 my $rowid = $optionsprefix.$status;
                   6420:                 my $hidden = 1;
                   6421:                 my $currstyle = 'display:none';
                   6422:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   6423:                     $currstyle = $rowstyle;
                   6424:                     $hidden = 0;
                   6425:                 }
                   6426:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6427:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   6428:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   6429:                 unless ($hidden) {
                   6430:                     $$rowtotal ++;
                   6431:                 }
1.160.6.89  raeburn  6432:             }
                   6433:         } else {
1.160.6.93  raeburn  6434:             my $css_class;
                   6435:             if ($$rowtotal%2) {
                   6436:                 $css_class = 'LC_odd_row ';
                   6437:             }
                   6438:             $css_class .= $customclass;
1.160.6.89  raeburn  6439:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  6440:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   6441:                                          $emailrules,$emailruleorder,$settings,'default','',
                   6442:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   6443:             $$rowtotal ++;
1.160.6.34  raeburn  6444:         }
1.160.6.35  raeburn  6445:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   6446:         $numinrow = 1;
1.160.6.93  raeburn  6447:         if (@posstypes) {
                   6448:             foreach my $status (@posstypes) {
                   6449:                 my $rowid = $classprefix.$status;
                   6450:                 my $datarowstyle = 'display:none';
                   6451:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   6452:                     $datarowstyle = $rowstyle;
                   6453:                 }
                   6454:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   6455:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6456:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   6457:                 unless ($datarowstyle eq 'display:none') {
                   6458:                     $$rowtotal ++;
                   6459:                 }
1.160.6.34  raeburn  6460:             }
1.160.6.93  raeburn  6461:         } else {
                   6462:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   6463:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   6464:                                                    $infotitles,'',$customclass,$rowstyle);
1.160.6.34  raeburn  6465:         }
                   6466:     }
                   6467:     return $datatable;
                   6468: }
                   6469: 
1.160.6.93  raeburn  6470: sub selfcreate_javascript {
                   6471:     return <<"ENDSCRIPT";
                   6472: 
                   6473: <script type="text/javascript">
                   6474: // <![CDATA[
                   6475: 
                   6476: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   6477:     var x = document.getElementsByClassName(target);
                   6478:     var insttypes = 0;
                   6479:     var insttypeRegExp = new RegExp(prefix);
                   6480:     if ((x.length != undefined) && (x.length > 0)) {
                   6481:         if (form.elements[radio].length != undefined) {
                   6482:             for (var i=0; i<form.elements[radio].length; i++) {
                   6483:                 if (form.elements[radio][i].checked) {
                   6484:                     if (form.elements[radio][i].value == 1) {
                   6485:                         for (var j=0; j<x.length; j++) {
                   6486:                             if (x[j].id == 'undefined') {
                   6487:                                 x[j].style.display = 'table-row';
                   6488:                             } else if (insttypeRegExp.test(x[j].id)) {
                   6489:                                 insttypes ++;
                   6490:                             } else {
                   6491:                                 x[j].style.display = 'table-row';
                   6492:                             }
                   6493:                         }
                   6494:                     } else {
                   6495:                         for (var j=0; j<x.length; j++) {
                   6496:                             x[j].style.display = 'none';
                   6497:                         }
1.160.6.40  raeburn  6498:                     }
1.160.6.93  raeburn  6499:                     break;
                   6500:                 }
                   6501:             }
                   6502:             if (insttypes > 0) {
                   6503:                 toggleDataRow(form,checkbox,target,altprefix);
                   6504:                 toggleDataRow(form,checkbox,target,prefix,1);
                   6505:             }
                   6506:         }
                   6507:     }
                   6508:     return;
                   6509: }
                   6510: 
                   6511: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   6512:     if (form.elements[checkbox].length != undefined) {
                   6513:         var count = 0;
                   6514:         if (docount) {
                   6515:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   6516:                 if (form.elements[checkbox][i].checked) {
                   6517:                     count ++;
                   6518:                 }
                   6519:             }
                   6520:         }
                   6521:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   6522:             var type = form.elements[checkbox][i].value;
                   6523:             if (document.getElementById(prefix+type)) {
                   6524:                 if (form.elements[checkbox][i].checked) {
                   6525:                     document.getElementById(prefix+type).style.display = 'table-row';
                   6526:                     if (count % 2 == 1) {
                   6527:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   6528:                     } else {
                   6529:                         document.getElementById(prefix+type).className = target;
                   6530:                     }
                   6531:                     count ++;
1.160.6.40  raeburn  6532:                 } else {
1.160.6.93  raeburn  6533:                     document.getElementById(prefix+type).style.display = 'none';
                   6534:                 }
                   6535:             }
                   6536:         }
                   6537:     }
                   6538:     return;
                   6539: }
                   6540: 
                   6541: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   6542:     var caller = radio+'_'+status;
                   6543:     if (form.elements[caller].length != undefined) {
                   6544:         for (var i=0; i<form.elements[caller].length; i++) {
                   6545:             if (form.elements[caller][i].checked) {
                   6546:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   6547:                     var curr = form.elements[caller][i].value;
                   6548:                     if (prefix) {
                   6549:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   6550:                     }
                   6551:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   6552:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   6553:                     if (curr == 'custom') {
                   6554:                         if (prefix) {
                   6555:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   6556:                         }
                   6557:                     } else if (curr == 'inst') {
                   6558:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   6559:                     } else if (curr == 'noninst') {
                   6560:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40  raeburn  6561:                     }
1.160.6.93  raeburn  6562:                     break;
1.160.6.40  raeburn  6563:                 }
1.160.6.93  raeburn  6564:             }
                   6565:         }
                   6566:     }
                   6567: }
                   6568: 
                   6569: // ]]>
                   6570: </script>
                   6571: 
                   6572: ENDSCRIPT
                   6573: }
                   6574: 
                   6575: sub noninst_users {
                   6576:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   6577:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
                   6578:     my $class = 'LC_left_item';
                   6579:     if ($css_class) {
                   6580:         $css_class = ' class="'.$css_class.'"';
                   6581:     }
                   6582:     if ($rowid) {
                   6583:         $rowid = ' id="'.$rowid.'"';
                   6584:     }
                   6585:     if ($rowstyle) {
                   6586:         $rowstyle = ' style="'.$rowstyle.'"';
                   6587:     }
                   6588:     my ($output,$description);
                   6589:     if ($type eq 'default') {
                   6590:         $description = &mt('Requests for: [_1]',$typetitle);
                   6591:     } else {
                   6592:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   6593:     }
                   6594:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   6595:               "<td>$description</td>\n".
                   6596:               '<td class="'.$class.'" colspan="2">'.
                   6597:               '<table><tr>';
                   6598:     my %headers = &Apache::lonlocal::texthash(
                   6599:               approve  => 'Processing',
                   6600:               email    => 'E-mail',
                   6601:               username => 'Username',
                   6602:     );
                   6603:     foreach my $item ('approve','email','username') {
                   6604:         $output .= '<th>'.$headers{$item}.'</th>';
                   6605:     }
                   6606:     $output .= '</tr><tr>';
                   6607:     foreach my $item ('approve','email','username') {
                   6608:         $output .= '<td valign="top">';
                   6609:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   6610:         if ($item eq 'approve') {
                   6611:             %choices = &Apache::lonlocal::texthash (
                   6612:                                                      automatic => 'Automatically approved',
                   6613:                                                      approval  => 'Queued for approval',
                   6614:                                                    );
                   6615:             @options = ('automatic','approval');
                   6616:             $hashref = $processing;
                   6617:             $defoption = 'automatic';
                   6618:             $name = 'cancreate_emailprocess_'.$type;
                   6619:         } elsif ($item eq 'email') {
                   6620:             %choices = &Apache::lonlocal::texthash (
                   6621:                                                      any     => 'Any e-mail',
                   6622:                                                      inst    => 'Institutional only',
                   6623:                                                      noninst => 'Non-institutional only',
                   6624:                                                      custom  => 'Custom restrictions',
                   6625:                                                    );
                   6626:             @options = ('any','inst','noninst');
                   6627:             my $showcustom;
                   6628:             if (ref($emailrules) eq 'HASH') {
                   6629:                 if (keys(%{$emailrules}) > 0) {
                   6630:                     push(@options,'custom');
                   6631:                     $showcustom = 'cancreate_emailrule';
                   6632:                     if (ref($settings) eq 'HASH') {
                   6633:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   6634:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   6635:                                 if (exists($emailrules->{$rule})) {
                   6636:                                     $hascustom ++;
                   6637:                                 }
                   6638:                             }
                   6639:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   6640:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   6641:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   6642:                                     if (exists($emailrules->{$rule})) {
                   6643:                                         $hascustom ++;
                   6644:                                     }
                   6645:                                 }
                   6646:                             }
                   6647:                         }
                   6648:                     }
                   6649:                 }
                   6650:             }
                   6651:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   6652:                                                      "'cancreate_emaildomain','$type'".');"';
                   6653:             $hashref = $emailoptions;
                   6654:             $defoption = 'any';
                   6655:             $name = 'cancreate_emailoptions_'.$type;
                   6656:         } elsif ($item eq 'username') {
                   6657:             %choices = &Apache::lonlocal::texthash (
                   6658:                                                      all    => 'Same as e-mail',
                   6659:                                                      first  => 'Omit @domain',
                   6660:                                                      free   => 'Free to choose',
                   6661:                                                    );
                   6662:             @options = ('all','first','free');
                   6663:             $hashref = $emailverified;
                   6664:             $defoption = 'all';
                   6665:             $name = 'cancreate_usernameoptions_'.$type;
                   6666:         }
                   6667:         foreach my $option (@options) {
                   6668:             my $checked;
                   6669:             if (ref($hashref) eq 'HASH') {
                   6670:                 if ($type eq '') {
                   6671:                     if (!exists($hashref->{'default'})) {
                   6672:                         if ($option eq $defoption) {
                   6673:                             $checked = ' checked="checked"';
                   6674:                         }
                   6675:                     } else {
                   6676:                         if ($hashref->{'default'} eq $option) {
                   6677:                             $checked = ' checked="checked"';
                   6678:                         }
1.160.6.40  raeburn  6679:                     }
                   6680:                 } else {
1.160.6.93  raeburn  6681:                     if (!exists($hashref->{$type})) {
                   6682:                         if ($option eq $defoption) {
                   6683:                             $checked = ' checked="checked"';
                   6684:                         }
                   6685:                     } else {
                   6686:                         if ($hashref->{$type} eq $option) {
                   6687:                             $checked = ' checked="checked"';
                   6688:                         }
1.160.6.40  raeburn  6689:                     }
                   6690:                 }
1.160.6.93  raeburn  6691:             } elsif (($item eq 'email') && ($hascustom)) {
                   6692:                 if ($option eq 'custom') {
                   6693:                     $checked = ' checked="checked"';
                   6694:                 }
                   6695:             } elsif ($option eq $defoption) {
                   6696:                 $checked = ' checked="checked"';
                   6697:             }
                   6698:             $output .= '<span class="LC_nobreak"><label>'.
                   6699:                        '<input type="radio" name="'.$name.'"'.
                   6700:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   6701:                        $choices{$option}.'</label></span><br />';
                   6702:             if ($item eq 'email') {
                   6703:                 if ($option eq 'custom') {
                   6704:                     my $id = 'cancreate_emailrule_'.$type;
                   6705:                     my $display = 'none';
                   6706:                     if ($checked) {
                   6707:                         $display = 'inline';
                   6708:                     }
                   6709:                     my $numinrow = 2;
                   6710:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   6711:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   6712:                                &user_formats_row('email',$settings,$emailrules,
                   6713:                                                  $emailruleorder,$numinrow,'',$type);
                   6714:                               '</table></fieldset>';
                   6715:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   6716:                     my %text = &Apache::lonlocal::texthash (
                   6717:                                                              inst    => 'must end:',
                   6718:                                                              noninst => 'cannot end:',
                   6719:                                                            );
                   6720:                     my $value;
                   6721:                     if (ref($emaildomain) eq 'HASH') {
                   6722:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   6723:                             $value = $emaildomain->{$type}->{$option};
                   6724:                         }
                   6725:                     }
                   6726:                     if ($value eq '') {
                   6727:                         $value = '@'.$intdom;
                   6728:                     }
                   6729:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   6730:                     my $display = 'none';
                   6731:                     if ($checked) {
                   6732:                         $display = 'inline';
                   6733:                     }
                   6734:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   6735:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   6736:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   6737:                                '</div>';
                   6738:                 }
1.160.6.40  raeburn  6739:             }
                   6740:         }
1.160.6.93  raeburn  6741:         $output .= '</td>'."\n";
1.160.6.40  raeburn  6742:     }
1.160.6.93  raeburn  6743:     $output .= "</tr></table></td></tr>\n";
1.160.6.40  raeburn  6744:     return $output;
                   6745: }
                   6746: 
1.160.6.5  raeburn  6747: sub captcha_choice {
1.160.6.93  raeburn  6748:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69  raeburn  6749:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   6750:         $vertext,$currver); 
1.160.6.5  raeburn  6751:     my %lt = &captcha_phrases();
                   6752:     $keyentry = 'hidden';
1.160.6.98  raeburn  6753:     my $colspan=2;
1.160.6.5  raeburn  6754:     if ($context eq 'cancreate') {
1.160.6.34  raeburn  6755:         $rowname = &mt('CAPTCHA validation');
1.160.6.5  raeburn  6756:     } elsif ($context eq 'login') {
                   6757:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98  raeburn  6758:     } elsif ($context eq 'passwords') {
                   6759:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   6760:         $colspan=1;
1.160.6.5  raeburn  6761:     }
                   6762:     if (ref($settings) eq 'HASH') {
                   6763:         if ($settings->{'captcha'}) {
                   6764:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   6765:         } else {
                   6766:             $checked{'original'} = ' checked="checked"';
                   6767:         }
                   6768:         if ($settings->{'captcha'} eq 'recaptcha') {
                   6769:             $pubtext = $lt{'pub'};
                   6770:             $privtext = $lt{'priv'};
                   6771:             $keyentry = 'text';
1.160.6.69  raeburn  6772:             $vertext = $lt{'ver'};
                   6773:             $currver = $settings->{'recaptchaversion'};
                   6774:             if ($currver ne '2') {
                   6775:                 $currver = 1;
                   6776:             }
1.160.6.5  raeburn  6777:         }
                   6778:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   6779:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   6780:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   6781:         }
                   6782:     } else {
                   6783:         $checked{'original'} = ' checked="checked"';
                   6784:     }
1.160.6.93  raeburn  6785:     my $css_class;
                   6786:     if ($itemcount%2) {
                   6787:         $css_class = 'LC_odd_row';
                   6788:     }
                   6789:     if ($customcss) {
                   6790:         $css_class .= " $customcss";
                   6791:     }
                   6792:     $css_class =~ s/^\s+//;
                   6793:     if ($css_class) {
                   6794:         $css_class = ' class="'.$css_class.'"';
                   6795:     }
                   6796:     if ($rowstyle) {
                   6797:         $css_class .= ' style="'.$rowstyle.'"';
                   6798:     }
1.160.6.5  raeburn  6799:     my $output = '<tr'.$css_class.'>'.
1.160.6.98  raeburn  6800:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5  raeburn  6801:                  '<table><tr><td>'."\n";
                   6802:     foreach my $option ('original','recaptcha','notused') {
                   6803:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   6804:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   6805:                    $lt{$option}.'</label></span>';
                   6806:         unless ($option eq 'notused') {
                   6807:             $output .= ('&nbsp;'x2)."\n";
                   6808:         }
                   6809:     }
                   6810: #
                   6811: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   6812: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   6813: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
                   6814: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   6815: #
                   6816:     $output .= '</td></tr>'."\n".
1.160.6.93  raeburn  6817:                '<tr><td class="LC_zero_height">'."\n".
1.160.6.5  raeburn  6818:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   6819:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   6820:                $currpub.'" size="40" /></span><br />'."\n".
                   6821:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   6822:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69  raeburn  6823:                $currpriv.'" size="40" /></span><br />'.
                   6824:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   6825:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   6826:                $currver.'" size="3" /></span><br />'.
                   6827:                '</td></tr></table>'."\n".
1.160.6.5  raeburn  6828:                '</td></tr>';
                   6829:     return $output;
                   6830: }
                   6831: 
1.32      raeburn  6832: sub user_formats_row {
1.160.6.93  raeburn  6833:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  6834:     my $output;
                   6835:     my %text = (
                   6836:                    'username' => 'new usernames',
                   6837:                    'id'       => 'IDs',
                   6838:                );
1.160.6.93  raeburn  6839:     unless ($type eq 'email') {
                   6840:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6841:         $output = '<tr '.$css_class.'>'.
                   6842:                   '<td><span class="LC_nobreak">'.
                   6843:                   &mt("Format rules to check for $text{$type}: ").
                   6844:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  6845:     }
1.27      raeburn  6846:     my $rem;
                   6847:     if (ref($ruleorder) eq 'ARRAY') {
                   6848:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   6849:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   6850:                 my $rem = $i%($numinrow);
                   6851:                 if ($rem == 0) {
                   6852:                     if ($i > 0) {
                   6853:                         $output .= '</tr>';
                   6854:                     }
                   6855:                     $output .= '<tr>';
                   6856:                 }
                   6857:                 my $check = ' ';
1.39      raeburn  6858:                 if (ref($settings) eq 'HASH') {
                   6859:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   6860:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   6861:                             $check = ' checked="checked" ';
                   6862:                         }
1.160.6.93  raeburn  6863:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   6864:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   6865:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   6866:                                 $check = ' checked="checked" ';
                   6867:                             }
                   6868:                         }
1.27      raeburn  6869:                     }
                   6870:                 }
1.160.6.93  raeburn  6871:                 my $name = $type.'_rule';
                   6872:                 if ($type eq 'email') {
                   6873:                     $name .= '_'.$status;
                   6874:                 }
1.27      raeburn  6875:                 $output .= '<td class="LC_left_item">'.
                   6876:                            '<span class="LC_nobreak"><label>'.
1.160.6.93  raeburn  6877:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  6878:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   6879:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   6880:             }
                   6881:         }
                   6882:         $rem = @{$ruleorder}%($numinrow);
                   6883:     }
1.160.6.93  raeburn  6884:     my $colsleft;
                   6885:     if ($rem) {
                   6886:         $colsleft = $numinrow - $rem;
                   6887:     }
1.27      raeburn  6888:     if ($colsleft > 1 ) {
                   6889:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6890:                    '&nbsp;</td>';
                   6891:     } elsif ($colsleft == 1) {
                   6892:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6893:     }
1.160.6.93  raeburn  6894:     $output .= '</tr></table>';
                   6895:     unless ($type eq 'email') {
                   6896:         $output .= '</td></tr>';
                   6897:     }
1.27      raeburn  6898:     return $output;
                   6899: }
                   6900: 
1.34      raeburn  6901: sub usercreation_types {
                   6902:     my %lt = &Apache::lonlocal::texthash (
                   6903:                     author     => 'When adding a co-author',
                   6904:                     course     => 'When adding a user to a course',
1.100     raeburn  6905:                     requestcrs => 'When requesting a course',
1.34      raeburn  6906:                     any        => 'Any',
                   6907:                     official   => 'Institutional only ',
                   6908:                     unofficial => 'Non-institutional only',
                   6909:                     none       => 'None',
                   6910:     );
                   6911:     return %lt;
1.48      raeburn  6912: }
1.34      raeburn  6913: 
1.160.6.34  raeburn  6914: sub selfcreation_types {
                   6915:     my %lt = &Apache::lonlocal::texthash (
                   6916:                     selfcreate => 'User creates own account',
                   6917:                     any        => 'Any',
                   6918:                     official   => 'Institutional only ',
                   6919:                     unofficial => 'Non-institutional only',
                   6920:                     email      => 'E-mail address',
                   6921:                     login      => 'Institutional Login',
                   6922:                     sso        => 'SSO',
                   6923:              );
                   6924: }
                   6925: 
1.28      raeburn  6926: sub authtype_names {
                   6927:     my %lt = &Apache::lonlocal::texthash(
                   6928:                       int    => 'Internal',
                   6929:                       krb4   => 'Kerberos 4',
                   6930:                       krb5   => 'Kerberos 5',
                   6931:                       loc    => 'Local',
                   6932:                   );
                   6933:     return %lt;
                   6934: }
                   6935: 
                   6936: sub context_names {
                   6937:     my %context_title = &Apache::lonlocal::texthash(
                   6938:        author => 'Creating users when an Author',
                   6939:        course => 'Creating users when in a course',
                   6940:        domain => 'Creating users when a Domain Coordinator',
                   6941:     );
                   6942:     return %context_title;
                   6943: }
                   6944: 
1.33      raeburn  6945: sub print_usermodification {
                   6946:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6947:     my $numinrow = 4;
                   6948:     my ($context,$datatable,$rowcount);
                   6949:     if ($position eq 'top') {
                   6950:         $rowcount = 0;
                   6951:         $context = 'author'; 
                   6952:         foreach my $role ('ca','aa') {
                   6953:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6954:                                                    $numinrow,$rowcount);
                   6955:             $$rowtotal ++;
                   6956:             $rowcount ++;
                   6957:         }
1.160.6.37  raeburn  6958:     } elsif ($position eq 'bottom') {
1.33      raeburn  6959:         $context = 'course';
                   6960:         $rowcount = 0;
                   6961:         foreach my $role ('st','ep','ta','in','cr') {
                   6962:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   6963:                                                    $numinrow,$rowcount);
                   6964:             $$rowtotal ++;
                   6965:             $rowcount ++;
                   6966:         }
                   6967:     }
                   6968:     return $datatable;
                   6969: }
                   6970: 
1.43      raeburn  6971: sub print_defaults {
1.160.6.40  raeburn  6972:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  6973:     my $rownum = 0;
1.160.6.80  raeburn  6974:     my ($datatable,$css_class,$titles);
                   6975:     unless ($position eq 'bottom') {
                   6976:         $titles = &defaults_titles($dom);
                   6977:     }
1.160.6.40  raeburn  6978:     if ($position eq 'top') {
                   6979:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   6980:                      'datelocale_def','portal_def');
                   6981:         my %defaults;
                   6982:         if (ref($settings) eq 'HASH') {
                   6983:             %defaults = %{$settings};
1.43      raeburn  6984:         } else {
1.160.6.40  raeburn  6985:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   6986:             foreach my $item (@items) {
                   6987:                 $defaults{$item} = $domdefaults{$item};
                   6988:             }
1.43      raeburn  6989:         }
1.160.6.40  raeburn  6990:         foreach my $item (@items) {
                   6991:             if ($rownum%2) {
                   6992:                 $css_class = '';
                   6993:             } else {
                   6994:                 $css_class = ' class="LC_odd_row" ';
1.43      raeburn  6995:             }
1.160.6.40  raeburn  6996:             $datatable .= '<tr'.$css_class.'>'.
                   6997:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   6998:                           '</span></td><td class="LC_right_item" colspan="3">';
                   6999:             if ($item eq 'auth_def') {
                   7000:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   7001:                 my %shortauth = (
                   7002:                                  internal => 'int',
                   7003:                                  krb4 => 'krb4',
                   7004:                                  krb5 => 'krb5',
                   7005:                                  localauth  => 'loc'
                   7006:                                 );
                   7007:                 my %authnames = &authtype_names();
                   7008:                 foreach my $auth (@authtypes) {
                   7009:                     my $checked = ' ';
                   7010:                     if ($defaults{$item} eq $auth) {
                   7011:                         $checked = ' checked="checked" ';
                   7012:                     }
                   7013:                     $datatable .= '<label><input type="radio" name="'.$item.
                   7014:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   7015:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   7016:                 }
                   7017:             } elsif ($item eq 'timezone_def') {
                   7018:                 my $includeempty = 1;
                   7019:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   7020:             } elsif ($item eq 'datelocale_def') {
1.160.6.98  raeburn  7021:                 my $includeempty = 1;
                   7022:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   7023:             } elsif ($item eq 'lang_def') {
                   7024:                 my $includeempty = 1;
                   7025:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80  raeburn  7026:             } else {
1.160.6.98  raeburn  7027:                 my $size;
                   7028:                 if ($item eq 'portal_def') {
                   7029:                     $size = ' size="25"';
                   7030:                 }
1.160.6.80  raeburn  7031:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98  raeburn  7032:                               $defaults{$item}.'"'.$size.' />';
1.160.6.80  raeburn  7033:             }
                   7034:             $datatable .= '</td></tr>';
                   7035:             $rownum ++;
                   7036:         }
1.160.6.40  raeburn  7037:     } else {
1.160.6.80  raeburn  7038:         my %defaults;
1.160.6.40  raeburn  7039:         if (ref($settings) eq 'HASH') {
1.160.6.93  raeburn  7040:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40  raeburn  7041:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   7042:                 for (my $i=0; $i<$maxnum; $i++) {
                   7043:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   7044:                     my $item = $settings->{'inststatusorder'}->[$i];
                   7045:                     my $title = $settings->{'inststatustypes'}->{$item};
                   7046:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   7047:                     $datatable .= '<tr'.$css_class.'>'.
                   7048:                                   '<td><span class="LC_nobreak">'.
                   7049:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   7050:                     for (my $k=0; $k<=$maxnum; $k++) {
                   7051:                         my $vpos = $k+1;
                   7052:                         my $selstr;
                   7053:                         if ($k == $i) {
                   7054:                             $selstr = ' selected="selected" ';
                   7055:                         }
                   7056:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7057:                     }
                   7058:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   7059:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   7060:                                   &mt('delete').'</span></td>'.
                   7061:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
                   7062:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93  raeburn  7063:                                   '</span></td></tr>';
1.160.6.40  raeburn  7064:                 }
                   7065:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   7066:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   7067:                 $datatable .= '<tr '.$css_class.'>'.
                   7068:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   7069:                 for (my $k=0; $k<=$maxnum; $k++) {
                   7070:                     my $vpos = $k+1;
                   7071:                     my $selstr;
                   7072:                     if ($k == $maxnum) {
                   7073:                         $selstr = ' selected="selected" ';
                   7074:                     }
                   7075:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7076:                 }
                   7077:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.160.6.63  raeburn  7078:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40  raeburn  7079:                               '&nbsp;'.&mt('(new)').
                   7080:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
                   7081:                               &mt('Name displayed:').
                   7082:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   7083:                               '</tr>'."\n";
                   7084:                 $rownum ++;
1.141     raeburn  7085:             }
1.43      raeburn  7086:         }
                   7087:     }
                   7088:     $$rowtotal += $rownum;
                   7089:     return $datatable;
                   7090: }
                   7091: 
1.160.6.5  raeburn  7092: sub get_languages_hash {
                   7093:     my %langchoices;
                   7094:     foreach my $id (&Apache::loncommon::languageids()) {
                   7095:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   7096:         if ($code ne '') {
                   7097:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   7098:         }
                   7099:     }
                   7100:     return %langchoices;
                   7101: }
                   7102: 
1.43      raeburn  7103: sub defaults_titles {
1.141     raeburn  7104:     my ($dom) = @_;
1.43      raeburn  7105:     my %titles = &Apache::lonlocal::texthash (
                   7106:                    'auth_def'      => 'Default authentication type',
                   7107:                    'auth_arg_def'  => 'Default authentication argument',
                   7108:                    'lang_def'      => 'Default language',
1.54      raeburn  7109:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  7110:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  7111:                    'portal_def'     => 'Portal/Default URL',
1.160.6.80  raeburn  7112:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   7113:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   7114:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  7115:                  );
1.141     raeburn  7116:     if ($dom) {
                   7117:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   7118:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   7119:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   7120:         $protocol = 'http' if ($protocol ne 'https');
                   7121:         if ($uint_dom) {
                   7122:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   7123:                                          $uint_dom);
                   7124:         }
                   7125:     }
1.43      raeburn  7126:     return (\%titles);
                   7127: }
                   7128: 
1.160.6.97  raeburn  7129: sub print_scantron {
                   7130:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   7131:     if ($position eq 'top') {
                   7132:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   7133:     } else {
                   7134:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   7135:     }
                   7136: }
                   7137: 
                   7138: sub scantron_javascript {
                   7139:     return <<"ENDSCRIPT";
                   7140: 
                   7141: <script type="text/javascript">
                   7142: // <![CDATA[
                   7143: 
                   7144: function toggleScantron(form) {
                   7145:     var csvfieldset = new Array();
                   7146:     if (document.getElementById('scantroncsv_cols')) {
                   7147:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   7148:     }
                   7149:     if (document.getElementById('scantroncsv_options')) {
                   7150:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   7151:     }
                   7152:     if (csvfieldset.length) {
                   7153:         if (document.getElementById('scantronconfcsv')) {
                   7154:             var scantroncsv = document.getElementById('scantronconfcsv');
                   7155:             if (scantroncsv.checked) {
                   7156:                 for (var i=0; i<csvfieldset.length; i++) {
                   7157:                     csvfieldset[i].style.display = 'block';
                   7158:                 }
                   7159:             } else {
                   7160:                 for (var i=0; i<csvfieldset.length; i++) {
                   7161:                     csvfieldset[i].style.display = 'none';
                   7162:                 }
                   7163:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   7164:                 if (csvselects.length) {
                   7165:                     for (var j=0; j<csvselects.length; j++) {
                   7166:                         csvselects[j].selectedIndex = 0;
                   7167:                     }
                   7168:                 }
                   7169:             }
                   7170:         }
                   7171:     }
                   7172:     return;
                   7173: }
                   7174: // ]]>
                   7175: </script>
                   7176: 
                   7177: ENDSCRIPT
                   7178: 
                   7179: }
                   7180: 
1.46      raeburn  7181: sub print_scantronformat {
                   7182:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   7183:     my $itemcount = 1;
1.60      raeburn  7184:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   7185:         %confhash);
1.46      raeburn  7186:     my $switchserver = &check_switchserver($dom,$confname);
                   7187:     my %lt = &Apache::lonlocal::texthash (
1.95      www      7188:                 default => 'Default bubblesheet format file error',
                   7189:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  7190:              );
                   7191:     my %scantronfiles = (
                   7192:         default => 'default.tab',
                   7193:         custom => 'custom.tab',
                   7194:     );
                   7195:     foreach my $key (keys(%scantronfiles)) {
                   7196:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   7197:                               .$scantronfiles{$key};
                   7198:     }
                   7199:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   7200:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   7201:         if (!$switchserver) {
                   7202:             my $servadm = $r->dir_config('lonAdmEMail');
                   7203:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   7204:             if ($configuserok eq 'ok') {
                   7205:                 if ($author_ok eq 'ok') {
                   7206:                     my %legacyfile = (
1.160.6.97  raeburn  7207:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   7208:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  7209:                     );
                   7210:                     my %md5chk;
                   7211:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  7212:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   7213:                         chomp($md5chk{$type});
1.46      raeburn  7214:                     }
                   7215:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   7216:                         foreach my $type (keys(%legacyfile)) {
1.160.6.97  raeburn  7217:                             ($scantronurls{$type},my $error) =
1.46      raeburn  7218:                                 &legacy_scantronformat($r,$dom,$confname,
                   7219:                                                  $type,$legacyfile{$type},
                   7220:                                                  $scantronurls{$type},
                   7221:                                                  $scantronfiles{$type});
1.60      raeburn  7222:                             if ($error ne '') {
                   7223:                                 $error{$type} = $error;
                   7224:                             }
                   7225:                         }
                   7226:                         if (keys(%error) == 0) {
                   7227:                             $is_custom = 1;
1.160.6.97  raeburn  7228:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  7229:                                 $scantronurls{'custom'};
1.160.6.97  raeburn  7230:                             my $putresult =
1.60      raeburn  7231:                                 &Apache::lonnet::put_dom('configuration',
                   7232:                                                          \%confhash,$dom);
                   7233:                             if ($putresult ne 'ok') {
1.160.6.97  raeburn  7234:                                 $error{'custom'} =
1.60      raeburn  7235:                                     '<span class="LC_error">'.
                   7236:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   7237:                             }
1.46      raeburn  7238:                         }
                   7239:                     } else {
1.60      raeburn  7240:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  7241:                             &legacy_scantronformat($r,$dom,$confname,
                   7242:                                           'default',$legacyfile{'default'},
                   7243:                                           $scantronurls{'default'},
                   7244:                                           $scantronfiles{'default'});
1.60      raeburn  7245:                         if ($error eq '') {
                   7246:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   7247:                             my $putresult =
                   7248:                                 &Apache::lonnet::put_dom('configuration',
                   7249:                                                          \%confhash,$dom);
                   7250:                             if ($putresult ne 'ok') {
                   7251:                                 $error{'default'} =
                   7252:                                     '<span class="LC_error">'.
                   7253:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   7254:                             }
                   7255:                         } else {
                   7256:                             $error{'default'} = $error;
                   7257:                         }
1.46      raeburn  7258:                     }
                   7259:                 }
                   7260:             }
                   7261:         } else {
1.95      www      7262:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  7263:         }
                   7264:     }
                   7265:     if (ref($settings) eq 'HASH') {
                   7266:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   7267:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   7268:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   7269:                 $scantronurl = '';
                   7270:             } else {
                   7271:                 $scantronurl = $settings->{'scantronformat'};
                   7272:             }
                   7273:             $is_custom = 1;
                   7274:         } else {
                   7275:             $scantronurl = $scantronurls{'default'};
                   7276:         }
                   7277:     } else {
1.60      raeburn  7278:         if ($is_custom) {
                   7279:             $scantronurl = $scantronurls{'custom'};
                   7280:         } else {
                   7281:             $scantronurl = $scantronurls{'default'};
                   7282:         }
1.46      raeburn  7283:     }
                   7284:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7285:     $datatable .= '<tr'.$css_class.'>';
                   7286:     if (!$is_custom) {
1.65      raeburn  7287:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   7288:                       '<span class="LC_nobreak">';
1.46      raeburn  7289:         if ($scantronurl) {
1.160.6.21  raeburn  7290:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   7291:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  7292:         } else {
                   7293:             $datatable = &mt('File unavailable for display');
                   7294:         }
1.65      raeburn  7295:         $datatable .= '</span></td>';
1.60      raeburn  7296:         if (keys(%error) == 0) { 
                   7297:             $datatable .= '<td valign="bottom">';
                   7298:             if (!$switchserver) {
                   7299:                 $datatable .= &mt('Upload:').'<br />';
                   7300:             }
                   7301:         } else {
                   7302:             my $errorstr;
                   7303:             foreach my $key (sort(keys(%error))) {
                   7304:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   7305:             }
                   7306:             $datatable .= '<td>'.$errorstr;
                   7307:         }
1.46      raeburn  7308:     } else {
                   7309:         if (keys(%error) > 0) {
                   7310:             my $errorstr;
                   7311:             foreach my $key (sort(keys(%error))) {
                   7312:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   7313:             } 
1.60      raeburn  7314:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  7315:         } elsif ($scantronurl) {
1.160.6.26  raeburn  7316:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21  raeburn  7317:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  7318:             $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21  raeburn  7319:                           $link.
                   7320:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   7321:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  7322:                           '<td><span class="LC_nobreak">&nbsp;'.
                   7323:                           &mt('Replace:').'</span><br />';
1.46      raeburn  7324:         }
                   7325:     }
                   7326:     if (keys(%error) == 0) {
                   7327:         if ($switchserver) {
                   7328:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   7329:         } else {
1.65      raeburn  7330:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   7331:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  7332:         }
                   7333:     }
                   7334:     $datatable .= '</td></tr>';
                   7335:     $$rowtotal ++;
                   7336:     return $datatable;
                   7337: }
                   7338: 
                   7339: sub legacy_scantronformat {
                   7340:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   7341:     my ($url,$error);
                   7342:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   7343:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   7344:         (my $result,$url) =
                   7345:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   7346:                          '','',$newfile);
                   7347:         if ($result ne 'ok') {
1.130     raeburn  7348:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  7349:         }
                   7350:     }
                   7351:     return ($url,$error);
                   7352: }
1.43      raeburn  7353: 
1.160.6.97  raeburn  7354: sub print_scantronconfig {
                   7355:     my ($dom,$settings,$rowtotal) = @_;
                   7356:     my $itemcount = 2;
                   7357:     my $is_checked = ' checked="checked"';
                   7358:     my %optionson = (
                   7359:                      hdr => ' checked="checked"',
                   7360:                      pad => ' checked="checked"',
                   7361:                      rem => ' checked="checked"',
                   7362:                     );
                   7363:     my %optionsoff = (
                   7364:                       hdr => '',
                   7365:                       pad => '',
                   7366:                       rem => '',
                   7367:                      );
                   7368:     my $currcsvsty = 'none';
                   7369:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
                   7370:     my @fields = &scantroncsv_fields();
                   7371:     my %titles = &scantronconfig_titles();
                   7372:     if (ref($settings) eq 'HASH') {
                   7373:         if (ref($settings->{config}) eq 'HASH') {
                   7374:             if ($settings->{config}->{dat}) {
                   7375:                 $checked{'dat'} = $is_checked;
                   7376:             }
                   7377:             if (ref($settings->{config}->{csv}) eq 'HASH') {
                   7378:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   7379:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   7380:                     if (keys(%csvfields) > 0) {
                   7381:                         $checked{'csv'} = $is_checked;
                   7382:                         $currcsvsty = 'block';
                   7383:                     }
                   7384:                 }
                   7385:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   7386:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   7387:                     foreach my $option (keys(%optionson)) {
                   7388:                         unless ($csvoptions{$option}) {
                   7389:                             $optionsoff{$option} = $optionson{$option};
                   7390:                             $optionson{$option} = '';
                   7391:                         }
                   7392:                     }
                   7393:                 }
                   7394:             }
                   7395:         } else {
                   7396:             $checked{'dat'} = $is_checked;
                   7397:         }
                   7398:     } else {
                   7399:         $checked{'dat'} = $is_checked;
                   7400:     }
                   7401:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   7402:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   7403:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   7404:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   7405:     foreach my $item ('dat','csv') {
                   7406:         my $id;
                   7407:         if ($item eq 'csv') {
                   7408:             $id = 'id="scantronconfcsv" ';
                   7409:         }
                   7410:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   7411:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   7412:         if ($item eq 'csv') {
                   7413:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   7414:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   7415:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   7416:             foreach my $col (@fields) {
                   7417:                 my $selnone;
                   7418:                 if ($csvfields{$col} eq '') {
                   7419:                     $selnone = ' selected="selected"';
                   7420:                 }
                   7421:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   7422:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   7423:                               '<option value=""'.$selnone.'></option>';
                   7424:                 for (my $i=0; $i<20; $i++) {
                   7425:                     my $shown = $i+1;
                   7426:                     my $sel;
                   7427:                     unless ($selnone) {
                   7428:                         if (exists($csvfields{$col})) {
                   7429:                             if ($csvfields{$col} == $i) {
                   7430:                                 $sel = ' selected="selected"';
                   7431:                             }
                   7432:                         }
                   7433:                     }
                   7434:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   7435:                 }
                   7436:                 $datatable .= '</select></td></tr>';
                   7437:            }
                   7438:            $datatable .= '</table></fieldset>'.
                   7439:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   7440:                          '<legend>'.&mt('CSV Options').'</legend>';
                   7441:            foreach my $option ('hdr','pad','rem') {
                   7442:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   7443:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   7444:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   7445:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   7446:            }
                   7447:            $datatable .= '</fieldset>';
                   7448:            $itemcount ++;
                   7449:         }
                   7450:     }
                   7451:     $datatable .= '</td></tr>';
                   7452:     $$rowtotal ++;
                   7453:     return $datatable;
                   7454: }
                   7455: 
                   7456: sub scantronconfig_titles {
                   7457:     return &Apache::lonlocal::texthash(
                   7458:                                           dat => 'Standard format (.dat)',
                   7459:                                           csv => 'Comma separated values (.csv)',
                   7460:                                           hdr => 'Remove first line in file (contains column titles)',
                   7461:                                           pad => 'Prepend 0s to PaperID',
                   7462:                                           rem => 'Remove leading spaces (except Question Response columns)',
                   7463:                                           CODE => 'CODE',
                   7464:                                           ID   => 'Student ID',
                   7465:                                           PaperID => 'Paper ID',
                   7466:                                           FirstName => 'First Name',
                   7467:                                           LastName => 'Last Name',
                   7468:                                           FirstQuestion => 'First Question Response',
                   7469:                                           Section => 'Section',
                   7470:     );
                   7471: }
                   7472: 
                   7473: sub scantroncsv_fields {
                   7474:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   7475: }
                   7476: 
1.49      raeburn  7477: sub print_coursecategories {
1.57      raeburn  7478:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   7479:     my $datatable;
                   7480:     if ($position eq 'top') {
1.160.6.42  raeburn  7481:         my (%checked);
                   7482:         my @catitems = ('unauth','auth');
                   7483:         my @cattypes = ('std','domonly','codesrch','none');
                   7484:         $checked{'unauth'} = 'std';
                   7485:         $checked{'auth'} = 'std';
                   7486:         if (ref($settings) eq 'HASH') {
                   7487:             foreach my $type (@cattypes) {
                   7488:                 if ($type eq $settings->{'unauth'}) {
                   7489:                     $checked{'unauth'} = $type;
                   7490:                 }
                   7491:                 if ($type eq $settings->{'auth'}) {
                   7492:                     $checked{'auth'} = $type;
                   7493:                 }
                   7494:             }
                   7495:         }
                   7496:         my %lt = &Apache::lonlocal::texthash (
                   7497:                                                unauth   => 'Catalog type for unauthenticated users',
                   7498:                                                auth     => 'Catalog type for authenticated users',
                   7499:                                                none     => 'No catalog',
                   7500:                                                std      => 'Standard catalog',
                   7501:                                                domonly  => 'Domain-only catalog',
                   7502:                                                codesrch => "Code search form",
                   7503:                                              );
                   7504:        my $itemcount = 0;
                   7505:        foreach my $item (@catitems) {
                   7506:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   7507:            $datatable .= '<tr '.$css_class.'>'.
                   7508:                          '<td>'.$lt{$item}.'</td>'.
                   7509:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   7510:            foreach my $type (@cattypes) {
                   7511:                my $ischecked;
                   7512:                if ($checked{$item} eq $type) {
                   7513:                    $ischecked=' checked="checked"';
                   7514:                }
                   7515:                $datatable .= '<label>'.
                   7516:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   7517:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   7518:            }
1.160.6.87  raeburn  7519:            $datatable .= '</span></td></tr>';
1.160.6.42  raeburn  7520:            $itemcount ++;
                   7521:         }
                   7522:         $$rowtotal += $itemcount;
                   7523:     } elsif ($position eq 'middle') {
1.57      raeburn  7524:         my $toggle_cats_crs = ' ';
                   7525:         my $toggle_cats_dom = ' checked="checked" ';
                   7526:         my $can_cat_crs = ' ';
                   7527:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  7528:         my $toggle_catscomm_comm = ' ';
                   7529:         my $toggle_catscomm_dom = ' checked="checked" ';
                   7530:         my $can_catcomm_comm = ' ';
                   7531:         my $can_catcomm_dom = ' checked="checked" ';
                   7532: 
1.57      raeburn  7533:         if (ref($settings) eq 'HASH') {
                   7534:             if ($settings->{'togglecats'} eq 'crs') {
                   7535:                 $toggle_cats_crs = $toggle_cats_dom;
                   7536:                 $toggle_cats_dom = ' ';
                   7537:             }
                   7538:             if ($settings->{'categorize'} eq 'crs') {
                   7539:                 $can_cat_crs = $can_cat_dom;
                   7540:                 $can_cat_dom = ' ';
                   7541:             }
1.120     raeburn  7542:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   7543:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   7544:                 $toggle_catscomm_dom = ' ';
                   7545:             }
                   7546:             if ($settings->{'categorizecomm'} eq 'comm') {
                   7547:                 $can_catcomm_comm = $can_catcomm_dom;
                   7548:                 $can_catcomm_dom = ' ';
                   7549:             }
1.57      raeburn  7550:         }
                   7551:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  7552:                      togglecats     => 'Show/Hide a course in catalog',
                   7553:                      togglecatscomm => 'Show/Hide a community in catalog',
                   7554:                      categorize     => 'Assign a category to a course',
                   7555:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  7556:                     );
                   7557:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  7558:                      dom  => 'Set in Domain',
                   7559:                      crs  => 'Set in Course',
                   7560:                      comm => 'Set in Community',
1.57      raeburn  7561:                     );
                   7562:         $datatable = '<tr class="LC_odd_row">'.
                   7563:                   '<td>'.$title{'togglecats'}.'</td>'.
                   7564:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7565:                   '<input type="radio" name="togglecats"'.
                   7566:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7567:                   '<label><input type="radio" name="togglecats"'.
                   7568:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   7569:                   '</tr><tr>'.
                   7570:                   '<td>'.$title{'categorize'}.'</td>'.
                   7571:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7572:                   '<label><input type="radio" name="categorize"'.
                   7573:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7574:                   '<label><input type="radio" name="categorize"'.
                   7575:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  7576:                   '</tr><tr class="LC_odd_row">'.
                   7577:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   7578:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   7579:                   '<input type="radio" name="togglecatscomm"'.
                   7580:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7581:                   '<label><input type="radio" name="togglecatscomm"'.
                   7582:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   7583:                   '</tr><tr>'.
                   7584:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   7585:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   7586:                   '<label><input type="radio" name="categorizecomm"'.
                   7587:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   7588:                   '<label><input type="radio" name="categorizecomm"'.
                   7589:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  7590:                   '</tr>';
1.120     raeburn  7591:         $$rowtotal += 4;
1.57      raeburn  7592:     } else {
                   7593:         my $css_class;
                   7594:         my $itemcount = 1;
                   7595:         my $cathash; 
                   7596:         if (ref($settings) eq 'HASH') {
                   7597:             $cathash = $settings->{'cats'};
                   7598:         }
                   7599:         if (ref($cathash) eq 'HASH') {
                   7600:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   7601:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   7602:                                                    \%allitems,\%idx,\@jsarray);
                   7603:             my $maxdepth = scalar(@cats);
                   7604:             my $colattrib = '';
                   7605:             if ($maxdepth > 2) {
                   7606:                 $colattrib = ' colspan="2" ';
                   7607:             }
                   7608:             my @path;
                   7609:             if (@cats > 0) {
                   7610:                 if (ref($cats[0]) eq 'ARRAY') {
                   7611:                     my $numtop = @{$cats[0]};
                   7612:                     my $maxnum = $numtop;
1.120     raeburn  7613:                     my %default_names = (
                   7614:                           instcode    => &mt('Official courses'),
                   7615:                           communities => &mt('Communities'),
                   7616:                     );
                   7617: 
                   7618:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   7619:                         ($cathash->{'instcode::0'} eq '') ||
                   7620:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   7621:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  7622:                         $maxnum ++;
                   7623:                     }
                   7624:                     my $lastidx;
                   7625:                     for (my $i=0; $i<$numtop; $i++) {
                   7626:                         my $parent = $cats[0][$i];
                   7627:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7628:                         my $item = &escape($parent).'::0';
                   7629:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   7630:                         $lastidx = $idx{$item};
                   7631:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   7632:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   7633:                         for (my $k=0; $k<=$maxnum; $k++) {
                   7634:                             my $vpos = $k+1;
                   7635:                             my $selstr;
                   7636:                             if ($k == $i) {
                   7637:                                 $selstr = ' selected="selected" ';
                   7638:                             }
                   7639:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7640:                         }
1.160.6.29  raeburn  7641:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  7642:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   7643:                             $datatable .=  '<span class="LC_nobreak">'
                   7644:                                            .$default_names{$parent}.'</span>';
                   7645:                             if ($parent eq 'instcode') {
                   7646:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   7647:                                               .&mt('with institutional codes')
                   7648:                                               .')</span></td><td'.$colattrib.'>';
                   7649:                             } else {
                   7650:                                 $datatable .= '<table><tr><td>';
                   7651:                             }
                   7652:                             $datatable .= '<span class="LC_nobreak">'
                   7653:                                           .'<label><input type="radio" name="'
                   7654:                                           .$parent.'" value="1" checked="checked" />'
                   7655:                                           .&mt('Display').'</label>';
                   7656:                             if ($parent eq 'instcode') {
                   7657:                                 $datatable .= '&nbsp;';
                   7658:                             } else {
                   7659:                                 $datatable .= '</span></td></tr><tr><td>'
                   7660:                                               .'<span class="LC_nobreak">';
                   7661:                             }
                   7662:                             $datatable .= '<label><input type="radio" name="'
                   7663:                                           .$parent.'" value="0" />'
                   7664:                                           .&mt('Do not display').'</label></span>';
                   7665:                             if ($parent eq 'communities') {
                   7666:                                 $datatable .= '</td></tr></table>';
                   7667:                             }
                   7668:                             $datatable .= '</td>';
1.57      raeburn  7669:                         } else {
                   7670:                             $datatable .= $parent
1.160.6.29  raeburn  7671:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   7672:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  7673:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   7674:                         }
                   7675:                         my $depth = 1;
                   7676:                         push(@path,$parent);
                   7677:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   7678:                         pop(@path);
                   7679:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   7680:                         $itemcount ++;
                   7681:                     }
1.48      raeburn  7682:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  7683:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   7684:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  7685:                     for (my $k=0; $k<=$maxnum; $k++) {
                   7686:                         my $vpos = $k+1;
                   7687:                         my $selstr;
1.57      raeburn  7688:                         if ($k == $numtop) {
1.48      raeburn  7689:                             $selstr = ' selected="selected" ';
                   7690:                         }
                   7691:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   7692:                     }
1.59      bisitz   7693:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  7694:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   7695:                                   .'</tr>'."\n";
1.48      raeburn  7696:                     $itemcount ++;
1.120     raeburn  7697:                     foreach my $default ('instcode','communities') {
                   7698:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   7699:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   7700:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   7701:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   7702:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   7703:                             for (my $k=0; $k<=$maxnum; $k++) {
                   7704:                                 my $vpos = $k+1;
                   7705:                                 my $selstr;
                   7706:                                 if ($k == $maxnum) {
                   7707:                                     $selstr = ' selected="selected" ';
                   7708:                                 }
                   7709:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  7710:                             }
1.120     raeburn  7711:                             $datatable .= '</select></span></td>'.
                   7712:                                           '<td><span class="LC_nobreak">'.
                   7713:                                           $default_names{$default}.'</span>';
                   7714:                             if ($default eq 'instcode') {
                   7715:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   7716:                                               .&mt('with institutional codes').')</span>';
                   7717:                             }
                   7718:                             $datatable .= '</td>'
                   7719:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   7720:                                           .&mt('Display').'</label>&nbsp;'
                   7721:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   7722:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  7723:                         }
                   7724:                     }
                   7725:                 }
1.57      raeburn  7726:             } else {
                   7727:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  7728:             }
                   7729:         } else {
1.160.6.87  raeburn  7730:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  7731:                           .&initialize_categories($itemcount);
1.48      raeburn  7732:         }
1.57      raeburn  7733:         $$rowtotal += $itemcount;
1.48      raeburn  7734:     }
                   7735:     return $datatable;
                   7736: }
                   7737: 
1.69      raeburn  7738: sub print_serverstatuses {
                   7739:     my ($dom,$settings,$rowtotal) = @_;
                   7740:     my $datatable;
                   7741:     my @pages = &serverstatus_pages();
                   7742:     my (%namedaccess,%machineaccess);
                   7743:     foreach my $type (@pages) {
                   7744:         $namedaccess{$type} = '';
                   7745:         $machineaccess{$type}= '';
                   7746:     }
                   7747:     if (ref($settings) eq 'HASH') {
                   7748:         foreach my $type (@pages) {
                   7749:             if (exists($settings->{$type})) {
                   7750:                 if (ref($settings->{$type}) eq 'HASH') {
                   7751:                     foreach my $key (keys(%{$settings->{$type}})) {
                   7752:                         if ($key eq 'namedusers') {
                   7753:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   7754:                         } elsif ($key eq 'machines') {
                   7755:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   7756:                         }
                   7757:                     }
                   7758:                 }
                   7759:             }
                   7760:         }
                   7761:     }
1.81      raeburn  7762:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  7763:     my $rownum = 0;
                   7764:     my $css_class;
                   7765:     foreach my $type (@pages) {
                   7766:         $rownum ++;
                   7767:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   7768:         $datatable .= '<tr'.$css_class.'>'.
                   7769:                       '<td><span class="LC_nobreak">'.
                   7770:                       $titles->{$type}.'</span></td>'.
                   7771:                       '<td class="LC_left_item">'.
                   7772:                       '<input type="text" name="'.$type.'_namedusers" '.
                   7773:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   7774:                       '<td class="LC_right_item">'.
                   7775:                       '<span class="LC_nobreak">'.
                   7776:                       '<input type="text" name="'.$type.'_machines" '.
                   7777:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87  raeburn  7778:                       '</span></td></tr>'."\n";
1.69      raeburn  7779:     }
                   7780:     $$rowtotal += $rownum;
                   7781:     return $datatable;
                   7782: }
                   7783: 
                   7784: sub serverstatus_pages {
                   7785:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15  raeburn  7786:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31  raeburn  7787:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62  raeburn  7788:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  7789: }
                   7790: 
1.160.6.40  raeburn  7791: sub defaults_javascript {
                   7792:     my ($settings) = @_;
1.160.6.98  raeburn  7793:     return unless (ref($settings) eq 'HASH');
1.160.6.40  raeburn  7794:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   7795:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   7796:         if ($maxnum eq '') {
                   7797:             $maxnum = 0;
                   7798:         }
                   7799:         $maxnum ++;
1.160.6.51  raeburn  7800:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.160.6.40  raeburn  7801:         return <<"ENDSCRIPT";
                   7802: <script type="text/javascript">
                   7803: // <![CDATA[
                   7804: function reorderTypes(form,caller) {
                   7805:     var changedVal;
                   7806: $jstext 
                   7807:     var newpos = 'addinststatus_pos';
                   7808:     var current = new Array;
                   7809:     var maxh = $maxnum;
                   7810:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7811:     var oldVal;
                   7812:     if (caller == newpos) {
                   7813:         changedVal = newitemVal;
                   7814:     } else {
                   7815:         var curritem = 'inststatus_pos_'+caller;
                   7816:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   7817:         current[newitemVal] = newpos;
                   7818:     }
                   7819:     for (var i=0; i<inststatuses.length; i++) {
                   7820:         if (inststatuses[i] != caller) {
                   7821:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   7822:             if (form.elements[elementName]) {
                   7823:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   7824:                 current[currVal] = elementName;
                   7825:             }
                   7826:         }
                   7827:     }
                   7828:     for (var j=0; j<maxh; j++) {
                   7829:         if (current[j] == undefined) {
                   7830:             oldVal = j;
                   7831:         }
                   7832:     }
                   7833:     if (oldVal < changedVal) {
                   7834:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   7835:            var elementName = current[k];
                   7836:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   7837:         }
                   7838:     } else {
                   7839:         for (var k=changedVal; k<oldVal; k++) {
                   7840:             var elementName = current[k];
                   7841:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   7842:         }
                   7843:     }
                   7844:     return;
                   7845: }
                   7846: 
                   7847: // ]]>
                   7848: </script>
                   7849: 
                   7850: ENDSCRIPT
                   7851:     }
                   7852: }
                   7853: 
1.160.6.98  raeburn  7854: sub passwords_javascript {
1.160.6.99  raeburn  7855:     my %intalert = &Apache::lonlocal::texthash (
                   7856:         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.',
                   7857:         authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   7858:         passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   7859:         passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   7860:         passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
                   7861:         passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   7862:     );
                   7863:     &js_escape(\%intalert);
                   7864:     my $defmin = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  7865:     my $intauthjs = <<"ENDSCRIPT";
                   7866: 
                   7867: function warnIntAuth(field) {
                   7868:     if (field.name == 'intauth_check') {
                   7869:         if (field.value == '2') {
1.160.6.99  raeburn  7870:             alert('$intalert{authcheck}');
1.160.6.98  raeburn  7871:         }
                   7872:     }
                   7873:     if (field.name == 'intauth_cost') {
                   7874:         field.value.replace(/\s/g,'');
                   7875:         if (field.value != '') {
                   7876:             var regexdigit=/^\\d+\$/;
                   7877:             if (!regexdigit.test(field.value)) {
1.160.6.99  raeburn  7878:                 alert('$intalert{authcost}');
                   7879:             }
                   7880:         }
                   7881:     }
                   7882:     return;
                   7883: }
                   7884: 
                   7885: function warnIntPass(field) {
                   7886:     field.value.replace(/^\s+/,'');
                   7887:     field.value.replace(/\s+\$/,'');
                   7888:     var regexdigit=/^\\d+\$/;
                   7889:     if (field.name == 'passwords_min') {
                   7890:         if (field.value == '') {
                   7891:             alert('$intalert{passmin}');
                   7892:             field.value = '$defmin';
                   7893:         } else {
                   7894:             if (!regexdigit.test(field.value)) {
                   7895:                 alert('$intalert{passmin}');
                   7896:                 field.value = '$defmin';
                   7897:             }
                   7898:             var minval = parseInt(field.value,10);
                   7899:             if (minval < $defmin) {
                   7900:                 alert('$intalert{passmin}');
                   7901:                 field.value = '$defmin';
                   7902:             }
                   7903:         }
                   7904:     } else {
                   7905:         if (field.value == '0') {
                   7906:             field.value = '';
                   7907:         }
                   7908:         if (field.value != '') {
                   7909:             if (field.name == 'passwords_expire') {
                   7910:                 var regexpposnum=/^\\d+(|\\.\\d*)\$/;
                   7911:                 if (!regexpposnum.test(field.value)) {
                   7912:                     alert('$intalert{passexp}');
                   7913:                     field.value = '';
                   7914:                 } else {
                   7915:                     var expval = parseFloat(field.value);
                   7916:                     if (expval == 0) {
                   7917:                         alert('$intalert{passexp}');
                   7918:                         field.value = '';
                   7919:                     }
                   7920:                 }
                   7921:             } else {
                   7922:                 if (!regexdigit.test(field.value)) {
                   7923:                     if (field.name == 'passwords_max') {
                   7924:                         alert('$intalert{passmax}');
                   7925:                     } else {
                   7926:                         if (field.name == 'passwords_numsaved') {
                   7927:                             alert('$intalert{passnum}');
                   7928:                         }
                   7929:                     }
1.160.6.102.2  3(raebur 7930:0):                     field.value = '';
1.160.6.99  raeburn  7931:                 }
1.160.6.98  raeburn  7932:             }
                   7933:         }
                   7934:     }
                   7935:     return;
                   7936: }
                   7937: 
                   7938: ENDSCRIPT
                   7939:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   7940: }
                   7941: 
1.49      raeburn  7942: sub coursecategories_javascript {
                   7943:     my ($settings) = @_;
1.57      raeburn  7944:     my ($output,$jstext,$cathash);
1.49      raeburn  7945:     if (ref($settings) eq 'HASH') {
1.57      raeburn  7946:         $cathash = $settings->{'cats'};
                   7947:     }
                   7948:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  7949:         my (@cats,@jsarray,%idx);
1.57      raeburn  7950:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  7951:         if (@jsarray > 0) {
                   7952:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   7953:             for (my $i=0; $i<@jsarray; $i++) {
                   7954:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   7955:                     my $catstr = join('","',@{$jsarray[$i]});
                   7956:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   7957:                 }
                   7958:             }
                   7959:         }
                   7960:     } else {
                   7961:         $jstext  = '    var categories = Array(1);'."\n".
                   7962:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   7963:     }
1.160.6.42  raeburn  7964:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   7965:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66  raeburn  7966:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   7967:     &js_escape(\$instcode_reserved);
                   7968:     &js_escape(\$communities_reserved);
                   7969:     &js_escape(\$choose_again);
1.49      raeburn  7970:     $output = <<"ENDSCRIPT";
                   7971: <script type="text/javascript">
1.109     raeburn  7972: // <![CDATA[
1.49      raeburn  7973: function reorderCats(form,parent,item,idx) {
                   7974:     var changedVal;
                   7975: $jstext
                   7976:     var newpos = 'addcategory_pos';
                   7977:     if (parent == '') {
                   7978:         var has_instcode = 0;
                   7979:         var maxtop = categories[idx].length;
                   7980:         for (var j=0; j<maxtop; j++) {
                   7981:             if (categories[idx][j] == 'instcode::0') {
                   7982:                 has_instcode == 1;
                   7983:             }
                   7984:         }
                   7985:         if (has_instcode == 0) {
                   7986:             categories[idx][maxtop] = 'instcode_pos';
                   7987:         }
                   7988:     } else {
                   7989:         newpos += '_'+parent;
                   7990:     }
                   7991:     var maxh = 1 + categories[idx].length;
                   7992:     var current = new Array;
                   7993:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   7994:     if (item == newpos) {
                   7995:         changedVal = newitemVal;
                   7996:     } else {
                   7997:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   7998:         current[newitemVal] = newpos;
                   7999:     }
                   8000:     for (var i=0; i<categories[idx].length; i++) {
                   8001:         var elementName = categories[idx][i];
                   8002:         if (elementName != item) {
                   8003:             if (form.elements[elementName]) {
                   8004:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   8005:                 current[currVal] = elementName;
                   8006:             }
                   8007:         }
                   8008:     }
                   8009:     var oldVal;
                   8010:     for (var j=0; j<maxh; j++) {
                   8011:         if (current[j] == undefined) {
                   8012:             oldVal = j;
                   8013:         }
                   8014:     }
                   8015:     if (oldVal < changedVal) {
                   8016:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   8017:            var elementName = current[k];
                   8018:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   8019:         }
                   8020:     } else {
                   8021:         for (var k=changedVal; k<oldVal; k++) {
                   8022:             var elementName = current[k];
                   8023:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   8024:         }
                   8025:     }
                   8026:     return;
                   8027: }
1.120     raeburn  8028: 
                   8029: function categoryCheck(form) {
                   8030:     if (form.elements['addcategory_name'].value == 'instcode') {
                   8031:         alert('$instcode_reserved\\n$choose_again');
                   8032:         return false;
                   8033:     }
                   8034:     if (form.elements['addcategory_name'].value == 'communities') {
                   8035:         alert('$communities_reserved\\n$choose_again');
                   8036:         return false;
                   8037:     }
                   8038:     return true;
                   8039: }
                   8040: 
1.109     raeburn  8041: // ]]>
1.49      raeburn  8042: </script>
                   8043: 
                   8044: ENDSCRIPT
                   8045:     return $output;
                   8046: }
                   8047: 
1.48      raeburn  8048: sub initialize_categories {
                   8049:     my ($itemcount) = @_;
1.120     raeburn  8050:     my ($datatable,$css_class,$chgstr);
                   8051:     my %default_names = (
                   8052:                       instcode    => 'Official courses (with institutional codes)',
                   8053:                       communities => 'Communities',
                   8054:                         );
                   8055:     my $select0 = ' selected="selected"';
                   8056:     my $select1 = '';
                   8057:     foreach my $default ('instcode','communities') {
                   8058:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87  raeburn  8059:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120     raeburn  8060:         if ($default eq 'communities') {
                   8061:             $select1 = $select0;
                   8062:             $select0 = '';
                   8063:         }
                   8064:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   8065:                      .'<select name="'.$default.'_pos">'
                   8066:                      .'<option value="0"'.$select0.'>1</option>'
                   8067:                      .'<option value="1"'.$select1.'>2</option>'
                   8068:                      .'<option value="2">3</option></select>&nbsp;'
                   8069:                      .$default_names{$default}
                   8070:                      .'</span></td><td><span class="LC_nobreak">'
                   8071:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   8072:                      .&mt('Display').'</label>&nbsp;<label>'
                   8073:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  8074:                  .'</label></span></td></tr>';
1.120     raeburn  8075:         $itemcount ++;
                   8076:     }
1.48      raeburn  8077:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  8078:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  8079:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  8080:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   8081:                   .'<option value="0">1</option>'
                   8082:                   .'<option value="1">2</option>'
                   8083:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.160.6.102.2  2(raebur 8084:0):                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87  raeburn  8085:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   8086:                   .'</td></tr>';
1.48      raeburn  8087:     return $datatable;
                   8088: }
                   8089: 
                   8090: sub build_category_rows {
1.49      raeburn  8091:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   8092:     my ($text,$name,$item,$chgstr);
1.48      raeburn  8093:     if (ref($cats) eq 'ARRAY') {
                   8094:         my $maxdepth = scalar(@{$cats});
                   8095:         if (ref($cats->[$depth]) eq 'HASH') {
                   8096:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   8097:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   8098:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23  raeburn  8099:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  8100:                 my ($idxnum,$parent_name,$parent_item);
                   8101:                 my $higher = $depth - 1;
                   8102:                 if ($higher == 0) {
                   8103:                     $parent_name = &escape($parent).'::'.$higher;
                   8104:                 } else {
                   8105:                     if (ref($path) eq 'ARRAY') {
                   8106:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   8107:                     }
                   8108:                 }
                   8109:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  8110:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  8111:                     if ($j < $numchildren) {
1.48      raeburn  8112:                         $name = $cats->[$depth]{$parent}[$j];
                   8113:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  8114:                         $idxnum = $idx->{$item};
                   8115:                     } else {
                   8116:                         $name = $parent_name;
                   8117:                         $item = $parent_item;
1.48      raeburn  8118:                     }
1.49      raeburn  8119:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   8120:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  8121:                     for (my $i=0; $i<=$numchildren; $i++) {
                   8122:                         my $vpos = $i+1;
                   8123:                         my $selstr;
                   8124:                         if ($j == $i) {
                   8125:                             $selstr = ' selected="selected" ';
                   8126:                         }
                   8127:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   8128:                     }
                   8129:                     $text .= '</select>&nbsp;';
                   8130:                     if ($j < $numchildren) {
                   8131:                         my $deeper = $depth+1;
                   8132:                         $text .= $name.'&nbsp;'
                   8133:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   8134:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   8135:                         if(ref($path) eq 'ARRAY') {
                   8136:                             push(@{$path},$name);
1.49      raeburn  8137:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  8138:                             pop(@{$path});
                   8139:                         }
                   8140:                     } else {
1.160.6.87  raeburn  8141:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  8142:                         if ($j == $numchildren) {
                   8143:                             $text .= $name;
                   8144:                         } else {
                   8145:                             $text .= $item;
                   8146:                         }
                   8147:                         $text .= '" value="" />';
                   8148:                     }
                   8149:                     $text .= '</td></tr>';
                   8150:                 }
                   8151:                 $text .= '</table></td>';
                   8152:             } else {
                   8153:                 my $higher = $depth-1;
                   8154:                 if ($higher == 0) {
                   8155:                     $name = &escape($parent).'::'.$higher;
                   8156:                 } else {
                   8157:                     if (ref($path) eq 'ARRAY') {
                   8158:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   8159:                     }
                   8160:                 }
                   8161:                 my $colspan;
                   8162:                 if ($parent ne 'instcode') {
                   8163:                     $colspan = $maxdepth - $depth - 1;
1.160.6.87  raeburn  8164:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  8165:                 }
                   8166:             }
                   8167:         }
                   8168:     }
                   8169:     return $text;
                   8170: }
                   8171: 
1.33      raeburn  8172: sub modifiable_userdata_row {
1.160.6.93  raeburn  8173:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
                   8174:         $rowid,$customcss,$rowstyle) = @_;
1.160.6.35  raeburn  8175:     my ($role,$rolename,$statustype);
                   8176:     $role = $item;
1.160.6.34  raeburn  8177:     if ($context eq 'cancreate') {
1.160.6.93  raeburn  8178:         if ($item =~ /^(emailusername)_(.+)$/) {
                   8179:             $role = $1;
                   8180:             $statustype = $2;
1.160.6.35  raeburn  8181:             if (ref($usertypes) eq 'HASH') {
                   8182:                 if ($usertypes->{$statustype}) {
                   8183:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   8184:                 } else {
                   8185:                     $rolename = &mt('Data provided by user');
                   8186:                 }
                   8187:             }
1.160.6.34  raeburn  8188:         }
                   8189:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  8190:         if (ref($usertypes) eq 'HASH') {
                   8191:             $rolename = $usertypes->{$role};
                   8192:         } else {
                   8193:             $rolename = $role;
                   8194:         }
1.33      raeburn  8195:     } else {
1.63      raeburn  8196:         if ($role eq 'cr') {
                   8197:             $rolename = &mt('Custom role');
                   8198:         } else {
                   8199:             $rolename = &Apache::lonnet::plaintext($role);
                   8200:         }
1.33      raeburn  8201:     }
1.160.6.34  raeburn  8202:     my (@fields,%fieldtitles);
                   8203:     if (ref($fieldsref) eq 'ARRAY') {
                   8204:         @fields = @{$fieldsref};
                   8205:     } else {
                   8206:         @fields = ('lastname','firstname','middlename','generation',
                   8207:                    'permanentemail','id');
                   8208:     }
                   8209:     if ((ref($titlesref) eq 'HASH')) {
                   8210:         %fieldtitles = %{$titlesref};
                   8211:     } else {
                   8212:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   8213:     }
1.33      raeburn  8214:     my $output;
1.160.6.93  raeburn  8215:     my $css_class;
                   8216:     if ($rowcount%2) {
                   8217:         $css_class = 'LC_odd_row';
                   8218:     }
                   8219:     if ($customcss) {
                   8220:         $css_class .= " $customcss";
                   8221:     }
                   8222:     $css_class =~ s/^\s+//;
                   8223:     if ($css_class) {
                   8224:         $css_class = ' class="'.$css_class.'"';
                   8225:     }
                   8226:     if ($rowstyle) {
                   8227:         $css_class .= ' style="'.$rowstyle.'"';
                   8228:     }
                   8229:     if ($rowid) {
                   8230:         $rowid = ' id="'.$rowid.'"';
                   8231:     }
                   8232: 
                   8233:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  8234:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   8235:               '<td class="LC_left_item" colspan="2"><table>';
                   8236:     my $rem;
                   8237:     my %checks;
                   8238:     if (ref($settings) eq 'HASH') {
                   8239:         if (ref($settings->{$context}) eq 'HASH') {
                   8240:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35  raeburn  8241:                 my $hashref = $settings->{$context}->{$role};
                   8242:                 if ($role eq 'emailusername') {
                   8243:                     if ($statustype) {
                   8244:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   8245:                             $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39  raeburn  8246:                             if (ref($hashref) eq 'HASH') { 
1.160.6.35  raeburn  8247:                                 foreach my $field (@fields) {
                   8248:                                     if ($hashref->{$field}) {
                   8249:                                         $checks{$field} = $hashref->{$field};
                   8250:                                     }
                   8251:                                 }
                   8252:                             }
                   8253:                         }
                   8254:                     }
                   8255:                 } else {
                   8256:                     if (ref($hashref) eq 'HASH') {
                   8257:                         foreach my $field (@fields) {
                   8258:                             if ($hashref->{$field}) {
                   8259:                                 $checks{$field} = ' checked="checked" ';
                   8260:                             }
                   8261:                         }
1.33      raeburn  8262:                     }
                   8263:                 }
                   8264:             }
                   8265:         }
                   8266:     }
1.160.6.93  raeburn  8267: 
                   8268:     my $total = scalar(@fields);
                   8269:     for (my $i=0; $i<$total; $i++) {
                   8270:         $rem = $i%($numinrow);
1.33      raeburn  8271:         if ($rem == 0) {
                   8272:             if ($i > 0) {
                   8273:                 $output .= '</tr>';
                   8274:             }
                   8275:             $output .= '<tr>';
                   8276:         }
                   8277:         my $check = ' ';
1.160.6.35  raeburn  8278:         unless ($role eq 'emailusername') {
                   8279:             if (exists($checks{$fields[$i]})) {
1.160.6.98  raeburn  8280:                 $check = $checks{$fields[$i]};
1.160.6.35  raeburn  8281:             } else {
                   8282:                 if ($role eq 'st') {
                   8283:                     if (ref($settings) ne 'HASH') {
1.160.6.39  raeburn  8284:                         $check = ' checked="checked" '; 
1.160.6.35  raeburn  8285:                     }
1.33      raeburn  8286:                 }
                   8287:             }
                   8288:         }
                   8289:         $output .= '<td class="LC_left_item">'.
1.160.6.35  raeburn  8290:                    '<span class="LC_nobreak">';
                   8291:         if ($role eq 'emailusername') {
                   8292:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   8293:                 $checks{$fields[$i]} = 'omit';
                   8294:             }
                   8295:             foreach my $option ('required','optional','omit') {
                   8296:                 my $checked='';
                   8297:                 if ($checks{$fields[$i]} eq $option) {
                   8298:                     $checked='checked="checked" ';
                   8299:                 }
                   8300:                 $output .= '<label>'.
                   8301:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   8302:                            &mt($option).'</label>'.('&nbsp;' x2);
                   8303:             }
                   8304:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   8305:         } else {
                   8306:             $output .= '<label>'.
                   8307:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   8308:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   8309:                        '</label>';
                   8310:         }
                   8311:         $output .= '</span></td>';
1.33      raeburn  8312:     }
1.160.6.93  raeburn  8313:     $rem = $total%$numinrow;
                   8314:     my $colsleft;
                   8315:     if ($rem) {
                   8316:         $colsleft = $numinrow - $rem;
                   8317:     }
                   8318:     if ($colsleft > 1) {
1.33      raeburn  8319:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8320:                    '&nbsp;</td>';
                   8321:     } elsif ($colsleft == 1) {
                   8322:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   8323:     }
                   8324:     $output .= '</tr></table></td></tr>';
                   8325:     return $output;
                   8326: }
1.28      raeburn  8327: 
1.93      raeburn  8328: sub insttypes_row {
1.160.6.93  raeburn  8329:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   8330:         $customcss,$rowstyle) = @_;
1.93      raeburn  8331:     my %lt = &Apache::lonlocal::texthash (
                   8332:                       cansearch => 'Users allowed to search',
                   8333:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  8334:                       lockablenames => 'User preference to lock name',
1.160.6.93  raeburn  8335:                       selfassign    => 'Self-reportable affiliations',
1.160.6.101  raeburn  8336:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  8337:              );
                   8338:     my $showdom;
                   8339:     if ($context eq 'cansearch') {
                   8340:         $showdom = ' ('.$dom.')';
                   8341:     }
1.160.6.5  raeburn  8342:     my $class = 'LC_left_item';
                   8343:     if ($context eq 'statustocreate') {
                   8344:         $class = 'LC_right_item';
                   8345:     }
1.160.6.93  raeburn  8346:     my $css_class;
                   8347:     if ($$rowtotal%2) {
                   8348:         $css_class = 'LC_odd_row';
                   8349:     }
                   8350:     if ($customcss) {
                   8351:         $css_class .= ' '.$customcss;
                   8352:     }
                   8353:     $css_class =~ s/^\s+//;
                   8354:     if ($css_class) {
                   8355:         $css_class = ' class="'.$css_class.'"';
                   8356:     }
                   8357:     if ($rowstyle) {
                   8358:         $css_class .= ' style="'.$rowstyle.'"';
                   8359:     }
                   8360:     if ($onclick) {
                   8361:         $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34  raeburn  8362:     }
                   8363:     my $output = '<tr'.$css_class.'>'.
                   8364:                  '<td>'.$lt{$context}.$showdom.
                   8365:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  8366:     my $rem;
                   8367:     if (ref($types) eq 'ARRAY') {
                   8368:         for (my $i=0; $i<@{$types}; $i++) {
                   8369:             if (defined($usertypes->{$types->[$i]})) {
                   8370:                 my $rem = $i%($numinrow);
                   8371:                 if ($rem == 0) {
                   8372:                     if ($i > 0) {
                   8373:                         $output .= '</tr>';
                   8374:                     }
                   8375:                     $output .= '<tr>';
1.23      raeburn  8376:                 }
1.26      raeburn  8377:                 my $check = ' ';
1.99      raeburn  8378:                 if (ref($settings) eq 'HASH') {
                   8379:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   8380:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   8381:                             $check = ' checked="checked" ';
                   8382:                         }
1.160.6.101  raeburn  8383:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   8384:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   8385:                             $check = ' checked="checked" ';
                   8386:                         }
1.99      raeburn  8387:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  8388:                         $check = ' checked="checked" ';
                   8389:                     }
1.23      raeburn  8390:                 }
1.26      raeburn  8391:                 $output .= '<td class="LC_left_item">'.
                   8392:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  8393:                            '<input type="checkbox" name="'.$context.'" '.
1.160.6.93  raeburn  8394:                            'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26      raeburn  8395:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  8396:             }
                   8397:         }
1.26      raeburn  8398:         $rem = @{$types}%($numinrow);
1.23      raeburn  8399:     }
                   8400:     my $colsleft = $numinrow - $rem;
1.160.6.101  raeburn  8401:     if ($context eq 'overrides') {
                   8402:         if ($colsleft > 1) {
                   8403:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   8404:         } else {
                   8405:             $output .= '<td class="LC_left_item">';
                   8406:         }
                   8407:         $output .= '&nbsp;';
1.23      raeburn  8408:     } else {
1.160.6.101  raeburn  8409:         if ($rem == 0) {
                   8410:             $output .= '<tr>';
                   8411:         }
                   8412:         if ($colsleft > 1) {
                   8413:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   8414:         } else {
                   8415:             $output .= '<td class="LC_left_item">';
                   8416:         }
                   8417:         my $defcheck = ' ';
                   8418:         if (ref($settings) eq 'HASH') {  
                   8419:             if (ref($settings->{$context}) eq 'ARRAY') {
                   8420:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   8421:                     $defcheck = ' checked="checked" ';
                   8422:                 }
                   8423:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  8424:                 $defcheck = ' checked="checked" ';
                   8425:             }
1.26      raeburn  8426:         }
1.160.6.101  raeburn  8427:         $output .= '<span class="LC_nobreak"><label>'.
                   8428:                    '<input type="checkbox" name="'.$context.'" '.
                   8429:                    'value="default"'.$defcheck.$onclick.' />'.
                   8430:                    $othertitle.'</label></span>';
1.23      raeburn  8431:     }
1.160.6.101  raeburn  8432:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  8433:     return $output;
1.23      raeburn  8434: }
                   8435: 
                   8436: sub sorted_searchtitles {
                   8437:     my %searchtitles = &Apache::lonlocal::texthash(
                   8438:                          'uname' => 'username',
                   8439:                          'lastname' => 'last name',
                   8440:                          'lastfirst' => 'last name, first name',
                   8441:                      );
                   8442:     my @titleorder = ('uname','lastname','lastfirst');
                   8443:     return (\%searchtitles,\@titleorder);
                   8444: }
                   8445: 
1.25      raeburn  8446: sub sorted_searchtypes {
                   8447:     my %srchtypes_desc = (
                   8448:                            exact    => 'is exact match',
                   8449:                            contains => 'contains ..',
                   8450:                            begins   => 'begins with ..',
                   8451:                          );
                   8452:     my @srchtypeorder = ('exact','begins','contains');
                   8453:     return (\%srchtypes_desc,\@srchtypeorder);
                   8454: }
                   8455: 
1.3       raeburn  8456: sub usertype_update_row {
                   8457:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   8458:     my $datatable;
                   8459:     my $numinrow = 4;
                   8460:     foreach my $type (@{$types}) {
                   8461:         if (defined($usertypes->{$type})) {
                   8462:             $$rownums ++;
                   8463:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   8464:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   8465:                           '</td><td class="LC_left_item"><table>';
                   8466:             for (my $i=0; $i<@{$fields}; $i++) {
                   8467:                 my $rem = $i%($numinrow);
                   8468:                 if ($rem == 0) {
                   8469:                     if ($i > 0) {
                   8470:                         $datatable .= '</tr>';
                   8471:                     }
                   8472:                     $datatable .= '<tr>';
                   8473:                 }
                   8474:                 my $check = ' ';
1.39      raeburn  8475:                 if (ref($settings) eq 'HASH') {
                   8476:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   8477:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   8478:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   8479:                                 $check = ' checked="checked" ';
                   8480:                             }
1.3       raeburn  8481:                         }
                   8482:                     }
                   8483:                 }
                   8484: 
                   8485:                 if ($i == @{$fields}-1) {
                   8486:                     my $colsleft = $numinrow - $rem;
                   8487:                     if ($colsleft > 1) {
                   8488:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   8489:                     } else {
                   8490:                         $datatable .= '<td>';
                   8491:                     }
                   8492:                 } else {
                   8493:                     $datatable .= '<td>';
                   8494:                 }
1.8       raeburn  8495:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   8496:                               '<input type="checkbox" name="updateable_'.$type.
                   8497:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   8498:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  8499:             }
                   8500:             $datatable .= '</tr></table></td></tr>';
                   8501:         }
                   8502:     }
                   8503:     return $datatable;
1.1       raeburn  8504: }
                   8505: 
                   8506: sub modify_login {
1.160.6.24  raeburn  8507:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  8508:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   8509:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   8510:     %title = ( coursecatalog => 'Display course catalog',
                   8511:                adminmail => 'Display administrator E-mail address',
1.160.6.14  raeburn  8512:                helpdesk  => 'Display "Contact Helpdesk" link',
1.160.6.5  raeburn  8513:                newuser => 'Link for visitors to create a user account',
                   8514:                loginheader => 'Log-in box header');
                   8515:     @offon = ('off','on');
1.112     raeburn  8516:     if (ref($domconfig{login}) eq 'HASH') {
                   8517:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   8518:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   8519:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   8520:             }
                   8521:         }
                   8522:     }
1.9       raeburn  8523:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   8524:                                            \%domconfig,\%loginhash);
1.160.6.14  raeburn  8525:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8526:     foreach my $item (@toggles) {
                   8527:         $loginhash{login}{$item} = $env{'form.'.$item};
                   8528:     }
1.41      raeburn  8529:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  8530:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   8531:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   8532:                                          \%loginhash);
                   8533:     }
1.110     raeburn  8534: 
1.149     raeburn  8535:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56  raeburn  8536:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  8537:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  8538:     if (keys(%servers) > 1) {
                   8539:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  8540:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   8541:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   8542:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   8543:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   8544:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   8545:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8546:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8547:                         $changes{'loginvia'}{$lonhost} = 1;
                   8548:                     } else {
                   8549:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   8550:                         $changes{'loginvia'}{$lonhost} = 1;
                   8551:                     }
                   8552:                 } else {
                   8553:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8554:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   8555:                         $changes{'loginvia'}{$lonhost} = 1;
                   8556:                     }
                   8557:                 }
                   8558:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   8559:                     foreach my $item (@loginvia_attribs) {
                   8560:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   8561:                     }
                   8562:                 } else {
                   8563:                     foreach my $item (@loginvia_attribs) {
                   8564:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8565:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8566:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   8567:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8568:                                 $new = '/';
                   8569:                             }
                   8570:                         }
                   8571:                         if (($item eq 'custompath') && 
                   8572:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8573:                             $new = '';
                   8574:                         }
                   8575:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   8576:                             $changes{'loginvia'}{$lonhost} = 1;
                   8577:                         }
                   8578:                         if ($item eq 'exempt') {
1.160.6.56  raeburn  8579:                             $new = &check_exempt_addresses($new);
1.128     raeburn  8580:                         }
                   8581:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8582:                     }
                   8583:                 }
1.112     raeburn  8584:             } else {
1.128     raeburn  8585:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   8586:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  8587:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  8588:                     foreach my $item (@loginvia_attribs) {
                   8589:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   8590:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   8591:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   8592:                                 $new = '/';
                   8593:                             }
                   8594:                         }
                   8595:                         if (($item eq 'custompath') && 
                   8596:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   8597:                             $new = '';
                   8598:                         }
                   8599:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   8600:                     }
1.110     raeburn  8601:                 }
                   8602:             }
                   8603:         }
                   8604:     }
1.119     raeburn  8605: 
1.160.6.5  raeburn  8606:     my $servadm = $r->dir_config('lonAdmEMail');
                   8607:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   8608:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8609:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   8610:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   8611:                 if ($lang eq 'nolang') {
                   8612:                     push(@currlangs,$lang);
                   8613:                 } elsif (defined($langchoices{$lang})) {
                   8614:                     push(@currlangs,$lang);
                   8615:                 } else {
                   8616:                     next;
                   8617:                 }
                   8618:             }
                   8619:         }
                   8620:     }
                   8621:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   8622:     if (@currlangs > 0) {
                   8623:         foreach my $lang (@currlangs) {
                   8624:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8625:                 $changes{'helpurl'}{$lang} = 1;
                   8626:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   8627:                 $changes{'helpurl'}{$lang} = 1;
                   8628:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   8629:                 push(@newlangs,$lang);
                   8630:             } else {
                   8631:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8632:             }
                   8633:         }
                   8634:     }
                   8635:     unless (grep(/^nolang$/,@currlangs)) {
                   8636:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   8637:             $changes{'helpurl'}{'nolang'} = 1;
                   8638:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   8639:             push(@newlangs,'nolang');
                   8640:         }
                   8641:     }
                   8642:     if ($env{'form.loginhelpurl_add_lang'}) {
                   8643:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   8644:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   8645:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   8646:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   8647:         }
                   8648:     }
                   8649:     if ((@newlangs > 0) || ($addedfile)) {
                   8650:         my $error;
                   8651:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8652:         if ($configuserok eq 'ok') {
                   8653:             if ($switchserver) {
                   8654:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   8655:             } elsif ($author_ok eq 'ok') {
                   8656:                 my @allnew = @newlangs;
                   8657:                 if ($addedfile ne '') {
                   8658:                     push(@allnew,$addedfile);
                   8659:                 }
                   8660:                 foreach my $lang (@allnew) {
                   8661:                     my $formelem = 'loginhelpurl_'.$lang;
                   8662:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   8663:                         $formelem = 'loginhelpurl_add_file';
                   8664:                     }
                   8665:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8666:                                                                "help/$lang",'','',$newfile{$lang});
                   8667:                     if ($result eq 'ok') {
                   8668:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   8669:                         $changes{'helpurl'}{$lang} = 1;
                   8670:                     } else {
                   8671:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   8672:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   8673:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                   8674:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   8675:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   8676:                         }
                   8677:                     }
                   8678:                 }
                   8679:             } else {
                   8680:                 $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);
                   8681:             }
                   8682:         } else {
                   8683:             $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);
                   8684:         }
                   8685:         if ($error) {
                   8686:             &Apache::lonnet::logthis($error);
                   8687:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8688:         }
                   8689:     }
1.160.6.56  raeburn  8690: 
                   8691:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   8692:     if (ref($domconfig{'login'}) eq 'HASH') {
                   8693:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   8694:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   8695:                 if ($domservers{$lonhost}) {
                   8696:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8697:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73  raeburn  8698:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56  raeburn  8699:                     }
                   8700:                 }
                   8701:             }
                   8702:         }
                   8703:     }
                   8704:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   8705:     foreach my $lonhost (sort(keys(%domservers))) {
                   8706:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8707:             $changes{'headtag'}{$lonhost} = 1;
                   8708:         } else {
                   8709:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   8710:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   8711:             }
                   8712:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   8713:                 push(@newhosts,$lonhost);
                   8714:             } elsif ($currheadtagurls{$lonhost}) {
                   8715:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   8716:                 if ($currexempt{$lonhost}) {
                   8717:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
                   8718:                         $changes{'headtag'}{$lonhost} = 1;
                   8719:                     }
                   8720:                 } elsif ($possexempt{$lonhost}) {
                   8721:                     $changes{'headtag'}{$lonhost} = 1;
                   8722:                 }
                   8723:                 if ($possexempt{$lonhost}) {
                   8724:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8725:                 }
                   8726:             }
                   8727:         }
                   8728:     }
                   8729:     if (@newhosts) {
                   8730:         my $error;
                   8731:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8732:         if ($configuserok eq 'ok') {
                   8733:             if ($switchserver) {
                   8734:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   8735:             } elsif ($author_ok eq 'ok') {
                   8736:                 foreach my $lonhost (@newhosts) {
                   8737:                     my $formelem = 'loginheadtag_'.$lonhost;
                   8738:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   8739:                                                                           "login/headtag/$lonhost",'','',
                   8740:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   8741:                     if ($result eq 'ok') {
                   8742:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   8743:                         $changes{'headtag'}{$lonhost} = 1;
                   8744:                         if ($possexempt{$lonhost}) {
                   8745:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   8746:                         }
                   8747:                     } else {
                   8748:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   8749:                                            $newheadtagurls{$lonhost},$result);
                   8750:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   8751:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   8752:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   8753:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   8754:                         }
                   8755:                     }
                   8756:                 }
                   8757:             } else {
                   8758:                 $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);
                   8759:             }
                   8760:         } else {
                   8761:             $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);
                   8762:         }
                   8763:         if ($error) {
                   8764:             &Apache::lonnet::logthis($error);
                   8765:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8766:         }
                   8767:     }
1.160.6.5  raeburn  8768:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
                   8769: 
                   8770:     my $defaulthelpfile = '/adm/loginproblems.html';
                   8771:     my $defaulttext = &mt('Default in use');
                   8772: 
1.1       raeburn  8773:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   8774:                                              $dom);
                   8775:     if ($putresult eq 'ok') {
1.160.6.14  raeburn  8776:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  8777:         my %defaultchecked = (
                   8778:                     'coursecatalog' => 'on',
1.160.6.14  raeburn  8779:                     'helpdesk'      => 'on',
1.42      raeburn  8780:                     'adminmail'     => 'off',
1.43      raeburn  8781:                     'newuser'       => 'off',
1.42      raeburn  8782:         );
1.55      raeburn  8783:         if (ref($domconfig{'login'}) eq 'HASH') {
                   8784:             foreach my $item (@toggles) {
                   8785:                 if ($defaultchecked{$item} eq 'on') { 
                   8786:                     if (($domconfig{'login'}{$item} eq '0') &&
                   8787:                         ($env{'form.'.$item} eq '1')) {
                   8788:                         $changes{$item} = 1;
                   8789:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8790:                               $domconfig{'login'}{$item} eq '1') &&
                   8791:                              ($env{'form.'.$item} eq '0')) {
                   8792:                         $changes{$item} = 1;
                   8793:                     }
                   8794:                 } elsif ($defaultchecked{$item} eq 'off') {
                   8795:                     if (($domconfig{'login'}{$item} eq '1') &&
                   8796:                         ($env{'form.'.$item} eq '0')) {
                   8797:                         $changes{$item} = 1;
                   8798:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   8799:                               $domconfig{'login'}{$item} eq '0') &&
                   8800:                              ($env{'form.'.$item} eq '1')) {
                   8801:                         $changes{$item} = 1;
                   8802:                     }
1.42      raeburn  8803:                 }
                   8804:             }
1.41      raeburn  8805:         }
1.6       raeburn  8806:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  8807:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  8808:             if (ref($lastactref) eq 'HASH') {
                   8809:                 $lastactref->{'domainconfig'} = 1;
                   8810:             }
1.1       raeburn  8811:             $resulttext = &mt('Changes made:').'<ul>';
                   8812:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   8813:                 if ($item eq 'loginvia') {
1.112     raeburn  8814:                     if (ref($changes{$item}) eq 'HASH') {
                   8815:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   8816:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  8817:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   8818:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   8819:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   8820:                                     $protocol = 'http' if ($protocol ne 'https');
                   8821:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   8822: 
                   8823:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   8824:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   8825:                                     } else {
                   8826:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   8827:                                     }
                   8828:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   8829:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   8830:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   8831:                                     }
                   8832:                                     $resulttext .= '</li>';
                   8833:                                 } else {
                   8834:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   8835:                                 }
1.112     raeburn  8836:                             } else {
1.128     raeburn  8837:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  8838:                             }
                   8839:                         }
1.128     raeburn  8840:                         $resulttext .= '</ul></li>';
1.112     raeburn  8841:                     }
1.160.6.5  raeburn  8842:                 } elsif ($item eq 'helpurl') {
                   8843:                     if (ref($changes{$item}) eq 'HASH') {
                   8844:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   8845:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   8846:                                 my ($chg,$link);
                   8847:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   8848:                                 if ($lang eq 'nolang') {
                   8849:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   8850:                                 } else {
                   8851:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   8852:                                 }
                   8853:                                 $resulttext .= '<li>'.$chg.'</li>';
                   8854:                             } else {
                   8855:                                 my $chg;
                   8856:                                 if ($lang eq 'nolang') {
                   8857:                                     $chg = &mt('custom log-in help file for no preferred language');
                   8858:                                 } else {
                   8859:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   8860:                                 }
                   8861:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   8862:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   8863:                                                       '?inhibitmenu=yes',$chg,600,500).
                   8864:                                                '</li>';
                   8865:                             }
                   8866:                         }
                   8867:                     }
1.160.6.56  raeburn  8868:                 } elsif ($item eq 'headtag') {
                   8869:                     if (ref($changes{$item}) eq 'HASH') {
                   8870:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   8871:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   8872:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   8873:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   8874:                                 $resulttext .= '<li><a href="'.
                   8875:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   8876:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   8877:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   8878:                                 if ($possexempt{$lonhost}) {
                   8879:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   8880:                                 } else {
                   8881:                                     $resulttext .= &mt('included for any client IP');
                   8882:                                 }
                   8883:                                 $resulttext .= '</li>';
                   8884:                             }
                   8885:                         }
                   8886:                     }
1.160.6.5  raeburn  8887:                 } elsif ($item eq 'captcha') {
                   8888:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8889:                         my $chgtxt;
                   8890:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   8891:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   8892:                         } else {
                   8893:                             my %captchas = &captcha_phrases();
                   8894:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   8895:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   8896:                             } else {
                   8897:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   8898:                             }
                   8899:                         }
                   8900:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8901:                     }
                   8902:                 } elsif ($item eq 'recaptchakeys') {
                   8903:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8904:                         my ($privkey,$pubkey);
                   8905:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   8906:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   8907:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   8908:                         }
                   8909:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   8910:                         if (!$pubkey) {
                   8911:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   8912:                         } else {
                   8913:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   8914:                         }
                   8915:                         if (!$privkey) {
                   8916:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   8917:                         } else {
1.160.6.53  raeburn  8918:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5  raeburn  8919:                         }
                   8920:                         $chgtxt .= '</ul>';
                   8921:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   8922:                     }
1.160.6.69  raeburn  8923:                 } elsif ($item eq 'recaptchaversion') {
                   8924:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   8925:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
                   8926:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                   8927:                                            '</li>';
                   8928:                         }
                   8929:                     }
1.41      raeburn  8930:                 } else {
                   8931:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   8932:                 }
1.1       raeburn  8933:             }
1.6       raeburn  8934:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  8935:         } else {
                   8936:             $resulttext = &mt('No changes made to log-in page settings');
                   8937:         }
                   8938:     } else {
1.11      albertel 8939:         $resulttext = '<span class="LC_error">'.
                   8940: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8941:     }
1.6       raeburn  8942:     if ($errors) {
1.9       raeburn  8943:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  8944:                        $errors.'</ul>';
                   8945:     }
                   8946:     return $resulttext;
                   8947: }
                   8948: 
1.160.6.56  raeburn  8949: sub check_exempt_addresses {
                   8950:     my ($iplist) = @_;
                   8951:     $iplist =~ s/^\s+//;
                   8952:     $iplist =~ s/\s+$//;
                   8953:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   8954:     my (@okips,$new);
                   8955:     foreach my $ip (@poss_ips) {
                   8956:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   8957:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   8958:                 push(@okips,$ip);
                   8959:             }
                   8960:         }
                   8961:     }
                   8962:     if (@okips > 0) {
                   8963:         $new = join(',',@okips);
                   8964:     } else {
                   8965:         $new = '';
                   8966:     }
                   8967:     return $new;
                   8968: }
                   8969: 
1.6       raeburn  8970: sub color_font_choices {
                   8971:     my %choices =
                   8972:         &Apache::lonlocal::texthash (
                   8973:             img => "Header",
                   8974:             bgs => "Background colors",
                   8975:             links => "Link colors",
1.55      raeburn  8976:             images => "Images",
1.6       raeburn  8977:             font => "Font color",
1.160.6.22  raeburn  8978:             fontmenu => "Font menu",
1.76      raeburn  8979:             pgbg => "Page",
1.6       raeburn  8980:             tabbg => "Header",
                   8981:             sidebg => "Border",
                   8982:             link => "Link",
                   8983:             alink => "Active link",
                   8984:             vlink => "Visited link",
                   8985:         );
                   8986:     return %choices;
                   8987: }
                   8988: 
                   8989: sub modify_rolecolors {
1.160.6.24  raeburn  8990:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  8991:     my ($resulttext,%rolehash);
                   8992:     $rolehash{'rolecolors'} = {};
1.55      raeburn  8993:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   8994:         if ($domconfig{'rolecolors'} eq '') {
                   8995:             $domconfig{'rolecolors'} = {};
                   8996:         }
                   8997:     }
1.9       raeburn  8998:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  8999:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   9000:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   9001:                                              $dom);
                   9002:     if ($putresult eq 'ok') {
                   9003:         if (keys(%changes) > 0) {
1.41      raeburn  9004:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  9005:             if (ref($lastactref) eq 'HASH') {
                   9006:                 $lastactref->{'domainconfig'} = 1;
                   9007:             }
1.6       raeburn  9008:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   9009:                                              $rolehash{'rolecolors'});
                   9010:         } else {
                   9011:             $resulttext = &mt('No changes made to default color schemes');
                   9012:         }
                   9013:     } else {
1.11      albertel 9014:         $resulttext = '<span class="LC_error">'.
                   9015: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  9016:     }
                   9017:     if ($errors) {
                   9018:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   9019:                        $errors.'</ul>';
                   9020:     }
                   9021:     return $resulttext;
                   9022: }
                   9023: 
                   9024: sub modify_colors {
1.9       raeburn  9025:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  9026:     my (%changes,%choices);
1.51      raeburn  9027:     my @bgs;
1.6       raeburn  9028:     my @links = ('link','alink','vlink');
1.41      raeburn  9029:     my @logintext;
1.6       raeburn  9030:     my @images;
                   9031:     my $servadm = $r->dir_config('lonAdmEMail');
                   9032:     my $errors;
1.160.6.22  raeburn  9033:     my %defaults;
1.6       raeburn  9034:     foreach my $role (@{$roles}) {
                   9035:         if ($role eq 'login') {
1.12      raeburn  9036:             %choices = &login_choices();
1.41      raeburn  9037:             @logintext = ('textcol','bgcol');
1.12      raeburn  9038:         } else {
                   9039:             %choices = &color_font_choices();
                   9040:         }
                   9041:         if ($role eq 'login') {
1.41      raeburn  9042:             @images = ('img','logo','domlogo','login');
1.51      raeburn  9043:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  9044:         } else {
                   9045:             @images = ('img');
1.160.6.22  raeburn  9046:             @bgs = ('pgbg','tabbg','sidebg');
                   9047:         }
                   9048:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   9049:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   9050:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   9051:         }
                   9052:         if ($role eq 'login') {
                   9053:             foreach my $item (@logintext) {
1.160.6.39  raeburn  9054:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   9055:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   9056:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   9057:                 }
                   9058:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22  raeburn  9059:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   9060:                 }
                   9061:             }
                   9062:         } else {
1.160.6.39  raeburn  9063:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   9064:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   9065:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   9066:             }
                   9067:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22  raeburn  9068:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   9069:             }
1.6       raeburn  9070:         }
1.160.6.22  raeburn  9071:         foreach my $item (@bgs) {
1.160.6.39  raeburn  9072:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   9073:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   9074:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   9075:             }
                   9076:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22  raeburn  9077:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   9078:             }
                   9079:         }
                   9080:         foreach my $item (@links) {
1.160.6.39  raeburn  9081:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   9082:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   9083:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   9084:             }
                   9085:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22  raeburn  9086:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   9087:             }
1.6       raeburn  9088:         }
1.46      raeburn  9089:         my ($configuserok,$author_ok,$switchserver) = 
                   9090:             &config_check($dom,$confname,$servadm);
1.9       raeburn  9091:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  9092:         if (ref($domconfig->{$role}) ne 'HASH') {
                   9093:             $domconfig->{$role} = {};
                   9094:         }
1.8       raeburn  9095:         foreach my $img (@images) {
1.70      raeburn  9096:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   9097:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   9098:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   9099:                 } else { 
                   9100:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   9101:                 }
                   9102:             } 
1.18      albertel 9103: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   9104: 		 && !defined($domconfig->{$role}{$img})
                   9105: 		 && !$env{'form.'.$role.'_del_'.$img}
                   9106: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   9107: 		# import the old configured image from the .tab setting
                   9108: 		# if they haven't provided a new one 
                   9109: 		$domconfig->{$role}{$img} = 
                   9110: 		    $env{'form.'.$role.'_import_'.$img};
                   9111: 	    }
1.6       raeburn  9112:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  9113:                 my $error;
1.6       raeburn  9114:                 if ($configuserok eq 'ok') {
1.9       raeburn  9115:                     if ($switchserver) {
1.12      raeburn  9116:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  9117:                     } else {
                   9118:                         if ($author_ok eq 'ok') {
                   9119:                             my ($result,$logourl) = 
                   9120:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   9121:                                            $dom,$confname,$img,$width,$height);
                   9122:                             if ($result eq 'ok') {
                   9123:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  9124:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  9125:                             } else {
1.12      raeburn  9126:                                 $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  9127:                             }
                   9128:                         } else {
1.46      raeburn  9129:                             $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  9130:                         }
                   9131:                     }
                   9132:                 } else {
1.46      raeburn  9133:                     $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  9134:                 }
                   9135:                 if ($error) {
1.8       raeburn  9136:                     &Apache::lonnet::logthis($error);
1.11      albertel 9137:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  9138:                 }
                   9139:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  9140:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   9141:                     my $error;
                   9142:                     if ($configuserok eq 'ok') {
                   9143: # is confname an author?
                   9144:                         if ($switchserver eq '') {
                   9145:                             if ($author_ok eq 'ok') {
                   9146:                                 my ($result,$logourl) = 
                   9147:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   9148:                                             $dom,$confname,$img,$width,$height);
                   9149:                                 if ($result eq 'ok') {
                   9150:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 9151: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  9152:                                 }
                   9153:                             }
                   9154:                         }
                   9155:                     }
1.6       raeburn  9156:                 }
                   9157:             }
                   9158:         }
                   9159:         if (ref($domconfig) eq 'HASH') {
                   9160:             if (ref($domconfig->{$role}) eq 'HASH') {
                   9161:                 foreach my $img (@images) {
                   9162:                     if ($domconfig->{$role}{$img} ne '') {
                   9163:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   9164:                             $confhash->{$role}{$img} = '';
1.12      raeburn  9165:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  9166:                         } else {
1.9       raeburn  9167:                             if ($confhash->{$role}{$img} eq '') {
                   9168:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   9169:                             }
1.6       raeburn  9170:                         }
                   9171:                     } else {
                   9172:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   9173:                             $confhash->{$role}{$img} = '';
1.12      raeburn  9174:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  9175:                         } 
                   9176:                     }
1.70      raeburn  9177:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   9178:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   9179:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   9180:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   9181:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   9182:                             }
                   9183:                         } else {
                   9184:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   9185:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   9186:                             }
                   9187:                         }
                   9188:                     }
                   9189:                 }
1.6       raeburn  9190:                 if ($domconfig->{$role}{'font'} ne '') {
                   9191:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   9192:                         $changes{$role}{'font'} = 1;
                   9193:                     }
                   9194:                 } else {
                   9195:                     if ($confhash->{$role}{'font'}) {
                   9196:                         $changes{$role}{'font'} = 1;
                   9197:                     }
                   9198:                 }
1.107     raeburn  9199:                 if ($role ne 'login') {
                   9200:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   9201:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   9202:                             $changes{$role}{'fontmenu'} = 1;
                   9203:                         }
                   9204:                     } else {
                   9205:                         if ($confhash->{$role}{'fontmenu'}) {
                   9206:                             $changes{$role}{'fontmenu'} = 1;
                   9207:                         }
1.97      tempelho 9208:                     }
                   9209:                 }
1.6       raeburn  9210:                 foreach my $item (@bgs) {
                   9211:                     if ($domconfig->{$role}{$item} ne '') {
                   9212:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   9213:                             $changes{$role}{'bgs'}{$item} = 1;
                   9214:                         } 
                   9215:                     } else {
                   9216:                         if ($confhash->{$role}{$item}) {
                   9217:                             $changes{$role}{'bgs'}{$item} = 1;
                   9218:                         }
                   9219:                     }
                   9220:                 }
                   9221:                 foreach my $item (@links) {
                   9222:                     if ($domconfig->{$role}{$item} ne '') {
                   9223:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   9224:                             $changes{$role}{'links'}{$item} = 1;
                   9225:                         }
                   9226:                     } else {
                   9227:                         if ($confhash->{$role}{$item}) {
                   9228:                             $changes{$role}{'links'}{$item} = 1;
                   9229:                         }
                   9230:                     }
                   9231:                 }
1.41      raeburn  9232:                 foreach my $item (@logintext) {
                   9233:                     if ($domconfig->{$role}{$item} ne '') {
                   9234:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   9235:                             $changes{$role}{'logintext'}{$item} = 1;
                   9236:                         }
                   9237:                     } else {
                   9238:                         if ($confhash->{$role}{$item}) {
                   9239:                             $changes{$role}{'logintext'}{$item} = 1;
                   9240:                         }
                   9241:                     }
                   9242:                 }
1.6       raeburn  9243:             } else {
                   9244:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  9245:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  9246:             }
                   9247:         } else {
                   9248:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  9249:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  9250:         }
                   9251:     }
                   9252:     return ($errors,%changes);
                   9253: }
                   9254: 
1.46      raeburn  9255: sub config_check {
                   9256:     my ($dom,$confname,$servadm) = @_;
                   9257:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   9258:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   9259:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   9260:                                                    $confname,$servadm);
                   9261:     if ($configuserok eq 'ok') {
                   9262:         $switchserver = &check_switchserver($dom,$confname);
                   9263:         if ($switchserver eq '') {
                   9264:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   9265:         }
                   9266:     }
                   9267:     return ($configuserok,$author_ok,$switchserver);
                   9268: }
                   9269: 
1.6       raeburn  9270: sub default_change_checker {
1.41      raeburn  9271:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  9272:     foreach my $item (@{$links}) {
                   9273:         if ($confhash->{$role}{$item}) {
                   9274:             $changes->{$role}{'links'}{$item} = 1;
                   9275:         }
                   9276:     }
                   9277:     foreach my $item (@{$bgs}) {
                   9278:         if ($confhash->{$role}{$item}) {
                   9279:             $changes->{$role}{'bgs'}{$item} = 1;
                   9280:         }
                   9281:     }
1.41      raeburn  9282:     foreach my $item (@{$logintext}) {
                   9283:         if ($confhash->{$role}{$item}) {
                   9284:             $changes->{$role}{'logintext'}{$item} = 1;
                   9285:         }
                   9286:     }
1.6       raeburn  9287:     foreach my $img (@{$images}) {
                   9288:         if ($env{'form.'.$role.'_del_'.$img}) {
                   9289:             $confhash->{$role}{$img} = '';
1.12      raeburn  9290:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  9291:         }
1.70      raeburn  9292:         if ($role eq 'login') {
                   9293:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   9294:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   9295:             }
                   9296:         }
1.6       raeburn  9297:     }
                   9298:     if ($confhash->{$role}{'font'}) {
                   9299:         $changes->{$role}{'font'} = 1;
                   9300:     }
1.48      raeburn  9301: }
1.6       raeburn  9302: 
                   9303: sub display_colorchgs {
                   9304:     my ($dom,$changes,$roles,$confhash) = @_;
                   9305:     my (%choices,$resulttext);
                   9306:     if (!grep(/^login$/,@{$roles})) {
                   9307:         $resulttext = &mt('Changes made:').'<br />';
                   9308:     }
                   9309:     foreach my $role (@{$roles}) {
                   9310:         if ($role eq 'login') {
                   9311:             %choices = &login_choices();
                   9312:         } else {
                   9313:             %choices = &color_font_choices();
                   9314:         }
                   9315:         if (ref($changes->{$role}) eq 'HASH') {
                   9316:             if ($role ne 'login') {
                   9317:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   9318:             }
                   9319:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   9320:                 if ($role ne 'login') {
                   9321:                     $resulttext .= '<ul>';
                   9322:                 }
                   9323:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   9324:                     if ($role ne 'login') {
                   9325:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   9326:                     }
                   9327:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  9328:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   9329:                             if ($confhash->{$role}{$key}{$item}) {
                   9330:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   9331:                             } else {
                   9332:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   9333:                             }
                   9334:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  9335:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   9336:                         } else {
1.12      raeburn  9337:                             my $newitem = $confhash->{$role}{$item};
                   9338:                             if ($key eq 'images') {
                   9339:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   9340:                             }
                   9341:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  9342:                         }
                   9343:                     }
                   9344:                     if ($role ne 'login') {
                   9345:                         $resulttext .= '</ul></li>';
                   9346:                     }
                   9347:                 } else {
                   9348:                     if ($confhash->{$role}{$key} eq '') {
                   9349:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   9350:                     } else {
                   9351:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   9352:                     }
                   9353:                 }
                   9354:                 if ($role ne 'login') {
                   9355:                     $resulttext .= '</ul>';
                   9356:                 }
                   9357:             }
                   9358:         }
                   9359:     }
1.3       raeburn  9360:     return $resulttext;
1.1       raeburn  9361: }
                   9362: 
1.9       raeburn  9363: sub thumb_dimensions {
                   9364:     return ('200','50');
                   9365: }
                   9366: 
1.16      raeburn  9367: sub check_dimensions {
                   9368:     my ($inputfile) = @_;
                   9369:     my ($fullwidth,$fullheight);
                   9370:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   9371:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   9372:             my $imageinfo = <PIPE>;
                   9373:             if (!close(PIPE)) {
                   9374:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   9375:             }
                   9376:             chomp($imageinfo);
                   9377:             my ($fullsize) = 
1.21      raeburn  9378:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  9379:             if ($fullsize) {
                   9380:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   9381:             }
                   9382:         }
                   9383:     }
                   9384:     return ($fullwidth,$fullheight);
                   9385: }
                   9386: 
1.9       raeburn  9387: sub check_configuser {
                   9388:     my ($uhome,$dom,$confname,$servadm) = @_;
                   9389:     my ($configuserok,%currroles);
                   9390:     if ($uhome eq 'no_host') {
                   9391:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.160.6.98  raeburn  9392:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  9393:         $configuserok = 
                   9394:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   9395:                              $configpass,'','','','','',undef,$servadm);
                   9396:     } else {
                   9397:         $configuserok = 'ok';
                   9398:         %currroles = 
                   9399:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   9400:     }
                   9401:     return ($configuserok,%currroles);
                   9402: }
                   9403: 
                   9404: sub check_authorstatus {
                   9405:     my ($dom,$confname,%currroles) = @_;
                   9406:     my $author_ok;
1.40      raeburn  9407:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  9408:         my $start = time;
                   9409:         my $end = 0;
                   9410:         $author_ok = 
                   9411:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  9412:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  9413:     } else {
                   9414:         $author_ok = 'ok';
                   9415:     }
                   9416:     return $author_ok;
                   9417: }
                   9418: 
                   9419: sub publishlogo {
1.46      raeburn  9420:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  9421:     my ($output,$fname,$logourl);
                   9422:     if ($action eq 'upload') {
                   9423:         $fname=$env{'form.'.$formname.'.filename'};
                   9424:         chop($env{'form.'.$formname});
                   9425:     } else {
                   9426:         ($fname) = ($formname =~ /([^\/]+)$/);
                   9427:     }
1.46      raeburn  9428:     if ($savefileas ne '') {
                   9429:         $fname = $savefileas;
                   9430:     }
1.9       raeburn  9431:     $fname=&Apache::lonnet::clean_filename($fname);
                   9432: # See if there is anything left
                   9433:     unless ($fname) { return ('error: no uploaded file'); }
                   9434:     $fname="$subdir/$fname";
1.160.6.5  raeburn  9435:     my $docroot=$r->dir_config('lonDocRoot');
                   9436:     my $filepath="$docroot/priv";
                   9437:     my $relpath = "$dom/$confname";
1.9       raeburn  9438:     my ($fnamepath,$file,$fetchthumb);
                   9439:     $file=$fname;
                   9440:     if ($fname=~m|/|) {
                   9441:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   9442:     }
1.160.6.26  raeburn  9443:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  9444:     my $count;
1.160.6.5  raeburn  9445:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  9446:         $filepath.="/$parts[$count]";
                   9447:         if ((-e $filepath)!=1) {
                   9448:             mkdir($filepath,02770);
                   9449:         }
                   9450:     }
                   9451:     # Check for bad extension and disallow upload
                   9452:     if ($file=~/\.(\w+)$/ &&
                   9453:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   9454:         $output = 
1.160.6.25  raeburn  9455:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  9456:     } elsif ($file=~/\.(\w+)$/ &&
                   9457:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   9458:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   9459:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18  raeburn  9460:         $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  9461:     } elsif (-d "$filepath/$file") {
1.160.6.18  raeburn  9462:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  9463:     } else {
                   9464:         my $source = $filepath.'/'.$file;
                   9465:         my $logfile;
1.160.6.88  raeburn  9466:         if (!open($logfile,">>",$source.'.log')) {
1.160.6.19  raeburn  9467:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  9468:         }
                   9469:         print $logfile
                   9470: "\n================= Publish ".localtime()." ================\n".
                   9471: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   9472: # Save the file
1.160.6.88  raeburn  9473:         if (!open(FH,">",$source)) {
1.9       raeburn  9474:             &Apache::lonnet::logthis('Failed to create '.$source);
                   9475:             return (&mt('Failed to create file'));
                   9476:         }
                   9477:         if ($action eq 'upload') {
                   9478:             if (!print FH ($env{'form.'.$formname})) {
                   9479:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   9480:                 return (&mt('Failed to write file'));
                   9481:             }
                   9482:         } else {
                   9483:             my $original = &Apache::lonnet::filelocation('',$formname);
                   9484:             if(!copy($original,$source)) {
                   9485:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   9486:                 return (&mt('Failed to write file'));
                   9487:             }
                   9488:         }
                   9489:         close(FH);
                   9490:         chmod(0660, $source); # Permissions to rw-rw---.
                   9491: 
                   9492:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   9493:         my $copyfile=$targetdir.'/'.$file;
                   9494: 
                   9495:         my @parts=split(/\//,$targetdir);
                   9496:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   9497:         for (my $count=5;$count<=$#parts;$count++) {
                   9498:             $path.="/$parts[$count]";
                   9499:             if (!-e $path) {
                   9500:                 print $logfile "\nCreating directory ".$path;
                   9501:                 mkdir($path,02770);
                   9502:             }
                   9503:         }
                   9504:         my $versionresult;
                   9505:         if (-e $copyfile) {
                   9506:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   9507:         } else {
                   9508:             $versionresult = 'ok';
                   9509:         }
                   9510:         if ($versionresult eq 'ok') {
                   9511:             if (copy($source,$copyfile)) {
                   9512:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   9513:                 $output = 'ok';
                   9514:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  9515:                 push(@{$modified_urls},[$copyfile,$source]);
                   9516:                 my $metaoutput = 
                   9517:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   9518:                 unless ($registered_cleanup) {
                   9519:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9520:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9521:                     $registered_cleanup=1;
                   9522:                 }
1.9       raeburn  9523:             } else {
                   9524:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   9525:                 $output = &mt('Failed to copy file to RES space').", $!";
                   9526:             }
                   9527:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   9528:                 my $inputfile = $filepath.'/'.$file;
                   9529:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  9530:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   9531:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   9532:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   9533:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88  raeburn  9534:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   9535:                         system({$args[0]} @args);
1.16      raeburn  9536:                         chmod(0660, $filepath.'/tn-'.$file);
                   9537:                         if (-e $outfile) {
                   9538:                             my $copyfile=$targetdir.'/tn-'.$file;
                   9539:                             if (copy($outfile,$copyfile)) {
                   9540:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  9541:                                 my $thumb_metaoutput = 
                   9542:                                     &write_metadata($dom,$confname,$formname,
                   9543:                                                     $targetdir,'tn-'.$file,$logfile);
                   9544:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   9545:                                 unless ($registered_cleanup) {
                   9546:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   9547:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   9548:                                     $registered_cleanup=1;
                   9549:                                 }
1.16      raeburn  9550:                             } else {
                   9551:                                 print $logfile "\nUnable to write ".$copyfile.
                   9552:                                                ':'.$!."\n";
                   9553:                             }
                   9554:                         }
1.9       raeburn  9555:                     }
                   9556:                 }
                   9557:             }
                   9558:         } else {
                   9559:             $output = $versionresult;
                   9560:         }
                   9561:     }
                   9562:     return ($output,$logourl);
                   9563: }
                   9564: 
                   9565: sub logo_versioning {
                   9566:     my ($targetdir,$file,$logfile) = @_;
                   9567:     my $target = $targetdir.'/'.$file;
                   9568:     my ($maxversion,$fn,$extn,$output);
                   9569:     $maxversion = 0;
                   9570:     if ($file =~ /^(.+)\.(\w+)$/) {
                   9571:         $fn=$1;
                   9572:         $extn=$2;
                   9573:     }
                   9574:     opendir(DIR,$targetdir);
                   9575:     while (my $filename=readdir(DIR)) {
                   9576:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   9577:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   9578:         }
                   9579:     }
                   9580:     $maxversion++;
                   9581:     print $logfile "\nCreating old version ".$maxversion."\n";
                   9582:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   9583:     if (copy($target,$copyfile)) {
                   9584:         print $logfile "Copied old target to ".$copyfile."\n";
                   9585:         $copyfile=$copyfile.'.meta';
                   9586:         if (copy($target.'.meta',$copyfile)) {
                   9587:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   9588:             $output = 'ok';
                   9589:         } else {
                   9590:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   9591:             $output = &mt('Failed to copy old meta').", $!, ";
                   9592:         }
                   9593:     } else {
                   9594:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   9595:         $output = &mt('Failed to copy old target').", $!, ";
                   9596:     }
                   9597:     return $output;
                   9598: }
                   9599: 
                   9600: sub write_metadata {
                   9601:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   9602:     my (%metadatafields,%metadatakeys,$output);
                   9603:     $metadatafields{'title'}=$formname;
                   9604:     $metadatafields{'creationdate'}=time;
                   9605:     $metadatafields{'lastrevisiondate'}=time;
                   9606:     $metadatafields{'copyright'}='public';
                   9607:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   9608:                                          $env{'user.domain'};
                   9609:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   9610:     $metadatafields{'domain'}=$dom;
                   9611:     {
                   9612:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   9613:         my $mfh;
1.160.6.88  raeburn  9614:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13  raeburn  9615:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  9616:                 unless ($_=~/\./) {
                   9617:                     my $unikey=$_;
                   9618:                     $unikey=~/^([A-Za-z]+)/;
                   9619:                     my $tag=$1;
                   9620:                     $tag=~tr/A-Z/a-z/;
                   9621:                     print $mfh "\n\<$tag";
                   9622:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   9623:                         my $value=$metadatafields{$unikey.'.'.$_};
                   9624:                         $value=~s/\"/\'\'/g;
                   9625:                         print $mfh ' '.$_.'="'.$value.'"';
                   9626:                     }
                   9627:                     print $mfh '>'.
                   9628:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   9629:                             .'</'.$tag.'>';
                   9630:                 }
                   9631:             }
                   9632:             $output = 'ok';
                   9633:             print $logfile "\nWrote metadata";
                   9634:             close($mfh);
                   9635:         } else {
                   9636:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  9637:             $output = &mt('Could not write metadata');
                   9638:         }
                   9639:     }
1.155     raeburn  9640:     return $output;
                   9641: }
                   9642: 
                   9643: sub notifysubscribed {
                   9644:     foreach my $targetsource (@{$modified_urls}){
                   9645:         next unless (ref($targetsource) eq 'ARRAY');
                   9646:         my ($target,$source)=@{$targetsource};
                   9647:         if ($source ne '') {
1.160.6.88  raeburn  9648:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  9649:                 print $logfh "\nCleanup phase: Notifications\n";
                   9650:                 my @subscribed=&subscribed_hosts($target);
                   9651:                 foreach my $subhost (@subscribed) {
                   9652:                     print $logfh "\nNotifying host ".$subhost.':';
                   9653:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   9654:                     print $logfh $reply;
                   9655:                 }
                   9656:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   9657:                 foreach my $subhost (@subscribedmeta) {
                   9658:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   9659:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   9660:                                                         $subhost);
                   9661:                     print $logfh $reply;
                   9662:                 }
                   9663:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  9664:                 close($logfh);
1.155     raeburn  9665:             }
                   9666:         }
                   9667:     }
                   9668:     return OK;
                   9669: }
                   9670: 
                   9671: sub subscribed_hosts {
                   9672:     my ($target) = @_;
                   9673:     my @subscribed;
1.160.6.88  raeburn  9674:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  9675:         while (my $subline=<$fh>) {
                   9676:             if ($subline =~ /^($match_lonid):/) {
                   9677:                 my $host = $1;
                   9678:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   9679:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   9680:                         push(@subscribed,$host);
                   9681:                     }
                   9682:                 }
                   9683:             }
                   9684:         }
                   9685:     }
                   9686:     return @subscribed;
1.9       raeburn  9687: }
                   9688: 
                   9689: sub check_switchserver {
                   9690:     my ($dom,$confname) = @_;
                   9691:     my ($allowed,$switchserver);
                   9692:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   9693:     if ($home eq 'no_host') {
                   9694:         $home = &Apache::lonnet::domain($dom,'primary');
                   9695:     }
                   9696:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 9697:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   9698:     if (!$allowed) {
1.160.6.11  raeburn  9699: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  9700:     }
                   9701:     return $switchserver;
                   9702: }
                   9703: 
1.1       raeburn  9704: sub modify_quotas {
1.160.6.30  raeburn  9705:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  9706:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30  raeburn  9707:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39  raeburn  9708:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   9709:         $validationfieldsref);
1.86      raeburn  9710:     if ($action eq 'quotas') {
                   9711:         $context = 'tools'; 
1.160.6.26  raeburn  9712:     } else {
1.86      raeburn  9713:         $context = $action;
                   9714:     }
                   9715:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  9716:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  9717:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  9718:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   9719:         %titles = &courserequest_titles();
                   9720:         $toolregexp = join('|',@usertools);
                   9721:         %conditions = &courserequest_conditions();
1.160.6.30  raeburn  9722:         $confname = $dom.'-domainconfig';
                   9723:         my $servadm = $r->dir_config('lonAdmEMail');
                   9724:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39  raeburn  9725:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   9726:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5  raeburn  9727:     } elsif ($context eq 'requestauthor') {
                   9728:         @usertools = ('author');
                   9729:         %titles = &authorrequest_titles();
1.86      raeburn  9730:     } else {
1.160.6.4  raeburn  9731:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  9732:         %titles = &tool_titles();
1.86      raeburn  9733:     }
1.160.6.27  raeburn  9734:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  9735:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  9736:     foreach my $key (keys(%env)) {
1.101     raeburn  9737:         if ($context eq 'requestcourses') {
                   9738:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   9739:                 my $item = $1;
                   9740:                 my $type = $2;
                   9741:                 if ($type =~ /^limit_(.+)/) {
                   9742:                     $limithash{$item}{$1} = $env{$key};
                   9743:                 } else {
                   9744:                     $confhash{$item}{$type} = $env{$key};
                   9745:                 }
                   9746:             }
1.160.6.5  raeburn  9747:         } elsif ($context eq 'requestauthor') {
                   9748:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   9749:                 $confhash{$1} = $env{$key};
                   9750:             }
1.101     raeburn  9751:         } else {
1.86      raeburn  9752:             if ($key =~ /^form\.quota_(.+)$/) {
                   9753:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20  raeburn  9754:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   9755:                 $confhash{'authorquota'}{$1} = $env{$key};
                   9756:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  9757:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   9758:             }
1.72      raeburn  9759:         }
                   9760:     }
1.160.6.5  raeburn  9761:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34  raeburn  9762:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  9763:         @approvalnotify = sort(@approvalnotify);
                   9764:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30  raeburn  9765:         my @crstypes = ('official','unofficial','community','textbook');
                   9766:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   9767:         foreach my $type (@hasuniquecode) {
                   9768:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   9769:                 $confhash{'uniquecode'}{$type} = 1;
                   9770:             }
                   9771:         }
1.160.6.46  raeburn  9772:         my (%newbook,%allpos);
1.160.6.30  raeburn  9773:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9774:             foreach my $type ('textbooks','templates') {
                   9775:                 @{$allpos{$type}} = (); 
                   9776:                 my $invalid;
                   9777:                 if ($type eq 'textbooks') {
                   9778:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   9779:                 } else {
                   9780:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   9781:                 }
                   9782:                 if ($env{'form.'.$type.'_addbook'}) {
                   9783:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   9784:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   9785:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   9786:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   9787:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   9788:                         } else {
                   9789:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   9790:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   9791:                             $position =~ s/\D+//g;
                   9792:                             if ($position ne '') {
                   9793:                                 $allpos{$type}[$position] = $newbook{$type};
                   9794:                             }
1.160.6.30  raeburn  9795:                         }
1.160.6.46  raeburn  9796:                     } else {
                   9797:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30  raeburn  9798:                     }
                   9799:                 }
1.160.6.46  raeburn  9800:             } 
1.160.6.30  raeburn  9801:         }
1.102     raeburn  9802:         if (ref($domconfig{$action}) eq 'HASH') {
                   9803:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   9804:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   9805:                     $changes{'notify'}{'approval'} = 1;
                   9806:                 }
                   9807:             } else {
1.144     raeburn  9808:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9809:                     $changes{'notify'}{'approval'} = 1;
                   9810:                 }
                   9811:             }
1.160.6.30  raeburn  9812:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   9813:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9814:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   9815:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   9816:                             $changes{'uniquecode'} = 1;
                   9817:                         }
                   9818:                     }
                   9819:                     unless ($changes{'uniquecode'}) {
                   9820:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   9821:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   9822:                                 $changes{'uniquecode'} = 1;
                   9823:                             }
                   9824:                         }
                   9825:                     }
                   9826:                } else {
                   9827:                    $changes{'uniquecode'} = 1;
                   9828:                }
                   9829:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9830:                 $changes{'uniquecode'} = 1;
                   9831:             }
                   9832:             if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9833:                 foreach my $type ('textbooks','templates') {
                   9834:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9835:                         my %deletions;
                   9836:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   9837:                         if (@todelete) {
                   9838:                             map { $deletions{$_} = 1; } @todelete;
                   9839:                         }
                   9840:                         my %imgdeletions;
                   9841:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   9842:                         if (@todeleteimages) {
                   9843:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   9844:                         }
                   9845:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   9846:                         for (my $i=0; $i<=$maxnum; $i++) {
                   9847:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   9848:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   9849:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   9850:                                 if ($deletions{$key}) {
                   9851:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   9852:                                         #FIXME need to obsolete item in RES space
                   9853:                                     }
                   9854:                                     next;
                   9855:                                 } else {
                   9856:                                     my $newpos = $env{'form.'.$itemid};
                   9857:                                     $newpos =~ s/\D+//g;
1.160.6.47  raeburn  9858:                                     foreach my $item ('subject','title','publisher','author') {
                   9859:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9860:                                                  ($type eq 'templates'));
1.160.6.46  raeburn  9861:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   9862:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   9863:                                             $changes{$type}{$key} = 1;
                   9864:                                         }
                   9865:                                     }
                   9866:                                     $allpos{$type}[$newpos] = $key;
1.160.6.30  raeburn  9867:                                 }
1.160.6.46  raeburn  9868:                                 if ($imgdeletions{$key}) {
                   9869:                                     $changes{$type}{$key} = 1;
                   9870:                                     #FIXME need to obsolete item in RES space
                   9871:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   9872:                                     my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88  raeburn  9873:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9874:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9875:                                     } else {
                   9876:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   9877:                                                                                       $cdom,$cnum,$type,$configuserok,
                   9878:                                                                                       $switchserver,$author_ok);
                   9879:                                         if ($imgurl) {
                   9880:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   9881:                                             $changes{$type}{$key} = 1; 
                   9882:                                         }
                   9883:                                         if ($error) {
                   9884:                                             &Apache::lonnet::logthis($error);
                   9885:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9886:                                         }
1.160.6.46  raeburn  9887:                                     } 
                   9888:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   9889:                                     $confhash{$type}{$key}{'image'} = 
                   9890:                                         $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30  raeburn  9891:                                 }
                   9892:                             }
                   9893:                         }
                   9894:                     }
                   9895:                 }
                   9896:             }
1.102     raeburn  9897:         } else {
1.144     raeburn  9898:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  9899:                 $changes{'notify'}{'approval'} = 1;
                   9900:             }
1.160.6.30  raeburn  9901:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
                   9902:                 $changes{'uniquecode'} = 1;
                   9903:             }
                   9904:         }
                   9905:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  9906:             foreach my $type ('textbooks','templates') {
                   9907:                 if ($newbook{$type}) {
                   9908:                     $changes{$type}{$newbook{$type}} = 1;
1.160.6.47  raeburn  9909:                     foreach my $item ('subject','title','publisher','author') {
                   9910:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9911:                                  ($type eq 'template'));
1.160.6.46  raeburn  9912:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   9913:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   9914:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   9915:                         }
                   9916:                     }
                   9917:                     if ($type eq 'textbooks') {
                   9918:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   9919:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88  raeburn  9920:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   9921:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   9922:                             } else {
                   9923:                                 my ($imageurl,$error) =
                   9924:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   9925:                                                             $configuserok,$switchserver,$author_ok);
                   9926:                                 if ($imageurl) {
                   9927:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   9928:                                 }
                   9929:                                 if ($error) {
                   9930:                                     &Apache::lonnet::logthis($error);
                   9931:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9932:                                 }
1.160.6.46  raeburn  9933:                             }
                   9934:                         }
1.160.6.30  raeburn  9935:                     }
                   9936:                 }
1.160.6.46  raeburn  9937:                 if (@{$allpos{$type}} > 0) {
                   9938:                     my $idx = 0;
                   9939:                     foreach my $item (@{$allpos{$type}}) {
                   9940:                         if ($item ne '') {
                   9941:                             $confhash{$type}{$item}{'order'} = $idx;
                   9942:                             if (ref($domconfig{$action}) eq 'HASH') {
                   9943:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   9944:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   9945:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   9946:                                             $changes{$type}{$item} = 1;
                   9947:                                         }
1.160.6.30  raeburn  9948:                                     }
                   9949:                                 }
                   9950:                             }
1.160.6.46  raeburn  9951:                             $idx ++;
1.160.6.30  raeburn  9952:                         }
                   9953:                     }
                   9954:                 }
                   9955:             }
1.160.6.39  raeburn  9956:             if (ref($validationitemsref) eq 'ARRAY') {
                   9957:                 foreach my $item (@{$validationitemsref}) {
                   9958:                     if ($item eq 'fields') {
                   9959:                         my @changed;
                   9960:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   9961:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   9962:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   9963:                         }
1.160.6.65  raeburn  9964:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9965:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9966:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   9967:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   9968:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   9969:                                 } else {
                   9970:                                     @changed = @{$confhash{'validation'}{$item}};
                   9971:                                 }
1.160.6.39  raeburn  9972:                             } else {
                   9973:                                 @changed = @{$confhash{'validation'}{$item}};
                   9974:                             }
                   9975:                         } else {
                   9976:                             @changed = @{$confhash{'validation'}{$item}};
                   9977:                         }
                   9978:                         if (@changed) {
                   9979:                             if ($confhash{'validation'}{$item}) {
                   9980:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   9981:                             } else {
                   9982:                                 $changes{'validation'}{$item} = &mt('None');
                   9983:                             }
                   9984:                         }
                   9985:                     } else {
                   9986:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   9987:                         if ($item eq 'markup') {
                   9988:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   9989:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   9990:                             }
                   9991:                         }
1.160.6.65  raeburn  9992:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   9993:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   9994:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   9995:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   9996:                                 }
                   9997:                             } else {
                   9998:                                 if ($confhash{'validation'}{$item} ne '') {
                   9999:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   10000:                                 }
1.160.6.39  raeburn  10001:                             }
                   10002:                         } else {
                   10003:                             if ($confhash{'validation'}{$item} ne '') {
                   10004:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   10005:                             }
                   10006:                         }
                   10007:                     }
                   10008:                 }
                   10009:             }
                   10010:             if ($env{'form.validationdc'}) {
                   10011:                 my $newval = $env{'form.validationdc'};
1.160.6.77  raeburn  10012:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39  raeburn  10013:                 if (exists($domcoords{$newval})) {
                   10014:                     $confhash{'validation'}{'dc'} = $newval;
                   10015:                 }
                   10016:             }
                   10017:             if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65  raeburn  10018:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   10019:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   10020:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   10021:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   10022:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   10023:                                     $changes{'validation'}{'dc'} = &mt('None');
                   10024:                                 } else {
                   10025:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   10026:                                 }
1.160.6.39  raeburn  10027:                             }
1.160.6.65  raeburn  10028:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   10029:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39  raeburn  10030:                         }
                   10031:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   10032:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   10033:                     }
                   10034:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   10035:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   10036:                 }
1.160.6.65  raeburn  10037:             } else {
                   10038:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   10039:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   10040:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   10041:                             $changes{'validation'}{'dc'} = &mt('None');
                   10042:                         }
                   10043:                     }
1.160.6.39  raeburn  10044:                 }
                   10045:             }
1.102     raeburn  10046:         }
                   10047:     } else {
1.86      raeburn  10048:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20  raeburn  10049:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  10050:     }
1.72      raeburn  10051:     foreach my $item (@usertools) {
                   10052:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  10053:             my $unset; 
1.101     raeburn  10054:             if ($context eq 'requestcourses') {
1.104     raeburn  10055:                 $unset = '0';
                   10056:                 if ($type eq '_LC_adv') {
                   10057:                     $unset = '';
                   10058:                 }
1.101     raeburn  10059:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   10060:                     $confhash{$item}{$type} .= '=';
                   10061:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   10062:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   10063:                     }
                   10064:                 }
1.160.6.5  raeburn  10065:             } elsif ($context eq 'requestauthor') {
                   10066:                 $unset = '0';
                   10067:                 if ($type eq '_LC_adv') {
                   10068:                     $unset = '';
                   10069:                 }
1.72      raeburn  10070:             } else {
1.101     raeburn  10071:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   10072:                     $confhash{$item}{$type} = 1;
                   10073:                 } else {
                   10074:                     $confhash{$item}{$type} = 0;
                   10075:                 }
1.72      raeburn  10076:             }
1.86      raeburn  10077:             if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5  raeburn  10078:                 if ($action eq 'requestauthor') {
                   10079:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   10080:                         $changes{$type} = 1;
                   10081:                     }
                   10082:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  10083:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   10084:                         $changes{$item}{$type} = 1;
                   10085:                     }
                   10086:                 } else {
                   10087:                     if ($context eq 'requestcourses') {
1.104     raeburn  10088:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  10089:                             $changes{$item}{$type} = 1;
                   10090:                         }
                   10091:                     } else {
                   10092:                         if (!$confhash{$item}{$type}) {
                   10093:                             $changes{$item}{$type} = 1;
                   10094:                         }
                   10095:                     }
                   10096:                 }
                   10097:             } else {
                   10098:                 if ($context eq 'requestcourses') {
1.104     raeburn  10099:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  10100:                         $changes{$item}{$type} = 1;
                   10101:                     }
1.160.6.5  raeburn  10102:                 } elsif ($context eq 'requestauthor') {
                   10103:                     if ($confhash{$type} ne $unset) {
                   10104:                         $changes{$type} = 1;
                   10105:                     }
1.72      raeburn  10106:                 } else {
                   10107:                     if (!$confhash{$item}{$type}) {
                   10108:                         $changes{$item}{$type} = 1;
                   10109:                     }
                   10110:                 }
                   10111:             }
1.1       raeburn  10112:         }
                   10113:     }
1.160.6.5  raeburn  10114:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  10115:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   10116:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   10117:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   10118:                     if (exists($confhash{'defaultquota'}{$key})) {
                   10119:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   10120:                             $changes{'defaultquota'}{$key} = 1;
                   10121:                         }
                   10122:                     } else {
                   10123:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  10124:                     }
                   10125:                 }
1.86      raeburn  10126:             } else {
                   10127:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   10128:                     if (exists($confhash{'defaultquota'}{$key})) {
                   10129:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   10130:                             $changes{'defaultquota'}{$key} = 1;
                   10131:                         }
                   10132:                     } else {
                   10133:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  10134:                     }
1.1       raeburn  10135:                 }
                   10136:             }
1.160.6.20  raeburn  10137:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   10138:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   10139:                     if (exists($confhash{'authorquota'}{$key})) {
                   10140:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   10141:                             $changes{'authorquota'}{$key} = 1;
                   10142:                         }
                   10143:                     } else {
                   10144:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   10145:                     }
                   10146:                 }
                   10147:             }
1.1       raeburn  10148:         }
1.86      raeburn  10149:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   10150:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   10151:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   10152:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   10153:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   10154:                             $changes{'defaultquota'}{$key} = 1;
                   10155:                         }
                   10156:                     } else {
                   10157:                         if (!exists($domconfig{'quotas'}{$key})) {
                   10158:                             $changes{'defaultquota'}{$key} = 1;
                   10159:                         }
1.72      raeburn  10160:                     }
                   10161:                 } else {
1.86      raeburn  10162:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  10163:                 }
1.1       raeburn  10164:             }
                   10165:         }
1.160.6.20  raeburn  10166:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   10167:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   10168:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   10169:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   10170:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   10171:                             $changes{'authorquota'}{$key} = 1;
                   10172:                         }
                   10173:                     } else {
                   10174:                         $changes{'authorquota'}{$key} = 1;
                   10175:                     }
                   10176:                 } else {
                   10177:                     $changes{'authorquota'}{$key} = 1;
                   10178:                 }
                   10179:             }
                   10180:         }
1.1       raeburn  10181:     }
1.72      raeburn  10182: 
1.160.6.5  raeburn  10183:     if ($context eq 'requestauthor') {
                   10184:         $domdefaults{'requestauthor'} = \%confhash;
                   10185:     } else {
                   10186:         foreach my $key (keys(%confhash)) {
1.160.6.46  raeburn  10187:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30  raeburn  10188:                 $domdefaults{$key} = $confhash{$key};
                   10189:             }
1.160.6.5  raeburn  10190:         }
1.72      raeburn  10191:     }
1.160.6.5  raeburn  10192: 
1.1       raeburn  10193:     my %quotahash = (
1.86      raeburn  10194:                       $action => { %confhash }
1.1       raeburn  10195:                     );
                   10196:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   10197:                                              $dom);
                   10198:     if ($putresult eq 'ok') {
                   10199:         if (keys(%changes) > 0) {
1.72      raeburn  10200:             my $cachetime = 24*60*60;
                   10201:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  10202:             if (ref($lastactref) eq 'HASH') {
                   10203:                 $lastactref->{'domdefaults'} = 1;
                   10204:             }
1.1       raeburn  10205:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5  raeburn  10206:             unless (($context eq 'requestcourses') ||
                   10207:                     ($context eq 'requestauthor')) {
1.86      raeburn  10208:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   10209:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   10210:                     foreach my $type (@{$types},'default') {
                   10211:                         if (defined($changes{'defaultquota'}{$type})) {
                   10212:                             my $typetitle = $usertypes->{$type};
                   10213:                             if ($type eq 'default') {
                   10214:                                 $typetitle = $othertitle;
                   10215:                             }
1.160.6.28  raeburn  10216:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  10217:                         }
                   10218:                     }
1.86      raeburn  10219:                     $resulttext .= '</ul></li>';
1.72      raeburn  10220:                 }
1.160.6.20  raeburn  10221:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34  raeburn  10222:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20  raeburn  10223:                     foreach my $type (@{$types},'default') {
                   10224:                         if (defined($changes{'authorquota'}{$type})) {
                   10225:                             my $typetitle = $usertypes->{$type};
                   10226:                             if ($type eq 'default') {
                   10227:                                 $typetitle = $othertitle;
                   10228:                             }
1.160.6.28  raeburn  10229:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20  raeburn  10230:                         }
                   10231:                     }
                   10232:                     $resulttext .= '</ul></li>';
                   10233:                 }
1.72      raeburn  10234:             }
1.80      raeburn  10235:             my %newenv;
1.72      raeburn  10236:             foreach my $item (@usertools) {
1.160.6.5  raeburn  10237:                 my (%haschgs,%inconf);
                   10238:                 if ($context eq 'requestauthor') {
                   10239:                     %haschgs = %changes;
                   10240:                     %inconf = %confhash;
                   10241:                 } else {
                   10242:                     if (ref($changes{$item}) eq 'HASH') {
                   10243:                         %haschgs = %{$changes{$item}};
                   10244:                     }
                   10245:                     if (ref($confhash{$item}) eq 'HASH') {
                   10246:                         %inconf = %{$confhash{$item}};
                   10247:                     }
                   10248:                 }
                   10249:                 if (keys(%haschgs) > 0) {
1.80      raeburn  10250:                     my $newacc = 
                   10251:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   10252:                                                           $env{'user.domain'},
1.86      raeburn  10253:                                                           $item,'reload',$context);
1.160.6.5  raeburn  10254:                     if (($context eq 'requestcourses') ||
                   10255:                         ($context eq 'requestauthor')) {
1.108     raeburn  10256:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   10257:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  10258:                         }
                   10259:                     } else {
                   10260:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   10261:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   10262:                         }
1.80      raeburn  10263:                     }
1.160.6.5  raeburn  10264:                     unless ($context eq 'requestauthor') {
                   10265:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   10266:                     }
1.72      raeburn  10267:                     foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5  raeburn  10268:                         if ($haschgs{$type}) {
1.72      raeburn  10269:                             my $typetitle = $usertypes->{$type};
                   10270:                             if ($type eq 'default') {
                   10271:                                 $typetitle = $othertitle;
                   10272:                             } elsif ($type eq '_LC_adv') {
                   10273:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   10274:                             }
1.160.6.5  raeburn  10275:                             if ($inconf{$type}) {
1.101     raeburn  10276:                                 if ($context eq 'requestcourses') {
                   10277:                                     my $cond;
1.160.6.5  raeburn  10278:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  10279:                                         if ($1 eq '') {
                   10280:                                             $cond = &mt('(Automatic processing of any request).');
                   10281:                                         } else {
                   10282:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   10283:                                         }
                   10284:                                     } else { 
1.160.6.5  raeburn  10285:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  10286:                                     }
                   10287:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8  raeburn  10288:                                 } elsif ($context eq 'requestauthor') {
                   10289:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   10290:                                                              $titles{$inconf{$type}},$typetitle);
                   10291: 
1.101     raeburn  10292:                                 } else {
                   10293:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   10294:                                 }
1.72      raeburn  10295:                             } else {
1.104     raeburn  10296:                                 if ($type eq '_LC_adv') {
1.160.6.5  raeburn  10297:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  10298:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   10299:                                     } else { 
                   10300:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   10301:                                     }
                   10302:                                 } else {
                   10303:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   10304:                                 }
1.72      raeburn  10305:                             }
                   10306:                         }
1.26      raeburn  10307:                     }
1.160.6.5  raeburn  10308:                     unless ($context eq 'requestauthor') {
                   10309:                         $resulttext .= '</ul></li>';
                   10310:                     }
1.26      raeburn  10311:                 }
1.1       raeburn  10312:             }
1.160.6.5  raeburn  10313:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  10314:                 if (ref($changes{'notify'}) eq 'HASH') {
                   10315:                     if ($changes{'notify'}{'approval'}) {
                   10316:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   10317:                             if ($confhash{'notify'}{'approval'}) {
                   10318:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   10319:                             } else {
1.160.6.5  raeburn  10320:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  10321:                             }
                   10322:                         }
                   10323:                     }
                   10324:                 }
                   10325:             }
1.160.6.30  raeburn  10326:             if ($action eq 'requestcourses') {
                   10327:                 my @offon = ('off','on');
                   10328:                 if ($changes{'uniquecode'}) {
                   10329:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   10330:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   10331:                         $resulttext .= '<li>'.
                   10332:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   10333:                                        '</li>';
                   10334:                     } else {
                   10335:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   10336:                                        '</li>';
                   10337:                     }
                   10338:                 }
1.160.6.46  raeburn  10339:                 foreach my $type ('textbooks','templates') {
                   10340:                     if (ref($changes{$type}) eq 'HASH') {
                   10341:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   10342:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   10343:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   10344:                             my $coursetitle = $coursehash{'description'};
                   10345:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   10346:                             $resulttext .= '<li>';
1.160.6.47  raeburn  10347:                             foreach my $item ('subject','title','publisher','author') {
                   10348:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   10349:                                          ($type eq 'templates'));
1.160.6.46  raeburn  10350:                                 my $name = $item.':';
                   10351:                                 $name =~ s/^(\w)/\U$1/;
                   10352:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   10353:                             }
                   10354:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   10355:                             if ($type eq 'textbooks') {
                   10356:                                 if ($confhash{$type}{$key}{'image'}) {
                   10357:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   10358:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   10359:                                                    ' alt="Textbook cover" />').'<br />';
                   10360:                                 }
                   10361:                             }
                   10362:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30  raeburn  10363:                         }
1.160.6.46  raeburn  10364:                         $resulttext .= '</ul></li>';
1.160.6.30  raeburn  10365:                     }
                   10366:                 }
1.160.6.39  raeburn  10367:                 if (ref($changes{'validation'}) eq 'HASH') {
                   10368:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   10369:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   10370:                         foreach my $item (@{$validationitemsref}) {
                   10371:                             if (exists($changes{'validation'}{$item})) {
                   10372:                                 if ($item eq 'markup') {
                   10373:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   10374:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   10375:                                 } else {
                   10376:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   10377:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   10378:                                 }
                   10379:                             }
                   10380:                         }
                   10381:                         if (exists($changes{'validation'}{'dc'})) {
                   10382:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   10383:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   10384:                         }
                   10385:                     }
                   10386:                 }
1.160.6.30  raeburn  10387:             }
1.1       raeburn  10388:             $resulttext .= '</ul>';
1.80      raeburn  10389:             if (keys(%newenv)) {
                   10390:                 &Apache::lonnet::appenv(\%newenv);
                   10391:             }
1.1       raeburn  10392:         } else {
1.86      raeburn  10393:             if ($context eq 'requestcourses') {
                   10394:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5  raeburn  10395:             } elsif ($context eq 'requestauthor') {
                   10396:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  10397:             } else {
1.90      weissno  10398:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  10399:             }
1.1       raeburn  10400:         }
                   10401:     } else {
1.11      albertel 10402:         $resulttext = '<span class="LC_error">'.
                   10403: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10404:     }
1.160.6.30  raeburn  10405:     if ($errors) {
                   10406:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   10407:                        '<ul>'.$errors.'</ul></p>';
                   10408:     }
1.3       raeburn  10409:     return $resulttext;
1.1       raeburn  10410: }
                   10411: 
1.160.6.30  raeburn  10412: sub process_textbook_image {
1.160.6.46  raeburn  10413:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30  raeburn  10414:     my $filename = $env{'form.'.$caller.'.filename'};
                   10415:     my ($error,$url);
                   10416:     my ($width,$height) = (50,50);
                   10417:     if ($configuserok eq 'ok') {
                   10418:         if ($switchserver) {
                   10419:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   10420:                          $switchserver);
                   10421:         } elsif ($author_ok eq 'ok') {
                   10422:             my ($result,$imageurl) =
                   10423:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88  raeburn  10424:                              "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30  raeburn  10425:             if ($result eq 'ok') {
                   10426:                 $url = $imageurl;
                   10427:             } else {
                   10428:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   10429:             }
                   10430:         } else {
                   10431:             $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);
                   10432:         }
                   10433:     } else {
                   10434:         $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);
                   10435:     }
                   10436:     return ($url,$error);
                   10437: }
                   10438: 
1.160.6.102.2  1(raebur 10439:0): sub modify_ltitools {
                   10440:0):     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   10441:0):     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10442:0):     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   10443:0):     my $confname = $dom.'-domainconfig';
                   10444:0):     my $servadm = $r->dir_config('lonAdmEMail');
                   10445:0):     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10446:0):     my (%posslti,%possfield);
                   10447:0):     my @courseroles = ('cc','in','ta','ep','st');
                   10448:0):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   10449:0):     map { $posslti{$_} = 1; } @ltiroles;
                   10450:0):     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   10451:0):     map { $possfield{$_} = 1; } @allfields;
                   10452:0):     my %lt = &ltitools_names();
                   10453:0):     if ($env{'form.ltitools_add'}) {
                   10454:0):         my $title = $env{'form.ltitools_add_title'};
                   10455:0):         $title =~ s/(`)/'/g;
                   10456:0):         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   10457:0):         if ($newid) {
                   10458:0):             my $position = $env{'form.ltitools_add_pos'};
                   10459:0):             $position =~ s/\D+//g;
                   10460:0):             if ($position ne '') {
                   10461:0):                 $allpos[$position] = $newid;
                   10462:0):             }
                   10463:0):             $changes{$newid} = 1;
          5(raebur 10464:0):             foreach my $item ('title','url','key','secret','lifetime') {
          1(raebur 10465:0):                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
          5(raebur 10466:0):                 if ($item eq 'lifetime') {
                   10467:0):                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   10468:0):                 }
          1(raebur 10469:0):                 if ($env{'form.ltitools_add_'.$item}) {
                   10470:0):                     if (($item eq 'key') || ($item eq 'secret')) {
                   10471:0):                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   10472:0):                     } else {
                   10473:0):                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   10474:0):                     }
                   10475:0):                 }
                   10476:0):             }
                   10477:0):             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   10478:0):                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   10479:0):             }
                   10480:0):             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   10481:0):                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   10482:0):             }
          5(raebur 10483:0):             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   10484:0):                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   10485:0):             } else {
                   10486:0):                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   10487:0):             }
          1(raebur 10488:0):             foreach my $item ('width','height','linktext','explanation') {
                   10489:0):                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   10490:0):                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
                   10491:0):                 if (($item eq 'width') || ($item eq 'height')) {
                   10492:0):                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   10493:0):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   10494:0):                     }
                   10495:0):                 } else {
                   10496:0):                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   10497:0):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   10498:0):                     }
                   10499:0):                 }
                   10500:0):             }
                   10501:0):             if ($env{'form.ltitools_add_target'} eq 'window') {
                   10502:0):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   10503:0):             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   10504:0):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   10505:0):             } else {
                   10506:0):                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   10507:0):             }
                   10508:0):             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   10509:0):                 my ($imageurl,$error) =
                   10510:0):                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
                   10511:0):                                             $configuserok,$switchserver,$author_ok);
                   10512:0):                 if ($imageurl) {
                   10513:0):                     $confhash{$newid}{'image'} = $imageurl;
                   10514:0):                 }
                   10515:0):                 if ($error) {
                   10516:0):                     &Apache::lonnet::logthis($error);
                   10517:0):                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10518:0):                 }
                   10519:0):             }
                   10520:0):             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   10521:0):             foreach my $field (@fields) {
                   10522:0):                 if ($possfield{$field}) {
                   10523:0):                     if ($field eq 'roles') {
                   10524:0):                         foreach my $role (@courseroles) {
                   10525:0):                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   10526:0):                             if (($choice ne '') && ($posslti{$choice})) {
                   10527:0):                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   10528:0):                                 if ($role eq 'cc') {
                   10529:0):                                     $confhash{$newid}{'roles'}{'co'} = $choice;
                   10530:0):                                 }
                   10531:0):                             }
                   10532:0):                         }
                   10533:0):                     } else {
                   10534:0):                         $confhash{$newid}{'fields'}{$field} = 1;
                   10535:0):                     }
                   10536:0):                 }
                   10537:0):             }
          5(raebur 10538:0):             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   10539:0):                 if ($confhash{$newid}{'fields'}{'user'}) {
                   10540:0):                     if ($env{'form.ltitools_userincdom_add'}) {
                   10541:0):                         $confhash{$newid}{'incdom'} = 1;
                   10542:0):                     }
                   10543:0):                 }
                   10544:0):             }
          1(raebur 10545:0):             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   10546:0):             foreach my $item (@courseconfig) {
                   10547:0):                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   10548:0):             }
                   10549:0):             if ($env{'form.ltitools_add_custom'}) {
                   10550:0):                 my $name = $env{'form.ltitools_add_custom_name'};
                   10551:0):                 my $value = $env{'form.ltitools_add_custom_value'};
                   10552:0):                 $value =~ s/(`)/'/g;
                   10553:0):                 $name =~ s/(`)/'/g;
                   10554:0):                 $confhash{$newid}{'custom'}{$name} = $value;
                   10555:0):             }
                   10556:0):         } else {
                   10557:0):             my $error = &mt('Failed to acquire unique ID for new external tool');
                   10558:0):             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10559:0):         }
                   10560:0):     }
                   10561:0):     if (ref($domconfig{$action}) eq 'HASH') {
                   10562:0):         my %deletions;
                   10563:0):         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   10564:0):         if (@todelete) {
                   10565:0):             map { $deletions{$_} = 1; } @todelete;
                   10566:0):         }
                   10567:0):         my %customadds;
                   10568:0):         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   10569:0):         if (@newcustom) {
                   10570:0):             map { $customadds{$_} = 1; } @newcustom;
                   10571:0):         }
                   10572:0):         my %imgdeletions;
                   10573:0):         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   10574:0):         if (@todeleteimages) {
                   10575:0):             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   10576:0):         }
                   10577:0):         my $maxnum = $env{'form.ltitools_maxnum'};
                   10578:0):         for (my $i=0; $i<=$maxnum; $i++) {
                   10579:0):             my $itemid = $env{'form.ltitools_id_'.$i};
                   10580:0):             $itemid =~ s/\D+//g;
                   10581:0):             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   10582:0):                 if ($deletions{$itemid}) {
                   10583:0):                     if ($domconfig{$action}{$itemid}{'image'}) {
                   10584:0):                         #FIXME need to obsolete item in RES space
                   10585:0):                     }
                   10586:0):                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   10587:0):                     next;
                   10588:0):                 } else {
                   10589:0):                     my $newpos = $env{'form.ltitools_'.$itemid};
                   10590:0):                     $newpos =~ s/\D+//g;
          5(raebur 10591:0):                     foreach my $item ('title','url','lifetime') {
          1(raebur 10592:0):                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10593:0):                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   10594:0):                             $changes{$itemid} = 1;
                   10595:0):                         }
                   10596:0):                     }
                   10597:0):                     foreach my $item ('key','secret') {
                   10598:0):                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10599:0):                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   10600:0):                             $changes{$itemid} = 1;
                   10601:0):                         }
                   10602:0):                     }
                   10603:0):                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   10604:0):                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   10605:0):                     }
                   10606:0):                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   10607:0):                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   10608:0):                     }
          5(raebur 10609:0):                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   10610:0):                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   10611:0):                     } else {
                   10612:0):                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
                   10613:0):                     }
                   10614:0):                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   10615:0):                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   10616:0):                             $changes{$itemid} = 1;
                   10617:0):                         }
                   10618:0):                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   10619:0):                         $changes{$itemid} = 1;
                   10620:0):                     }
          1(raebur 10621:0):                     foreach my $size ('width','height') {
                   10622:0):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   10623:0):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   10624:0):                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   10625:0):                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   10626:0):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10627:0):                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   10628:0):                                     $changes{$itemid} = 1;
                   10629:0):                                 }
                   10630:0):                             } else {
                   10631:0):                                 $changes{$itemid} = 1;
                   10632:0):                             }
                   10633:0):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10634:0):                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   10635:0):                                 $changes{$itemid} = 1;
                   10636:0):                             }
                   10637:0):                         }
                   10638:0):                     }
                   10639:0):                     foreach my $item ('linktext','explanation') {
                   10640:0):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   10641:0):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   10642:0):                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   10643:0):                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   10644:0):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10645:0):                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   10646:0):                                     $changes{$itemid} = 1;
                   10647:0):                                 }
                   10648:0):                             } else {
                   10649:0):                                 $changes{$itemid} = 1;
                   10650:0):                             }
                   10651:0):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10652:0):                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   10653:0):                                 $changes{$itemid} = 1;
                   10654:0):                             }
                   10655:0):                         }
                   10656:0):                     }
                   10657:0):                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   10658:0):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   10659:0):                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   10660:0):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   10661:0):                     } else {
                   10662:0):                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   10663:0):                     }
                   10664:0):                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   10665:0):                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   10666:0):                             $changes{$itemid} = 1;
                   10667:0):                         }
                   10668:0):                     } else {
                   10669:0):                         $changes{$itemid} = 1;
                   10670:0):                     }
                   10671:0):                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
          5(raebur 10672:0):                     foreach my $item ('label','title','target','linktext','explanation','append') {
          1(raebur 10673:0):                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   10674:0):                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   10675:0):                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   10676:0):                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   10677:0):                                     $changes{$itemid} = 1;
                   10678:0):                                 }
                   10679:0):                             } else {
                   10680:0):                                 $changes{$itemid} = 1;
                   10681:0):                             }
                   10682:0):                         }
                   10683:0):                     }
                   10684:0):                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   10685:0):                     foreach my $field (@fields) {
                   10686:0):                         if ($possfield{$field}) {
                   10687:0):                             if ($field eq 'roles') {
                   10688:0):                                 foreach my $role (@courseroles) {
                   10689:0):                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   10690:0):                                     if (($choice ne '') && ($posslti{$choice})) {
                   10691:0):                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   10692:0):                                         if ($role eq 'cc') {
                   10693:0):                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   10694:0):                                         }
                   10695:0):                                     }
                   10696:0):                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   10697:0):                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   10698:0):                                             $changes{$itemid} = 1;
                   10699:0):                                         }
                   10700:0):                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   10701:0):                                         $changes{$itemid} = 1;
                   10702:0):                                     }
                   10703:0):                                 }
                   10704:0):                             } else {
                   10705:0):                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   10706:0):                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   10707:0):                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   10708:0):                                         $changes{$itemid} = 1;
                   10709:0):                                     }
                   10710:0):                                 } else {
                   10711:0):                                     $changes{$itemid} = 1;
                   10712:0):                                 }
                   10713:0):                             }
                   10714:0):                         }
                   10715:0):                     }
          5(raebur 10716:0):                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   10717:0):                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   10718:0):                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   10719:0):                                 $confhash{$itemid}{'incdom'} = 1;
                   10720:0):                             }
                   10721:0):                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   10722:0):                                 $changes{$itemid} = 1;
                   10723:0):                             }
                   10724:0):                         }
                   10725:0):                     }
          1(raebur 10726:0):                     $allpos[$newpos] = $itemid;
                   10727:0):                 }
                   10728:0):                 if ($imgdeletions{$itemid}) {
                   10729:0):                     $changes{$itemid} = 1;
                   10730:0):                     #FIXME need to obsolete item in RES space
                   10731:0):                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   10732:0):                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   10733:0):                                                                  $itemid,$configuserok,$switchserver,
                   10734:0):                                                                  $author_ok);
                   10735:0):                     if ($imgurl) {
                   10736:0):                         $confhash{$itemid}{'image'} = $imgurl;
                   10737:0):                         $changes{$itemid} = 1;
                   10738:0):                     }
                   10739:0):                     if ($error) {
                   10740:0):                         &Apache::lonnet::logthis($error);
                   10741:0):                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10742:0):                     }
                   10743:0):                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   10744:0):                     $confhash{$itemid}{'image'} =
                   10745:0):                        $domconfig{$action}{$itemid}{'image'};
                   10746:0):                 }
                   10747:0):                 if ($customadds{$i}) {
                   10748:0):                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   10749:0):                     $name =~ s/(`)/'/g;
                   10750:0):                     $name =~ s/^\s+//;
                   10751:0):                     $name =~ s/\s+$//;
                   10752:0):                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   10753:0):                     $value =~ s/(`)/'/g;
                   10754:0):                     $value =~ s/^\s+//;
                   10755:0):                     $value =~ s/\s+$//;
                   10756:0):                     if ($name ne '') {
                   10757:0):                         $confhash{$itemid}{'custom'}{$name} = $value;
                   10758:0):                         $changes{$itemid} = 1;
                   10759:0):                     }
                   10760:0):                 }
                   10761:0):                 my %customdels;
                   10762:0):                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
                   10763:0):                 if (@customdeletions) {
                   10764:0):                     $changes{$itemid} = 1;
                   10765:0):                 }
                   10766:0):                 map { $customdels{$_} = 1; } @customdeletions;
                   10767:0):                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   10768:0):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   10769:0):                         unless ($customdels{$key}) {
                   10770:0):                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   10771:0):                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
                   10772:0):                             }
                   10773:0):                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   10774:0):                                 $changes{$itemid} = 1;
                   10775:0):                             }
                   10776:0):                         }
                   10777:0):                     }
                   10778:0):                 }
                   10779:0):                 unless ($changes{$itemid}) {
                   10780:0):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   10781:0):                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   10782:0):                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   10783:0):                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   10784:0):                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   10785:0):                                         $changes{$itemid} = 1;
                   10786:0):                                         last;
                   10787:0):                                     }
                   10788:0):                                 }
                   10789:0):                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   10790:0):                                 $changes{$itemid} = 1;
                   10791:0):                             }
                   10792:0):                         }
                   10793:0):                         last if ($changes{$itemid});
                   10794:0):                     }
                   10795:0):                 }
                   10796:0):             }
                   10797:0):         }
                   10798:0):     }
                   10799:0):     if (@allpos > 0) {
                   10800:0):         my $idx = 0;
                   10801:0):         foreach my $itemid (@allpos) {
                   10802:0):             if ($itemid ne '') {
                   10803:0):                 $confhash{$itemid}{'order'} = $idx;
                   10804:0):                 if (ref($domconfig{$action}) eq 'HASH') {
                   10805:0):                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   10806:0):                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   10807:0):                             $changes{$itemid} = 1;
                   10808:0):                         }
                   10809:0):                     }
                   10810:0):                 }
                   10811:0):                 $idx ++;
                   10812:0):             }
                   10813:0):         }
                   10814:0):     }
                   10815:0):     my %ltitoolshash = (
                   10816:0):                           $action => { %confhash }
                   10817:0):                        );
                   10818:0):     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   10819:0):                                              $dom);
                   10820:0):     if ($putresult eq 'ok') {
                   10821:0):         my %ltienchash = (
                   10822:0):                              $action => { %encconfig }
                   10823:0):                          );
                   10824:0):         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
                   10825:0):         if (keys(%changes) > 0) {
                   10826:0):             my $cachetime = 24*60*60;
                   10827:0):             my %ltiall = %confhash;
                   10828:0):             foreach my $id (keys(%ltiall)) {
                   10829:0):                 if (ref($encconfig{$id}) eq 'HASH') {
                   10830:0):                     foreach my $item ('key','secret') {
                   10831:0):                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   10832:0):                     }
                   10833:0):                 }
                   10834:0):             }
                   10835:0):             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
                   10836:0):             if (ref($lastactref) eq 'HASH') {
                   10837:0):                 $lastactref->{'ltitools'} = 1;
                   10838:0):             }
                   10839:0):             $resulttext = &mt('Changes made:').'<ul>';
                   10840:0):             my %bynum;
                   10841:0):             foreach my $itemid (sort(keys(%changes))) {
                   10842:0):                 my $position = $confhash{$itemid}{'order'};
                   10843:0):                 $bynum{$position} = $itemid;
                   10844:0):             }
                   10845:0):             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   10846:0):                 my $itemid = $bynum{$pos};
                   10847:0):                 if (ref($confhash{$itemid}) ne 'HASH') {
                   10848:0):                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   10849:0):                 } else {
                   10850:0):                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   10851:0):                     if ($confhash{$itemid}{'image'}) {
                   10852:0):                         $resulttext .= '&nbsp;'.
                   10853:0):                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   10854:0):                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   10855:0):                     }
                   10856:0):                     $resulttext .= '</li><ul>';
                   10857:0):                     my $position = $pos + 1;
                   10858:0):                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
          5(raebur 10859:0):                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
          1(raebur 10860:0):                         if ($confhash{$itemid}{$item} ne '') {
                   10861:0):                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   10862:0):                         }
                   10863:0):                     }
                   10864:0):                     if ($encconfig{$itemid}{'key'} ne '') {
                   10865:0):                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   10866:0):                     }
                   10867:0):                     if ($encconfig{$itemid}{'secret'} ne '') {
                   10868:0):                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   10869:0):                         my $num = length($encconfig{$itemid}{'secret'});
                   10870:0):                         $resulttext .= ('*'x$num).'</li>';
                   10871:0):                     }
                   10872:0):                     $resulttext .= '<li>'.&mt('Configurable in course:');
          5(raebur 10873:0):                     my @possconfig = ('label','title','target','linktext','explanation','append');
          1(raebur 10874:0):                     my $numconfig = 0;
                   10875:0):                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
                   10876:0):                         foreach my $item (@possconfig) {
                   10877:0):                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   10878:0):                                 $numconfig ++;
                   10879:0):                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
                   10880:0):                             }
                   10881:0):                         }
                   10882:0):                     }
                   10883:0):                     if (!$numconfig) {
                   10884:0):                         $resulttext .= &mt('None');
                   10885:0):                     }
                   10886:0):                     $resulttext .= '</li>';
                   10887:0):                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   10888:0):                         my $displaylist;
                   10889:0):                         if ($confhash{$itemid}{'display'}{'target'}) {
                   10890:0):                             $displaylist = &mt('Display target').':&nbsp;'.
                   10891:0):                                            $confhash{$itemid}{'display'}{'target'}.',';
                   10892:0):                         }
                   10893:0):                         foreach my $size ('width','height') {
                   10894:0):                             if ($confhash{$itemid}{'display'}{$size}) {
                   10895:0):                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   10896:0):                                                 $confhash{$itemid}{'display'}{$size}.',';
                   10897:0):                             }
                   10898:0):                         }
                   10899:0):                         if ($displaylist) {
                   10900:0):                             $displaylist =~ s/,$//;
                   10901:0):                             $resulttext .= '<li>'.$displaylist.'</li>';
                   10902:0):                         }
                   10903:0):                         foreach my $item ('linktext','explanation') {
                   10904:0):                             if ($confhash{$itemid}{'display'}{$item}) {
                   10905:0):                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   10906:0):                             }
                   10907:0):                         }
                   10908:0):                     }
                   10909:0):                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   10910:0):                         my $fieldlist;
                   10911:0):                         foreach my $field (@allfields) {
                   10912:0):                             if ($confhash{$itemid}{'fields'}{$field}) {
                   10913:0):                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   10914:0):                             }
                   10915:0):                         }
                   10916:0):                         if ($fieldlist) {
                   10917:0):                             $fieldlist =~ s/,$//;
          5(raebur 10918:0):                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   10919:0):                                 if ($confhash{$itemid}{'incdom'}) {
                   10920:0):                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   10921:0):                                 } else {
                   10922:0):                                     $fieldlist .= ' ('.&mt('username').')';
                   10923:0):                                 }
                   10924:0):                             }
          1(raebur 10925:0):                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   10926:0):                         }
                   10927:0):                     }
                   10928:0):                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   10929:0):                         my $rolemaps;
                   10930:0):                         foreach my $role (@courseroles) {
                   10931:0):                             if ($confhash{$itemid}{'roles'}{$role}) {
                   10932:0):                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   10933:0):                                              $confhash{$itemid}{'roles'}{$role}.',';
                   10934:0):                             }
                   10935:0):                         }
                   10936:0):                         if ($rolemaps) {
                   10937:0):                             $rolemaps =~ s/,$//;
                   10938:0):                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   10939:0):                         }
                   10940:0):                     }
                   10941:0):                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   10942:0):                         my $customlist;
                   10943:0):                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   10944:0):                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   10945:0):                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   10946:0):                             }
                   10947:0):                         }
                   10948:0):                         if ($customlist) {
          5(raebur 10949:0):                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
          1(raebur 10950:0):                         }
                   10951:0):                     }
                   10952:0):                     $resulttext .= '</ul></li>';
                   10953:0):                 }
                   10954:0):             }
                   10955:0):             $resulttext .= '</ul>';
                   10956:0):         } else {
                   10957:0):             $resulttext = &mt('No changes made.');
                   10958:0):         }
                   10959:0):     } else {
                   10960:0):         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   10961:0):     }
                   10962:0):     if ($errors) {
                   10963:0):         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10964:0):                        $errors.'</ul>';
                   10965:0):     }
                   10966:0):     return $resulttext;
                   10967:0): }
                   10968:0): 
                   10969:0): sub process_ltitools_image {
                   10970:0):     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   10971:0):     my $filename = $env{'form.'.$caller.'.filename'};
                   10972:0):     my ($error,$url);
                   10973:0):     my ($width,$height) = (21,21);
                   10974:0):     if ($configuserok eq 'ok') {
                   10975:0):         if ($switchserver) {
                   10976:0):             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   10977:0):                          $switchserver);
                   10978:0):         } elsif ($author_ok eq 'ok') {
                   10979:0):             my ($result,$imageurl,$madethumb) =
                   10980:0):                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   10981:0):                              "ltitools/$itemid/icon",$width,$height);
                   10982:0):             if ($result eq 'ok') {
                   10983:0):                 if ($madethumb) {
                   10984:0):                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   10985:0):                     my $imagethumb = "$path/tn-".$imagefile;
                   10986:0):                     $url = $imagethumb;
                   10987:0):                 } else {
                   10988:0):                     $url = $imageurl;
                   10989:0):                 }
                   10990:0):             } else {
                   10991:0):                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   10992:0):             }
                   10993:0):         } else {
                   10994:0):             $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);
                   10995:0):         }
                   10996:0):     } else {
                   10997:0):         $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);
                   10998:0):     }
                   10999:0):     return ($url,$error);
                   11000:0): }
                   11001:0): 
                   11002:0): sub get_ltitools_id {
                   11003:0):     my ($cdom,$title) = @_;
                   11004:0):     # get lock on ltitools db
                   11005:0):     my $lockhash = {
                   11006:0):                       lock => $env{'user.name'}.
                   11007:0):                               ':'.$env{'user.domain'},
                   11008:0):                    };
                   11009:0):     my $tries = 0;
                   11010:0):     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   11011:0):     my ($id,$error);
                   11012:0): 
                   11013:0):     while (($gotlock ne 'ok') && ($tries<10)) {
                   11014:0):         $tries ++;
                   11015:0):         sleep (0.1);
                   11016:0):         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   11017:0):     }
                   11018:0):     if ($gotlock eq 'ok') {
                   11019:0):         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   11020:0):         if ($currids{'lock'}) {
                   11021:0):             delete($currids{'lock'});
                   11022:0):             if (keys(%currids)) {
                   11023:0):                 my @curr = sort { $a <=> $b } keys(%currids);
                   11024:0):                 if ($curr[-1] =~ /^\d+$/) {
                   11025:0):                     $id = 1 + $curr[-1];
                   11026:0):                 }
                   11027:0):             } else {
                   11028:0):                 $id = 1;
                   11029:0):             }
                   11030:0):             if ($id) {
                   11031:0):                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   11032:0):                     $error = 'nostore';
                   11033:0):                 }
                   11034:0):             } else {
                   11035:0):                 $error = 'nonumber';
                   11036:0):             }
                   11037:0):         }
                   11038:0):         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   11039:0):     } else {
                   11040:0):         $error = 'nolock';
                   11041:0):     }
                   11042:0):     return ($id,$error);
                   11043:0): }
                   11044:0): 
1.3       raeburn  11045: sub modify_autoenroll {
1.160.6.24  raeburn  11046:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  11047:     my ($resulttext,%changes);
                   11048:     my %currautoenroll;
                   11049:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   11050:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   11051:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   11052:         }
                   11053:     }
                   11054:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   11055:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  11056:                   sender => 'Sender for notification messages',
1.160.6.68  raeburn  11057:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   11058:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  11059:     my @offon = ('off','on');
1.17      raeburn  11060:     my $sender_uname = $env{'form.sender_uname'};
                   11061:     my $sender_domain = $env{'form.sender_domain'};
                   11062:     if ($sender_domain eq '') {
                   11063:         $sender_uname = '';
                   11064:     } elsif ($sender_uname eq '') {
                   11065:         $sender_domain = '';
                   11066:     }
1.129     raeburn  11067:     my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68  raeburn  11068:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   11069:     $failsafe =~ s{^\s+|\s+$}{}g;
                   11070:     if ($failsafe =~ /\D/) {
                   11071:         undef($failsafe);
                   11072:     }
1.1       raeburn  11073:     my %autoenrollhash =  (
1.129     raeburn  11074:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   11075:                                        'sender_uname' => $sender_uname,
                   11076:                                        'sender_domain' => $sender_domain,
                   11077:                                        'co-owners' => $coowners,
1.160.6.68  raeburn  11078:                                        'autofailsafe' => $failsafe,
1.1       raeburn  11079:                                 }
                   11080:                      );
1.4       raeburn  11081:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   11082:                                              $dom);
1.1       raeburn  11083:     if ($putresult eq 'ok') {
                   11084:         if (exists($currautoenroll{'run'})) {
                   11085:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   11086:                  $changes{'run'} = 1;
                   11087:              }
                   11088:         } elsif ($autorun) {
                   11089:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  11090:                  $changes{'run'} = 1;
1.1       raeburn  11091:             }
                   11092:         }
1.17      raeburn  11093:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  11094:             $changes{'sender'} = 1;
                   11095:         }
1.17      raeburn  11096:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  11097:             $changes{'sender'} = 1;
                   11098:         }
1.129     raeburn  11099:         if ($currautoenroll{'co-owners'} ne '') {
                   11100:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   11101:                 $changes{'coowners'} = 1;
                   11102:             }
                   11103:         } elsif ($coowners) {
                   11104:             $changes{'coowners'} = 1;
1.160.6.68  raeburn  11105:         }
                   11106:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   11107:             $changes{'autofailsafe'} = 1;
                   11108:         }
1.1       raeburn  11109:         if (keys(%changes) > 0) {
                   11110:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  11111:             if ($changes{'run'}) {
1.1       raeburn  11112:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   11113:             }
                   11114:             if ($changes{'sender'}) {
1.17      raeburn  11115:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   11116:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   11117:                 } else {
                   11118:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   11119:                 }
1.1       raeburn  11120:             }
1.129     raeburn  11121:             if ($changes{'coowners'}) {
                   11122:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   11123:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  11124:                 if (ref($lastactref) eq 'HASH') {
                   11125:                     $lastactref->{'domainconfig'} = 1;
                   11126:                 }
1.129     raeburn  11127:             }
1.160.6.68  raeburn  11128:             if ($changes{'autofailsafe'}) {
                   11129:                 if ($failsafe ne '') {
1.160.6.82  raeburn  11130:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68  raeburn  11131:                 } else {
1.160.6.82  raeburn  11132:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68  raeburn  11133:                 }
                   11134:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   11135:                 if (ref($lastactref) eq 'HASH') {
                   11136:                     $lastactref->{'domdefaults'} = 1;
                   11137:                 }
                   11138:             }
1.1       raeburn  11139:             $resulttext .= '</ul>';
                   11140:         } else {
                   11141:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   11142:         }
                   11143:     } else {
1.11      albertel 11144:         $resulttext = '<span class="LC_error">'.
                   11145: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  11146:     }
1.3       raeburn  11147:     return $resulttext;
1.1       raeburn  11148: }
                   11149: 
                   11150: sub modify_autoupdate {
1.3       raeburn  11151:     my ($dom,%domconfig) = @_;
1.1       raeburn  11152:     my ($resulttext,%currautoupdate,%fields,%changes);
                   11153:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   11154:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   11155:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   11156:         }
                   11157:     }
                   11158:     my @offon = ('off','on');
                   11159:     my %title = &Apache::lonlocal::texthash (
                   11160:                    run => 'Auto-update:',
                   11161:                    classlists => 'Updates to user information in classlists?'
                   11162:                 );
1.44      raeburn  11163:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  11164:     my %fieldtitles = &Apache::lonlocal::texthash (
                   11165:                         id => 'Student/Employee ID',
1.20      raeburn  11166:                         permanentemail => 'E-mail address',
1.1       raeburn  11167:                         lastname => 'Last Name',
                   11168:                         firstname => 'First Name',
                   11169:                         middlename => 'Middle Name',
1.132     raeburn  11170:                         generation => 'Generation',
1.1       raeburn  11171:                       );
1.142     raeburn  11172:     $othertitle = &mt('All users');
1.1       raeburn  11173:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  11174:         $othertitle = &mt('Other users');
1.1       raeburn  11175:     }
                   11176:     foreach my $key (keys(%env)) {
                   11177:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  11178:             my ($usertype,$item) = ($1,$2);
                   11179:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   11180:                 if ($usertype eq 'default') {   
                   11181:                     push(@{$fields{$1}},$2);
                   11182:                 } elsif (ref($types) eq 'ARRAY') {
                   11183:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   11184:                         push(@{$fields{$1}},$2);
                   11185:                     }
                   11186:                 }
                   11187:             }
1.1       raeburn  11188:         }
                   11189:     }
1.131     raeburn  11190:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   11191:     @lockablenames = sort(@lockablenames);
                   11192:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   11193:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   11194:         if (@changed) {
                   11195:             $changes{'lockablenames'} = 1;
                   11196:         }
                   11197:     } else {
                   11198:         if (@lockablenames) {
                   11199:             $changes{'lockablenames'} = 1;
                   11200:         }
                   11201:     }
1.1       raeburn  11202:     my %updatehash = (
                   11203:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   11204:                                       classlists => $env{'form.classlists'},
                   11205:                                       fields => {%fields},
1.131     raeburn  11206:                                       lockablenames => \@lockablenames,
1.1       raeburn  11207:                                     }
                   11208:                      );
                   11209:     foreach my $key (keys(%currautoupdate)) {
                   11210:         if (($key eq 'run') || ($key eq 'classlists')) {
                   11211:             if (exists($updatehash{autoupdate}{$key})) {
                   11212:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   11213:                     $changes{$key} = 1;
                   11214:                 }
                   11215:             }
                   11216:         } elsif ($key eq 'fields') {
                   11217:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  11218:                 foreach my $item (@{$types},'default') {
1.1       raeburn  11219:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   11220:                         my $change = 0;
                   11221:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   11222:                             if (!exists($fields{$item})) {
                   11223:                                 $change = 1;
1.132     raeburn  11224:                                 last;
1.1       raeburn  11225:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  11226:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  11227:                                     $change = 1;
1.132     raeburn  11228:                                     last;
1.1       raeburn  11229:                                 }
                   11230:                             }
                   11231:                         }
                   11232:                         if ($change) {
                   11233:                             push(@{$changes{$key}},$item);
                   11234:                         }
1.26      raeburn  11235:                     } 
1.1       raeburn  11236:                 }
                   11237:             }
1.131     raeburn  11238:         } elsif ($key eq 'lockablenames') {
                   11239:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   11240:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   11241:                 if (@changed) {
                   11242:                     $changes{'lockablenames'} = 1;
                   11243:                 }
                   11244:             } else {
                   11245:                 if (@lockablenames) {
                   11246:                     $changes{'lockablenames'} = 1;
                   11247:                 }
                   11248:             }
                   11249:         }
                   11250:     }
                   11251:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   11252:         if (@lockablenames) {
                   11253:             $changes{'lockablenames'} = 1;
1.1       raeburn  11254:         }
                   11255:     }
1.26      raeburn  11256:     foreach my $item (@{$types},'default') {
                   11257:         if (defined($fields{$item})) {
                   11258:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  11259:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   11260:                     my $change = 0;
                   11261:                     if (ref($fields{$item}) eq 'ARRAY') {
                   11262:                         foreach my $type (@{$fields{$item}}) {
                   11263:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   11264:                                 $change = 1;
                   11265:                                 last;
                   11266:                             }
                   11267:                         }
                   11268:                     }
                   11269:                     if ($change) {
                   11270:                         push(@{$changes{'fields'}},$item);
                   11271:                     }
                   11272:                 } else {
1.26      raeburn  11273:                     push(@{$changes{'fields'}},$item);
                   11274:                 }
                   11275:             } else {
                   11276:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  11277:             }
                   11278:         }
                   11279:     }
                   11280:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   11281:                                              $dom);
                   11282:     if ($putresult eq 'ok') {
                   11283:         if (keys(%changes) > 0) {
                   11284:             $resulttext = &mt('Changes made:').'<ul>';
                   11285:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  11286:                 if ($key eq 'lockablenames') {
                   11287:                     $resulttext .= '<li>';
                   11288:                     if (@lockablenames) {
                   11289:                         $usertypes->{'default'} = $othertitle;
                   11290:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   11291:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   11292:                     } else {
                   11293:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   11294:                     }
                   11295:                     $resulttext .= '</li>';
                   11296:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  11297:                     foreach my $item (@{$changes{$key}}) {
                   11298:                         my @newvalues;
                   11299:                         foreach my $type (@{$fields{$item}}) {
                   11300:                             push(@newvalues,$fieldtitles{$type});
                   11301:                         }
1.3       raeburn  11302:                         my $newvaluestr;
                   11303:                         if (@newvalues > 0) {
                   11304:                             $newvaluestr = join(', ',@newvalues);
                   11305:                         } else {
                   11306:                             $newvaluestr = &mt('none');
1.6       raeburn  11307:                         }
1.1       raeburn  11308:                         if ($item eq 'default') {
1.26      raeburn  11309:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  11310:                         } else {
1.26      raeburn  11311:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  11312:                         }
                   11313:                     }
                   11314:                 } else {
                   11315:                     my $newvalue;
                   11316:                     if ($key eq 'run') {
                   11317:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   11318:                     } else {
                   11319:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  11320:                     }
1.1       raeburn  11321:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   11322:                 }
                   11323:             }
                   11324:             $resulttext .= '</ul>';
                   11325:         } else {
1.3       raeburn  11326:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  11327:         }
                   11328:     } else {
1.11      albertel 11329:         $resulttext = '<span class="LC_error">'.
                   11330: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  11331:     }
1.3       raeburn  11332:     return $resulttext;
1.1       raeburn  11333: }
                   11334: 
1.125     raeburn  11335: sub modify_autocreate {
                   11336:     my ($dom,%domconfig) = @_;
                   11337:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   11338:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   11339:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   11340:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   11341:         }
                   11342:     }
                   11343:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   11344:                  req => 'Auto-creation of validated requests for official courses',
                   11345:                  xmldc => 'Identity of course creator of courses from XML files',
                   11346:                );
                   11347:     my @types = ('xml','req');
                   11348:     foreach my $item (@types) {
                   11349:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   11350:         $newvals{$item} =~ s/\D//g;
                   11351:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   11352:     }
                   11353:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77  raeburn  11354:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  11355:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   11356:         $newvals{'xmldc'} = '';
                   11357:     } 
                   11358:     %autocreatehash =  (
                   11359:                         autocreate => { xml => $newvals{'xml'},
                   11360:                                         req => $newvals{'req'},
                   11361:                                       }
                   11362:                        );
                   11363:     if ($newvals{'xmldc'} ne '') {
                   11364:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   11365:     }
                   11366:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   11367:                                              $dom);
                   11368:     if ($putresult eq 'ok') {
                   11369:         my @items = @types;
                   11370:         if ($newvals{'xml'}) {
                   11371:             push(@items,'xmldc');
                   11372:         }
                   11373:         foreach my $item (@items) {
                   11374:             if (exists($currautocreate{$item})) {
                   11375:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   11376:                     $changes{$item} = 1;
                   11377:                 }
                   11378:             } elsif ($newvals{$item}) {
                   11379:                 $changes{$item} = 1;
                   11380:             }
                   11381:         }
                   11382:         if (keys(%changes) > 0) {
                   11383:             my @offon = ('off','on'); 
                   11384:             $resulttext = &mt('Changes made:').'<ul>';
                   11385:             foreach my $item (@types) {
                   11386:                 if ($changes{$item}) {
                   11387:                     my $newtxt = $offon[$newvals{$item}];
1.160.6.13  raeburn  11388:                     $resulttext .= '<li>'.
                   11389:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   11390:                                        '<b>','</b>').
                   11391:                                    '</li>';
1.125     raeburn  11392:                 }
                   11393:             }
                   11394:             if ($changes{'xmldc'}) {
                   11395:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   11396:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13  raeburn  11397:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  11398:             }
                   11399:             $resulttext .= '</ul>';
                   11400:         } else {
                   11401:             $resulttext = &mt('No changes made to auto-creation settings');
                   11402:         }
                   11403:     } else {
                   11404:         $resulttext = '<span class="LC_error">'.
                   11405:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11406:     }
                   11407:     return $resulttext;
                   11408: }
                   11409: 
1.23      raeburn  11410: sub modify_directorysrch {
1.160.6.81  raeburn  11411:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  11412:     my ($resulttext,%changes);
                   11413:     my %currdirsrch;
                   11414:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   11415:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   11416:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   11417:         }
                   11418:     }
1.160.6.72  raeburn  11419:     my %title = ( available => 'Institutional directory search available',
                   11420:                   localonly => 'Other domains can search institution',
                   11421:                   lcavailable => 'LON-CAPA directory search available',
                   11422:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  11423:                   searchby => 'Search types',
                   11424:                   searchtypes => 'Search latitude');
                   11425:     my @offon = ('off','on');
1.24      raeburn  11426:     my @otherdoms = ('Yes','No');
1.23      raeburn  11427: 
1.25      raeburn  11428:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  11429:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   11430:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   11431: 
1.44      raeburn  11432:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  11433:     if (keys(%{$usertypes}) == 0) {
                   11434:         @cansearch = ('default');
                   11435:     } else {
                   11436:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   11437:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   11438:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   11439:                     push(@{$changes{'cansearch'}},$type);
                   11440:                 }
1.23      raeburn  11441:             }
1.26      raeburn  11442:             foreach my $type (@cansearch) {
                   11443:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   11444:                     push(@{$changes{'cansearch'}},$type);
                   11445:                 }
1.23      raeburn  11446:             }
1.26      raeburn  11447:         } else {
                   11448:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  11449:         }
                   11450:     }
                   11451: 
                   11452:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   11453:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   11454:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   11455:                 push(@{$changes{'searchby'}},$by);
                   11456:             }
                   11457:         }
                   11458:         foreach my $by (@searchby) {
                   11459:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   11460:                 push(@{$changes{'searchby'}},$by);
                   11461:             }
                   11462:         }
                   11463:     } else {
                   11464:         push(@{$changes{'searchby'}},@searchby);
                   11465:     }
1.25      raeburn  11466: 
                   11467:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   11468:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   11469:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   11470:                 push(@{$changes{'searchtypes'}},$type);
                   11471:             }
                   11472:         }
                   11473:         foreach my $type (@searchtypes) {
                   11474:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   11475:                 push(@{$changes{'searchtypes'}},$type);
                   11476:             }
                   11477:         }
                   11478:     } else {
                   11479:         if (exists($currdirsrch{'searchtypes'})) {
                   11480:             foreach my $type (@searchtypes) {  
                   11481:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   11482:                     push(@{$changes{'searchtypes'}},$type);
                   11483:                 }
                   11484:             }
                   11485:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   11486:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   11487:             }   
                   11488:         } else {
                   11489:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   11490:         }
                   11491:     }
                   11492: 
1.23      raeburn  11493:     my %dirsrch_hash =  (
                   11494:             directorysrch => { available => $env{'form.dirsrch_available'},
                   11495:                                cansearch => \@cansearch,
1.160.6.72  raeburn  11496:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   11497:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   11498:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  11499:                                searchby => \@searchby,
1.25      raeburn  11500:                                searchtypes => \@searchtypes,
1.23      raeburn  11501:                              }
                   11502:             );
                   11503:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   11504:                                              $dom);
                   11505:     if ($putresult eq 'ok') {
                   11506:         if (exists($currdirsrch{'available'})) {
                   11507:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   11508:                  $changes{'available'} = 1;
                   11509:              }
                   11510:         } else {
                   11511:             if ($env{'form.dirsrch_available'} eq '1') {
                   11512:                 $changes{'available'} = 1;
                   11513:             }
                   11514:         }
1.160.6.72  raeburn  11515:         if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78  raeburn  11516:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   11517:                 $changes{'lcavailable'} = 1;
                   11518:             }
1.24      raeburn  11519:         } else {
1.160.6.72  raeburn  11520:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   11521:                 $changes{'lcavailable'} = 1;
                   11522:             }
                   11523:         }
                   11524:         if (exists($currdirsrch{'localonly'})) {
                   11525:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  11526:                 $changes{'localonly'} = 1;
                   11527:             }
1.160.6.72  raeburn  11528:         } else {
                   11529:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
                   11530:                 $changes{'localonly'} = 1;
                   11531:             }
                   11532:         }
                   11533:         if (exists($currdirsrch{'lclocalonly'})) {
                   11534:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   11535:                 $changes{'lclocalonly'} = 1;
                   11536:             }
                   11537:         } else {
                   11538:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   11539:                 $changes{'lclocalonly'} = 1;
                   11540:             }
1.24      raeburn  11541:         }
1.23      raeburn  11542:         if (keys(%changes) > 0) {
                   11543:             $resulttext = &mt('Changes made:').'<ul>';
                   11544:             if ($changes{'available'}) {
                   11545:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   11546:             }
1.160.6.72  raeburn  11547:             if ($changes{'lcavailable'}) {
                   11548:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   11549:             }
1.24      raeburn  11550:             if ($changes{'localonly'}) {
1.160.6.72  raeburn  11551:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
                   11552:             }
                   11553:             if ($changes{'lclocalonly'}) {
                   11554:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24      raeburn  11555:             }
1.23      raeburn  11556:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   11557:                 my $chgtext;
1.26      raeburn  11558:                 if (ref($usertypes) eq 'HASH') {
                   11559:                     if (keys(%{$usertypes}) > 0) {
                   11560:                         foreach my $type (@{$types}) {
                   11561:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   11562:                                 $chgtext .= $usertypes->{$type}.'; ';
                   11563:                             }
                   11564:                         }
                   11565:                         if (grep(/^default$/,@cansearch)) {
                   11566:                             $chgtext .= $othertitle;
                   11567:                         } else {
                   11568:                             $chgtext =~ s/\; $//;
                   11569:                         }
1.160.6.13  raeburn  11570:                         $resulttext .=
                   11571:                             '<li>'.
                   11572:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   11573:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   11574:                             '</li>';
1.23      raeburn  11575:                     }
                   11576:                 }
                   11577:             }
                   11578:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   11579:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   11580:                 my $chgtext;
                   11581:                 foreach my $type (@{$titleorder}) {
                   11582:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   11583:                         if (defined($searchtitles->{$type})) {
                   11584:                             $chgtext .= $searchtitles->{$type}.'; ';
                   11585:                         }
                   11586:                     }
                   11587:                 }
                   11588:                 $chgtext =~ s/\; $//;
                   11589:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   11590:             }
1.25      raeburn  11591:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   11592:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   11593:                 my $chgtext;
                   11594:                 foreach my $type (@{$srchtypeorder}) {
                   11595:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   11596:                         if (defined($srchtypes_desc->{$type})) {
                   11597:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   11598:                         }
                   11599:                     }
                   11600:                 }
                   11601:                 $chgtext =~ s/\; $//;
1.160.6.13  raeburn  11602:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  11603:             }
                   11604:             $resulttext .= '</ul>';
1.160.6.81  raeburn  11605:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   11606:             if (ref($lastactref) eq 'HASH') {
                   11607:                 $lastactref->{'directorysrch'} = 1;
                   11608:             }
1.23      raeburn  11609:         } else {
1.160.6.72  raeburn  11610:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  11611:         }
                   11612:     } else {
                   11613:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  11614:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   11615:     }
                   11616:     return $resulttext;
                   11617: }
                   11618: 
1.28      raeburn  11619: sub modify_contacts {
1.160.6.24  raeburn  11620:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  11621:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   11622:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   11623:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   11624:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   11625:         }
                   11626:     }
1.160.6.78  raeburn  11627:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  11628:     my @contacts = ('supportemail','adminemail');
1.160.6.78  raeburn  11629:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95  raeburn  11630:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.23  raeburn  11631:     my @toggles = ('reporterrors','reportupdates');
1.160.6.78  raeburn  11632:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  11633:     foreach my $type (@mailings) {
                   11634:         @{$newsetting{$type}} = 
                   11635:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   11636:         foreach my $item (@contacts) {
                   11637:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   11638:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   11639:             } else {
                   11640:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   11641:             }
1.160.6.78  raeburn  11642:         }
1.28      raeburn  11643:         $others{$type} = $env{'form.'.$type.'_others'};
                   11644:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78  raeburn  11645:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11646:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   11647:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78  raeburn  11648:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   11649:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   11650:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   11651:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   11652:             }
1.134     raeburn  11653:         }
1.28      raeburn  11654:     }
                   11655:     foreach my $item (@contacts) {
                   11656:         $to{$item} = $env{'form.'.$item};
                   11657:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   11658:     }
1.160.6.23  raeburn  11659:     foreach my $item (@toggles) {
                   11660:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   11661:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   11662:         }
                   11663:     }
1.160.6.78  raeburn  11664:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   11665:         foreach my $field (@{$fields}) {
                   11666:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   11667:                 my $value = $env{'form.helpform_'.$field};
                   11668:                 $value =~ s/^\s+|\s+$//g;
                   11669:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101  raeburn  11670:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78  raeburn  11671:                     if ($field eq 'screenshot') {
                   11672:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   11673:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101  raeburn  11674:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78  raeburn  11675:                         }
                   11676:                     }
                   11677:                 }
                   11678:             }
                   11679:         }
                   11680:     }
1.160.6.101  raeburn  11681:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   11682:     my (@statuses,%usertypeshash,@overrides);
                   11683:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   11684:         @statuses = @{$types};
                   11685:         if (ref($usertypes) eq 'HASH') {
                   11686:             %usertypeshash = %{$usertypes};
                   11687:         }
                   11688:     }
                   11689:     if (@statuses) {
                   11690:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   11691:         foreach my $type (@possoverrides) {
                   11692:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   11693:                 push(@overrides,$type);
                   11694:             }
                   11695:         }
                   11696:         if (@overrides) {
                   11697:             foreach my $type (@overrides) {
                   11698:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   11699:                 foreach my $item (@contacts) {
                   11700:                     if (grep(/^\Q$item\E$/,@standard)) {
                   11701:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   11702:                         $newsetting{'override_'.$type}{$item} = 1;
                   11703:                     } else {
                   11704:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   11705:                         $newsetting{'override_'.$type}{$item} = 0;
                   11706:                     }
                   11707:                 }
                   11708:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   11709:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   11710:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   11711:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   11712:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   11713:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   11714:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   11715:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   11716:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   11717:                 }
                   11718:             }    
                   11719:         }
                   11720:     }
1.28      raeburn  11721:     if (keys(%currsetting) > 0) {
                   11722:         foreach my $item (@contacts) {
                   11723:             if ($to{$item} ne $currsetting{$item}) {
                   11724:                 $changes{$item} = 1;
                   11725:             }
                   11726:         }
                   11727:         foreach my $type (@mailings) {
                   11728:             foreach my $item (@contacts) {
                   11729:                 if (ref($currsetting{$type}) eq 'HASH') {
                   11730:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   11731:                         push(@{$changes{$type}},$item);
                   11732:                     }
                   11733:                 } else {
                   11734:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   11735:                 }
                   11736:             }
                   11737:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   11738:                 push(@{$changes{$type}},'others');
                   11739:             }
1.160.6.78  raeburn  11740:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11741:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   11742:                     push(@{$changes{$type}},'bcc'); 
                   11743:                 }
1.160.6.78  raeburn  11744:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   11745:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   11746:                     push(@{$changes{$type}},'include');
                   11747:                 }
                   11748:             }
                   11749:         }
                   11750:         if (ref($fields) eq 'ARRAY') {
                   11751:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   11752:                 foreach my $field (@{$fields}) {
                   11753:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   11754:                         push(@{$changes{'helpform'}},$field);
                   11755:                     }
                   11756:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11757:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   11758:                             push(@{$changes{'helpform'}},'maxsize');
                   11759:                         }
                   11760:                     }
                   11761:                 }
                   11762:             } else {
                   11763:                 foreach my $field (@{$fields}) {
                   11764:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   11765:                         push(@{$changes{'helpform'}},$field);
                   11766:                     }
                   11767:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11768:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   11769:                             push(@{$changes{'helpform'}},'maxsize');
                   11770:                         }
                   11771:                     }
                   11772:                 }
1.134     raeburn  11773:             }
1.28      raeburn  11774:         }
1.160.6.101  raeburn  11775:         if (@statuses) {
                   11776:             if (ref($currsetting{'overrides'}) eq 'HASH') {
                   11777:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   11778:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   11779:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   11780:                             foreach my $item (@contacts,'bcc','others','include') {
                   11781:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
                   11782:                                     push(@{$changes{'overrides'}},$key);
                   11783:                                     last;
                   11784:                                 }
                   11785:                             }
                   11786:                         } else {
                   11787:                             push(@{$changes{'overrides'}},$key);
                   11788:                         }
                   11789:                     }
                   11790:                 }
                   11791:                 foreach my $key (@overrides) {
                   11792:                     unless (exists($currsetting{'overrides'}{$key})) {
                   11793:                         push(@{$changes{'overrides'}},$key);
                   11794:                     }
                   11795:                 }
                   11796:             } else {
                   11797:                 foreach my $key (@overrides) {
                   11798:                     push(@{$changes{'overrides'}},$key);
                   11799:                 }
                   11800:             }
                   11801:         }
1.28      raeburn  11802:     } else {
                   11803:         my %default;
                   11804:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   11805:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   11806:         $default{'errormail'} = 'adminemail';
                   11807:         $default{'packagesmail'} = 'adminemail';
                   11808:         $default{'helpdeskmail'} = 'supportemail';
1.160.6.78  raeburn  11809:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  11810:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  11811:         $default{'requestsmail'} = 'adminemail';
1.160.6.15  raeburn  11812:         $default{'updatesmail'} = 'adminemail';
1.160.6.91  raeburn  11813:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  11814:         foreach my $item (@contacts) {
                   11815:            if ($to{$item} ne $default{$item}) {
1.160.6.78  raeburn  11816:                $changes{$item} = 1;
1.160.6.23  raeburn  11817:            }
1.28      raeburn  11818:         }
                   11819:         foreach my $type (@mailings) {
                   11820:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   11821:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   11822:             }
                   11823:             if ($others{$type} ne '') {
                   11824:                 push(@{$changes{$type}},'others');
1.134     raeburn  11825:             }
1.160.6.78  raeburn  11826:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11827:                 if ($bcc{$type} ne '') {
                   11828:                     push(@{$changes{$type}},'bcc');
                   11829:                 }
1.160.6.78  raeburn  11830:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   11831:                     push(@{$changes{$type}},'include');
                   11832:                 }
                   11833:             }
                   11834:         }
                   11835:         if (ref($fields) eq 'ARRAY') {
                   11836:             foreach my $field (@{$fields}) {
                   11837:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   11838:                     push(@{$changes{'helpform'}},$field);
                   11839:                 }
                   11840:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   11841:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   11842:                         push(@{$changes{'helpform'}},'maxsize');
                   11843:                     }
                   11844:                 }
1.134     raeburn  11845:             }
1.28      raeburn  11846:         }
                   11847:     }
1.160.6.23  raeburn  11848:     foreach my $item (@toggles) {
                   11849:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   11850:             $changes{$item} = 1;
                   11851:         } elsif ((!$env{'form.'.$item}) &&
                   11852:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   11853:             $changes{$item} = 1;
                   11854:         }
                   11855:     }
1.28      raeburn  11856:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   11857:                                              $dom);
                   11858:     if ($putresult eq 'ok') {
                   11859:         if (keys(%changes) > 0) {
1.160.6.24  raeburn  11860:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  11861:             if (ref($lastactref) eq 'HASH') {
                   11862:                 $lastactref->{'domainconfig'} = 1;
                   11863:             }
1.28      raeburn  11864:             my ($titles,$short_titles)  = &contact_titles();
                   11865:             $resulttext = &mt('Changes made:').'<ul>';
                   11866:             foreach my $item (@contacts) {
                   11867:                 if ($changes{$item}) {
                   11868:                     $resulttext .= '<li>'.$titles->{$item}.
                   11869:                                     &mt(' set to: ').
                   11870:                                     '<span class="LC_cusr_emph">'.
                   11871:                                     $to{$item}.'</span></li>';
                   11872:                 }
                   11873:             }
                   11874:             foreach my $type (@mailings) {
                   11875:                 if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78  raeburn  11876:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   11877:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
                   11878:                     } else {
                   11879:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   11880:                     }
1.28      raeburn  11881:                     my @text;
                   11882:                     foreach my $item (@{$newsetting{$type}}) {
                   11883:                         push(@text,$short_titles->{$item});
                   11884:                     }
                   11885:                     if ($others{$type} ne '') {
                   11886:                         push(@text,$others{$type});
                   11887:                     }
1.160.6.78  raeburn  11888:                     if (@text) {
                   11889:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   11890:                                        join(', ',@text).'</span>';
                   11891:                     }
                   11892:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  11893:                         if ($bcc{$type} ne '') {
1.160.6.78  raeburn  11894:                             my $bcctext;
                   11895:                             if (@text) {
                   11896:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
                   11897:                             } else {
                   11898:                                 $bcctext = '(Bcc)';
                   11899:                             }
                   11900:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   11901:                         } elsif (!@text) {
                   11902:                             $resulttext .= &mt('No one');
1.134     raeburn  11903:                         }
1.160.6.78  raeburn  11904:                         if ($includestr{$type} ne '') {
                   11905:                             if ($includeloc{$type} eq 'b') {
                   11906:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   11907:                             } elsif ($includeloc{$type} eq 's') {
                   11908:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   11909:                             }
                   11910:                         }
                   11911:                     } elsif (!@text) {
                   11912:                         $resulttext .= &mt('No recipients');
1.134     raeburn  11913:                     }
                   11914:                     $resulttext .= '</li>';
1.28      raeburn  11915:                 }
                   11916:             }
1.160.6.101  raeburn  11917:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   11918:                 my @deletions;
                   11919:                 foreach my $type (@{$changes{'overrides'}}) {
                   11920:                     if ($usertypeshash{$type}) {
                   11921:                         if (grep(/^\Q$type\E/,@overrides)) {
                   11922:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   11923:                                                       $usertypeshash{$type}).'<ul><li>';
                   11924:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   11925:                                 my @text;
                   11926:                                 foreach my $item (@contacts) {
                   11927:                                     if ($newsetting{'override_'.$type}{$item}) {
                   11928:                                         push(@text,$short_titles->{$item});
                   11929:                                     }
                   11930:                                 }
                   11931:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   11932:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   11933:                                 }
                   11934: 
                   11935:                                 if (@text) {
                   11936:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   11937:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   11938:                                 }
                   11939:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   11940:                                     my $bcctext;
                   11941:                                     if (@text) {
                   11942:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   11943:                                     } else {
                   11944:                                         $bcctext = '(Bcc)';
                   11945:                                     }
                   11946:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   11947:                                 } elsif (!@text) {
                   11948:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   11949:                                 }
                   11950:                                 $resulttext .= '</li>';
                   11951:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   11952:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   11953:                                     if ($loc eq 'b') {
                   11954:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   11955:                                     } elsif ($loc eq 's') {
                   11956:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   11957:                                     }
                   11958:                                 }
                   11959:                             }
                   11960:                             $resulttext .= '</li></ul></li>';
                   11961:                         } else {
                   11962:                             push(@deletions,$usertypeshash{$type});
                   11963:                         }
                   11964:                     }
                   11965:                 }
                   11966:                 if (@deletions) {
                   11967:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   11968:                                               join(', ',@deletions)).'</li>';
                   11969:                 }
                   11970:             }
1.160.6.23  raeburn  11971:             my @offon = ('off','on');
                   11972:             if ($changes{'reporterrors'}) {
                   11973:                 $resulttext .= '<li>'.
                   11974:                                &mt('E-mail error reports to [_1] set to "'.
                   11975:                                    $offon[$env{'form.reporterrors'}].'".',
                   11976:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   11977:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   11978:                                '</li>';
                   11979:             }
                   11980:             if ($changes{'reportupdates'}) {
                   11981:                 $resulttext .= '<li>'.
                   11982:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   11983:                                     $offon[$env{'form.reportupdates'}].'".',
                   11984:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   11985:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   11986:                                 '</li>';
                   11987:             }
1.160.6.78  raeburn  11988:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   11989:                 my (@optional,@required,@unused,$maxsizechg);
                   11990:                 foreach my $field (@{$changes{'helpform'}}) {
                   11991:                     if ($field eq 'maxsize') {
                   11992:                         $maxsizechg = 1;
                   11993:                         next;
                   11994:                     }
                   11995:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                   11996:                         push(@optional,$field);
                   11997:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   11998:                         push(@unused,$field);
                   11999:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                   12000:                         push(@required,$field);
                   12001:                     }
                   12002:                 }
                   12003:                 if (@optional) {
                   12004:                     $resulttext .= '<li>'.
                   12005:                                    &mt('Help form fields changed to "Optional": [_1].',
                   12006:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   12007:                                    '</li>';
                   12008:                 }
                   12009:                 if (@required) {
                   12010:                     $resulttext .= '<li>'.
                   12011:                                    &mt('Help form fields changed to "Required": [_1].',
                   12012:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   12013:                                    '</li>';
                   12014:                 }
                   12015:                 if (@unused) {
                   12016:                     $resulttext .= '<li>'.
                   12017:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   12018:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   12019:                                    '</li>';
                   12020:                 }
                   12021:                 if ($maxsizechg) {
                   12022:                     $resulttext .= '<li>'.
                   12023:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   12024:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   12025:                                    '</li>';
                   12026:                 }
                   12027:             }
1.28      raeburn  12028:             $resulttext .= '</ul>';
                   12029:         } else {
1.160.6.78  raeburn  12030:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  12031:         }
                   12032:     } else {
                   12033:         $resulttext = '<span class="LC_error">'.
                   12034:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   12035:     }
                   12036:     return $resulttext;
                   12037: }
                   12038: 
1.160.6.98  raeburn  12039: sub modify_passwords {
                   12040:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
                   12041:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   12042:         $updatedefaults,$updateconf);
                   12043:     my $customfn = 'resetpw.html';
                   12044:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   12045:         %current = %{$domconfig{'passwords'}};
                   12046:     }
                   12047:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12048:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   12049:     if (ref($types) eq 'ARRAY') {
                   12050:         @oktypes = @{$types};
                   12051:     }
                   12052:     push(@oktypes,'default');
                   12053: 
                   12054:     my %titles = &Apache::lonlocal::texthash (
                   12055:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   12056:         intauth_check  => 'Check bcrypt cost if authenticated',
                   12057:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   12058:         permanent      => 'Permanent e-mail address',
                   12059:         critical       => 'Critical notification address',
                   12060:         notify         => 'Notification address',
                   12061:         min            => 'Minimum password length',
                   12062:         max            => 'Maximum password length',
                   12063:         chars          => 'Required characters',
                   12064:         numsaved       => 'Number of previous passwords to save',
                   12065:         reset          => 'Resetting Forgotten Password',
                   12066:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   12067:         rules          => 'Rules for LON-CAPA Passwords',
                   12068:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   12069:         username       => 'Username',
                   12070:         email          => 'E-mail address',
                   12071:     );
                   12072: 
                   12073: #
                   12074: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   12075: #
                   12076:     my (%curr_defaults,%save_defaults);
                   12077:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   12078:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   12079:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   12080:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   12081:             } else {
                   12082:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   12083:             }
                   12084:         }
                   12085:     }
                   12086:     my %staticdefaults = (
                   12087:         'resetlink'      => 2,
                   12088:         'resetcase'      => \@oktypes,
                   12089:         'resetprelink'   => 'both',
                   12090:         'resetemail'     => ['critical','notify','permanent'],
                   12091:         'intauth_cost'   => 10,
                   12092:         'intauth_check'  => 0,
                   12093:         'intauth_switch' => 0,
                   12094:     );
1.160.6.99  raeburn  12095:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  12096:     foreach my $type (@oktypes) {
                   12097:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   12098:     }
                   12099:     my $linklife = $env{'form.passwords_link'};
                   12100:     $linklife =~ s/^\s+|\s+$//g;
                   12101:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   12102:         $newvalues{'resetlink'} = $linklife;
                   12103:         if ($current{'resetlink'}) {
                   12104:             if ($current{'resetlink'} ne $linklife) {
                   12105:                 $changes{'reset'} = 1;
                   12106:             }
1.160.6.102  raeburn  12107:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  12108:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   12109:                 $changes{'reset'} = 1;
                   12110:             }
                   12111:         }
                   12112:     } elsif ($current{'resetlink'}) {
                   12113:         $changes{'reset'} = 1;
                   12114:     }
                   12115:     my @casesens;
                   12116:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   12117:     foreach my $case (sort(@posscase)) {
                   12118:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   12119:             push(@casesens,$case);
                   12120:         }
                   12121:     }
                   12122:     $newvalues{'resetcase'} = \@casesens;
                   12123:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   12124:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   12125:         if (@diffs > 0) {
                   12126:             $changes{'reset'} = 1;
                   12127:         }
1.160.6.102  raeburn  12128:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  12129:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   12130:         if (@diffs > 0) {
                   12131:             $changes{'reset'} = 1;
                   12132:         }
                   12133:     }
                   12134:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   12135:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   12136:         if (exists($current{'resetprelink'})) {
                   12137:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   12138:                 $changes{'reset'} = 1;
                   12139:             }
1.160.6.102  raeburn  12140:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  12141:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   12142:                 $changes{'reset'} = 1;
                   12143:             }
                   12144:         }
                   12145:     } elsif ($current{'resetprelink'}) {
                   12146:         $changes{'reset'} = 1;
                   12147:     }
                   12148:     foreach my $type (@oktypes) {
                   12149:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   12150:         my @postlink;
                   12151:         foreach my $item (sort(@possplink)) {
                   12152:             if ($item =~ /^(email|username)$/) {
                   12153:                 push(@postlink,$item);
                   12154:             }
                   12155:         }
                   12156:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   12157:         unless ($changes{'reset'}) {
                   12158:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   12159:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   12160:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   12161:                     if (@diffs > 0) {
                   12162:                         $changes{'reset'} = 1;
                   12163:                     }
                   12164:                 } else {
                   12165:                     $changes{'reset'} = 1;
                   12166:                 }
1.160.6.102  raeburn  12167:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  12168:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   12169:                 if (@diffs > 0) {
                   12170:                     $changes{'reset'} = 1;
                   12171:                 }
                   12172:             }
                   12173:         }
                   12174:     }
                   12175:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   12176:     my @resetemail;
                   12177:     foreach my $item (sort(@possemailsrc)) {
                   12178:         if ($item =~ /^(permanent|critical|notify)$/) {
                   12179:             push(@resetemail,$item);
                   12180:         }
                   12181:     }
                   12182:     $newvalues{'resetemail'} = \@resetemail;
                   12183:     unless ($changes{'reset'}) {
                   12184:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   12185:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   12186:             if (@diffs > 0) {
                   12187:                 $changes{'reset'} = 1;
                   12188:             }
1.160.6.102  raeburn  12189:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  12190:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   12191:             if (@diffs > 0) {
                   12192:                 $changes{'reset'} = 1;
                   12193:             }
                   12194:         }
                   12195:     }
                   12196:     if ($env{'form.passwords_stdtext'} == 0) {
                   12197:         $newvalues{'resetremove'} = 1;
                   12198:         unless ($current{'resetremove'}) {
                   12199:             $changes{'reset'} = 1;
                   12200:         }
                   12201:     } elsif ($current{'resetremove'}) {
                   12202:         $changes{'reset'} = 1;
                   12203:     }
                   12204:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   12205:         my $servadm = $r->dir_config('lonAdmEMail');
                   12206:         my $servadm = $r->dir_config('lonAdmEMail');
                   12207:         my ($configuserok,$author_ok,$switchserver) =
                   12208:             &config_check($dom,$confname,$servadm);
                   12209:         my $error;
                   12210:         if ($configuserok eq 'ok') {
                   12211:             if ($switchserver) {
                   12212:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   12213:             } else {
                   12214:                 if ($author_ok eq 'ok') {
                   12215:                     my ($result,$customurl) =
                   12216:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   12217:                                      $confname,'customtext/resetpw','','',$customfn);
                   12218:                     if ($result eq 'ok') {
                   12219:                         $newvalues{'resetcustom'} = $customurl;
                   12220:                         $changes{'reset'} = 1;
                   12221:                     } else {
                   12222:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   12223:                     }
                   12224:                 } else {
                   12225:                     $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);
                   12226:                 }
                   12227:             }
                   12228:         } else {
                   12229:             $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);
                   12230:         }
                   12231:         if ($error) {
                   12232:             &Apache::lonnet::logthis($error);
                   12233:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12234:         }
                   12235:     } elsif ($current{'resetcustom'}) {
                   12236:         if ($env{'form.passwords_custom_del'}) {
                   12237:             $changes{'reset'} = 1;
                   12238:         } else {
                   12239:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   12240:         }
                   12241:     }
                   12242:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   12243:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   12244:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   12245:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   12246:             $changes{'intauth'} = 1;
                   12247:         }
                   12248:     } else {
                   12249:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   12250:     }
                   12251:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   12252:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   12253:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   12254:             $changes{'intauth'} = 1;
                   12255:         }
                   12256:     } else {
                   12257:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   12258:     }
                   12259:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   12260:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   12261:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   12262:             $changes{'intauth'} = 1;
                   12263:         }
                   12264:     } else {
                   12265:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   12266:     }
                   12267:     foreach my $item ('cost','check','switch') {
                   12268:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   12269:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   12270:             $updatedefaults = 1;
                   12271:         }
                   12272:     }
                   12273:     foreach my $rule ('min','max','numsaved') {
                   12274:         $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
1.160.6.99  raeburn  12275:         my $ruleok;
                   12276:         if ($rule eq 'min') {
                   12277:             if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   12278:                 if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                   12279:                     $ruleok = 1;
                   12280:                 }
                   12281:             }
                   12282:         } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                   12283:                  ($env{'form.passwords_'.$rule} ne '0')) {
                   12284:             $ruleok = 1;
                   12285:         }
                   12286:         if ($ruleok) {
1.160.6.98  raeburn  12287:             $newvalues{$rule} = $env{'form.passwords_'.$rule};
                   12288:             if (exists($current{$rule})) {
                   12289:                 if ($newvalues{$rule} ne $current{$rule}) {
                   12290:                     $changes{'rules'} = 1;
                   12291:                 }
                   12292:             } elsif ($rule eq 'min') {
                   12293:                 if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                   12294:                     $changes{'rules'} = 1;
                   12295:                 }
1.160.6.102.2  3(raebur 12296:0):             } else {
                   12297:0):                 $changes{'rules'} = 1;
1.160.6.98  raeburn  12298:             }
                   12299:         } elsif (exists($current{$rule})) {
                   12300:             $changes{'rules'} = 1;
                   12301:         }
                   12302:     }
                   12303:     my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
                   12304:     my @chars;
                   12305:     foreach my $item (sort(@posschars)) {
                   12306:         if ($item =~ /^(uc|lc|num|spec)$/) {
                   12307:             push(@chars,$item);
                   12308:         }
                   12309:     }
                   12310:     $newvalues{'chars'} = \@chars;
                   12311:     unless ($changes{'rules'}) {
                   12312:         if (ref($current{'chars'}) eq 'ARRAY') {
                   12313:             my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
                   12314:             if (@diffs > 0) {
                   12315:                 $changes{'rules'} = 1;
                   12316:             }
                   12317:         } else {
                   12318:             if (@chars > 0) {
                   12319:                 $changes{'rules'} = 1;
                   12320:             }
                   12321:         }
                   12322:     }
                   12323:     my %crsownerchg = (
                   12324:                         by => [],
                   12325:                         for => [],
                   12326:                       );
                   12327:     foreach my $item ('by','for') {
                   12328:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   12329:         foreach my $type (sort(@posstypes)) {
                   12330:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   12331:                 push(@{$crsownerchg{$item}},$type);
                   12332:             }
                   12333:         }
                   12334:     }
                   12335:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   12336:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   12337:         foreach my $item ('by','for') {
                   12338:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   12339:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   12340:                 if (@diffs > 0) {
                   12341:                     $changes{'crsownerchg'} = 1;
                   12342:                     last;
                   12343:                 }
                   12344:             }
                   12345:         }
1.160.6.102  raeburn  12346:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98  raeburn  12347:         foreach my $item ('by','for') {
                   12348:             if (@{$crsownerchg{$item}} > 0) {
                   12349:                 $changes{'crsownerchg'} = 1;
                   12350:                 last;
                   12351:             }
                   12352:         }
                   12353:     }
                   12354: 
                   12355:     my %confighash = (
                   12356:                         defaults  => \%save_defaults,
                   12357:                         passwords => \%newvalues,
                   12358:                      );
                   12359:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   12360: 
                   12361:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   12362:     if ($putresult eq 'ok') {
                   12363:         if (keys(%changes) > 0) {
                   12364:             $resulttext = &mt('Changes made: ').'<ul>';
                   12365:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   12366:                 if ($changes{$key}) {
                   12367:                     unless ($key eq 'intauth') {
                   12368:                         $updateconf = 1;
                   12369:                     }
                   12370:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   12371:                     if ($key eq 'reset') {
                   12372:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   12373:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   12374:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   12375:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.102.2  3(raebur 12376:0):                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   12377:0):                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   12378:0):                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   12379:0):                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   12380:0):                             }
1.160.6.98  raeburn  12381:                         } else {
                   12382:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   12383:                         }
                   12384:                         if ($confighash{'passwords'}{'resetlink'}) {
                   12385:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   12386:                         } else {
                   12387:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   12388:                                                   &mt('Will default to 2 hours').'</li>';
                   12389:                         }
                   12390:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   12391:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   12392:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   12393:                             } else {
                   12394:                                 my $casesens;
                   12395:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   12396:                                     if ($type eq 'default') {
                   12397:                                         $casesens .= $othertitle.', ';
                   12398:                                     } elsif ($usertypes->{$type} ne '') {
                   12399:                                         $casesens .= $usertypes->{$type}.', ';
                   12400:                                     }
                   12401:                                 }
                   12402:                                 $casesens =~ s/\Q, \E$//;
                   12403:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   12404:                             }
                   12405:                         } else {
                   12406:                             $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>';
                   12407:                         }
                   12408:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   12409:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   12410:                         } else {
                   12411:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   12412:                         }
                   12413:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   12414:                             my $output;
                   12415:                             if (ref($types) eq 'ARRAY') {
                   12416:                                 foreach my $type (@{$types}) {
                   12417:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   12418:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   12419:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   12420:                                         } else {
                   12421:                                             $output .= $usertypes->{$type}.' -- '.
                   12422:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   12423:                                         }
                   12424:                                     }
                   12425:                                 }
                   12426:                             }
                   12427:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   12428:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   12429:                                     $output .= $othertitle.' -- '.&mt('none');
                   12430:                                 } else {
                   12431:                                     $output .= $othertitle.' -- '.
                   12432:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   12433:                                 }
                   12434:                             }
                   12435:                             if ($output) {
                   12436:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   12437:                             } else {
                   12438:                                 $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>';
                   12439:                             }
                   12440:                         } else {
                   12441:                             $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>';
                   12442:                         }
                   12443:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   12444:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   12445:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   12446:                             } else {
                   12447:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   12448:                             }
                   12449:                         } else {
                   12450:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   12451:                         }
                   12452:                         if ($confighash{'passwords'}{'resetremove'}) {
                   12453:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   12454:                         } else {
                   12455:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   12456:                         }
                   12457:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   12458:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.102.2  3(raebur 12459:0):                                                                             &mt('custom text'),600,500,undef,undef,
                   12460:0):                                                                             undef,undef,'background-color:#ffffff');
                   12461:0):                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98  raeburn  12462:                         } else {
                   12463:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   12464:                         }
                   12465:                     } elsif ($key eq 'intauth') {
                   12466:                         foreach my $item ('cost','switch','check') {
                   12467:                             my $value = $save_defaults{$key.'_'.$item};
                   12468:                             if ($item eq 'switch') {
                   12469:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   12470:                                                      0 => 'No',
                   12471:                                                      1 => 'Yes',
                   12472:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   12473:                                                  );
                   12474:                                 if ($value =~ /^(0|1|2)$/) {
                   12475:                                     $value = $optiondesc{$value};
                   12476:                                 } else {
                   12477:                                     $value = &mt('none -- defaults to No');
                   12478:                                 }
                   12479:                             } elsif ($item eq 'check') {
                   12480:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   12481:                                                      0 => 'No',
                   12482:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   12483:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   12484:                                                  );
                   12485:                                 if ($value =~ /^(0|1|2)$/) {
                   12486:                                     $value = $optiondesc{$value};
                   12487:                                 } else {
                   12488:                                     $value = &mt('none -- defaults to No');
                   12489:                                 }
                   12490:                             }
                   12491:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   12492:                         }
                   12493:                     } elsif ($key eq 'rules') {
                   12494:                         foreach my $rule ('min','max','numsaved') {
                   12495:                             if ($confighash{'passwords'}{$rule} eq '') {
                   12496:                                 if ($rule eq 'min') {
                   12497:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99  raeburn  12498:                                                    ' '.&mt('Default of [_1] will be used',
                   12499:                                                            $Apache::lonnet::passwdmin).'</li>';
1.160.6.98  raeburn  12500:                                 } else {
                   12501:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   12502:                                 }
                   12503:                             } else {
                   12504:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   12505:                             }
                   12506:                         }
1.160.6.102.2  3(raebur 12507:0):                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   12508:0):                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   12509:0):                                 my %rulenames = &Apache::lonlocal::texthash(
                   12510:0):                                                      uc => 'At least one upper case letter',
                   12511:0):                                                      lc => 'At least one lower case letter',
                   12512:0):                                                      num => 'At least one number',
                   12513:0):                                                      spec => 'At least one non-alphanumeric',
                   12514:0):                                                    );
                   12515:0):                                 my $needed = '<ul><li>'.
                   12516:0):                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   12517:0):                                              '</li></ul>';
                   12518:0):                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   12519:0):                             } else {
                   12520:0):                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   12521:0):                             }
                   12522:0):                         } else {
                   12523:0):                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   12524:0):                         }
1.160.6.98  raeburn  12525:                     } elsif ($key eq 'crsownerchg') {
                   12526:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   12527:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   12528:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   12529:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   12530:                             } else {
                   12531:                                 my %crsownerstr;
                   12532:                                 foreach my $item ('by','for') {
                   12533:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   12534:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   12535:                                             if ($type eq 'default') {
                   12536:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   12537:                                             } elsif ($usertypes->{$type} ne '') {
                   12538:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   12539:                                             }
                   12540:                                         }
                   12541:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   12542:                                     }
                   12543:                                 }
                   12544:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   12545:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   12546:                             }
                   12547:                         } else {
                   12548:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   12549:                         }
                   12550:                     }
                   12551:                     $resulttext .= '</ul></li>';
                   12552:                 }
                   12553:             }
                   12554:             $resulttext .= '</ul>';
                   12555:         } else {
                   12556:             $resulttext = &mt('No changes made to password settings');
                   12557:         }
                   12558:         my $cachetime = 24*60*60;
                   12559:         if ($updatedefaults) {
                   12560:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12561:             if (ref($lastactref) eq 'HASH') {
                   12562:                 $lastactref->{'domdefaults'} = 1;
                   12563:             }
                   12564:         }
                   12565:         if ($updateconf) {
                   12566:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   12567:             if (ref($lastactref) eq 'HASH') {
                   12568:                 $lastactref->{'passwdconf'} = 1;
                   12569:             }
                   12570:         }
                   12571:     } else {
                   12572:         $resulttext = '<span class="LC_error">'.
                   12573:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12574:     }
                   12575:     if ($errors) {
                   12576:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   12577:                        $errors.'</ul></p>';
                   12578:     }
                   12579:     return $resulttext;
                   12580: }
                   12581: 
1.28      raeburn  12582: sub modify_usercreation {
1.27      raeburn  12583:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  12584:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  12585:     my $warningmsg;
1.27      raeburn  12586:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   12587:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34  raeburn  12588:             if ($key eq 'cancreate') {
                   12589:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   12590:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93  raeburn  12591:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34  raeburn  12592:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93  raeburn  12593:                         } else {
                   12594:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34  raeburn  12595:                         }
1.50      raeburn  12596:                     }
1.43      raeburn  12597:                 }
1.160.6.34  raeburn  12598:             } elsif ($key eq 'email_rule') {
                   12599:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   12600:             } else {
                   12601:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43      raeburn  12602:             }
                   12603:         }
1.34      raeburn  12604:     }
1.160.6.34  raeburn  12605:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
                   12606:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
                   12607:     my @contexts = ('author','course','requestcrs');
                   12608:     foreach my $item(@contexts) {
                   12609:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  12610:     }
1.34      raeburn  12611:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   12612:         foreach my $item (@contexts) {
1.160.6.34  raeburn  12613:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   12614:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  12615:             }
1.27      raeburn  12616:         }
1.34      raeburn  12617:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   12618:         foreach my $item (@contexts) {
1.43      raeburn  12619:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  12620:                 if ($cancreate{$item} ne 'any') {
                   12621:                     push(@{$changes{'cancreate'}},$item);
                   12622:                 }
                   12623:             } else {
                   12624:                 if ($cancreate{$item} ne 'none') {
                   12625:                     push(@{$changes{'cancreate'}},$item);
                   12626:                 }
1.27      raeburn  12627:             }
                   12628:         }
                   12629:     } else {
1.43      raeburn  12630:         foreach my $item (@contexts)  {
1.34      raeburn  12631:             push(@{$changes{'cancreate'}},$item);
                   12632:         }
1.27      raeburn  12633:     }
1.34      raeburn  12634: 
1.27      raeburn  12635:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   12636:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   12637:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   12638:                 push(@{$changes{'username_rule'}},$type);
                   12639:             }
                   12640:         }
                   12641:         foreach my $type (@username_rule) {
                   12642:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   12643:                 push(@{$changes{'username_rule'}},$type);
                   12644:             }
                   12645:         }
                   12646:     } else {
                   12647:         push(@{$changes{'username_rule'}},@username_rule);
                   12648:     }
                   12649: 
1.32      raeburn  12650:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   12651:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   12652:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   12653:                 push(@{$changes{'id_rule'}},$type);
                   12654:             }
                   12655:         }
                   12656:         foreach my $type (@id_rule) {
                   12657:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   12658:                 push(@{$changes{'id_rule'}},$type);
                   12659:             }
                   12660:         }
                   12661:     } else {
                   12662:         push(@{$changes{'id_rule'}},@id_rule);
                   12663:     }
                   12664: 
1.43      raeburn  12665:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  12666:     my @authtypes = ('int','krb4','krb5','loc');
                   12667:     my %authhash;
1.43      raeburn  12668:     foreach my $item (@authen_contexts) {
1.28      raeburn  12669:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   12670:         foreach my $auth (@authtypes) {
                   12671:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   12672:                 $authhash{$item}{$auth} = 1;
                   12673:             } else {
                   12674:                 $authhash{$item}{$auth} = 0;
                   12675:             }
                   12676:         }
                   12677:     }
                   12678:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  12679:         foreach my $item (@authen_contexts) {
1.28      raeburn  12680:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   12681:                 foreach my $auth (@authtypes) {
                   12682:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   12683:                         push(@{$changes{'authtypes'}},$item);
                   12684:                         last;
                   12685:                     }
                   12686:                 }
                   12687:             }
                   12688:         }
                   12689:     } else {
1.43      raeburn  12690:         foreach my $item (@authen_contexts) {
1.28      raeburn  12691:             push(@{$changes{'authtypes'}},$item);
                   12692:         }
                   12693:     }
                   12694: 
1.160.6.34  raeburn  12695:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   12696:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   12697:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   12698:     $save_usercreate{'id_rule'} = \@id_rule;
                   12699:     $save_usercreate{'username_rule'} = \@username_rule,
                   12700:     $save_usercreate{'authtypes'} = \%authhash;
                   12701: 
1.27      raeburn  12702:     my %usercreation_hash =  (
1.160.6.34  raeburn  12703:         usercreation     => \%save_usercreate,
                   12704:     );
1.27      raeburn  12705: 
                   12706:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   12707:                                              $dom);
1.50      raeburn  12708: 
1.160.6.34  raeburn  12709:     if ($putresult eq 'ok') {
                   12710:         if (keys(%changes) > 0) {
                   12711:             $resulttext = &mt('Changes made:').'<ul>';
                   12712:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   12713:                 my %lt = &usercreation_types();
                   12714:                 foreach my $type (@{$changes{'cancreate'}}) {
                   12715:                     my $chgtext = $lt{$type}.', ';
                   12716:                     if ($cancreate{$type} eq 'none') {
                   12717:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   12718:                     } elsif ($cancreate{$type} eq 'any') {
                   12719:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   12720:                     } elsif ($cancreate{$type} eq 'official') {
                   12721:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   12722:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   12723:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   12724:                     }
                   12725:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   12726:                 }
                   12727:             }
                   12728:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   12729:                 my ($rules,$ruleorder) = 
                   12730:                     &Apache::lonnet::inst_userrules($dom,'username');
                   12731:                 my $chgtext = '<ul>';
                   12732:                 foreach my $type (@username_rule) {
                   12733:                     if (ref($rules->{$type}) eq 'HASH') {
                   12734:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   12735:                     }
                   12736:                 }
                   12737:                 $chgtext .= '</ul>';
                   12738:                 if (@username_rule > 0) {
                   12739:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   12740:                 } else {
                   12741:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   12742:                 }
                   12743:             }
                   12744:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   12745:                 my ($idrules,$idruleorder) = 
                   12746:                     &Apache::lonnet::inst_userrules($dom,'id');
                   12747:                 my $chgtext = '<ul>';
                   12748:                 foreach my $type (@id_rule) {
                   12749:                     if (ref($idrules->{$type}) eq 'HASH') {
                   12750:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   12751:                     }
                   12752:                 }
                   12753:                 $chgtext .= '</ul>';
                   12754:                 if (@id_rule > 0) {
                   12755:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   12756:                 } else {
                   12757:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   12758:                 }
                   12759:             }
                   12760:             my %authname = &authtype_names();
                   12761:             my %context_title = &context_names();
                   12762:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   12763:                 my $chgtext = '<ul>';
                   12764:                 foreach my $type (@{$changes{'authtypes'}}) {
                   12765:                     my @allowed;
                   12766:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   12767:                     foreach my $auth (@authtypes) {
                   12768:                         if ($authhash{$type}{$auth}) {
                   12769:                             push(@allowed,$authname{$auth});
                   12770:                         }
                   12771:                     }
                   12772:                     if (@allowed > 0) {
                   12773:                         $chgtext .= join(', ',@allowed).'</li>';
                   12774:                     } else {
                   12775:                         $chgtext .= &mt('none').'</li>';
                   12776:                     }
                   12777:                 }
                   12778:                 $chgtext .= '</ul>';
                   12779:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   12780:                 $resulttext .= '</li>';
                   12781:             }
                   12782:             $resulttext .= '</ul>';
                   12783:         } else {
                   12784:             $resulttext = &mt('No changes made to user creation settings');
                   12785:         }
                   12786:     } else {
                   12787:         $resulttext = '<span class="LC_error">'.
                   12788:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   12789:     }
                   12790:     if ($warningmsg ne '') {
                   12791:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   12792:     }
                   12793:     return $resulttext;
                   12794: }
                   12795: 
                   12796: sub modify_selfcreation {
1.160.6.93  raeburn  12797:     my ($dom,$lastactref,%domconfig) = @_;
                   12798:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   12799:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   12800:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12801:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   12802:     if (ref($typesref) eq 'ARRAY') {
                   12803:         @types = @{$typesref};
                   12804:     }
                   12805:     if (ref($usertypesref) eq 'HASH') {
                   12806:         %usertypes = %{$usertypesref};
1.160.6.35  raeburn  12807:     }
1.160.6.93  raeburn  12808:     $usertypes{'default'} = $othertitle;
1.160.6.34  raeburn  12809: #
                   12810: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   12811: #
                   12812:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   12813:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   12814:             if ($key eq 'cancreate') {
                   12815:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   12816:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   12817:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93  raeburn  12818:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   12819:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   12820:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   12821:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
                   12822:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34  raeburn  12823:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   12824:                         } else {
                   12825:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   12826:                         }
                   12827:                     }
                   12828:                 }
                   12829:             } elsif ($key eq 'email_rule') {
                   12830:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   12831:             } else {
                   12832:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   12833:             }
                   12834:         }
                   12835:     }
                   12836: #
                   12837: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   12838: #
                   12839:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   12840:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   12841:             if ($key eq 'selfcreate') {
                   12842:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   12843:             } else {
                   12844:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   12845:             }
                   12846:         }
                   12847:     }
1.160.6.93  raeburn  12848: #
                   12849: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   12850: #
                   12851:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   12852:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   12853:             if ($key eq 'inststatusguest') {
                   12854:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   12855:             } else {
                   12856:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   12857:             }
                   12858:         }
                   12859:     }
1.160.6.34  raeburn  12860: 
                   12861:     my @contexts = ('selfcreate');
                   12862:     @{$cancreate{'selfcreate'}} = ();
                   12863:     %{$cancreate{'emailusername'}} = ();
1.160.6.93  raeburn  12864:     if (@types) {
                   12865:         @{$cancreate{'statustocreate'}} = ();
                   12866:     }
1.160.6.40  raeburn  12867:     %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44  raeburn  12868:     %{$cancreate{'shibenv'}} = ();
1.160.6.93  raeburn  12869:     %{$cancreate{'emailverified'}} = ();
                   12870:     %{$cancreate{'emailoptions'}} = ();
                   12871:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  12872:     my %selfcreatetypes = (
                   12873:                              sso   => 'users authenticated by institutional single sign on',
                   12874:                              login => 'users authenticated by institutional log-in',
1.160.6.93  raeburn  12875:                              email => 'users verified by e-mail',
1.50      raeburn  12876:                           );
1.160.6.34  raeburn  12877: #
                   12878: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   12879: # is permitted.
                   12880: #
1.160.6.40  raeburn  12881: 
1.160.6.93  raeburn  12882:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40  raeburn  12883: 
1.160.6.93  raeburn  12884:     my (@statuses,%email_rule);
1.160.6.35  raeburn  12885:     foreach my $item ('login','sso','email') {
1.160.6.34  raeburn  12886:         if ($item eq 'email') {
1.160.6.40  raeburn  12887:             if ($env{'form.cancreate_email'}) {
1.160.6.93  raeburn  12888:                 if (@types) {
                   12889:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   12890:                     foreach my $status (@poss_statuses) {
                   12891:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   12892:                             push(@statuses,$status);
                   12893:                         }
                   12894:                     }
                   12895:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   12896:                 } else {
                   12897:                     push(@statuses,'default');
                   12898:                 }
                   12899:                 if (@statuses) {
                   12900:                     my %curr_rule;
                   12901:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   12902:                         foreach my $type (@statuses) {
                   12903:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
                   12904:                         }
                   12905:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   12906:                         foreach my $type (@statuses) {
                   12907:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   12908:                         }
                   12909:                     }
                   12910:                     push(@{$cancreate{'selfcreate'}},'email');
                   12911:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   12912:                     my %curremaildom;
                   12913:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   12914:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   12915:                     }
                   12916:                     foreach my $type (@statuses) {
                   12917:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   12918:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   12919:                         }
                   12920:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   12921:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   12922:                         }
                   12923:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   12924: #
                   12925: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   12926: #
                   12927:                             my $chosen = $1;
                   12928:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   12929:                                 my $emaildom;
                   12930:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   12931:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
                   12932:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   12933:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   12934:                                         if (exists($curremaildom{$type}{$chosen})) {
                   12935:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   12936:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   12937:                                             }
                   12938:                                         } elsif ($emaildom ne '') {
                   12939:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   12940:                                         }
                   12941:                                     } elsif ($emaildom ne '') {
                   12942:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   12943:                                     }
                   12944:                                 }
                   12945:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   12946:                             } elsif ($chosen eq 'custom') {
                   12947:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   12948:                                 $email_rule{$type} = [];
                   12949:                                 if (ref($emailrules) eq 'HASH') {
                   12950:                                     foreach my $rule (@possemail_rules) {
                   12951:                                         if (exists($emailrules->{$rule})) {
                   12952:                                             push(@{$email_rule{$type}},$rule);
                   12953:                                         }
                   12954:                                     }
                   12955:                                 }
                   12956:                                 if (@{$email_rule{$type}}) {
                   12957:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   12958:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   12959:                                         if (@{$curr_rule{$type}} > 0) {
                   12960:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   12961:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   12962:                                                     push(@{$changes{'email_rule'}},$type);
                   12963:                                                 }
                   12964:                                             }
                   12965:                                         }
                   12966:                                         foreach my $type (@{$email_rule{$type}}) {
                   12967:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   12968:                                                 push(@{$changes{'email_rule'}},$type);
                   12969:                                             }
                   12970:                                         }
                   12971:                                     } else {
                   12972:                                         push(@{$changes{'email_rule'}},$type);
                   12973:                                     }
                   12974:                                 }
                   12975:                             } else {
                   12976:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   12977:                             }
                   12978:                         }
                   12979:                     }
                   12980:                     if (@types) {
                   12981:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12982:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   12983:                             if (@changed) {
                   12984:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   12985:                             }
                   12986:                         } else {
                   12987:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12988:                         }
                   12989:                     }
                   12990:                 } else {
                   12991:                     delete($env{'form.cancreate_email'});
                   12992:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   12993:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   12994:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   12995:                         }
                   12996:                     }
                   12997:                 }
                   12998:             } else {
                   12999:                 $save_inststatus{'inststatusguest'} = [];
                   13000:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   13001:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   13002:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40  raeburn  13003:                     }
                   13004:                 }
1.160.6.34  raeburn  13005:             }
                   13006:         } else {
                   13007:             if ($env{'form.cancreate_'.$item}) {
                   13008:                 push(@{$cancreate{'selfcreate'}},$item);
                   13009:             }
                   13010:         }
                   13011:     }
1.160.6.93  raeburn  13012:     my (%userinfo,%savecaptcha);
1.160.6.34  raeburn  13013:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   13014: #
1.160.6.35  raeburn  13015: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   13016: # 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  13017: #
1.160.6.40  raeburn  13018: 
1.160.6.48  raeburn  13019:     if ($env{'form.cancreate_email'}) {
1.160.6.37  raeburn  13020:         push(@contexts,'emailusername');
1.160.6.93  raeburn  13021:         if (@statuses) {
                   13022:             foreach my $type (@statuses) {
1.160.6.35  raeburn  13023:                 if (ref($infofields) eq 'ARRAY') {
                   13024:                     foreach my $field (@{$infofields}) {
                   13025:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   13026:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   13027:                         }
                   13028:                     }
1.160.6.34  raeburn  13029:                 }
                   13030:             }
                   13031:         }
                   13032: #
                   13033: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93  raeburn  13034: # queued requests for self-creation of account verified by e-mail.
1.160.6.34  raeburn  13035: #
                   13036: 
                   13037:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   13038:         @approvalnotify = sort(@approvalnotify);
                   13039:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   13040:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   13041:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   13042:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   13043:                     push(@{$changes{'cancreate'}},'notify');
                   13044:                 }
                   13045:             } else {
                   13046:                 if ($cancreate{'notify'}{'approval'}) {
                   13047:                     push(@{$changes{'cancreate'}},'notify');
                   13048:                 }
                   13049:             }
                   13050:         } elsif ($cancreate{'notify'}{'approval'}) {
                   13051:             push(@{$changes{'cancreate'}},'notify');
                   13052:         }
                   13053: 
                   13054:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   13055:     }
                   13056: #  
1.160.6.40  raeburn  13057: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34  raeburn  13058: # institutional log-in.
                   13059: #
                   13060:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   13061:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   13062:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   13063:             $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.').' '.
                   13064:                           &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.');
                   13065:         }
                   13066:     }
                   13067:     my @fields = ('lastname','firstname','middlename','generation',
                   13068:                   'permanentemail','id');
1.160.6.44  raeburn  13069:     my @shibfields = (@fields,'inststatus');
1.160.6.34  raeburn  13070:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   13071: #
                   13072: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   13073: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   13074: # may self-create accounts 
                   13075: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   13076: # which the user may supply, if institutional data is unavailable.
                   13077: #
                   13078:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93  raeburn  13079:         if (@types) {
                   13080:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   13081:             push(@contexts,'statustocreate');
                   13082:             foreach my $type (@types) {
1.160.6.34  raeburn  13083:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   13084:                 foreach my $field (@fields) {
                   13085:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   13086:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   13087:                     } else {
                   13088:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   13089:                     }
                   13090:                 }
                   13091:             }
                   13092:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93  raeburn  13093:                 foreach my $type (@types) {
1.160.6.34  raeburn  13094:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   13095:                         foreach my $field (@fields) {
                   13096:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   13097:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   13098:                                 push(@{$changes{'selfcreate'}},$type);
                   13099:                                 last;
                   13100:                             }
                   13101:                         }
                   13102:                     }
                   13103:                 }
                   13104:             } else {
1.160.6.93  raeburn  13105:                 foreach my $type (@types) {
1.160.6.34  raeburn  13106:                     push(@{$changes{'selfcreate'}},$type);
                   13107:                 }
                   13108:             }
                   13109:         }
1.160.6.44  raeburn  13110:         foreach my $field (@shibfields) {
                   13111:             if ($env{'form.shibenv_'.$field} ne '') {
                   13112:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   13113:             }
                   13114:         }
                   13115:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   13116:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   13117:                 foreach my $field (@shibfields) {
                   13118:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   13119:                         push(@{$changes{'cancreate'}},'shibenv');
                   13120:                     }
                   13121:                 }
                   13122:             } else {
                   13123:                 foreach my $field (@shibfields) {
                   13124:                     if ($env{'form.shibenv_'.$field}) {
                   13125:                         push(@{$changes{'cancreate'}},'shibenv');
                   13126:                         last;
                   13127:                     }
                   13128:                 }
                   13129:             }
                   13130:         }
1.160.6.34  raeburn  13131:     }
                   13132:     foreach my $item (@contexts) {
                   13133:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   13134:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   13135:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   13136:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   13137:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13138:                             push(@{$changes{'cancreate'}},$item);
                   13139:                         }
                   13140:                     }
                   13141:                 }
                   13142:             }
                   13143:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   13144:                 foreach my $type (@{$cancreate{$item}}) {
                   13145:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   13146:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13147:                             push(@{$changes{'cancreate'}},$item);
                   13148:                         }
                   13149:                     }
                   13150:                 }
                   13151:             }
                   13152:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   13153:             if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93  raeburn  13154:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   13155:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   13156:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   13157:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  13158:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13159:                                     push(@{$changes{'cancreate'}},$item);
                   13160:                                 }
                   13161:                             }
                   13162:                         }
1.160.6.93  raeburn  13163:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   13164:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  13165:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13166:                                 push(@{$changes{'cancreate'}},$item);
                   13167:                             }
1.160.6.34  raeburn  13168:                         }
                   13169:                     }
                   13170:                 }
1.160.6.93  raeburn  13171:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   13172:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   13173:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   13174:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   13175:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  13176:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13177:                                         push(@{$changes{'cancreate'}},$item);
                   13178:                                     }
                   13179:                                 }
                   13180:                             } else {
                   13181:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13182:                                     push(@{$changes{'cancreate'}},$item);
                   13183:                                 }
                   13184:                             }
                   13185:                         }
1.160.6.93  raeburn  13186:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   13187:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  13188:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13189:                                 push(@{$changes{'cancreate'}},$item);
                   13190:                             }
1.160.6.34  raeburn  13191:                         }
                   13192:                     }
                   13193:                 }
                   13194:             }
                   13195:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   13196:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   13197:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   13198:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13199:                         push(@{$changes{'cancreate'}},$item);
                   13200:                     }
                   13201:                 }
1.160.6.93  raeburn  13202:             }
                   13203:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   13204:             if (ref($cancreate{$item}) eq 'HASH') {
                   13205:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13206:                     push(@{$changes{'cancreate'}},$item);
1.160.6.34  raeburn  13207:                 }
                   13208:             }
                   13209:         } elsif ($item eq 'emailusername') {
1.160.6.35  raeburn  13210:             if (ref($cancreate{$item}) eq 'HASH') {
                   13211:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   13212:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   13213:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   13214:                             if ($cancreate{$item}{$type}{$field}) {
                   13215:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   13216:                                     push(@{$changes{'cancreate'}},$item);
                   13217:                                 }
                   13218:                                 last;
                   13219:                             }
                   13220:                         }
                   13221:                     }
                   13222:                 }
1.160.6.34  raeburn  13223:             }
                   13224:         }
                   13225:     }
                   13226: #
                   13227: # Populate %save_usercreate hash with updates to self-creation configuration.
                   13228: #
                   13229:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   13230:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69  raeburn  13231:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34  raeburn  13232:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   13233:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   13234:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   13235:     }
1.160.6.40  raeburn  13236:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   13237:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   13238:     }
1.160.6.93  raeburn  13239:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   13240:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   13241:     }
                   13242:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   13243:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   13244:     }
                   13245:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   13246:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   13247:     }
1.160.6.34  raeburn  13248:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   13249:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   13250:     }
1.160.6.44  raeburn  13251:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   13252:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   13253:     }
1.160.6.34  raeburn  13254:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93  raeburn  13255:     $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34  raeburn  13256: 
                   13257:     my %userconfig_hash = (
                   13258:             usercreation     => \%save_usercreate,
                   13259:             usermodification => \%save_usermodify,
1.160.6.93  raeburn  13260:             inststatus       => \%save_inststatus,
1.160.6.34  raeburn  13261:     );
1.160.6.93  raeburn  13262: 
1.160.6.34  raeburn  13263:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   13264:                                              $dom);
                   13265: #
1.160.6.93  raeburn  13266: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34  raeburn  13267: #
1.27      raeburn  13268:     if ($putresult eq 'ok') {
                   13269:         if (keys(%changes) > 0) {
                   13270:             $resulttext = &mt('Changes made:').'<ul>';
                   13271:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34  raeburn  13272:                 my %lt = &selfcreation_types();
1.34      raeburn  13273:                 foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93  raeburn  13274:                     my $chgtext = '';
1.45      raeburn  13275:                     if ($type eq 'selfcreate') {
1.50      raeburn  13276:                         if (@{$cancreate{$type}} == 0) {
1.160.6.34  raeburn  13277:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  13278:                         } else {
1.160.6.34  raeburn  13279:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   13280:                                         '<ul>';
1.50      raeburn  13281:                             foreach my $case (@{$cancreate{$type}}) {
                   13282:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   13283:                             }
                   13284:                             $chgtext .= '</ul>';
1.100     raeburn  13285:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   13286:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   13287:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   13288:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93  raeburn  13289:                                             $chgtext .= '<span class="LC_warning">'.
                   13290:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   13291:                                                         '</span><br />';
1.100     raeburn  13292:                                         }
                   13293:                                     }
                   13294:                                 }
1.160.6.93  raeburn  13295:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
                   13296:                                     if (!@statuses) {
                   13297:                                         $chgtext .= '<span class="LC_warning">'.
                   13298:                                                     &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.").
                   13299:                                                     '</span><br />';
                   13300: 
                   13301:                                     }
                   13302:                                 }
1.100     raeburn  13303:                             }
1.43      raeburn  13304:                         }
1.160.6.44  raeburn  13305:                     } elsif ($type eq 'shibenv') {
                   13306:                         if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93  raeburn  13307:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.160.6.44  raeburn  13308:                         } else {
                   13309:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   13310:                                         '<ul>';
                   13311:                             foreach my $field (@shibfields) {
                   13312:                                 next if ($cancreate{$type}{$field} eq '');
                   13313:                                 if ($field eq 'inststatus') {
                   13314:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   13315:                                 } else {
                   13316:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   13317:                                 }
                   13318:                             }
                   13319:                             $chgtext .= '</ul>';
1.160.6.93  raeburn  13320:                         }
1.93      raeburn  13321:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  13322:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   13323:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   13324:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   13325:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  13326:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  13327:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  13328:                                         $chgtext .= '<br />'.
                   13329:                                                     '<span class="LC_warning">'.
                   13330:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   13331:                                                     '</span>';
                   13332:                                     }
1.160.6.93  raeburn  13333:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  13334:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  13335:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   13336:                                     } else {
                   13337:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   13338:                                     }
                   13339:                                     $chgtext .= '<ul>';
                   13340:                                     foreach my $case (@{$cancreate{$type}}) {
                   13341:                                         if ($case eq 'default') {
                   13342:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   13343:                                         } else {
1.160.6.93  raeburn  13344:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  13345:                                         }
                   13346:                                     }
1.100     raeburn  13347:                                     $chgtext .= '</ul>';
                   13348:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93  raeburn  13349:                                         $chgtext .= '<span class="LC_warning">'.
1.160.6.34  raeburn  13350:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   13351:                                                     '</span>';
1.100     raeburn  13352:                                     }
                   13353:                                 }
                   13354:                             } else {
                   13355:                                 if (@{$cancreate{$type}} == 0) {
                   13356:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   13357:                                 } else {
                   13358:                                     $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  13359:                                 }
                   13360:                             }
1.160.6.93  raeburn  13361:                             $chgtext .= '<br />';
1.93      raeburn  13362:                         }
1.160.6.40  raeburn  13363:                     } elsif ($type eq 'selfcreateprocessing') {
                   13364:                         my %choices = &Apache::lonlocal::texthash (
                   13365:                                                                     automatic => 'Automatic approval',
                   13366:                                                                     approval  => 'Queued for approval',
                   13367:                                                                   );
1.160.6.93  raeburn  13368:                         if (@types) {
                   13369:                             if (@statuses) {
                   13370:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
                   13371:                                             '<ul>';
                   13372:                                 foreach my $status (@statuses) {
                   13373:                                     if ($status eq 'default') {
                   13374:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   13375:                                     } else {
                   13376:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   13377:                                     }
                   13378:                                 }
                   13379:                                 $chgtext .= '</ul>';
                   13380:                             }
                   13381:                         } else {
                   13382:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   13383:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   13384:                         }
                   13385:                     } elsif ($type eq 'emailverified') {
                   13386:                         my %options = &Apache::lonlocal::texthash (
                   13387:                                                                     all   => 'Same as e-mail',
                   13388:                                                                     first => 'Omit @domain',
                   13389:                                                                     free  => 'Free to choose',
                   13390:                                                                   );
                   13391:                         if (@types) {
                   13392:                             if (@statuses) {
                   13393:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   13394:                                             '<ul>';
                   13395:                                 foreach my $status (@statuses) {
                   13396:                                     if ($status eq 'default') {
                   13397:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   13398:                                     } else {
                   13399:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   13400:                                     }
                   13401:                                 }
                   13402:                                 $chgtext .= '</ul>';
                   13403:                             }
1.160.6.40  raeburn  13404:                         } else {
1.160.6.93  raeburn  13405:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
                   13406:                                             $options{$cancreate{'emailverified'}{'default'}});
                   13407:                         }
                   13408:                     } elsif ($type eq 'emailoptions') {
                   13409:                         my %options = &Apache::lonlocal::texthash (
                   13410:                                                                     any     => 'Any e-mail',
                   13411:                                                                     inst    => 'Institutional only',
                   13412:                                                                     noninst => 'Non-institutional only',
                   13413:                                                                     custom  => 'Custom restrictions',
                   13414:                                                                   );
                   13415:                         if (@types) {
                   13416:                             if (@statuses) {
                   13417:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   13418:                                             '<ul>';
                   13419:                                 foreach my $status (@statuses) {
                   13420:                                     if ($type eq 'default') {
                   13421:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   13422:                                     } else {
                   13423:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   13424:                                     }
                   13425:                                 }
                   13426:                                 $chgtext .= '</ul>';
                   13427:                             }
                   13428:                         } else {
                   13429:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   13430:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   13431:                             } else {
                   13432:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   13433:                                                 $options{$cancreate{'emailoptions'}{'default'}});
                   13434:                             }
                   13435:                         }
                   13436:                     } elsif ($type eq 'emaildomain') {
                   13437:                         my $output;
                   13438:                         if (@statuses) {
                   13439:                             foreach my $type (@statuses) {
                   13440:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   13441:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   13442:                                         if ($type eq 'default') {
                   13443:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   13444:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   13445:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   13446:                                             } else {
                   13447:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   13448:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   13449:                                             }
                   13450:                                         } else {
                   13451:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   13452:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   13453:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   13454:                                             } else {
                   13455:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   13456:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   13457:                                             }
                   13458:                                         }
                   13459:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   13460:                                         if ($type eq 'default') {
                   13461:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   13462:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   13463:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   13464:                                             } else {
                   13465:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   13466:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   13467:                                             }
                   13468:                                         } else {
                   13469:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   13470:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   13471:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   13472:                                             } else {
                   13473:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   13474:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   13475:                                             }
                   13476:                                         }
                   13477:                                     }
                   13478:                                 }
                   13479:                             }
                   13480:                         }
                   13481:                         if ($output ne '') {
                   13482:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   13483:                                         '<ul>'.$output.'</ul>';
1.160.6.40  raeburn  13484:                         }
1.160.6.5  raeburn  13485:                     } elsif ($type eq 'captcha') {
1.160.6.34  raeburn  13486:                         if ($savecaptcha{$type} eq 'notused') {
1.160.6.5  raeburn  13487:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   13488:                         } else {
                   13489:                             my %captchas = &captcha_phrases();
1.160.6.34  raeburn  13490:                             if ($captchas{$savecaptcha{$type}}) {
                   13491:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5  raeburn  13492:                             } else {
                   13493:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                   13494:                             }
                   13495:                         }
                   13496:                     } elsif ($type eq 'recaptchakeys') {
                   13497:                         my ($privkey,$pubkey);
1.160.6.34  raeburn  13498:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   13499:                             $pubkey = $savecaptcha{$type}{'public'};
                   13500:                             $privkey = $savecaptcha{$type}{'private'};
1.160.6.5  raeburn  13501:                         }
                   13502:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   13503:                         if (!$pubkey) {
                   13504:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   13505:                         } else {
                   13506:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   13507:                         }
                   13508:                         if (!$privkey) {
                   13509:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   13510:                         } else {
                   13511:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   13512:                         }
                   13513:                         $chgtext .= '</ul>';
1.160.6.69  raeburn  13514:                     } elsif ($type eq 'recaptchaversion') {
                   13515:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
                   13516:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                   13517:                         }
1.160.6.34  raeburn  13518:                     } elsif ($type eq 'emailusername') {
                   13519:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93  raeburn  13520:                             if (@statuses) {
                   13521:                                 foreach my $type (@statuses) {
1.160.6.35  raeburn  13522:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   13523:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93  raeburn  13524:                                             $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  13525:                                                     '<ul>';
                   13526:                                             foreach my $field (@{$infofields}) {
                   13527:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   13528:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   13529:                                                 }
                   13530:                                             }
1.160.6.50  raeburn  13531:                                             $chgtext .= '</ul>';
                   13532:                                         } else {
1.160.6.93  raeburn  13533:                                             $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  13534:                                         }
                   13535:                                     } else {
1.160.6.93  raeburn  13536:                                         $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  13537:                                     }
                   13538:                                 }
                   13539:                             }
                   13540:                         }
                   13541:                     } elsif ($type eq 'notify') {
1.160.6.93  raeburn  13542:                         my $numapprove = 0;
1.160.6.34  raeburn  13543:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   13544:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   13545:                                 if ($cancreate{'notify'}{'approval'}) {
1.160.6.93  raeburn  13546:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   13547:                                     $numapprove ++;
1.160.6.34  raeburn  13548:                                 }
                   13549:                             }
1.43      raeburn  13550:                         }
1.160.6.93  raeburn  13551:                         unless ($numapprove) {
                   13552:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   13553:                         }
1.34      raeburn  13554:                     }
1.160.6.34  raeburn  13555:                     if ($chgtext) {
                   13556:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  13557:                     }
                   13558:                 }
                   13559:             }
1.160.6.93  raeburn  13560:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  13561:                 my ($emailrules,$emailruleorder) =
                   13562:                     &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93  raeburn  13563:                 foreach my $type (@{$changes{'email_rule'}}) {
                   13564:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   13565:                         my $chgtext = '<ul>';
                   13566:                         foreach my $rule (@{$email_rule{$type}}) {
                   13567:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   13568:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   13569:                             }
                   13570:                         }
                   13571:                         $chgtext .= '</ul>';
                   13572:                         my $typename;
                   13573:                         if (@types) {
                   13574:                             if ($type eq 'default') {
                   13575:                                 $typename = $othertitle;
                   13576:                             } else {
                   13577:                                 $typename = $usertypes{$type};
                   13578:                             }
                   13579:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   13580:                         }
                   13581:                         if (@{$email_rule{$type}} > 0) {
                   13582:                             $resulttext .= '<li>'.
                   13583:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   13584:                                                $usertypes{$type}).
                   13585:                                            $chgtext.
                   13586:                                            '</li>';
                   13587:                         } else {
                   13588:                             $resulttext .= '<li>'.
                   13589:                                            &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
                   13590:                                            '</li>'.
                   13591:                                            &mt('(Affiliation: [_1])',$typename);
                   13592:                         }
1.43      raeburn  13593:                     }
                   13594:                 }
1.160.6.93  raeburn  13595:             }
                   13596:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   13597:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   13598:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   13599:                         my $chgtext = '<ul>';
                   13600:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   13601:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   13602:                         }
                   13603:                         $chgtext .= '</ul>';
                   13604:                         $resulttext .= '<li>'.
                   13605:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   13606:                                           $chgtext.
                   13607:                                        '</li>';
                   13608:                     } else {
                   13609:                         $resulttext .= '<li>'.
                   13610:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   13611:                                        '</li>';
                   13612:                     }
1.43      raeburn  13613:                 }
                   13614:             }
1.160.6.34  raeburn  13615:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   13616:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   13617:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   13618:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   13619:                     my $typename = $type;
1.160.6.93  raeburn  13620:                     if (keys(%usertypes) > 0) {
                   13621:                         if ($usertypes{$type} ne '') {
                   13622:                             $typename = $usertypes{$type};
1.28      raeburn  13623:                         }
                   13624:                     }
1.160.6.34  raeburn  13625:                     my @modifiable;
                   13626:                     $resulttext .= '<li>'.
                   13627:                                     &mt('Self-creation of account by users with status: [_1]',
                   13628:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   13629:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   13630:                     foreach my $field (@fields) {
                   13631:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   13632:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
                   13633:                         }
                   13634:                     }
                   13635:                     if (@modifiable > 0) {
                   13636:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  13637:                     } else {
1.160.6.34  raeburn  13638:                         $resulttext .= &mt('none');
1.43      raeburn  13639:                     }
1.160.6.34  raeburn  13640:                     $resulttext .= '</li>';
1.28      raeburn  13641:                 }
1.160.6.34  raeburn  13642:                 $resulttext .= '</ul></li>';
1.28      raeburn  13643:             }
1.27      raeburn  13644:             $resulttext .= '</ul>';
1.160.6.93  raeburn  13645:             my $cachetime = 24*60*60;
                   13646:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   13647:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   13648:             if (ref($lastactref) eq 'HASH') {
                   13649:                 $lastactref->{'domdefaults'} = 1;
                   13650:             }
1.27      raeburn  13651:         } else {
1.160.6.34  raeburn  13652:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  13653:         }
                   13654:     } else {
                   13655:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  13656:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13657:     }
1.43      raeburn  13658:     if ($warningmsg ne '') {
                   13659:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   13660:     }
1.23      raeburn  13661:     return $resulttext;
                   13662: }
                   13663: 
1.160.6.5  raeburn  13664: sub process_captcha {
1.160.6.102.2  3(raebur 13665:0):     my ($container,$changes,$newsettings,$currsettings) = @_;
                   13666:0):     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5  raeburn  13667:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   13668:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   13669:         $newsettings->{'captcha'} = 'original';
                   13670:     }
1.160.6.102.2  3(raebur 13671:0):     my %current;
                   13672:0):     if (ref($currsettings) eq 'HASH') {
                   13673:0):         %current = %{$currsettings};
                   13674:0):     }
                   13675:0):     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5  raeburn  13676:         if ($container eq 'cancreate') {
                   13677:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   13678:                 push(@{$changes->{'cancreate'}},'captcha');
                   13679:             } elsif (!defined($changes->{'cancreate'})) {
                   13680:                 $changes->{'cancreate'} = ['captcha'];
                   13681:             }
1.160.6.102  raeburn  13682:         } elsif ($container eq 'passwords') {
                   13683:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  13684:         } else {
                   13685:             $changes->{'captcha'} = 1;
                   13686:         }
                   13687:     }
1.160.6.69  raeburn  13688:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5  raeburn  13689:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   13690:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   13691:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52  raeburn  13692:         $newpub =~ s/[^\w\-]//g;
                   13693:         $newpriv =~ s/[^\w\-]//g;
1.160.6.5  raeburn  13694:         $newsettings->{'recaptchakeys'} = {
                   13695:                                              public  => $newpub,
                   13696:                                              private => $newpriv,
                   13697:                                           };
1.160.6.69  raeburn  13698:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   13699:         $newversion =~ s/\D//g;
                   13700:         if ($newversion ne '2') {
                   13701:             $newversion = 1;
                   13702:         }
                   13703:         $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5  raeburn  13704:     }
1.160.6.102.2  3(raebur 13705:0):     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   13706:0):         $currpub = $current{'recaptchakeys'}{'public'};
                   13707:0):         $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10  raeburn  13708:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   13709:             $newsettings->{'recaptchakeys'} = {
                   13710:                                                  public  => '',
                   13711:                                                  private => '',
                   13712:                                               }
                   13713:         }
1.160.6.5  raeburn  13714:     }
1.160.6.102.2  3(raebur 13715:0):     if ($current{'captcha'} eq 'recaptcha') {
                   13716:0):         $currversion = $current{'recaptchaversion'};
1.160.6.69  raeburn  13717:         if ($currversion ne '2') {
                   13718:             $currversion = 1;
                   13719:         }
                   13720:     }
                   13721:     if ($currversion ne $newversion) {
                   13722:         if ($container eq 'cancreate') {
                   13723:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   13724:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   13725:             } elsif (!defined($changes->{'cancreate'})) {
                   13726:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   13727:             }
1.160.6.102  raeburn  13728:         } elsif ($container eq 'passwords') {
                   13729:             $changes->{'reset'} = 1;
1.160.6.69  raeburn  13730:         } else {
                   13731:             $changes->{'recaptchaversion'} = 1;
                   13732:         }
                   13733:     }
1.160.6.5  raeburn  13734:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
                   13735:         if ($container eq 'cancreate') {
                   13736:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   13737:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   13738:             } elsif (!defined($changes->{'cancreate'})) {
                   13739:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   13740:             }
1.160.6.102  raeburn  13741:         } elsif ($container eq 'passwords') {
                   13742:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  13743:         } else {
                   13744:             $changes->{'recaptchakeys'} = 1;
                   13745:         }
                   13746:     }
                   13747:     return;
                   13748: }
                   13749: 
1.33      raeburn  13750: sub modify_usermodification {
                   13751:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  13752:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  13753:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   13754:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34  raeburn  13755:             if ($key eq 'selfcreate') {
                   13756:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   13757:             } else {  
                   13758:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   13759:             }
1.33      raeburn  13760:         }
                   13761:     }
1.160.6.34  raeburn  13762:     my @contexts = ('author','course');
1.33      raeburn  13763:     my %context_title = (
                   13764:                            author => 'In author context',
                   13765:                            course => 'In course context',
                   13766:                         );
                   13767:     my @fields = ('lastname','firstname','middlename','generation',
                   13768:                   'permanentemail','id');
                   13769:     my %roles = (
                   13770:                   author => ['ca','aa'],
                   13771:                   course => ['st','ep','ta','in','cr'],
                   13772:                 );
                   13773:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   13774:     foreach my $context (@contexts) {
                   13775:         foreach my $role (@{$roles{$context}}) {
                   13776:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   13777:             foreach my $item (@fields) {
                   13778:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   13779:                     $modifyhash{$context}{$role}{$item} = 1;
                   13780:                 } else {
                   13781:                     $modifyhash{$context}{$role}{$item} = 0;
                   13782:                 }
                   13783:             }
                   13784:         }
                   13785:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   13786:             foreach my $role (@{$roles{$context}}) {
                   13787:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   13788:                     foreach my $field (@fields) {
                   13789:                         if ($modifyhash{$context}{$role}{$field} ne 
                   13790:                                 $curr_usermodification{$context}{$role}{$field}) {
                   13791:                             push(@{$changes{$context}},$role);
                   13792:                             last;
                   13793:                         }
                   13794:                     }
                   13795:                 }
                   13796:             }
                   13797:         } else {
                   13798:             foreach my $context (@contexts) {
                   13799:                 foreach my $role (@{$roles{$context}}) {
                   13800:                     push(@{$changes{$context}},$role);
                   13801:                 }
                   13802:             }
                   13803:         }
                   13804:     }
                   13805:     my %usermodification_hash =  (
                   13806:                                    usermodification => \%modifyhash,
                   13807:                                  );
                   13808:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   13809:                                              \%usermodification_hash,$dom);
                   13810:     if ($putresult eq 'ok') {
                   13811:         if (keys(%changes) > 0) {
                   13812:             $resulttext = &mt('Changes made: ').'<ul>';
                   13813:             foreach my $context (@contexts) {
                   13814:                 if (ref($changes{$context}) eq 'ARRAY') {
                   13815:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   13816:                     if (ref($changes{$context}) eq 'ARRAY') {
                   13817:                         foreach my $role (@{$changes{$context}}) {
                   13818:                             my $rolename;
1.160.6.34  raeburn  13819:                             if ($role eq 'cr') {
                   13820:                                 $rolename = &mt('Custom');
1.33      raeburn  13821:                             } else {
1.160.6.34  raeburn  13822:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  13823:                             }
                   13824:                             my @modifiable;
1.160.6.34  raeburn  13825:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  13826:                             foreach my $field (@fields) {
                   13827:                                 if ($modifyhash{$context}{$role}{$field}) {
                   13828:                                     push(@modifiable,$fieldtitles{$field});
                   13829:                                 }
                   13830:                             }
                   13831:                             if (@modifiable > 0) {
                   13832:                                 $resulttext .= join(', ',@modifiable);
                   13833:                             } else {
                   13834:                                 $resulttext .= &mt('none'); 
                   13835:                             }
                   13836:                             $resulttext .= '</li>';
                   13837:                         }
                   13838:                         $resulttext .= '</ul></li>';
                   13839:                     }
                   13840:                 }
                   13841:             }
                   13842:             $resulttext .= '</ul>';
                   13843:         } else {
                   13844:             $resulttext = &mt('No changes made to user modification settings');
                   13845:         }
                   13846:     } else {
                   13847:         $resulttext = '<span class="LC_error">'.
                   13848:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13849:     }
                   13850:     return $resulttext;
                   13851: }
                   13852: 
1.43      raeburn  13853: sub modify_defaults {
1.160.6.27  raeburn  13854:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  13855:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27  raeburn  13856:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80  raeburn  13857:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98  raeburn  13858:                  'portal_def');
1.43      raeburn  13859:     my @authtypes = ('internal','krb4','krb5','localauth');
                   13860:     foreach my $item (@items) {
                   13861:         $newvalues{$item} = $env{'form.'.$item};
                   13862:         if ($item eq 'auth_def') {
                   13863:             if ($newvalues{$item} ne '') {
                   13864:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   13865:                     push(@errors,$item);
                   13866:                 }
                   13867:             }
                   13868:         } elsif ($item eq 'lang_def') {
                   13869:             if ($newvalues{$item} ne '') {
                   13870:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   13871:                     my $langcode = $1;
1.103     raeburn  13872:                     if ($langcode ne 'x_chef') {
                   13873:                         if (code2language($langcode) eq '') {
                   13874:                             push(@errors,$item);
                   13875:                         }
1.43      raeburn  13876:                     }
                   13877:                 } else {
                   13878:                     push(@errors,$item);
                   13879:                 }
                   13880:             }
1.54      raeburn  13881:         } elsif ($item eq 'timezone_def') {
                   13882:             if ($newvalues{$item} ne '') {
1.62      raeburn  13883:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  13884:                     push(@errors,$item);   
                   13885:                 }
                   13886:             }
1.68      raeburn  13887:         } elsif ($item eq 'datelocale_def') {
                   13888:             if ($newvalues{$item} ne '') {
                   13889:                 my @datelocale_ids = DateTime::Locale->ids();
                   13890:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   13891:                     push(@errors,$item);
                   13892:                 }
                   13893:             }
1.141     raeburn  13894:         } elsif ($item eq 'portal_def') {
                   13895:             if ($newvalues{$item} ne '') {
                   13896:                 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])\/?$/) {
                   13897:                     push(@errors,$item);
                   13898:                 }
                   13899:             }
1.43      raeburn  13900:         }
                   13901:         if (grep(/^\Q$item\E$/,@errors)) {
                   13902:             $newvalues{$item} = $domdefaults{$item};
                   13903:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   13904:             $changes{$item} = 1;
                   13905:         }
1.72      raeburn  13906:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  13907:     }
1.160.6.98  raeburn  13908:     my %staticdefaults = (
                   13909:                            'intauth_cost'   => 10,
                   13910:                            'intauth_check'  => 0,
                   13911:                            'intauth_switch' => 0,
                   13912:                          );
                   13913:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   13914:         if (exists($domdefaults{$item})) {
                   13915:             $newvalues{$item} = $domdefaults{$item};
                   13916:         } else {
                   13917:             $newvalues{$item} = $staticdefaults{$item};
                   13918:         }
                   13919:     }
1.43      raeburn  13920:     my %defaults_hash = (
1.72      raeburn  13921:                          defaults => \%newvalues,
                   13922:                         );
1.43      raeburn  13923:     my $title = &defaults_titles();
1.160.6.40  raeburn  13924: 
                   13925:     my $currinststatus;
                   13926:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   13927:         $currinststatus = $domconfig{'inststatus'};
                   13928:     } else {
                   13929:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   13930:         $currinststatus = {
                   13931:                              inststatustypes => $usertypes,
                   13932:                              inststatusorder => $types,
                   13933:                              inststatusguest => [],
                   13934:                           };
                   13935:     }
                   13936:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   13937:     my @allpos;
                   13938:     my %alltypes;
1.160.6.93  raeburn  13939:     my @inststatusguest;
                   13940:     if (ref($currinststatus) eq 'HASH') {
                   13941:         if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   13942:             foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   13943:                 unless (grep(/^\Q$type\E$/,@todelete)) {
                   13944:                     push(@inststatusguest,$type);
                   13945:                 }
                   13946:             }
                   13947:         }
                   13948:     }
                   13949:     my ($currtitles,$currorder);
1.160.6.40  raeburn  13950:     if (ref($currinststatus) eq 'HASH') {
                   13951:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   13952:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   13953:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   13954:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   13955:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   13956:                     }
                   13957:                 }
                   13958:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   13959:                     my $position = $env{'form.inststatus_pos_'.$type};
                   13960:                     $position =~ s/\D+//g;
                   13961:                     $allpos[$position] = $type;
                   13962:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   13963:                     $alltypes{$type} =~ s/`//g;
                   13964:                 }
                   13965:             }
                   13966:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   13967:             $currtitles =~ s/,$//;
                   13968:         }
                   13969:     }
                   13970:     if ($env{'form.addinststatus'}) {
                   13971:         my $newtype = $env{'form.addinststatus'};
                   13972:         $newtype =~ s/\W//g;
                   13973:         unless (exists($alltypes{$newtype})) {
                   13974:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   13975:             $alltypes{$newtype} =~ s/`//g; 
                   13976:             my $position = $env{'form.addinststatus_pos'};
                   13977:             $position =~ s/\D+//g;
                   13978:             if ($position ne '') {
                   13979:                 $allpos[$position] = $newtype;
                   13980:             }
                   13981:         }
                   13982:     }
1.160.6.93  raeburn  13983:     my @orderedstatus;
1.160.6.40  raeburn  13984:     foreach my $type (@allpos) {
                   13985:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   13986:             push(@orderedstatus,$type);
                   13987:         }
                   13988:     }
                   13989:     foreach my $type (keys(%alltypes)) {
                   13990:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   13991:             delete($alltypes{$type});
                   13992:         }
                   13993:     }
                   13994:     $defaults_hash{'inststatus'} = {
                   13995:                                      inststatustypes => \%alltypes,
                   13996:                                      inststatusorder => \@orderedstatus,
1.160.6.93  raeburn  13997:                                      inststatusguest => \@inststatusguest,
1.160.6.40  raeburn  13998:                                    };
                   13999:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   14000:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   14001:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   14002:         }
                   14003:     }
                   14004:     if ($currorder ne join(',',@orderedstatus)) {
                   14005:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   14006:     }
                   14007:     my $newtitles;
                   14008:     foreach my $item (@orderedstatus) {
                   14009:         $newtitles .= $alltypes{$item}.',';
                   14010:     }
                   14011:     $newtitles =~ s/,$//;
                   14012:     if ($currtitles ne $newtitles) {
                   14013:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   14014:     }
1.43      raeburn  14015:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   14016:                                              $dom);
                   14017:     if ($putresult eq 'ok') {
                   14018:         if (keys(%changes) > 0) {
                   14019:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27  raeburn  14020:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  14021:             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";
                   14022:             foreach my $item (sort(keys(%changes))) {
1.160.6.40  raeburn  14023:                 if ($item eq 'inststatus') {
                   14024:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93  raeburn  14025:                         if (@orderedstatus) {
1.160.6.40  raeburn  14026:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   14027:                             foreach my $type (@orderedstatus) { 
                   14028:                                 $resulttext .= $alltypes{$type}.', ';
                   14029:                             }
                   14030:                             $resulttext =~ s/, $//;
                   14031:                             $resulttext .= '</li>';
1.160.6.93  raeburn  14032:                         } else {
                   14033:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40  raeburn  14034:                         }
                   14035:                     }
                   14036:                 } else {
                   14037:                     my $value = $env{'form.'.$item};
                   14038:                     if ($value eq '') {
                   14039:                         $value = &mt('none');
                   14040:                     } elsif ($item eq 'auth_def') {
                   14041:                         my %authnames = &authtype_names();
                   14042:                         my %shortauth = (
                   14043:                                           internal   => 'int',
                   14044:                                           krb4       => 'krb4',
                   14045:                                           krb5       => 'krb5',
                   14046:                                           localauth  => 'loc',
                   14047:                         );
                   14048:                         $value = $authnames{$shortauth{$value}};
                   14049:                     }
                   14050:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   14051:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  14052:                 }
                   14053:             }
                   14054:             $resulttext .= '</ul>';
                   14055:             $mailmsgtext .= "\n";
                   14056:             my $cachetime = 24*60*60;
1.72      raeburn  14057:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  14058:             if (ref($lastactref) eq 'HASH') {
                   14059:                 $lastactref->{'domdefaults'} = 1;
                   14060:             }
1.68      raeburn  14061:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23  raeburn  14062:                 my $notify = 1;
                   14063:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   14064:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   14065:                         $notify = 0;
                   14066:                     }
                   14067:                 }
                   14068:                 if ($notify) {
                   14069:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   14070:                                                "LON-CAPA Domain Settings Change - $dom",
                   14071:                                                $mailmsgtext);
                   14072:                 }
1.54      raeburn  14073:             }
1.43      raeburn  14074:         } else {
1.54      raeburn  14075:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  14076:         }
                   14077:     } else {
                   14078:         $resulttext = '<span class="LC_error">'.
                   14079:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14080:     }
                   14081:     if (@errors > 0) {
                   14082:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   14083:         foreach my $item (@errors) {
                   14084:             $resulttext .= ' "'.$title->{$item}.'",';
                   14085:         }
                   14086:         $resulttext =~ s/,$//;
                   14087:     }
                   14088:     return $resulttext;
                   14089: }
                   14090: 
1.46      raeburn  14091: sub modify_scantron {
1.160.6.24  raeburn  14092:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  14093:     my ($resulttext,%confhash,%changes,$errors);
                   14094:     my $custom = 'custom.tab';
                   14095:     my $default = 'default.tab';
                   14096:     my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97  raeburn  14097:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  14098:         &config_check($dom,$confname,$servadm);
                   14099:     if ($env{'form.scantronformat.filename'} ne '') {
                   14100:         my $error;
                   14101:         if ($configuserok eq 'ok') {
                   14102:             if ($switchserver) {
1.130     raeburn  14103:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  14104:             } else {
                   14105:                 if ($author_ok eq 'ok') {
                   14106:                     my ($result,$scantronurl) =
                   14107:                         &publishlogo($r,'upload','scantronformat',$dom,
                   14108:                                      $confname,'scantron','','',$custom);
                   14109:                     if ($result eq 'ok') {
                   14110:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  14111:                         $changes{'scantronformat'} = 1;
1.46      raeburn  14112:                     } else {
                   14113:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   14114:                     }
                   14115:                 } else {
                   14116:                     $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);
                   14117:                 }
                   14118:             }
                   14119:         } else {
                   14120:             $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);
                   14121:         }
                   14122:         if ($error) {
                   14123:             &Apache::lonnet::logthis($error);
                   14124:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14125:         }
                   14126:     }
1.48      raeburn  14127:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   14128:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   14129:             if ($env{'form.scantronformat_del'}) {
                   14130:                 $confhash{'scantron'}{'scantronformat'} = '';
                   14131:                 $changes{'scantronformat'} = 1;
1.160.6.97  raeburn  14132:             } else {
                   14133:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
                   14134:             }
                   14135:         }
                   14136:     }
                   14137:     my @options = ('hdr','pad','rem');
                   14138:     my @fields = &scantroncsv_fields();
                   14139:     my %titles = &scantronconfig_titles();
                   14140:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
                   14141:     my ($newdat,$currdat,%newcol,%currcol);
                   14142:     if (grep(/^dat$/,@formats)) {
                   14143:         $confhash{'scantron'}{config}{dat} = 1;
                   14144:         $newdat = 1;
                   14145:     } else {
                   14146:         $newdat = 0;
                   14147:     }
                   14148:     if (grep(/^csv$/,@formats)) {
                   14149:         my %bynum;
                   14150:         foreach my $field (@fields) {
                   14151:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   14152:                 my $posscol = $1;
                   14153:                 if (($posscol < 20) && (!$bynum{$posscol})) {
                   14154:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
                   14155:                     $bynum{$posscol} = $field;
                   14156:                     $newcol{$field} = $posscol;
                   14157:                 }
                   14158:             }
                   14159:         }
                   14160:         if (keys(%newcol)) {
                   14161:             foreach my $option (@options) {
                   14162:                 if ($env{'form.scantroncsv_'.$option}) {
                   14163:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   14164:                 }
                   14165:             }
                   14166:         }
                   14167:     }
                   14168:     $currdat = 1;
                   14169:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   14170:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
                   14171:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
                   14172:                 $currdat = 0;
                   14173:             }
                   14174:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   14175:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   14176:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   14177:                 }
                   14178:             }
                   14179:         }
                   14180:     }
                   14181:     if ($currdat != $newdat) {
                   14182:         $changes{'config'} = 1;
                   14183:     } else {
                   14184:         foreach my $field (@fields) {
                   14185:             if ($currcol{$field} ne '') {
                   14186:                 if ($currcol{$field} ne $newcol{$field}) {
                   14187:                     $changes{'config'} = 1;
                   14188:                     last;
                   14189:                 }
                   14190:             } elsif ($newcol{$field} ne '') {
                   14191:                 $changes{'config'} = 1;
                   14192:                 last;
1.46      raeburn  14193:             }
                   14194:         }
                   14195:     }
                   14196:     if (keys(%confhash) > 0) {
                   14197:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   14198:                                                  $dom);
                   14199:         if ($putresult eq 'ok') {
                   14200:             if (keys(%changes) > 0) {
1.48      raeburn  14201:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   14202:                     $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97  raeburn  14203:                     if ($changes{'scantronformat'}) {
                   14204:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   14205:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   14206:                         } else {
                   14207:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   14208:                         }
                   14209:                     }
                   14210:                     if ($changes{'config'}) {
                   14211:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   14212:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   14213:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   14214:                             }
                   14215:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   14216:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   14217:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   14218:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   14219:                                         foreach my $field (@fields) {
                   14220:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   14221:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   14222:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   14223:                                             }
                   14224:                                         }
                   14225:                                         $resulttext .= '</ul></li>';
                   14226:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   14227:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   14228:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   14229:                                                 foreach my $option (@options) {
                   14230:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   14231:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   14232:                                                     }
                   14233:                                                 }
                   14234:                                                 $resulttext .= '</ul></li>';
                   14235:                                             }
                   14236:                                         }
                   14237:                                     }
                   14238:                                 }
                   14239:                             }
                   14240:                         } else {
                   14241:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   14242:                         }
1.46      raeburn  14243:                     }
1.48      raeburn  14244:                     $resulttext .= '</ul>';
                   14245:                 } else {
1.130     raeburn  14246:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  14247:                 }
                   14248:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  14249:                 if (ref($lastactref) eq 'HASH') {
                   14250:                     $lastactref->{'domainconfig'} = 1;
                   14251:                 }
1.46      raeburn  14252:             } else {
1.160.6.97  raeburn  14253:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  14254:             }
                   14255:         } else {
                   14256:             $resulttext = '<span class="LC_error">'.
                   14257:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   14258:         }
                   14259:     } else {
1.160.6.97  raeburn  14260:         $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  14261:     }
                   14262:     if ($errors) {
                   14263:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   14264:                        $errors.'</ul>';
                   14265:     }
                   14266:     return $resulttext;
                   14267: }
                   14268: 
1.48      raeburn  14269: sub modify_coursecategories {
1.160.6.43  raeburn  14270:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  14271:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   14272:         $cathash);
1.48      raeburn  14273:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42  raeburn  14274:     my @catitems = ('unauth','auth');
                   14275:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  14276:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  14277:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   14278:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   14279:             $changes{'togglecats'} = 1;
                   14280:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   14281:         }
                   14282:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   14283:             $changes{'categorize'} = 1;
                   14284:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   14285:         }
1.120     raeburn  14286:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   14287:             $changes{'togglecatscomm'} = 1;
                   14288:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   14289:         }
                   14290:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   14291:             $changes{'categorizecomm'} = 1;
                   14292:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   14293:         }
1.160.6.42  raeburn  14294:         foreach my $item (@catitems) {
                   14295:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   14296:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   14297:                     $changes{$item} = 1;
                   14298:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   14299:                 }
                   14300:             }
                   14301:         }
1.57      raeburn  14302:     } else {
                   14303:         $changes{'togglecats'} = 1;
                   14304:         $changes{'categorize'} = 1;
1.124     raeburn  14305:         $changes{'togglecatscomm'} = 1;
                   14306:         $changes{'categorizecomm'} = 1;
1.87      raeburn  14307:         $domconfig{'coursecategories'} = {
                   14308:                                              togglecats => $env{'form.togglecats'},
                   14309:                                              categorize => $env{'form.categorize'},
1.124     raeburn  14310:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   14311:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  14312:                                          };
1.160.6.42  raeburn  14313:         foreach my $item (@catitems) {
                   14314:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   14315:                 $changes{$item} = 1;
                   14316:             }
                   14317:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   14318:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   14319:             }
                   14320:         }
1.57      raeburn  14321:     }
                   14322:     if (ref($cathash) eq 'HASH') {
                   14323:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  14324:             push (@deletecategory,'instcode::0');
                   14325:         }
1.120     raeburn  14326:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   14327:             push(@deletecategory,'communities::0');
                   14328:         }
1.48      raeburn  14329:     }
1.57      raeburn  14330:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   14331:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  14332:         if (@deletecategory > 0) {
                   14333:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  14334:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  14335:             foreach my $item (@deletecategory) {
1.57      raeburn  14336:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   14337:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  14338:                     $deletions{$item} = 1;
1.57      raeburn  14339:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  14340:                 }
                   14341:             }
                   14342:         }
1.57      raeburn  14343:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  14344:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  14345:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  14346:                 $reorderings{$item} = 1;
1.57      raeburn  14347:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  14348:             }
                   14349:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   14350:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   14351:                 my $newdepth = $depth+1;
                   14352:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  14353:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  14354:                 $adds{$newitem} = 1; 
                   14355:             }
                   14356:             if ($env{'form.subcat_'.$item} ne '') {
                   14357:                 my $newcat = $env{'form.subcat_'.$item};
                   14358:                 my $newdepth = $depth+1;
                   14359:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  14360:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  14361:                 $adds{$newitem} = 1;
                   14362:             }
                   14363:         }
                   14364:     }
                   14365:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  14366:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  14367:             my $newitem = 'instcode::0';
1.57      raeburn  14368:             if ($cathash->{$newitem} eq '') {  
                   14369:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  14370:                 $adds{$newitem} = 1;
                   14371:             }
                   14372:         } else {
                   14373:             my $newitem = 'instcode::0';
1.57      raeburn  14374:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  14375:             $adds{$newitem} = 1;
                   14376:         }
                   14377:     }
1.120     raeburn  14378:     if ($env{'form.communities'} eq '1') {
                   14379:         if (ref($cathash) eq 'HASH') {
                   14380:             my $newitem = 'communities::0';
                   14381:             if ($cathash->{$newitem} eq '') {
                   14382:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   14383:                 $adds{$newitem} = 1;
                   14384:             }
                   14385:         } else {
                   14386:             my $newitem = 'communities::0';
                   14387:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   14388:             $adds{$newitem} = 1;
                   14389:         }
                   14390:     }
1.48      raeburn  14391:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  14392:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   14393:             ($env{'form.addcategory_name'} ne 'communities')) {
                   14394:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   14395:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   14396:             $adds{$newitem} = 1;
                   14397:         }
1.48      raeburn  14398:     }
1.57      raeburn  14399:     my $putresult;
1.48      raeburn  14400:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   14401:         if (keys(%deletions) > 0) {
                   14402:             foreach my $key (keys(%deletions)) {
                   14403:                 if ($predelallitems{$key} ne '') {
                   14404:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   14405:                 }
                   14406:             }
                   14407:         }
                   14408:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  14409:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  14410:         if (ref($chkcats[0]) eq 'ARRAY') {
                   14411:             my $depth = 0;
                   14412:             my $chg = 0;
                   14413:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   14414:                 my $name = $chkcats[0][$i];
                   14415:                 my $item;
                   14416:                 if ($name eq '') {
                   14417:                     $chg ++;
                   14418:                 } else {
                   14419:                     $item = &escape($name).'::0';
                   14420:                     if ($chg) {
1.57      raeburn  14421:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  14422:                     }
                   14423:                     $depth ++; 
1.57      raeburn  14424:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  14425:                     $depth --;
                   14426:                 }
                   14427:             }
                   14428:         }
1.57      raeburn  14429:     }
                   14430:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   14431:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  14432:         if ($putresult eq 'ok') {
1.57      raeburn  14433:             my %title = (
1.120     raeburn  14434:                          togglecats     => 'Show/Hide a course in catalog',
                   14435:                          categorize     => 'Assign a category to a course',
                   14436:                          togglecatscomm => 'Show/Hide a community in catalog',
                   14437:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  14438:                         );
                   14439:             my %level = (
1.120     raeburn  14440:                          dom  => 'set in Domain ("Modify Course/Community")',
                   14441:                          crs  => 'set in Course ("Course Configuration")',
                   14442:                          comm => 'set in Community ("Community Configuration")',
1.160.6.42  raeburn  14443:                          none     => 'No catalog',
                   14444:                          std      => 'Standard catalog',
                   14445:                          domonly  => 'Domain-only catalog',
                   14446:                          codesrch => 'Code search form',
1.57      raeburn  14447:                         );
1.48      raeburn  14448:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  14449:             if ($changes{'togglecats'}) {
                   14450:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   14451:             }
                   14452:             if ($changes{'categorize'}) {
                   14453:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  14454:             }
1.120     raeburn  14455:             if ($changes{'togglecatscomm'}) {
                   14456:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   14457:             }
                   14458:             if ($changes{'categorizecomm'}) {
                   14459:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   14460:             }
1.160.6.42  raeburn  14461:             if ($changes{'unauth'}) {
                   14462:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   14463:             }
                   14464:             if ($changes{'auth'}) {
                   14465:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   14466:             }
1.57      raeburn  14467:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   14468:                 my $cathash;
                   14469:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   14470:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   14471:                 } else {
                   14472:                     $cathash = {};
                   14473:                 } 
                   14474:                 my (@cats,@trails,%allitems);
                   14475:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   14476:                 if (keys(%deletions) > 0) {
                   14477:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   14478:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   14479:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   14480:                     }
                   14481:                     $resulttext .= '</ul></li>';
                   14482:                 }
                   14483:                 if (keys(%reorderings) > 0) {
                   14484:                     my %sort_by_trail;
                   14485:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   14486:                     foreach my $key (keys(%reorderings)) {
                   14487:                         if ($allitems{$key} ne '') {
                   14488:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   14489:                         }
1.48      raeburn  14490:                     }
1.57      raeburn  14491:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   14492:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   14493:                     }
                   14494:                     $resulttext .= '</ul></li>';
1.48      raeburn  14495:                 }
1.57      raeburn  14496:                 if (keys(%adds) > 0) {
                   14497:                     my %sort_by_trail;
                   14498:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   14499:                     foreach my $key (keys(%adds)) {
                   14500:                         if ($allitems{$key} ne '') {
                   14501:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   14502:                         }
                   14503:                     }
                   14504:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   14505:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  14506:                     }
1.57      raeburn  14507:                     $resulttext .= '</ul></li>';
1.48      raeburn  14508:                 }
1.160.6.92  raeburn  14509:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   14510:                 if (ref($lastactref) eq 'HASH') {
                   14511:                     $lastactref->{'cats'} = 1;
                   14512:                 }
1.48      raeburn  14513:             }
                   14514:             $resulttext .= '</ul>';
1.160.6.43  raeburn  14515:             if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50  raeburn  14516:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   14517:                 if ($changes{'auth'}) {
                   14518:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   14519:                 }
                   14520:                 if ($changes{'unauth'}) {
                   14521:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   14522:                 }
                   14523:                 my $cachetime = 24*60*60;
                   14524:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43  raeburn  14525:                 if (ref($lastactref) eq 'HASH') {
1.160.6.50  raeburn  14526:                     $lastactref->{'domdefaults'} = 1;
1.160.6.43  raeburn  14527:                 }
                   14528:             }
1.48      raeburn  14529:         } else {
                   14530:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  14531:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  14532:         }
                   14533:     } else {
1.120     raeburn  14534:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  14535:     }
                   14536:     return $resulttext;
                   14537: }
                   14538: 
1.69      raeburn  14539: sub modify_serverstatuses {
                   14540:     my ($dom,%domconfig) = @_;
                   14541:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   14542:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   14543:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   14544:     }
                   14545:     my @pages = &serverstatus_pages();
                   14546:     foreach my $type (@pages) {
                   14547:         $newserverstatus{$type}{'namedusers'} = '';
                   14548:         $newserverstatus{$type}{'machines'} = '';
                   14549:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   14550:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   14551:             my @okusers;
                   14552:             foreach my $user (@users) {
                   14553:                 my ($uname,$udom) = split(/:/,$user);
                   14554:                 if (($udom =~ /^$match_domain$/) &&   
                   14555:                     (&Apache::lonnet::domain($udom)) &&
                   14556:                     ($uname =~ /^$match_username$/)) {
                   14557:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   14558:                         push(@okusers,$user);
                   14559:                     }
                   14560:                 }
                   14561:             }
                   14562:             if (@okusers > 0) {
                   14563:                  @okusers = sort(@okusers);
                   14564:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   14565:             }
                   14566:         }
                   14567:         if (defined($env{'form.'.$type.'_machines'})) {
                   14568:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   14569:             my @okmachines;
                   14570:             foreach my $ip (@machines) {
                   14571:                 my @parts = split(/\./,$ip);
                   14572:                 next if (@parts < 4);
                   14573:                 my $badip = 0;
                   14574:                 for (my $i=0; $i<4; $i++) {
                   14575:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   14576:                         $badip = 1;
                   14577:                         last;
                   14578:                     }
                   14579:                 }
                   14580:                 if (!$badip) {
                   14581:                     push(@okmachines,$ip);     
                   14582:                 }
                   14583:             }
                   14584:             @okmachines = sort(@okmachines);
                   14585:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   14586:         }
                   14587:     }
                   14588:     my %serverstatushash =  (
                   14589:                                 serverstatuses => \%newserverstatus,
                   14590:                             );
                   14591:     foreach my $type (@pages) {
1.83      raeburn  14592:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  14593:             my (@current,@new);
1.83      raeburn  14594:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  14595:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   14596:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   14597:                 }
                   14598:             }
                   14599:             if ($newserverstatus{$type}{$setting} ne '') {
                   14600:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  14601:             }
                   14602:             if (@current > 0) {
                   14603:                 if (@new > 0) {
                   14604:                     foreach my $item (@current) {
                   14605:                         if (!grep(/^\Q$item\E$/,@new)) {
                   14606:                             $changes{$type}{$setting} = 1;
1.82      raeburn  14607:                             last;
                   14608:                         }
                   14609:                     }
1.84      raeburn  14610:                     foreach my $item (@new) {
                   14611:                         if (!grep(/^\Q$item\E$/,@current)) {
                   14612:                             $changes{$type}{$setting} = 1;
                   14613:                             last;
1.82      raeburn  14614:                         }
                   14615:                     }
                   14616:                 } else {
1.83      raeburn  14617:                     $changes{$type}{$setting} = 1;
1.69      raeburn  14618:                 }
1.83      raeburn  14619:             } elsif (@new > 0) {
                   14620:                 $changes{$type}{$setting} = 1;
1.69      raeburn  14621:             }
                   14622:         }
                   14623:     }
                   14624:     if (keys(%changes) > 0) {
1.81      raeburn  14625:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  14626:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   14627:                                                  \%serverstatushash,$dom);
                   14628:         if ($putresult eq 'ok') {
                   14629:             $resulttext .= &mt('Changes made:').'<ul>';
                   14630:             foreach my $type (@pages) {
1.84      raeburn  14631:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  14632:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  14633:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  14634:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   14635:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   14636:                         } else {
                   14637:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   14638:                         }
1.84      raeburn  14639:                     }
                   14640:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  14641:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   14642:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   14643:                         } else {
                   14644:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   14645:                         }
                   14646: 
                   14647:                     }
                   14648:                     $resulttext .= '</ul></li>';
                   14649:                 }
                   14650:             }
                   14651:             $resulttext .= '</ul>';
                   14652:         } else {
                   14653:             $resulttext = '<span class="LC_error">'.
                   14654:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   14655: 
                   14656:         }
                   14657:     } else {
                   14658:         $resulttext = &mt('No changes made to access to server status pages');
                   14659:     }
                   14660:     return $resulttext;
                   14661: }
                   14662: 
1.118     jms      14663: sub modify_helpsettings {
1.160.6.77  raeburn  14664:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  14665:     my ($resulttext,$errors,%changes,%helphash);
                   14666:     my %defaultchecked = ('submitbugs' => 'on');
                   14667:     my @offon = ('off','on');
1.118     jms      14668:     my @toggles = ('submitbugs');
1.160.6.77  raeburn  14669:     my %current = ('submitbugs' => '',
                   14670:                    'adhoc'      => {},
                   14671:                   );
1.118     jms      14672:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73  raeburn  14673:         %current = %{$domconfig{'helpsettings'}};
                   14674:     }
1.160.6.77  raeburn  14675:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73  raeburn  14676:     foreach my $item (@toggles) {
                   14677:         if ($defaultchecked{$item} eq 'on') { 
                   14678:             if ($current{$item} eq '') {
                   14679:                 if ($env{'form.'.$item} eq '0') {
1.160.6.5  raeburn  14680:                     $changes{$item} = 1;
                   14681:                 }
1.160.6.73  raeburn  14682:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   14683:                 $changes{$item} = 1;
                   14684:             }
                   14685:         } elsif ($defaultchecked{$item} eq 'off') {
                   14686:             if ($current{$item} eq '') {
                   14687:                 if ($env{'form.'.$item} eq '1') {
1.160.6.5  raeburn  14688:                     $changes{$item} = 1;
                   14689:                 }
1.160.6.73  raeburn  14690:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   14691:                 $changes{$item} = 1;
                   14692:             }
                   14693:         }
                   14694:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   14695:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   14696:         }
                   14697:     }
1.160.6.77  raeburn  14698:     my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73  raeburn  14699:     my $confname = $dom.'-domainconfig';
                   14700:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  14701:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   14702:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  14703:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
                   14704:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  14705:     my %lt = &Apache::lonlocal::texthash(
                   14706:                     s      => 'system',
                   14707:                     d      => 'domain',
                   14708:                     order  => 'Display order',
                   14709:                     access => 'Role usage',
1.160.6.79  raeburn  14710:                     all    => 'All with domain helpdesk or helpdesk assistant role',
                   14711:                     dh     => 'All with domain helpdesk role',
                   14712:                     da     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  14713:                     none   => 'None',
                   14714:                     status => 'Determined based on institutional status',
                   14715:                     inc    => 'Include all, but exclude specific personnel',
                   14716:                     exc    => 'Exclude all, but include specific personnel',
                   14717:     );
                   14718:     for (my $num=0; $num<=$maxnum; $num++) {
                   14719:         my ($prefix,$identifier,$rolename,%curr);
                   14720:         if ($num == $maxnum) {
                   14721:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   14722:             $identifier = 'custhelp'.$num;
                   14723:             $prefix = 'helproles_'.$num;
                   14724:             $rolename = $env{'form.custhelpname'.$num};
                   14725:             $rolename=~s/[^A-Za-z0-9]//gs;
                   14726:             next if ($rolename eq '');
                   14727:             next if (exists($existing{'rolesdef_'.$rolename}));
                   14728:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   14729:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   14730:                                                      $newprivs{'c'},$confname,$dom);
                   14731:             if ($result ne 'ok') {
                   14732:                 $errors .= '<li><span class="LC_error">'.
                   14733:                            &mt('An error occurred storing the new custom role: [_1]',
                   14734:                            $result).'</span></li>';
                   14735:                 next;
                   14736:             } else {
                   14737:                 $changedprivs{$rolename} = \%newprivs;
                   14738:                 $newrole = $rolename;
                   14739:             }
                   14740:         } else {
                   14741:             $prefix = 'helproles_'.$num;
                   14742:             $rolename = $env{'form.'.$prefix};
                   14743:             next if ($rolename eq '');
                   14744:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   14745:             $identifier = 'custhelp'.$num;
                   14746:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   14747:             my %currprivs;
                   14748:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
                   14749:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   14750:             foreach my $level ('c','d','s') {
                   14751:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   14752:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   14753:                                                              $newprivs{'c'},$confname,$dom);
                   14754:                     if ($result ne 'ok') {
                   14755:                         $errors .= '<li><span class="LC_error">'.
                   14756:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   14757:                                        $rolename,$result).'</span></li>';
                   14758:                     } else {
                   14759:                         $changedprivs{$rolename} = \%newprivs;
                   14760:                     }
                   14761:                     last;
                   14762:                 }
                   14763:             }
                   14764:             if (ref($current{'adhoc'}) eq 'HASH') {
                   14765:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   14766:                     %curr = %{$current{'adhoc'}{$rolename}};
                   14767:                 }
                   14768:             }
                   14769:         }
                   14770:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   14771:         $newpos =~ s/\D+//g;
                   14772:         $allpos[$newpos] = $rolename;
                   14773:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   14774:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   14775:         if ($curr{'desc'}) {
                   14776:             if ($curr{'desc'} ne $newdesc) {
                   14777:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   14778:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   14779:             }
                   14780:         } elsif ($newdesc ne '') {
                   14781:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   14782:             $newsettings{$rolename}{'desc'} = $newdesc;
                   14783:         }
                   14784:         my $access = $env{'form.'.$prefix.'_access'};
                   14785:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   14786:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   14787:             if ($access eq 'status') {
                   14788:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   14789:                 if (scalar(@statuses) == 0) {
                   14790:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
                   14791:                 } else {
                   14792:                     my (@shownstatus,$numtypes);
                   14793:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   14794:                     if (ref($types) eq 'ARRAY') {
                   14795:                         $numtypes = scalar(@{$types});
                   14796:                         foreach my $type (sort(@statuses)) {
                   14797:                             if ($type eq 'default') {
                   14798:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   14799:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   14800:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   14801:                                 push(@shownstatus,$usertypes->{$type});
                   14802:                             }
1.160.6.73  raeburn  14803:                         }
                   14804:                     }
1.160.6.77  raeburn  14805:                     if (grep(/^default$/,@statuses)) {
                   14806:                         push(@shownstatus,$othertitle);
                   14807:                     }
                   14808:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   14809:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   14810:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   14811:                     } else {
                   14812:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   14813:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   14814:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   14815:                             if (@diffs) {
                   14816:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   14817:                             }
                   14818:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   14819:                             $changes{'customrole'}{$rolename}{$access} = 1;
                   14820:                         }
                   14821:                     }
                   14822:                 }
                   14823:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   14824:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   14825:                 my @newspecstaff;
                   14826:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   14827:                 foreach my $person (sort(@personnel)) {
                   14828:                     if ($domhelpdesk{$person}) {
                   14829:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   14830:                     }
                   14831:                 }
                   14832:                 if (ref($curr{$access}) eq 'ARRAY') {
                   14833:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   14834:                     if (@diffs) {
                   14835:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   14836:                     }
                   14837:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   14838:                     $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73  raeburn  14839:                 }
1.160.6.77  raeburn  14840:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   14841:                     my ($uname,$udom) = split(/:/,$person);
                   14842:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   14843:                 }
                   14844:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26  raeburn  14845:             }
1.160.6.77  raeburn  14846:         } else {
                   14847:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   14848:         }
                   14849:         unless ($curr{'access'} eq $access) {
                   14850:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   14851:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73  raeburn  14852:         }
                   14853:     }
1.160.6.77  raeburn  14854:     if (@allpos > 0) {
                   14855:         my $idx = 0;
                   14856:         foreach my $rolename (@allpos) {
                   14857:             if ($rolename ne '') {
                   14858:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   14859:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   14860:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   14861:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   14862:                             $changes{'customrole'}{$rolename}{'order'} = 1;
                   14863:                             $newsettings{$rolename}{'order'} = $idx+1;
                   14864:                         }
                   14865:                     }
1.160.6.73  raeburn  14866:                 }
1.160.6.77  raeburn  14867:                 $idx ++;
1.122     jms      14868:             }
                   14869:         }
1.118     jms      14870:     }
1.123     jms      14871:     my $putresult;
                   14872:     if (keys(%changes) > 0) {
1.160.6.5  raeburn  14873:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   14874:         if ($putresult eq 'ok') {
1.160.6.77  raeburn  14875:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   14876:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   14877:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   14878:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   14879:                 }
                   14880:             }
                   14881:             my $cachetime = 24*60*60;
                   14882:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14883:             if (ref($lastactref) eq 'HASH') {
                   14884:                 $lastactref->{'domdefaults'} = 1;
                   14885:             }
                   14886:         } else {
                   14887:             $errors .= '<li><span class="LC_error">'.
                   14888:                        &mt('An error occurred storing the settings: [_1]',
                   14889:                            $putresult).'</span></li>';
                   14890:         }
                   14891:     }
                   14892:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   14893:         $resulttext = &mt('Changes made:').'<ul>';
                   14894:         my (%shownprivs,@levelorder);
                   14895:         @levelorder = ('c','d','s');
                   14896:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5  raeburn  14897:             foreach my $item (sort(keys(%changes))) {
                   14898:                 if ($item eq 'submitbugs') {
                   14899:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   14900:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   14901:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73  raeburn  14902:                 } elsif ($item eq 'customrole') {
                   14903:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77  raeburn  14904:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   14905:                         my %keytext = &Apache::lonlocal::texthash(
                   14906:                                                                    order  => 'Order',
                   14907:                                                                    desc   => 'Role description',
                   14908:                                                                    access => 'Role usage',
1.160.6.83  raeburn  14909:                                                                    status => 'Allowed institutional types',
1.160.6.77  raeburn  14910:                                                                    exc    => 'Allowed personnel',
                   14911:                                                                    inc    => 'Disallowed personnel',
                   14912:                         );
1.160.6.73  raeburn  14913:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77  raeburn  14914:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   14915:                                 if ($role eq $newrole) {
                   14916:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   14917:                                                               $role).'<ul>';
                   14918:                                 } else {
                   14919:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   14920:                                                               $role).'<ul>';
                   14921:                                 }
                   14922:                                 foreach my $key (@keyorder) {
                   14923:                                     if ($changes{'customrole'}{$role}{$key}) {
                   14924:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   14925:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   14926:                                                        '</li>';
                   14927:                                     }
                   14928:                                 }
                   14929:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   14930:                                     $shownprivs{$role} = 1;
                   14931:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   14932:                                     foreach my $level (@levelorder) {
                   14933:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   14934:                                             next if ($item eq '');
                   14935:                                             my ($priv) = split(/\&/,$item,2);
                   14936:                                             if (&Apache::lonnet::plaintext($priv)) {
                   14937:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   14938:                                                 unless ($level eq 'c') {
                   14939:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   14940:                                                 }
                   14941:                                                 $resulttext .= '</li>';
                   14942:                                             }
                   14943:                                         }
                   14944:                                     }
                   14945:                                     $resulttext .= '</ul>';
                   14946:                                 }
                   14947:                                 $resulttext .= '</ul></li>';
                   14948:                             }
1.160.6.73  raeburn  14949:                         }
                   14950:                     }
1.160.6.5  raeburn  14951:                 }
                   14952:             }
                   14953:         }
1.160.6.77  raeburn  14954:         if (keys(%changedprivs)) {
                   14955:             foreach my $role (sort(keys(%changedprivs))) {
                   14956:                 unless ($shownprivs{$role}) {
                   14957:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   14958:                                               $role).'<ul>'.
                   14959:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   14960:                     foreach my $level (@levelorder) {
                   14961:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   14962:                             next if ($item eq '');
                   14963:                             my ($priv) = split(/\&/,$item,2);
                   14964:                             if (&Apache::lonnet::plaintext($priv)) {
                   14965:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   14966:                                 unless ($level eq 'c') {
                   14967:                                     $resulttext .= ' ('.$lt{$level}.')';
                   14968:                                 }
                   14969:                                 $resulttext .= '</li>';
                   14970:                             }
                   14971:                         }
                   14972:                     }
                   14973:                     $resulttext .= '</ul></li></ul></li>';
                   14974:                 }
                   14975:             }
                   14976:         }
                   14977:         $resulttext .= '</ul>';
                   14978:     } else {
                   14979:         $resulttext = &mt('No changes made to help settings');
1.118     jms      14980:     }
                   14981:     if ($errors) {
1.160.6.5  raeburn  14982:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77  raeburn  14983:                                     $errors.'</ul>';
1.118     jms      14984:     }
                   14985:     return $resulttext;
                   14986: }
                   14987: 
1.121     raeburn  14988: sub modify_coursedefaults {
1.160.6.27  raeburn  14989:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  14990:     my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57  raeburn  14991:     my %defaultchecked = (
                   14992:                            'uselcmath'       => 'on',
                   14993:                            'usejsme'         => 'on'
                   14994:                          );
                   14995:     my @toggles = ('uselcmath','usejsme');
1.160.6.21  raeburn  14996:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70  raeburn  14997:                    'uploadquota_community','uploadquota_textbook','mysqltables_official',
                   14998:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30  raeburn  14999:     my @types = ('official','unofficial','community','textbook');
1.160.6.21  raeburn  15000:     my %staticdefaults = (
                   15001:                            anonsurvey_threshold => 10,
                   15002:                            uploadquota          => 500,
1.160.6.57  raeburn  15003:                            postsubmit           => 60,
1.160.6.70  raeburn  15004:                            mysqltables          => 172800,
1.160.6.21  raeburn  15005:                          );
1.160.6.90  raeburn  15006:     my %texoptions = (
                   15007:                         MathJax  => 'MathJax',
                   15008:                         mimetex  => &mt('Convert to Images'),
                   15009:                         tth      => &mt('TeX to HTML'),
                   15010:                      );
1.121     raeburn  15011:     $defaultshash{'coursedefaults'} = {};
                   15012: 
                   15013:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   15014:         if ($domconfig{'coursedefaults'} eq '') {
                   15015:             $domconfig{'coursedefaults'} = {};
                   15016:         }
                   15017:     }
                   15018: 
                   15019:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   15020:         foreach my $item (@toggles) {
                   15021:             if ($defaultchecked{$item} eq 'on') {
                   15022:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   15023:                     ($env{'form.'.$item} eq '0')) {
                   15024:                     $changes{$item} = 1;
1.160.6.16  raeburn  15025:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  15026:                     $changes{$item} = 1;
                   15027:                 }
                   15028:             } elsif ($defaultchecked{$item} eq 'off') {
                   15029:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   15030:                     ($env{'form.'.$item} eq '1')) {
                   15031:                     $changes{$item} = 1;
                   15032:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   15033:                     $changes{$item} = 1;
                   15034:                 }
                   15035:             }
                   15036:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   15037:         }
1.160.6.21  raeburn  15038:         foreach my $item (@numbers) {
                   15039:             my ($currdef,$newdef);
1.160.6.26  raeburn  15040:             $newdef = $env{'form.'.$item};
1.160.6.21  raeburn  15041:             if ($item eq 'anonsurvey_threshold') {
                   15042:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   15043:                 $newdef =~ s/\D//g;
                   15044:                 if ($newdef eq '' || $newdef < 1) {
                   15045:                     $newdef = 1;
                   15046:                 }
                   15047:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   15048:             } else {
1.160.6.70  raeburn  15049:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   15050:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   15051:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21  raeburn  15052:                 }
                   15053:                 $newdef =~ s/[^\w.\-]//g;
1.160.6.70  raeburn  15054:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21  raeburn  15055:             }
                   15056:             if ($currdef ne $newdef) {
                   15057:                 if ($item eq 'anonsurvey_threshold') {
                   15058:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   15059:                         $changes{$item} = 1;
                   15060:                     }
1.160.6.70  raeburn  15061:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   15062:                     my $setting = $1;
                   15063:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   15064:                         $changes{$setting} = 1;
1.160.6.21  raeburn  15065:                     }
                   15066:                 }
1.139     raeburn  15067:             }
                   15068:         }
1.160.6.90  raeburn  15069:         my $texengine;
                   15070:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   15071:             $texengine = $env{'form.texengine'};
                   15072:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   15073:             if ($currdef eq '') {
                   15074:                 unless ($texengine eq $Apache::lonnet::deftex) {
                   15075:                     $changes{'texengine'} = 1;
                   15076:                 }
                   15077:             } elsif ($currdef ne $texengine) {
                   15078:                 $changes{'texengine'} = 1;
                   15079:             }
                   15080:         }
                   15081:         if ($texengine ne '') {
                   15082:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   15083:         }
1.160.6.64  raeburn  15084:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   15085:         my @currclonecode;
                   15086:         if (ref($currclone) eq 'HASH') {
                   15087:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   15088:                 @currclonecode = @{$currclone->{'instcode'}};
                   15089:             }
                   15090:         }
                   15091:         my $newclone;
                   15092:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
                   15093:             $newclone = $env{'form.canclone'};
                   15094:         }
                   15095:         if ($newclone eq 'instcode') {
                   15096:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   15097:             my (%codedefaults,@code_order,@clonecode);
                   15098:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   15099:                                                     \@code_order);
                   15100:             foreach my $item (@code_order) {
                   15101:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   15102:                     push(@clonecode,$item);
                   15103:                 }
                   15104:             }
                   15105:             if (@clonecode) {
                   15106:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   15107:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   15108:                 if (@diffs) {
                   15109:                     $changes{'canclone'} = 1;
                   15110:                 }
                   15111:             } else {
                   15112:                 $newclone eq '';
                   15113:             }
                   15114:         } elsif ($newclone ne '') {
                   15115:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   15116:         }
                   15117:         if ($newclone ne $currclone) {
                   15118:             $changes{'canclone'} = 1;
                   15119:         }
1.160.6.57  raeburn  15120:         my %credits;
                   15121:         foreach my $type (@types) {
                   15122:             unless ($type eq 'community') {
                   15123:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   15124:                 $credits{$type} =~ s/[^\d.]+//g;
                   15125:             }
                   15126:         }
                   15127:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   15128:             ($env{'form.coursecredits'} eq '1')) {
                   15129:             $changes{'coursecredits'} = 1;
                   15130:             foreach my $type (keys(%credits)) {
                   15131:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   15132:             }
                   15133:         } else {
                   15134:             if ($env{'form.coursecredits'} eq '1') {
                   15135:                 foreach my $type (@types) {
                   15136:                     unless ($type eq 'community') {
                   15137:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
                   15138:                             $changes{'coursecredits'} = 1;
                   15139:                         }
                   15140:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   15141:                     }
                   15142:                 }
                   15143:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   15144:                 foreach my $type (@types) {
                   15145:                     unless ($type eq 'community') {
                   15146:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   15147:                             $changes{'coursecredits'} = 1;
                   15148:                             last;
                   15149:                         }
                   15150:                     }
                   15151:                 }
                   15152:             }
                   15153:         }
                   15154:         if ($env{'form.postsubmit'} eq '1') {
                   15155:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   15156:             my %currtimeout;
                   15157:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   15158:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   15159:                     $changes{'postsubmit'} = 1;
                   15160:                 }
                   15161:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   15162:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   15163:                 }
                   15164:             } else {
                   15165:                 $changes{'postsubmit'} = 1;
                   15166:             }
                   15167:             foreach my $type (@types) {
                   15168:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   15169:                 $timeout =~ s/\D//g;
                   15170:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   15171:                     $timeout = '';
                   15172:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   15173:                     $timeout = '0';
                   15174:                 }
                   15175:                 unless ($timeout eq '') {
                   15176:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   15177:                 }
                   15178:                 if (exists($currtimeout{$type})) {
                   15179:                     if ($timeout ne $currtimeout{$type}) {
                   15180:                         $changes{'postsubmit'} = 1;
                   15181:                     }
                   15182:                 } elsif ($timeout ne '') {
                   15183:                     $changes{'postsubmit'} = 1;
                   15184:                 }
                   15185:             }
                   15186:         } else {
                   15187:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   15188:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   15189:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   15190:                     $changes{'postsubmit'} = 1;
                   15191:                 }
                   15192:             } else {
                   15193:                 $changes{'postsubmit'} = 1;
                   15194:             }
1.160.6.16  raeburn  15195:         }
1.121     raeburn  15196:     }
                   15197:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   15198:                                              $dom);
                   15199:     if ($putresult eq 'ok') {
                   15200:         if (keys(%changes) > 0) {
1.160.6.27  raeburn  15201:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57  raeburn  15202:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64  raeburn  15203:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.90  raeburn  15204:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'})) {
                   15205:                 foreach my $item ('uselcmath','usejsme','texengine') {
1.160.6.57  raeburn  15206:                     if ($changes{$item}) {
                   15207:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   15208:                     }
1.160.6.16  raeburn  15209:                 }
                   15210:                 if ($changes{'coursecredits'}) {
                   15211:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  15212:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   15213:                             $domdefaults{$type.'credits'} =
                   15214:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   15215:                         }
                   15216:                     }
                   15217:                 }
                   15218:                 if ($changes{'postsubmit'}) {
                   15219:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   15220:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   15221:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   15222:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   15223:                                 $domdefaults{$type.'postsubtimeout'} =
                   15224:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   15225:                             }
                   15226:                         }
1.160.6.16  raeburn  15227:                     }
                   15228:                 }
1.160.6.21  raeburn  15229:                 if ($changes{'uploadquota'}) {
                   15230:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   15231:                         foreach my $type (@types) {
                   15232:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   15233:                         }
                   15234:                     }
                   15235:                 }
1.160.6.64  raeburn  15236:                 if ($changes{'canclone'}) {
                   15237:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   15238:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   15239:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   15240:                             if (@clonecodes) {
                   15241:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   15242:                             }
                   15243:                         }
                   15244:                     } else {
                   15245:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   15246:                     }
                   15247:                 }
1.121     raeburn  15248:                 my $cachetime = 24*60*60;
                   15249:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  15250:                 if (ref($lastactref) eq 'HASH') {
                   15251:                     $lastactref->{'domdefaults'} = 1;
                   15252:                 }
1.121     raeburn  15253:             }
                   15254:             $resulttext = &mt('Changes made:').'<ul>';
                   15255:             foreach my $item (sort(keys(%changes))) {
1.160.6.57  raeburn  15256:                 if ($item eq 'uselcmath') {
1.121     raeburn  15257:                     if ($env{'form.'.$item} eq '1') {
1.160.6.57  raeburn  15258:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121     raeburn  15259:                     } else {
1.160.6.57  raeburn  15260:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   15261:                     }
                   15262:                 } elsif ($item eq 'usejsme') {
                   15263:                     if ($env{'form.'.$item} eq '1') {
                   15264:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   15265:                     } else {
                   15266:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121     raeburn  15267:                     }
1.160.6.90  raeburn  15268:                 } elsif ($item eq 'texengine') {
                   15269:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   15270:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   15271:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   15272:                     }
1.139     raeburn  15273:                 } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26  raeburn  15274:                     $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  15275:                 } elsif ($item eq 'uploadquota') {
                   15276:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   15277:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   15278:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   15279:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30  raeburn  15280:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   15281: 
1.160.6.21  raeburn  15282:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   15283:                                        '</ul>'.
                   15284:                                        '</li>';
                   15285:                     } else {
                   15286:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   15287:                     }
1.160.6.70  raeburn  15288:                 } elsif ($item eq 'mysqltables') {
                   15289:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   15290:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   15291:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   15292:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   15293:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   15294:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   15295:                                        '</ul>'.
                   15296:                                        '</li>';
                   15297:                     } else {
                   15298:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   15299:                     }
1.160.6.57  raeburn  15300:                 } elsif ($item eq 'postsubmit') {
                   15301:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   15302:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   15303:                     } else {
                   15304:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   15305:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   15306:                             $resulttext .= &mt('durations:').'<ul>';
                   15307:                             foreach my $type (@types) {
                   15308:                                 $resulttext .= '<li>';
                   15309:                                 my $timeout;
                   15310:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   15311:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   15312:                                 }
                   15313:                                 my $display;
                   15314:                                 if ($timeout eq '0') {
                   15315:                                     $display = &mt('unlimited');
                   15316:                                 } elsif ($timeout eq '') {
                   15317:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   15318:                                 } else {
                   15319:                                     $display = &mt('[quant,_1,second]',$timeout);
                   15320:                                 }
                   15321:                                 if ($type eq 'community') {
                   15322:                                     $resulttext .= &mt('Communities');
                   15323:                                 } elsif ($type eq 'official') {
                   15324:                                     $resulttext .= &mt('Official courses');
                   15325:                                 } elsif ($type eq 'unofficial') {
                   15326:                                     $resulttext .= &mt('Unofficial courses');
                   15327:                                 } elsif ($type eq 'textbook') {
                   15328:                                     $resulttext .= &mt('Textbook courses');
                   15329:                                 }
                   15330:                                 $resulttext .= ' -- '.$display.'</li>';
                   15331:                             }
                   15332:                             $resulttext .= '</ul>';
                   15333:                         }
                   15334:                         $resulttext .= '</li>';
                   15335:                     }
1.160.6.16  raeburn  15336:                 } elsif ($item eq 'coursecredits') {
                   15337:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   15338:                         if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30  raeburn  15339:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   15340:                             ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16  raeburn  15341:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   15342:                         } else {
                   15343:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   15344:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   15345:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30  raeburn  15346:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16  raeburn  15347:                                            '</ul>'.
                   15348:                                            '</li>';
                   15349:                         }
                   15350:                     } else {
                   15351:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   15352:                     }
1.160.6.64  raeburn  15353:                 } elsif ($item eq 'canclone') {
                   15354:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   15355:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   15356:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   15357:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   15358:                         }
                   15359:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   15360:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   15361:                     } else {
                   15362:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
                   15363:                     }
1.140     raeburn  15364:                 }
1.121     raeburn  15365:             }
                   15366:             $resulttext .= '</ul>';
                   15367:         } else {
                   15368:             $resulttext = &mt('No changes made to course defaults');
                   15369:         }
                   15370:     } else {
                   15371:         $resulttext = '<span class="LC_error">'.
                   15372:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15373:     }
                   15374:     return $resulttext;
                   15375: }
                   15376: 
1.160.6.37  raeburn  15377: sub modify_selfenrollment {
                   15378:     my ($dom,$lastactref,%domconfig) = @_;
                   15379:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   15380:     my @types = ('official','unofficial','community','textbook');
                   15381:     my %titles = &tool_titles();
                   15382:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   15383:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   15384:     $ordered{'default'} = ['types','registered','approval','limit'];
                   15385: 
                   15386:     my (%roles,%shown,%toplevel);
                   15387:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   15388: 
                   15389:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   15390:         if ($domconfig{'selfenrollment'} eq '') {
                   15391:             $domconfig{'selfenrollment'} = {};
                   15392:         }
                   15393:     }
                   15394:     %toplevel = (
                   15395:                   admin      => 'Configuration Rights',
                   15396:                   default    => 'Default settings',
                   15397:                   validation => 'Validation of self-enrollment requests',
                   15398:                 );
                   15399:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   15400: 
                   15401:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   15402:         foreach my $item (@{$ordered{'admin'}}) {
                   15403:             foreach my $type (@types) {
                   15404:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   15405:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   15406:                 } else {
                   15407:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   15408:                 }
                   15409:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   15410:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   15411:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   15412:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   15413:                             push(@{$changes{'admin'}{$type}},$item);
                   15414:                         }
                   15415:                     } else {
                   15416:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   15417:                             push(@{$changes{'admin'}{$type}},$item);
                   15418:                         }
                   15419:                     }
                   15420:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   15421:                     push(@{$changes{'admin'}{$type}},$item);
                   15422:                 }
                   15423:             }
                   15424:         }
                   15425:     }
                   15426: 
                   15427:     foreach my $item (@{$ordered{'default'}}) {
                   15428:         foreach my $type (@types) {
                   15429:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   15430:             if ($item eq 'types') {
                   15431:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   15432:                     $value = '';
                   15433:                 }
                   15434:             } elsif ($item eq 'registered') {
                   15435:                 unless ($value eq '1') {
                   15436:                     $value = 0;
                   15437:                 }
                   15438:             } elsif ($item eq 'approval') {
                   15439:                 unless ($value =~ /^[012]$/) {
                   15440:                     $value = 0;
                   15441:                 }
                   15442:             } else {
                   15443:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   15444:                     $value = 'none';
                   15445:                 }
                   15446:             }
                   15447:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   15448:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   15449:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   15450:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   15451:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   15452:                          push(@{$changes{'default'}{$type}},$item);
                   15453:                     }
                   15454:                 } else {
                   15455:                     push(@{$changes{'default'}{$type}},$item);
                   15456:                 }
                   15457:             } else {
                   15458:                 push(@{$changes{'default'}{$type}},$item);
                   15459:             }
                   15460:             if ($item eq 'limit') {
                   15461:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   15462:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   15463:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   15464:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   15465:                     }
                   15466:                 } else {
                   15467:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   15468:                 }
                   15469:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   15470:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   15471:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   15472:                          push(@{$changes{'default'}{$type}},'cap');
                   15473:                     }
                   15474:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   15475:                     push(@{$changes{'default'}{$type}},'cap');
                   15476:                 }
                   15477:             }
                   15478:         }
                   15479:     }
                   15480: 
                   15481:     foreach my $item (@{$itemsref}) {
                   15482:         if ($item eq 'fields') {
                   15483:             my @changed;
                   15484:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   15485:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   15486:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   15487:             }
                   15488:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   15489:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   15490:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   15491:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   15492:                 } else {
                   15493:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   15494:                 }
                   15495:             } else {
                   15496:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   15497:             }
                   15498:             if (@changed) {
                   15499:                 if ($selfenrollhash{'validation'}{$item}) { 
                   15500:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   15501:                 } else {
                   15502:                     $changes{'validation'}{$item} = &mt('None');
                   15503:                 }
                   15504:             }
                   15505:         } else {
                   15506:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   15507:             if ($item eq 'markup') {
                   15508:                if ($env{'form.selfenroll_validation_'.$item}) {
                   15509:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   15510:                }
                   15511:             }
                   15512:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   15513:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   15514:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   15515:                 }
                   15516:             }
                   15517:         }
                   15518:     }
                   15519: 
                   15520:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   15521:                                              $dom);
                   15522:     if ($putresult eq 'ok') {
                   15523:         if (keys(%changes) > 0) {
                   15524:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15525:             $resulttext = &mt('Changes made:').'<ul>';
                   15526:             foreach my $key ('admin','default','validation') {
                   15527:                 if (ref($changes{$key}) eq 'HASH') {
                   15528:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   15529:                     if ($key eq 'validation') {
                   15530:                         foreach my $item (@{$itemsref}) {
                   15531:                             if (exists($changes{$key}{$item})) {
                   15532:                                 if ($item eq 'markup') {
                   15533:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   15534:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   15535:                                 } else {  
                   15536:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   15537:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   15538:                                 }
                   15539:                             }
                   15540:                         }
                   15541:                     } else {
                   15542:                         foreach my $type (@types) {
                   15543:                             if ($type eq 'community') {
                   15544:                                 $roles{'1'} = &mt('Community personnel');
                   15545:                             } else {
                   15546:                                 $roles{'1'} = &mt('Course personnel');
                   15547:                             }
                   15548:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
                   15549:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   15550:                                     if ($key eq 'admin') {
                   15551:                                         my @mgrdc = ();
                   15552:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   15553:                                             foreach my $item (@{$ordered{'admin'}}) {
                   15554:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   15555:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   15556:                                                         push(@mgrdc,$item);
                   15557:                                                     }
                   15558:                                                 }
                   15559:                                             }
                   15560:                                             if (@mgrdc) {
                   15561:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   15562:                                             } else {
                   15563:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   15564:                                             }
                   15565:                                         }
                   15566:                                     } else {
                   15567:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   15568:                                             foreach my $item (@{$ordered{$key}}) {
                   15569:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   15570:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   15571:                                                         $selfenrollhash{$key}{$type}{$item};
                   15572:                                                 }
                   15573:                                             }
                   15574:                                         }
                   15575:                                     }
                   15576:                                 }
                   15577:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   15578:                                 foreach my $item (@{$ordered{$key}}) {
                   15579:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   15580:                                         $resulttext .= '<li>';
                   15581:                                         if ($key eq 'admin') {
                   15582:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   15583:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   15584:                                         } else {
                   15585:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   15586:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   15587:                                         }
                   15588:                                         $resulttext .= '</li>';
                   15589:                                     }
                   15590:                                 }
                   15591:                                 $resulttext .= '</ul></li>';
                   15592:                             }
                   15593:                         }
                   15594:                         $resulttext .= '</ul></li>'; 
                   15595:                     }
                   15596:                 }
1.160.6.93  raeburn  15597:             }
                   15598:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   15599:                 my $cachetime = 24*60*60;
                   15600:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   15601:                 if (ref($lastactref) eq 'HASH') {
                   15602:                     $lastactref->{'domdefaults'} = 1;
1.160.6.37  raeburn  15603:                 }
                   15604:             }
                   15605:             $resulttext .= '</ul>';
                   15606:         } else {
                   15607:             $resulttext = &mt('No changes made to self-enrollment settings');
                   15608:         }
                   15609:     } else {
                   15610:         $resulttext = '<span class="LC_error">'.
                   15611:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15612:     }
                   15613:     return $resulttext;
                   15614: }
                   15615: 
1.137     raeburn  15616: sub modify_usersessions {
1.160.6.27  raeburn  15617:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  15618:     my @hostingtypes = ('version','excludedomain','includedomain');
                   15619:     my @offloadtypes = ('primary','default');
                   15620:     my %types = (
                   15621:                   remote => \@hostingtypes,
                   15622:                   hosted => \@hostingtypes,
                   15623:                   spares => \@offloadtypes,
                   15624:                 );
                   15625:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  15626:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  15627:     my (%by_ip,%by_location,@intdoms);
                   15628:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   15629:     my @locations = sort(keys(%by_location));
1.137     raeburn  15630:     my (%defaultshash,%changes);
                   15631:     foreach my $prefix (@prefixes) {
                   15632:         $defaultshash{'usersessions'}{$prefix} = {};
                   15633:     }
1.160.6.27  raeburn  15634:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  15635:     my $resulttext;
1.138     raeburn  15636:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  15637:     foreach my $prefix (@prefixes) {
1.145     raeburn  15638:         next if ($prefix eq 'spares');
                   15639:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  15640:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   15641:             if ($type eq 'version') {
                   15642:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   15643:                 my $okvalue;
                   15644:                 if ($value ne '') {
                   15645:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   15646:                         $okvalue = $value;
                   15647:                     }
                   15648:                 }
                   15649:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   15650:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   15651:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   15652:                             if ($inuse == 0) {
                   15653:                                 $changes{$prefix}{$type} = 1;
                   15654:                             } else {
                   15655:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   15656:                                     $changes{$prefix}{$type} = 1;
                   15657:                                 }
                   15658:                                 if ($okvalue ne '') {
                   15659:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   15660:                                 } 
                   15661:                             }
                   15662:                         } else {
                   15663:                             if (($inuse == 1) && ($okvalue ne '')) {
                   15664:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   15665:                                 $changes{$prefix}{$type} = 1;
                   15666:                             }
                   15667:                         }
                   15668:                     } else {
                   15669:                         if (($inuse == 1) && ($okvalue ne '')) {
                   15670:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   15671:                             $changes{$prefix}{$type} = 1;
                   15672:                         }
                   15673:                     }
                   15674:                 } else {
                   15675:                     if (($inuse == 1) && ($okvalue ne '')) {
                   15676:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   15677:                         $changes{$prefix}{$type} = 1;
                   15678:                     }
                   15679:                 }
                   15680:             } else {
                   15681:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   15682:                 my @okvals;
                   15683:                 foreach my $val (@vals) {
1.138     raeburn  15684:                     if ($val =~ /:/) {
                   15685:                         my @items = split(/:/,$val);
                   15686:                         foreach my $item (@items) {
                   15687:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   15688:                                 push(@okvals,$item);
                   15689:                             }
                   15690:                         }
                   15691:                     } else {
                   15692:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   15693:                             push(@okvals,$val);
                   15694:                         }
1.137     raeburn  15695:                     }
                   15696:                 }
                   15697:                 @okvals = sort(@okvals);
                   15698:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   15699:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   15700:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   15701:                             if ($inuse == 0) {
                   15702:                                 $changes{$prefix}{$type} = 1; 
                   15703:                             } else {
                   15704:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   15705:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   15706:                                 if (@changed > 0) {
                   15707:                                     $changes{$prefix}{$type} = 1;
                   15708:                                 }
                   15709:                             }
                   15710:                         } else {
                   15711:                             if ($inuse == 1) {
                   15712:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   15713:                                 $changes{$prefix}{$type} = 1;
                   15714:                             }
                   15715:                         } 
                   15716:                     } else {
                   15717:                         if ($inuse == 1) {
                   15718:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   15719:                             $changes{$prefix}{$type} = 1;
                   15720:                         }
                   15721:                     }
                   15722:                 } else {
                   15723:                     if ($inuse == 1) {
                   15724:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   15725:                         $changes{$prefix}{$type} = 1;
                   15726:                     }
                   15727:                 }
                   15728:             }
                   15729:         }
                   15730:     }
1.145     raeburn  15731: 
                   15732:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  15733:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  15734:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   15735:     my $savespares;
                   15736: 
                   15737:     foreach my $lonhost (sort(keys(%servers))) {
                   15738:         my $serverhomeID =
                   15739:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  15740:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  15741:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   15742:         my %spareschg;
                   15743:         foreach my $type (@{$types{'spares'}}) {
                   15744:             my @okspares;
                   15745:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   15746:             foreach my $server (@checked) {
1.152     raeburn  15747:                 if (&Apache::lonnet::hostname($server) ne '') {
                   15748:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   15749:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   15750:                             push(@okspares,$server);
                   15751:                         }
1.145     raeburn  15752:                     }
                   15753:                 }
                   15754:             }
                   15755:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   15756:             my $newspare;
1.152     raeburn  15757:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   15758:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  15759:                     $newspare = $new;
                   15760:                 }
                   15761:             }
1.152     raeburn  15762:             my @spares;
                   15763:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   15764:                 @spares = sort(@okspares,$newspare);
                   15765:             } else {
                   15766:                 @spares = sort(@okspares);
                   15767:             }
                   15768:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  15769:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   15770:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  15771:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  15772:                     if (@diffs > 0) {
                   15773:                         $spareschg{$type} = 1;
                   15774:                     }
                   15775:                 }
                   15776:             }
                   15777:         }
                   15778:         if (keys(%spareschg) > 0) {
                   15779:             $changes{'spares'}{$lonhost} = \%spareschg;
                   15780:         }
                   15781:     }
1.160.6.61  raeburn  15782:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.102.2  4(raebur 15783:0):     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61  raeburn  15784:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   15785:     my @okoffload;
                   15786:     if (@offloadnow) {
                   15787:         foreach my $server (@offloadnow) {
                   15788:             if (&Apache::lonnet::hostname($server) ne '') {
                   15789:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   15790:                     push(@okoffload,$server);
                   15791:                 }
                   15792:             }
                   15793:         }
                   15794:         if (@okoffload) {
                   15795:             foreach my $lonhost (@okoffload) {
                   15796:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   15797:             }
                   15798:         }
                   15799:     }
1.160.6.102.2  4(raebur 15800:0):     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   15801:0):     my @okoffloadoth;
                   15802:0):     if (@offloadoth) {
                   15803:0):         foreach my $server (@offloadoth) {
                   15804:0):             if (&Apache::lonnet::hostname($server) ne '') {
                   15805:0):                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   15806:0):                     push(@okoffloadoth,$server);
                   15807:0):                 }
                   15808:0):             }
                   15809:0):         }
                   15810:0):         if (@okoffloadoth) {
                   15811:0):             foreach my $lonhost (@okoffloadoth) {
                   15812:0):                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   15813:0):             }
                   15814:0):         }
                   15815:0):     }
1.145     raeburn  15816:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   15817:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   15818:             if (ref($changes{'spares'}) eq 'HASH') {
                   15819:                 if (keys(%{$changes{'spares'}}) > 0) {
                   15820:                     $savespares = 1;
                   15821:                 }
                   15822:             }
                   15823:         } else {
                   15824:             $savespares = 1;
                   15825:         }
1.160.6.102.2  4(raebur 15826:0):         foreach my $offload ('offloadnow','offloadoth') {
                   15827:0):             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   15828:0):                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   15829:0):                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   15830:0):                         $changes{$offload} = 1;
1.160.6.61  raeburn  15831:                         last;
                   15832:                     }
                   15833:                 }
1.160.6.102.2  4(raebur 15834:0):                 unless ($changes{$offload}) {
                   15835:0):                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   15836:0):                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   15837:0):                             $changes{$offload} = 1;
                   15838:0):                             last;
                   15839:0):                         }
                   15840:0):                     }
                   15841:0):                 }
                   15842:0):             } else {
                   15843:0):                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   15844:0):                      $changes{'offloadnow'} = 1;
                   15845:0):                 }
                   15846:0):                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   15847:0):                     $changes{'offloadoth'} = 1;
                   15848:0):                 }
1.160.6.61  raeburn  15849:             }
1.160.6.102.2  4(raebur 15850:0):         }
                   15851:0):     } else {
                   15852:0):         if (@okoffload) {
1.160.6.61  raeburn  15853:             $changes{'offloadnow'} = 1;
                   15854:         }
1.160.6.102.2  4(raebur 15855:0):         if (@okoffloadoth) {
                   15856:0):             $changes{'offloadoth'} = 1;
                   15857:0):         }
1.145     raeburn  15858:     }
1.147     raeburn  15859:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   15860:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  15861:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   15862:                                                  $dom);
                   15863:         if ($putresult eq 'ok') {
                   15864:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   15865:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   15866:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   15867:                 }
                   15868:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   15869:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   15870:                 }
1.160.6.61  raeburn  15871:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   15872:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   15873:                 }
1.160.6.102.2  4(raebur 15874:0):                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   15875:0):                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   15876:0):                 }
1.137     raeburn  15877:             }
                   15878:             my $cachetime = 24*60*60;
                   15879:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81  raeburn  15880:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27  raeburn  15881:             if (ref($lastactref) eq 'HASH') {
                   15882:                 $lastactref->{'domdefaults'} = 1;
1.160.6.81  raeburn  15883:                 $lastactref->{'usersessions'} = 1;
1.160.6.27  raeburn  15884:             }
1.147     raeburn  15885:             if (keys(%changes) > 0) {
                   15886:                 my %lt = &usersession_titles();
                   15887:                 $resulttext = &mt('Changes made:').'<ul>';
                   15888:                 foreach my $prefix (@prefixes) {
                   15889:                     if (ref($changes{$prefix}) eq 'HASH') {
                   15890:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   15891:                         if ($prefix eq 'spares') {
                   15892:                             if (ref($changes{$prefix}) eq 'HASH') {
                   15893:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   15894:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  15895:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27  raeburn  15896:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   15897:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  15898:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   15899:                                         foreach my $type (@{$types{$prefix}}) {
                   15900:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   15901:                                                 my $offloadto = &mt('None');
                   15902:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   15903:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   15904:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   15905:                                                     }
1.145     raeburn  15906:                                                 }
1.147     raeburn  15907:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  15908:                                             }
1.137     raeburn  15909:                                         }
                   15910:                                     }
1.147     raeburn  15911:                                     $resulttext .= '</li>';
1.137     raeburn  15912:                                 }
                   15913:                             }
1.147     raeburn  15914:                         } else {
                   15915:                             foreach my $type (@{$types{$prefix}}) {
                   15916:                                 if (defined($changes{$prefix}{$type})) {
                   15917:                                     my $newvalue;
                   15918:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   15919:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   15920:                                             if ($type eq 'version') {
                   15921:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   15922:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   15923:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   15924:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   15925:                                                 }
1.145     raeburn  15926:                                             }
                   15927:                                         }
                   15928:                                     }
1.147     raeburn  15929:                                     if ($newvalue eq '') {
                   15930:                                         if ($type eq 'version') {
                   15931:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   15932:                                         } else {
                   15933:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   15934:                                         }
1.145     raeburn  15935:                                     } else {
1.147     raeburn  15936:                                         if ($type eq 'version') {
                   15937:                                             $newvalue .= ' '.&mt('(or later)'); 
                   15938:                                         }
                   15939:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  15940:                                     }
1.137     raeburn  15941:                                 }
                   15942:                             }
                   15943:                         }
1.147     raeburn  15944:                         $resulttext .= '</ul>';
1.137     raeburn  15945:                     }
                   15946:                 }
1.160.6.61  raeburn  15947:                 if ($changes{'offloadnow'}) {
                   15948:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   15949:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.102.2  4(raebur 15950:0):                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61  raeburn  15951:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   15952:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   15953:                             }
                   15954:                             $resulttext .= '</ul>';
                   15955:                         } else {
1.160.6.102.2  4(raebur 15956:0):                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   15957:0):                         }
                   15958:0):                     } else {
                   15959:0):                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   15960:0):                     }
                   15961:0):                 }
                   15962:0):                 if ($changes{'offloadoth'}) {
                   15963:0):                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   15964:0):                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   15965:0):                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   15966:0):                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   15967:0):                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   15968:0):                             }
                   15969:0):                             $resulttext .= '</ul>';
                   15970:0):                         } else {
                   15971:0):                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61  raeburn  15972:                         }
                   15973:                     } else {
1.160.6.102.2  4(raebur 15974:0):                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61  raeburn  15975:                     }
                   15976:                 }
1.147     raeburn  15977:                 $resulttext .= '</ul>';
                   15978:             } else {
                   15979:                 $resulttext = $nochgmsg;
1.137     raeburn  15980:             }
                   15981:         } else {
                   15982:             $resulttext = '<span class="LC_error">'.
                   15983:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   15984:         }
                   15985:     } else {
1.147     raeburn  15986:         $resulttext = $nochgmsg;
1.137     raeburn  15987:     }
                   15988:     return $resulttext;
                   15989: }
                   15990: 
1.150     raeburn  15991: sub modify_loadbalancing {
                   15992:     my ($dom,%domconfig) = @_;
                   15993:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   15994:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   15995:     my ($othertitle,$usertypes,$types) =
                   15996:         &Apache::loncommon::sorted_inst_types($dom);
                   15997:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55  raeburn  15998:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  15999:     my @sparestypes = ('primary','default');
                   16000:     my %typetitles = &sparestype_titles();
                   16001:     my $resulttext;
1.160.6.94  raeburn  16002:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  16003:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   16004:         %existing = %{$domconfig{'loadbalancing'}};
                   16005:     }
                   16006:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  16007:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  16008:     my ($saveloadbalancing,%defaultshash,%changes);
                   16009:     my ($alltypes,$othertypes,$titles) =
                   16010:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   16011:     my %ruletitles = &offloadtype_text();
                   16012:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   16013:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   16014:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   16015:         if ($balancer eq '') {
                   16016:             next;
                   16017:         }
                   16018:         if (!exists($servers{$balancer})) {
                   16019:             if (exists($currbalancer{$balancer})) {
                   16020:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  16021:             }
1.160.6.7  raeburn  16022:             next;
                   16023:         }
                   16024:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   16025:             push(@{$changes{'delete'}},$balancer);
                   16026:             next;
                   16027:         }
                   16028:         if (!exists($currbalancer{$balancer})) {
                   16029:             push(@{$changes{'add'}},$balancer);
                   16030:         }
                   16031:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   16032:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   16033:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   16034:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   16035:             $saveloadbalancing = 1;
                   16036:         }
                   16037:         foreach my $sparetype (@sparestypes) {
                   16038:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   16039:             my @offloadto;
                   16040:             foreach my $target (@targets) {
                   16041:                 if (($servers{$target}) && ($target ne $balancer)) {
                   16042:                     if ($sparetype eq 'default') {
                   16043:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   16044:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  16045:                         }
                   16046:                     }
1.160.6.7  raeburn  16047:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   16048:                         push(@offloadto,$target);
                   16049:                     }
1.150     raeburn  16050:                 }
                   16051:             }
1.160.6.76  raeburn  16052:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   16053:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   16054:                     push(@offloadto,$balancer);
                   16055:                 }
                   16056:             }
                   16057:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  16058:         }
1.160.6.94  raeburn  16059:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   16060:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   16061:             if (exists($currbalancer{$balancer})) {
                   16062:                 unless ($currcookies{$balancer}) {
                   16063:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   16064:                 }
                   16065:             }
                   16066:         } elsif (exists($currbalancer{$balancer})) {
                   16067:             if ($currcookies{$balancer}) {
                   16068:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   16069:             }
                   16070:         }
1.160.6.7  raeburn  16071:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  16072:             foreach my $sparetype (@sparestypes) {
1.160.6.7  raeburn  16073:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   16074:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  16075:                     if (@targetdiffs > 0) {
1.160.6.7  raeburn  16076:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  16077:                     }
1.160.6.7  raeburn  16078:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   16079:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   16080:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  16081:                     }
                   16082:                 }
                   16083:             }
                   16084:         } else {
1.160.6.7  raeburn  16085:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   16086:                 foreach my $sparetype (@sparestypes) {
                   16087:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   16088:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   16089:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   16090:                         }
1.150     raeburn  16091:                     }
                   16092:                 }
1.160.6.7  raeburn  16093:             }
1.150     raeburn  16094:         }
                   16095:         my $ishomedom;
1.160.6.7  raeburn  16096:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   16097:             $ishomedom = 1;
1.150     raeburn  16098:         }
                   16099:         if (ref($alltypes) eq 'ARRAY') {
                   16100:             foreach my $type (@{$alltypes}) {
                   16101:                 my $rule;
1.160.6.7  raeburn  16102:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  16103:                          (!$ishomedom)) {
1.160.6.7  raeburn  16104:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   16105:                 }
                   16106:                 if ($rule eq 'specific') {
1.160.6.55  raeburn  16107:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   16108:                     if (exists($servers{$specifiedhost})) {
                   16109:                         $rule = $specifiedhost;
                   16110:                     }
1.150     raeburn  16111:                 }
1.160.6.7  raeburn  16112:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   16113:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   16114:                     if ($rule ne $currrules{$balancer}{$type}) {
                   16115:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  16116:                     }
                   16117:                 } elsif ($rule ne '') {
1.160.6.7  raeburn  16118:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  16119:                 }
                   16120:             }
                   16121:         }
1.160.6.7  raeburn  16122:     }
                   16123:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   16124:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   16125:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   16126:             $defaultshash{'loadbalancing'} = {};
                   16127:         }
                   16128:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   16129:                                                  \%defaultshash,$dom);
                   16130:         if ($putresult eq 'ok') {
                   16131:             if (keys(%changes) > 0) {
1.160.6.54  raeburn  16132:                 my %toupdate;
1.160.6.7  raeburn  16133:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   16134:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   16135:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54  raeburn  16136:                         $toupdate{$balancer} = 1;
1.150     raeburn  16137:                     }
1.160.6.7  raeburn  16138:                 }
                   16139:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   16140:                     foreach my $balancer (sort(@{$changes{'add'}})) {
                   16141:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54  raeburn  16142:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  16143:                     }
                   16144:                 }
                   16145:                 if (ref($changes{'curr'}) eq 'HASH') {
                   16146:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55  raeburn  16147:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  16148:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   16149:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   16150:                                 my %offloadstr;
                   16151:                                 foreach my $sparetype (@sparestypes) {
                   16152:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   16153:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   16154:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   16155:                                         }
                   16156:                                     }
1.150     raeburn  16157:                                 }
1.160.6.7  raeburn  16158:                                 if (keys(%offloadstr) == 0) {
                   16159:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  16160:                                 } else {
1.160.6.7  raeburn  16161:                                     my $showoffload;
                   16162:                                     foreach my $sparetype (@sparestypes) {
                   16163:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   16164:                                         if (defined($offloadstr{$sparetype})) {
                   16165:                                             $showoffload .= $offloadstr{$sparetype};
                   16166:                                         } else {
                   16167:                                             $showoffload .= &mt('None');
                   16168:                                         }
                   16169:                                         $showoffload .= ('&nbsp;'x3);
                   16170:                                     }
                   16171:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  16172:                                 }
                   16173:                             }
                   16174:                         }
1.160.6.7  raeburn  16175:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   16176:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   16177:                                 foreach my $type (@{$alltypes}) {
                   16178:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   16179:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   16180:                                         my $balancetext;
                   16181:                                         if ($rule eq '') {
                   16182:                                             $balancetext =  $ruletitles{'default'};
1.160.6.26  raeburn  16183:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55  raeburn  16184:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                   16185:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54  raeburn  16186:                                                 foreach my $sparetype (@sparestypes) {
                   16187:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   16188:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   16189:                                                     }
                   16190:                                                 }
1.160.6.55  raeburn  16191:                                                 foreach my $item (@{$alltypes}) {
                   16192:                                                     next if ($item =~  /^_LC_ipchange/);
                   16193:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   16194:                                                     if ($hasrule eq 'homeserver') {
                   16195:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   16196:                                                     } else {
                   16197:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   16198:                                                             if ($servers{$hasrule}) {
                   16199:                                                                 $toupdate{$hasrule} = 1;
                   16200:                                                             }
                   16201:                                                         }
                   16202:                                                     }
                   16203:                                                 }
                   16204:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   16205:                                                     $balancetext =  $ruletitles{$rule};
                   16206:                                                 } else {
                   16207:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   16208:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   16209:                                                     if ($receiver) {
                   16210:                                                         $toupdate{$receiver};
                   16211:                                                     }
                   16212:                                                 }
                   16213:                                             } else {
                   16214:                                                 $balancetext =  $ruletitles{$rule};
1.160.6.54  raeburn  16215:                                             }
1.160.6.7  raeburn  16216:                                         } else {
                   16217:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   16218:                                         }
1.160.6.26  raeburn  16219:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  16220:                                     }
                   16221:                                 }
                   16222:                             }
                   16223:                         }
1.160.6.94  raeburn  16224:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
                   16225:                             $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   16226:                                                       $balancer).'</li>';
                   16227:                         }
1.160.6.54  raeburn  16228:                         if (keys(%toupdate)) {
                   16229:                             my %thismachine;
                   16230:                             my $updatedhere;
                   16231:                             my $cachetime = 60*60*24;
                   16232:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   16233:                             foreach my $lonhost (keys(%toupdate)) {
                   16234:                                 if ($thismachine{$lonhost}) {
                   16235:                                     unless ($updatedhere) {
                   16236:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   16237:                                                                       $defaultshash{'loadbalancing'},
                   16238:                                                                       $cachetime);
                   16239:                                         $updatedhere = 1;
                   16240:                                     }
                   16241:                                 } else {
                   16242:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   16243:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   16244:                                 }
                   16245:                             }
                   16246:                         }
1.150     raeburn  16247:                     }
1.160.6.7  raeburn  16248:                 }
                   16249:                 if ($resulttext ne '') {
                   16250:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  16251:                 } else {
                   16252:                     $resulttext = $nochgmsg;
                   16253:                 }
                   16254:             } else {
1.160.6.7  raeburn  16255:                 $resulttext = $nochgmsg;
1.150     raeburn  16256:             }
                   16257:         } else {
1.160.6.7  raeburn  16258:             $resulttext = '<span class="LC_error">'.
                   16259:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  16260:         }
                   16261:     } else {
1.160.6.7  raeburn  16262:         $resulttext = $nochgmsg;
1.150     raeburn  16263:     }
                   16264:     return $resulttext;
                   16265: }
                   16266: 
1.48      raeburn  16267: sub recurse_check {
                   16268:     my ($chkcats,$categories,$depth,$name) = @_;
                   16269:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   16270:         my $chg = 0;
                   16271:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   16272:             my $category = $chkcats->[$depth]{$name}[$j];
                   16273:             my $item;
                   16274:             if ($category eq '') {
                   16275:                 $chg ++;
                   16276:             } else {
                   16277:                 my $deeper = $depth + 1;
                   16278:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   16279:                 if ($chg) {
                   16280:                     $categories->{$item} -= $chg;
                   16281:                 }
                   16282:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   16283:                 $deeper --;
                   16284:             }
                   16285:         }
                   16286:     }
                   16287:     return;
                   16288: }
                   16289: 
                   16290: sub recurse_cat_deletes {
                   16291:     my ($item,$coursecategories,$deletions) = @_;
                   16292:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   16293:     my $subdepth = $depth + 1;
                   16294:     if (ref($coursecategories) eq 'HASH') {
                   16295:         foreach my $subitem (keys(%{$coursecategories})) {
                   16296:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   16297:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   16298:                 delete($coursecategories->{$subitem});
                   16299:                 $deletions->{$subitem} = 1;
                   16300:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26  raeburn  16301:             }
1.48      raeburn  16302:         }
                   16303:     }
                   16304:     return;
                   16305: }
                   16306: 
1.125     raeburn  16307: sub active_dc_picker {
1.160.6.16  raeburn  16308:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77  raeburn  16309:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16  raeburn  16310:     my @domcoord = keys(%domcoords);
                   16311:     if (keys(%currhash)) {
                   16312:         foreach my $dc (keys(%currhash)) {
                   16313:             unless (exists($domcoords{$dc})) {
                   16314:                 push(@domcoord,$dc);
                   16315:             }
                   16316:         }
                   16317:     }
                   16318:     @domcoord = sort(@domcoord);
                   16319:     my $numdcs = scalar(@domcoord);
                   16320:     my $rows = 0;
                   16321:     my $table;
1.125     raeburn  16322:     if ($numdcs > 1) {
1.160.6.16  raeburn  16323:         $table = '<table>';
                   16324:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  16325:             my $rem = $i%($numinrow);
                   16326:             if ($rem == 0) {
                   16327:                 if ($i > 0) {
1.160.6.16  raeburn  16328:                     $table .= '</tr>';
1.125     raeburn  16329:                 }
1.160.6.16  raeburn  16330:                 $table .= '<tr>';
                   16331:                 $rows ++;
1.125     raeburn  16332:             }
1.160.6.16  raeburn  16333:             my $check = '';
                   16334:             if ($inputtype eq 'radio') {
                   16335:                 if (keys(%currhash) == 0) {
                   16336:                     if (!$i) {
                   16337:                         $check = ' checked="checked"';
                   16338:                     }
                   16339:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   16340:                     $check = ' checked="checked"';
                   16341:                 }
                   16342:             } else {
                   16343:                 if (exists($currhash{$domcoord[$i]})) {
                   16344:                     $check = ' checked="checked"';
1.125     raeburn  16345:                 }
                   16346:             }
1.160.6.16  raeburn  16347:             if ($i == @domcoord - 1) {
1.125     raeburn  16348:                 my $colsleft = $numinrow - $rem;
                   16349:                 if ($colsleft > 1) {
1.160.6.16  raeburn  16350:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  16351:                 } else {
1.160.6.16  raeburn  16352:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  16353:                 }
                   16354:             } else {
1.160.6.16  raeburn  16355:                 $table .= '<td class="LC_left_item">';
                   16356:             }
                   16357:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   16358:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   16359:             $table .= '<span class="LC_nobreak"><label>'.
                   16360:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   16361:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   16362:             if ($user ne $dcname.':'.$dcdom) {
1.160.6.32  raeburn  16363:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.125     raeburn  16364:             }
1.160.6.33  raeburn  16365:             $table .= '</label></span></td>';
1.125     raeburn  16366:         }
1.160.6.16  raeburn  16367:         $table .= '</tr></table>';
                   16368:     } elsif ($numdcs == 1) {
1.160.6.32  raeburn  16369:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   16370:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16  raeburn  16371:         if ($inputtype eq 'radio') {
1.160.6.50  raeburn  16372:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31  raeburn  16373:             if ($user ne $dcname.':'.$dcdom) {
                   16374:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   16375:             }
1.160.6.16  raeburn  16376:         } else {
                   16377:             my $check;
                   16378:             if (exists($currhash{$domcoord[0]})) {
                   16379:                 $check = ' checked="checked"';
                   16380:             }
1.160.6.50  raeburn  16381:             $table = '<span class="LC_nobreak"><label>'.
                   16382:                      '<input type="checkbox" name="'.$name.'" '.
                   16383:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31  raeburn  16384:             if ($user ne $dcname.':'.$dcdom) {
                   16385:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   16386:             }
                   16387:             $table .= '</label></span>';
1.160.6.16  raeburn  16388:             $rows ++;
                   16389:         }
1.125     raeburn  16390:     }
1.160.6.16  raeburn  16391:     return ($numdcs,$table,$rows);
1.125     raeburn  16392: }
                   16393: 
1.137     raeburn  16394: sub usersession_titles {
                   16395:     return &Apache::lonlocal::texthash(
                   16396:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   16397:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  16398:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  16399:                version => 'LON-CAPA version requirement',
1.138     raeburn  16400:                excludedomain => 'Allow all, but exclude specific domains',
                   16401:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  16402:                primary => 'Primary (checked first)',
1.154     raeburn  16403:                default => 'Default',
1.137     raeburn  16404:            );
                   16405: }
                   16406: 
1.152     raeburn  16407: sub id_for_thisdom {
                   16408:     my (%servers) = @_;
                   16409:     my %altids;
                   16410:     foreach my $server (keys(%servers)) {
                   16411:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   16412:         if ($serverhome ne $server) {
                   16413:             $altids{$serverhome} = $server;
                   16414:         }
                   16415:     }
                   16416:     return %altids;
                   16417: }
                   16418: 
1.150     raeburn  16419: sub count_servers {
                   16420:     my ($currbalancer,%servers) = @_;
                   16421:     my (@spares,$numspares);
                   16422:     foreach my $lonhost (sort(keys(%servers))) {
                   16423:         next if ($currbalancer eq $lonhost);
                   16424:         push(@spares,$lonhost);
                   16425:     }
                   16426:     if ($currbalancer) {
                   16427:         $numspares = scalar(@spares);
                   16428:     } else {
                   16429:         $numspares = scalar(@spares) - 1;
                   16430:     }
                   16431:     return ($numspares,@spares);
                   16432: }
                   16433: 
                   16434: sub lonbalance_targets_js {
1.160.6.7  raeburn  16435:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  16436:     my $select = &mt('Select');
                   16437:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   16438:     if (ref($servers) eq 'HASH') {
                   16439:         $alltargets = join("','",sort(keys(%{$servers})));
                   16440:         my @homedoms;
                   16441:         foreach my $server (sort(keys(%{$servers}))) {
                   16442:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   16443:                 push(@homedoms,'1');
                   16444:             } else {
                   16445:                 push(@homedoms,'0');
                   16446:             }
                   16447:         }
                   16448:         $allishome = join("','",@homedoms);
                   16449:     }
                   16450:     if (ref($types) eq 'ARRAY') {
                   16451:         if (@{$types} > 0) {
                   16452:             @alltypes = @{$types};
                   16453:         }
                   16454:     }
                   16455:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   16456:     $allinsttypes = join("','",@alltypes);
1.160.6.94  raeburn  16457:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  16458:     if (ref($settings) eq 'HASH') {
                   16459:         %existing = %{$settings};
                   16460:     }
                   16461:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  16462:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  16463:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  16464:     return <<"END";
                   16465: 
                   16466: <script type="text/javascript">
                   16467: // <![CDATA[
                   16468: 
1.160.6.7  raeburn  16469: currBalancers = new Array('$balancers');
                   16470: 
                   16471: function toggleTargets(balnum) {
                   16472:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   16473:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   16474:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   16475:     var prevbalancer = prevhostitem.value;
                   16476:     var baltotal = document.getElementById('loadbalancing_total').value;
                   16477:     prevhostitem.value = balancer;
                   16478:     if (prevbalancer != '') {
                   16479:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   16480:         if (prevIdx != -1) {
                   16481:             currBalancers.splice(prevIdx,1);
                   16482:         }
                   16483:     }
1.150     raeburn  16484:     if (balancer == '') {
1.160.6.7  raeburn  16485:         hideSpares(balnum);
1.150     raeburn  16486:     } else {
1.160.6.7  raeburn  16487:         var currIdx = currBalancers.indexOf(balancer);
                   16488:         if (currIdx == -1) {
                   16489:             currBalancers.push(balancer);
                   16490:         }
1.150     raeburn  16491:         var homedoms = new Array('$allishome');
1.160.6.7  raeburn  16492:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   16493:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  16494:     }
1.160.6.7  raeburn  16495:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  16496:     return;
                   16497: }
                   16498: 
1.160.6.7  raeburn  16499: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  16500:     var alltargets = new Array('$alltargets');
                   16501:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  16502:     var offloadtypes = new Array('primary','default');
                   16503: 
1.160.6.7  raeburn  16504:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   16505:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  16506:  
1.151     raeburn  16507:     for (var i=0; i<offloadtypes.length; i++) {
                   16508:         var count = 0;
                   16509:         for (var j=0; j<alltargets.length; j++) {
                   16510:             if (alltargets[j] != balancer) {
1.160.6.7  raeburn  16511:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   16512:                 item.value = alltargets[j];
                   16513:                 item.style.textAlign='left';
                   16514:                 item.style.textFace='normal';
                   16515:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   16516:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   16517:                     item.disabled = '';
                   16518:                 } else {
                   16519:                     item.disabled = 'disabled';
                   16520:                     item.checked = false;
                   16521:                 }
1.151     raeburn  16522:                 count ++;
                   16523:             }
1.150     raeburn  16524:         }
                   16525:     }
1.151     raeburn  16526:     for (var k=0; k<insttypes.length; k++) {
                   16527:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  16528:             if (ishomedom == 1) {
1.160.6.7  raeburn  16529:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   16530:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  16531:             } else {
1.160.6.7  raeburn  16532:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   16533:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  16534:             }
                   16535:         } else {
1.160.6.7  raeburn  16536:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   16537:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  16538:         }
1.151     raeburn  16539:         if ((insttypes[k] != '_LC_external') && 
                   16540:             ((insttypes[k] != '_LC_internetdom') ||
                   16541:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7  raeburn  16542:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   16543:             item.options.length = 0;
                   16544:             item.options[0] = new Option("","",true,true);
                   16545:             var idx = 0;
1.151     raeburn  16546:             for (var m=0; m<alltargets.length; m++) {
1.160.6.7  raeburn  16547:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   16548:                     idx ++;
                   16549:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  16550:                 }
                   16551:             }
                   16552:         }
                   16553:     }
                   16554:     return;
                   16555: }
                   16556: 
1.160.6.7  raeburn  16557: function hideSpares(balnum) {
1.150     raeburn  16558:     var alltargets = new Array('$alltargets');
                   16559:     var insttypes = new Array('$allinsttypes');
                   16560:     var offloadtypes = new Array('primary','default');
                   16561: 
1.160.6.7  raeburn  16562:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   16563:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  16564: 
                   16565:     var total = alltargets.length - 1;
                   16566:     for (var i=0; i<offloadtypes; i++) {
                   16567:         for (var j=0; j<total; j++) {
1.160.6.7  raeburn  16568:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   16569:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   16570:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  16571:         }
1.150     raeburn  16572:     }
                   16573:     for (var k=0; k<insttypes.length; k++) {
1.160.6.7  raeburn  16574:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   16575:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  16576:         if (insttypes[k] != '_LC_external') {
1.160.6.7  raeburn  16577:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   16578:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  16579:         }
                   16580:     }
                   16581:     return;
                   16582: }
                   16583: 
1.160.6.7  raeburn  16584: function checkOffloads(item,balnum,type) {
1.150     raeburn  16585:     var alltargets = new Array('$alltargets');
                   16586:     var offloadtypes = new Array('primary','default');
                   16587:     if (item.checked) {
                   16588:         var total = alltargets.length - 1;
                   16589:         var other;
                   16590:         if (type == offloadtypes[0]) {
1.151     raeburn  16591:             other = offloadtypes[1];
1.150     raeburn  16592:         } else {
1.151     raeburn  16593:             other = offloadtypes[0];
1.150     raeburn  16594:         }
                   16595:         for (var i=0; i<total; i++) {
1.160.6.7  raeburn  16596:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  16597:             if (server == item.value) {
1.160.6.7  raeburn  16598:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   16599:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  16600:                 }
                   16601:             }
                   16602:         }
                   16603:     }
                   16604:     return;
                   16605: }
                   16606: 
1.160.6.7  raeburn  16607: function singleServerToggle(balnum,type) {
                   16608:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  16609:     if (offloadtoSelIdx == 0) {
1.160.6.7  raeburn  16610:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   16611:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  16612: 
                   16613:     } else {
1.160.6.7  raeburn  16614:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   16615:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  16616:     }
                   16617:     return;
                   16618: }
                   16619: 
1.160.6.7  raeburn  16620: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  16621:     if (type == '_LC_external') {
1.160.6.26  raeburn  16622:         return;
1.150     raeburn  16623:     }
1.160.6.7  raeburn  16624:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  16625:     for (var i=0; i<typesRules.length; i++) {
                   16626:         if (formname.elements[typesRules[i]].checked) {
                   16627:             if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7  raeburn  16628:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   16629:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  16630:             } else {
1.160.6.7  raeburn  16631:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   16632:             }
                   16633:         }
                   16634:     }
                   16635:     return;
                   16636: }
                   16637: 
                   16638: function balancerDeleteChange(balnum) {
                   16639:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   16640:     var baltotal = document.getElementById('loadbalancing_total').value;
                   16641:     var addtarget;
                   16642:     var removetarget;
                   16643:     var action = 'delete';
                   16644:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   16645:         var lonhost = hostitem.value;
                   16646:         var currIdx = currBalancers.indexOf(lonhost);
                   16647:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   16648:             if (currIdx != -1) {
                   16649:                 currBalancers.splice(currIdx,1);
                   16650:             }
                   16651:             addtarget = lonhost;
                   16652:         } else {
                   16653:             if (currIdx == -1) {
                   16654:                 currBalancers.push(lonhost);
                   16655:             }
                   16656:             removetarget = lonhost;
                   16657:             action = 'undelete';
                   16658:         }
                   16659:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   16660:     }
                   16661:     return;
                   16662: }
                   16663: 
                   16664: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   16665:     if (baltotal > 1) {
                   16666:         var offloadtypes = new Array('primary','default');
                   16667:         var alltargets = new Array('$alltargets');
                   16668:         var insttypes = new Array('$allinsttypes');
                   16669:         for (var i=0; i<baltotal; i++) {
                   16670:             if (i != balnum) {
                   16671:                 for (var j=0; j<offloadtypes.length; j++) {
                   16672:                     var total = alltargets.length - 1;
                   16673:                     for (var k=0; k<total; k++) {
                   16674:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   16675:                         var server = serveritem.value;
                   16676:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   16677:                             if (server == addtarget) {
                   16678:                                 serveritem.disabled = '';
                   16679:                             }
                   16680:                         }
                   16681:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   16682:                             if (server == removetarget) {
                   16683:                                 serveritem.disabled = 'disabled';
                   16684:                                 serveritem.checked = false;
                   16685:                             }
                   16686:                         }
                   16687:                     }
                   16688:                 }
                   16689:                 for (var j=0; j<insttypes.length; j++) {
                   16690:                     if (insttypes[j] != '_LC_external') {
                   16691:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   16692:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   16693:                             var currSel = singleserver.selectedIndex;
                   16694:                             var currVal = singleserver.options[currSel].value;
                   16695:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   16696:                                 var numoptions = singleserver.options.length;
                   16697:                                 var needsnew = 1;
                   16698:                                 for (var k=0; k<numoptions; k++) {
                   16699:                                     if (singleserver.options[k] == addtarget) {
                   16700:                                         needsnew = 0;
                   16701:                                         break;
                   16702:                                     }
                   16703:                                 }
                   16704:                                 if (needsnew == 1) {
                   16705:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   16706:                                 }
                   16707:                             }
                   16708:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   16709:                                 singleserver.options.length = 0;
                   16710:                                 if ((currVal) && (currVal != removetarget)) {
                   16711:                                     singleserver.options[0] = new Option("","",false,false);
                   16712:                                 } else {
                   16713:                                     singleserver.options[0] = new Option("","",true,true);
                   16714:                                 }
                   16715:                                 var idx = 0;
                   16716:                                 for (var m=0; m<alltargets.length; m++) {
                   16717:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   16718:                                         idx ++;
                   16719:                                         if (currVal == alltargets[m]) {
                   16720:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   16721:                                         } else {
                   16722:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   16723:                                         }
                   16724:                                     }
                   16725:                                 }
                   16726:                             }
                   16727:                         }
                   16728:                     }
                   16729:                 }
1.150     raeburn  16730:             }
                   16731:         }
                   16732:     }
                   16733:     return;
                   16734: }
                   16735: 
1.152     raeburn  16736: // ]]>
                   16737: </script>
                   16738: 
                   16739: END
                   16740: }
                   16741: 
                   16742: sub new_spares_js {
                   16743:     my @sparestypes = ('primary','default');
                   16744:     my $types = join("','",@sparestypes);
                   16745:     my $select = &mt('Select');
                   16746:     return <<"END";
                   16747: 
                   16748: <script type="text/javascript">
                   16749: // <![CDATA[
                   16750: 
                   16751: function updateNewSpares(formname,lonhost) {
                   16752:     var types = new Array('$types');
                   16753:     var include = new Array();
                   16754:     var exclude = new Array();
                   16755:     for (var i=0; i<types.length; i++) {
                   16756:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   16757:         for (var j=0; j<spareboxes.length; j++) {
                   16758:             if (formname.elements[spareboxes[j]].checked) {
                   16759:                 exclude.push(formname.elements[spareboxes[j]].value);
                   16760:             } else {
                   16761:                 include.push(formname.elements[spareboxes[j]].value);
                   16762:             }
                   16763:         }
                   16764:     }
                   16765:     for (var i=0; i<types.length; i++) {
                   16766:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   16767:         var selIdx = newSpare.selectedIndex;
                   16768:         var currnew = newSpare.options[selIdx].value;
                   16769:         var okSpares = new Array();
                   16770:         for (var j=0; j<newSpare.options.length; j++) {
                   16771:             var possible = newSpare.options[j].value;
                   16772:             if (possible != '') {
                   16773:                 if (exclude.indexOf(possible) == -1) {
                   16774:                     okSpares.push(possible);
                   16775:                 } else {
                   16776:                     if (currnew == possible) {
                   16777:                         selIdx = 0;
                   16778:                     }
                   16779:                 }
                   16780:             }
                   16781:         }
                   16782:         for (var k=0; k<include.length; k++) {
                   16783:             if (okSpares.indexOf(include[k]) == -1) {
                   16784:                 okSpares.push(include[k]);
                   16785:             }
                   16786:         }
                   16787:         okSpares.sort();
                   16788:         newSpare.options.length = 0;
                   16789:         if (selIdx == 0) {
                   16790:             newSpare.options[0] = new Option("$select","",true,true);
                   16791:         } else {
                   16792:             newSpare.options[0] = new Option("$select","",false,false);
                   16793:         }
                   16794:         for (var m=0; m<okSpares.length; m++) {
                   16795:             var idx = m+1;
                   16796:             var selThis = 0;
                   16797:             if (selIdx != 0) {
                   16798:                 if (okSpares[m] == currnew) {
                   16799:                     selThis = 1;
                   16800:                 }
                   16801:             }
                   16802:             if (selThis == 1) {
                   16803:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   16804:             } else {
                   16805:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   16806:             }
                   16807:         }
                   16808:     }
                   16809:     return;
                   16810: }
                   16811: 
                   16812: function checkNewSpares(lonhost,type) {
                   16813:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   16814:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   16815:     if (chosen != '') { 
                   16816:         var othertype;
                   16817:         var othernewSpare;
                   16818:         if (type == 'primary') {
                   16819:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   16820:         }
                   16821:         if (type == 'default') {
                   16822:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   16823:         }
                   16824:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   16825:             othernewSpare.selectedIndex = 0;
                   16826:         }
                   16827:     }
                   16828:     return;
                   16829: }
                   16830: 
                   16831: // ]]>
                   16832: </script>
                   16833: 
                   16834: END
                   16835: 
                   16836: }
                   16837: 
                   16838: sub common_domprefs_js {
                   16839:     return <<"END";
                   16840: 
                   16841: <script type="text/javascript">
                   16842: // <![CDATA[
                   16843: 
1.150     raeburn  16844: function getIndicesByName(formname,item) {
1.152     raeburn  16845:     var group = new Array();
1.150     raeburn  16846:     for (var i=0;i<formname.elements.length;i++) {
                   16847:         if (formname.elements[i].name == item) {
1.152     raeburn  16848:             group.push(formname.elements[i].id);
1.150     raeburn  16849:         }
                   16850:     }
1.152     raeburn  16851:     return group;
1.150     raeburn  16852: }
                   16853: 
                   16854: // ]]>
                   16855: </script>
                   16856: 
                   16857: END
1.152     raeburn  16858: 
1.150     raeburn  16859: }
                   16860: 
1.160.6.5  raeburn  16861: sub recaptcha_js {
                   16862:     my %lt = &captcha_phrases();
                   16863:     return <<"END";
                   16864: 
                   16865: <script type="text/javascript">
                   16866: // <![CDATA[
                   16867: 
                   16868: function updateCaptcha(caller,context) {
                   16869:     var privitem;
                   16870:     var pubitem;
                   16871:     var privtext;
                   16872:     var pubtext;
1.160.6.69  raeburn  16873:     var versionitem;
                   16874:     var versiontext;
1.160.6.5  raeburn  16875:     if (document.getElementById(context+'_recaptchapub')) {
                   16876:         pubitem = document.getElementById(context+'_recaptchapub');
                   16877:     } else {
                   16878:         return;
                   16879:     }
                   16880:     if (document.getElementById(context+'_recaptchapriv')) {
                   16881:         privitem = document.getElementById(context+'_recaptchapriv');
                   16882:     } else {
                   16883:         return;
                   16884:     }
                   16885:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   16886:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   16887:     } else {
                   16888:         return;
                   16889:     }
                   16890:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   16891:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   16892:     } else {
                   16893:         return;
                   16894:     }
1.160.6.69  raeburn  16895:     if (document.getElementById(context+'_recaptchaversion')) {
                   16896:         versionitem = document.getElementById(context+'_recaptchaversion');
                   16897:     } else {
                   16898:         return;
                   16899:     }
                   16900:     if (document.getElementById(context+'_recaptchavertxt')) {
                   16901:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   16902:     } else {
                   16903:         return;
                   16904:     }
1.160.6.5  raeburn  16905:     if (caller.checked) {
                   16906:         if (caller.value == 'recaptcha') {
                   16907:             pubitem.type = 'text';
                   16908:             privitem.type = 'text';
                   16909:             pubitem.size = '40';
                   16910:             privitem.size = '40';
                   16911:             pubtext.innerHTML = "$lt{'pub'}";
                   16912:             privtext.innerHTML = "$lt{'priv'}";
1.160.6.69  raeburn  16913:             versionitem.type = 'text';
                   16914:             versionitem.size = '3';
                   16915:             versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5  raeburn  16916:         } else {
                   16917:             pubitem.type = 'hidden';
                   16918:             privitem.type = 'hidden';
1.160.6.69  raeburn  16919:             versionitem.type = 'hidden';
1.160.6.5  raeburn  16920:             pubtext.innerHTML = '';
                   16921:             privtext.innerHTML = '';
1.160.6.69  raeburn  16922:             versiontext.innerHTML = '';
1.160.6.5  raeburn  16923:         }
                   16924:     }
                   16925:     return;
                   16926: }
                   16927: 
                   16928: // ]]>
                   16929: </script>
                   16930: 
                   16931: END
                   16932: 
                   16933: }
                   16934: 
1.160.6.40  raeburn  16935: sub toggle_display_js {
1.160.6.16  raeburn  16936:     return <<"END";
                   16937: 
                   16938: <script type="text/javascript">
                   16939: // <![CDATA[
                   16940: 
1.160.6.40  raeburn  16941: function toggleDisplay(domForm,caller) {
                   16942:     if (document.getElementById(caller)) {
                   16943:         var divitem = document.getElementById(caller);
                   16944:         var optionsElement = domForm.coursecredits;
1.160.6.64  raeburn  16945:         var checkval = 1;
                   16946:         var dispval = 'block';
1.160.6.93  raeburn  16947:         var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40  raeburn  16948:         if (caller == 'emailoptions') {
                   16949:             optionsElement = domForm.cancreate_email; 
                   16950:         }
1.160.6.57  raeburn  16951:         if (caller == 'studentsubmission') {
                   16952:             optionsElement = domForm.postsubmit;
                   16953:         }
1.160.6.64  raeburn  16954:         if (caller == 'cloneinstcode') {
                   16955:             optionsElement = domForm.canclone;
                   16956:             checkval = 'instcode';
                   16957:         }
1.160.6.93  raeburn  16958:         if (selfcreateRegExp.test(caller)) {
                   16959:             optionsElement = domForm.elements[caller];
                   16960:             checkval = 'other';
                   16961:             dispval = 'inline'
                   16962:         }
1.160.6.40  raeburn  16963:         if (optionsElement.length) {
1.160.6.16  raeburn  16964:             var currval;
1.160.6.40  raeburn  16965:             for (var i=0; i<optionsElement.length; i++) {
                   16966:                 if (optionsElement[i].checked) {
                   16967:                    currval = optionsElement[i].value;
1.160.6.16  raeburn  16968:                 }
                   16969:             }
1.160.6.64  raeburn  16970:             if (currval == checkval) {
                   16971:                 divitem.style.display = dispval;
1.160.6.16  raeburn  16972:             } else {
1.160.6.40  raeburn  16973:                 divitem.style.display = 'none';
1.160.6.16  raeburn  16974:             }
                   16975:         }
                   16976:     }
                   16977:     return;
                   16978: }
                   16979: 
                   16980: // ]]>
                   16981: </script>
                   16982: 
                   16983: END
                   16984: 
                   16985: }
                   16986: 
1.160.6.5  raeburn  16987: sub captcha_phrases {
                   16988:     return &Apache::lonlocal::texthash (
                   16989:                  priv => 'Private key',
                   16990:                  pub  => 'Public key',
                   16991:                  original  => 'original (CAPTCHA)',
                   16992:                  recaptcha => 'successor (ReCAPTCHA)',
                   16993:                  notused   => 'unused',
1.160.6.69  raeburn  16994:                  ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5  raeburn  16995:     );
                   16996: }
                   16997: 
1.160.6.24  raeburn  16998: sub devalidate_remote_domconfs {
1.160.6.27  raeburn  16999:     my ($dom,$cachekeys) = @_;
                   17000:     return unless (ref($cachekeys) eq 'HASH');
1.160.6.24  raeburn  17001:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   17002:     my %thismachine;
                   17003:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.98  raeburn  17004:     my @posscached = ('domainconfig','domdefaults','usersessions',
1.160.6.102.2  1(raebur 17005:0):                       'ltitools','directorysrch','passwdconf','cats');
1.160.6.61  raeburn  17006:     if (keys(%servers)) {
1.160.6.24  raeburn  17007:         foreach my $server (keys(%servers)) {
                   17008:             next if ($thismachine{$server});
1.160.6.27  raeburn  17009:             my @cached;
                   17010:             foreach my $name (@posscached) {
                   17011:                 if ($cachekeys->{$name}) {
                   17012:                     push(@cached,&escape($name).':'.&escape($dom));
                   17013:                 }
                   17014:             }
                   17015:             if (@cached) {
                   17016:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   17017:             }
1.160.6.24  raeburn  17018:         }
                   17019:     }
                   17020:     return;
                   17021: }
                   17022: 
1.3       raeburn  17023: 1;

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