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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.160.6.118.2  9(raebur    4:2): # $Id: domainprefs.pm,v 1.160.6.118.2.8 2022/02/27 02:54:35 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.160.6.113  raeburn   177: use Net::CIDR;
1.1       raeburn   178: 
1.155     raeburn   179: my $registered_cleanup;
                    180: my $modified_urls;
                    181: 
1.1       raeburn   182: sub handler {
                    183:     my $r=shift;
                    184:     if ($r->header_only) {
                    185:         &Apache::loncommon::content_type($r,'text/html');
                    186:         $r->send_http_header;
                    187:         return OK;
                    188:     }
                    189: 
1.91      raeburn   190:     my $context = 'domain';
1.1       raeburn   191:     my $dom = $env{'request.role.domain'};
1.5       albertel  192:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   193:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    194:         &Apache::loncommon::content_type($r,'text/html');
                    195:         $r->send_http_header;
                    196:     } else {
                    197:         $env{'user.error.msg'}=
                    198:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    199:         return HTTP_NOT_ACCEPTABLE;
                    200:     }
1.155     raeburn   201: 
                    202:     $registered_cleanup=0;
                    203:     @{$modified_urls}=();
                    204: 
1.1       raeburn   205:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    206:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   207:                                             ['phase','actions']);
1.30      raeburn   208:     my $phase = 'pickactions';
1.3       raeburn   209:     if ( exists($env{'form.phase'}) ) {
                    210:         $phase = $env{'form.phase'};
                    211:     }
1.150     raeburn   212:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   213:     my %domconfig =
1.6       raeburn   214:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   215:                 'quotas','autoenroll','autoupdate','autocreate',
                    216:                 'directorysrch','usercreation','usermodification',
                    217:                 'contacts','defaults','scantron','coursecategories',
1.160.6.73  raeburn   218:                 'serverstatuses','requestcourses','helpsettings',
                    219:                 'coursedefaults','usersessions','loadbalancing',
1.160.6.113  raeburn   220:                 'requestauthor','selfenrollment','inststatus',
1.160.6.118.2  5(raebur  221:2):                 'passwords','ltitools','ltisec','wafproxy','ipaccess'],$dom);
          6(raebur  222:2):     my %encconfig =
                    223:2):         &Apache::lonnet::get_dom('encconfig',['ltitools','linkprot'],$dom,undef,1);
          1(raebur  224:1):     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    225:1):         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    226:1):             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
                    227:1):                 if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
                    228:1):                     foreach my $item ('key','secret') {
                    229:1):                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    230:1):                     }
                    231:1):                 }
                    232:1):             }
                    233:1):         }
                    234:1):     }
          5(raebur  235:2):     if (ref($domconfig{'ltisec'}) eq 'HASH') {
                    236:2):         if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
                    237:2):             if (ref($encconfig{'linkprot'}) eq 'HASH') {
                    238:2):                 foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
                    239:2):                     unless ($id =~ /^\d+$/) {
                    240:2):                         delete($domconfig{'ltisec'}{'linkprot'}{$id});
                    241:2):                     }
                    242:2):                     if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
                    243:2):                         (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
                    244:2):                         foreach my $item ('key','secret') {
                    245:2):                             $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
                    246:2):                         }
                    247:2):                     }
                    248:2):                 }
                    249:2):             }
                    250:2):         }
                    251:2):     }
1.160.6.113  raeburn   252:     my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
                    253:                        'quotas','autoenroll','autoupdate','autocreate','directorysrch',
                    254:                        'contacts','usercreation','selfcreation','usermodification',
                    255:                        'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73  raeburn   256:                        'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2  5(raebur  257:2):                        'ltitools','selfenrollment','usersessions','lti');
1.160.6.7  raeburn   258:     my %existing;
                    259:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    260:         %existing = %{$domconfig{'loadbalancing'}};
                    261:     }
                    262:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   263:         push(@prefs_order,'loadbalancing');
                    264:     }
1.30      raeburn   265:     my %prefs = (
                    266:         'rolecolors' =>
                    267:                    { text => 'Default color schemes',
1.67      raeburn   268:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   269:                      header => [{col1 => 'Student Settings',
                    270:                                  col2 => '',},
                    271:                                 {col1 => 'Coordinator Settings',
                    272:                                  col2 => '',},
                    273:                                 {col1 => 'Author Settings',
                    274:                                  col2 => '',},
                    275:                                 {col1 => 'Administrator Settings',
                    276:                                  col2 => '',}],
1.160.6.37  raeburn   277:                       print => \&print_rolecolors,
                    278:                       modify => \&modify_rolecolors,
1.30      raeburn   279:                     },
1.110     raeburn   280:         'login' =>
1.30      raeburn   281:                     { text => 'Log-in page options',
1.67      raeburn   282:                       help => 'Domain_Configuration_Login_Page',
1.160.6.5  raeburn   283:                       header => [{col1 => 'Log-in Page Items',
                    284:                                   col2 => '',},
                    285:                                  {col1 => 'Log-in Help',
1.160.6.56  raeburn   286:                                   col2 => 'Value'},
                    287:                                  {col1 => 'Custom HTML in document head',
1.160.6.113  raeburn   288:                                   col2 => 'Value'},
                    289:                                  {col1 => 'SSO',
                    290:                                   col2 => 'Dual login: SSO and non-SSO options'},
                    291:                                 ],
1.160.6.37  raeburn   292:                       print => \&print_login,
                    293:                       modify => \&modify_login,
1.30      raeburn   294:                     },
1.43      raeburn   295:         'defaults' => 
1.160.6.40  raeburn   296:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   297:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   298:                       header => [{col1 => 'Setting',
1.160.6.40  raeburn   299:                                   col2 => 'Value'},
                    300:                                  {col1 => 'Institutional user types',
1.160.6.118.2  8(raebur  301:2):                                   col2 => 'Name displayed'},
                    302:2):                                  {col1 => 'Mapping for missing usernames via standard log-in',
                    303:2):                                   col2 => 'Rules in use'}],
1.160.6.37  raeburn   304:                       print => \&print_defaults,
                    305:                       modify => \&modify_defaults,
1.43      raeburn   306:                     },
1.160.6.113  raeburn   307:         'wafproxy' =>
                    308:                     { text => 'Web Application Firewall/Reverse Proxy',
                    309:                       help => 'Domain_Configuration_WAF_Proxy',
                    310:                       header => [{col1 => 'Domain(s)',
                    311:                                   col2 => 'Servers and WAF/Reverse Proxy alias(es)',
                    312:                                  },
                    313:                                  {col1 => 'Domain(s)',
                    314:                                   col2 => 'WAF Configuration',}],
                    315:                       print => \&print_wafproxy,
                    316:                       modify => \&modify_wafproxy,
                    317:                     },
1.160.6.98  raeburn   318:         'passwords' =>
                    319:                     { text => 'Passwords (Internal authentication)',
                    320:                       help => 'Domain_Configuration_Passwords',
                    321:                       header => [{col1 => 'Resetting Forgotten Password',
                    322:                                   col2 => 'Settings'},
                    323:                                  {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                    324:                                   col2 => 'Settings'},
                    325:                                  {col1 => 'Rules for LON-CAPA Passwords',
                    326:                                   col2 => 'Settings'},
                    327:                                  {col1 => 'Course Owner Changing Student Passwords',
                    328:                                   col2 => 'Settings'}],
                    329:                       print => \&print_passwords,
                    330:                       modify => \&modify_passwords,
                    331:                     },
1.30      raeburn   332:         'quotas' => 
1.160.6.20  raeburn   333:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   334:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   335:                       header => [{col1 => 'User affiliation',
1.72      raeburn   336:                                   col2 => 'Available tools',
1.160.6.28  raeburn   337:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37  raeburn   338:                       print => \&print_quotas,
                    339:                       modify => \&modify_quotas,
1.30      raeburn   340:                     },
                    341:         'autoenroll' =>
                    342:                    { text => 'Auto-enrollment settings',
1.67      raeburn   343:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   344:                      header => [{col1 => 'Configuration setting',
                    345:                                  col2 => 'Value(s)'}],
1.160.6.37  raeburn   346:                      print => \&print_autoenroll,
                    347:                      modify => \&modify_autoenroll,
1.30      raeburn   348:                    },
                    349:         'autoupdate' => 
                    350:                    { text => 'Auto-update settings',
1.67      raeburn   351:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   352:                      header => [{col1 => 'Setting',
                    353:                                  col2 => 'Value',},
1.131     raeburn   354:                                 {col1 => 'Setting',
                    355:                                  col2 => 'Affiliation'},
1.43      raeburn   356:                                 {col1 => 'User population',
1.160.6.35  raeburn   357:                                  col2 => 'Updatable user data'}],
1.160.6.37  raeburn   358:                      print => \&print_autoupdate,
                    359:                      modify => \&modify_autoupdate,
1.30      raeburn   360:                   },
1.125     raeburn   361:         'autocreate' => 
                    362:                   { text => 'Auto-course creation settings',
                    363:                      help => 'Domain_Configuration_Auto_Creation',
                    364:                      header => [{col1 => 'Configuration Setting',
                    365:                                  col2 => 'Value',}],
1.160.6.37  raeburn   366:                      print => \&print_autocreate,
                    367:                      modify => \&modify_autocreate,
1.125     raeburn   368:                   },
1.30      raeburn   369:         'directorysrch' => 
1.160.6.72  raeburn   370:                   { text => 'Directory searches',
1.67      raeburn   371:                     help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72  raeburn   372:                     header => [{col1 => 'Institutional Directory Setting',
                    373:                                 col2 => 'Value',},
                    374:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   375:                                 col2 => 'Value',}],
1.160.6.37  raeburn   376:                     print => \&print_directorysrch,
                    377:                     modify => \&modify_directorysrch,
1.30      raeburn   378:                   },
                    379:         'contacts' =>
1.160.6.78  raeburn   380:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   381:                     help => 'Domain_Configuration_Contact_Info',
1.160.6.78  raeburn   382:                     header => [{col1 => 'Default e-mail addresses',
                    383:                                 col2 => 'Value',},
                    384:                                {col1 => 'Recipient(s) for notifications',
                    385:                                 col2 => 'Value',},
1.160.6.107  raeburn   386:                                {col1 => 'Nightly status check e-mail',
                    387:                                 col2 => 'Settings',},
1.160.6.78  raeburn   388:                                {col1 => 'Ask helpdesk form settings',
                    389:                                 col2 => 'Value',},],
1.160.6.37  raeburn   390:                     print => \&print_contacts,
                    391:                     modify => \&modify_contacts,
1.30      raeburn   392:                   },
                    393:         'usercreation' => 
                    394:                   { text => 'User creation',
1.67      raeburn   395:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   396:                     header => [{col1 => 'Format rule type',
                    397:                                 col2 => 'Format rules in force'},
1.34      raeburn   398:                                {col1 => 'User account creation',
                    399:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   400:                                {col1 => 'Context',
1.43      raeburn   401:                                 col2 => 'Assignable authentication types'}],
1.160.6.37  raeburn   402:                     print => \&print_usercreation,
                    403:                     modify => \&modify_usercreation,
1.30      raeburn   404:                   },
1.160.6.34  raeburn   405:         'selfcreation' => 
                    406:                   { text => 'Users self-creating accounts',
                    407:                     help => 'Domain_Configuration_Self_Creation', 
                    408:                     header => [{col1 => 'Self-creation with institutional username',
                    409:                                 col2 => 'Enabled?'},
                    410:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    411:                                 col2 => 'Information user can enter'},
1.160.6.93  raeburn   412:                                {col1 => 'Self-creation with e-mail verification',
1.160.6.34  raeburn   413:                                 col2 => 'Settings'}],
1.160.6.37  raeburn   414:                     print => \&print_selfcreation,
                    415:                     modify => \&modify_selfcreation,
1.160.6.34  raeburn   416:                   },
1.69      raeburn   417:         'usermodification' =>
1.33      raeburn   418:                   { text => 'User modification',
1.67      raeburn   419:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   420:                     header => [{col1 => 'Target user has role',
1.160.6.35  raeburn   421:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   422:                                {col1 => 'Target user has role',
1.160.6.35  raeburn   423:                                 col2 => 'User information updatable in course context'}],
1.160.6.37  raeburn   424:                     print => \&print_usermodification,
                    425:                     modify => \&modify_usermodification,
1.33      raeburn   426:                   },
1.69      raeburn   427:         'scantron' =>
1.160.6.97  raeburn   428:                   { text => 'Bubblesheet format',
1.67      raeburn   429:                     help => 'Domain_Configuration_Scantron_Format',
1.160.6.97  raeburn   430:                     header => [ {col1 => 'Bubblesheet format file',
                    431:                                  col2 => ''},
                    432:                                 {col1 => 'Bubblesheet data upload formats',
                    433:                                  col2 => 'Settings'}],
1.160.6.37  raeburn   434:                     print => \&print_scantron,
                    435:                     modify => \&modify_scantron,
1.46      raeburn   436:                   },
1.86      raeburn   437:         'requestcourses' => 
                    438:                  {text => 'Request creation of courses',
                    439:                   help => 'Domain_Configuration_Request_Courses',
                    440:                   header => [{col1 => 'User affiliation',
1.102     raeburn   441:                               col2 => 'Availability/Processing of requests',},
                    442:                              {col1 => 'Setting',
1.160.6.30  raeburn   443:                               col2 => 'Value'},
                    444:                              {col1 => 'Available textbooks',
1.160.6.39  raeburn   445:                               col2 => ''},
1.160.6.46  raeburn   446:                              {col1 => 'Available templates',
                    447:                               col2 => ''},
1.160.6.39  raeburn   448:                              {col1 => 'Validation (not official courses)',
                    449:                               col2 => 'Value'},],
1.160.6.37  raeburn   450:                   print => \&print_quotas,
                    451:                   modify => \&modify_quotas,
1.86      raeburn   452:                  },
1.160.6.5  raeburn   453:         'requestauthor' =>
1.160.6.34  raeburn   454:                  {text => 'Request Authoring Space',
1.160.6.5  raeburn   455:                   help => 'Domain_Configuration_Request_Author',
                    456:                   header => [{col1 => 'User affiliation',
                    457:                               col2 => 'Availability/Processing of requests',},
                    458:                              {col1 => 'Setting',
                    459:                               col2 => 'Value'}],
1.160.6.37  raeburn   460:                   print => \&print_quotas,
                    461:                   modify => \&modify_quotas,
1.160.6.5  raeburn   462:                  },
1.69      raeburn   463:         'coursecategories' =>
1.120     raeburn   464:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   465:                     help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42  raeburn   466:                     header => [{col1 => 'Catalog type/availability',
                    467:                                 col2 => '',},
                    468:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   469:                                 col2 => '',},
                    470:                                {col1 => 'Categories',
                    471:                                 col2 => '',
                    472:                                }],
1.160.6.37  raeburn   473:                     print => \&print_coursecategories,
                    474:                     modify => \&modify_coursecategories,
1.69      raeburn   475:                   },
                    476:         'serverstatuses' =>
1.77      raeburn   477:                  {text   => 'Access to server status pages',
1.69      raeburn   478:                   help   => 'Domain_Configuration_Server_Status',
                    479:                   header => [{col1 => 'Status Page',
                    480:                               col2 => 'Other named users',
                    481:                               col3 => 'Specific IPs',
                    482:                             }],
1.160.6.37  raeburn   483:                   print => \&print_serverstatuses,
                    484:                   modify => \&modify_serverstatuses,
1.69      raeburn   485:                  },
1.160.6.73  raeburn   486:         'helpsettings' =>
                    487:                  {text   => 'Support settings',
                    488:                   help   => 'Domain_Configuration_Help_Settings',
                    489:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    490:                               col2 => 'Value'},
                    491:                              {col1 => 'Helpdesk Roles',
                    492:                               col2 => 'Settings'},],
                    493:                   print  => \&print_helpsettings,
                    494:                   modify => \&modify_helpsettings,
                    495:                  },
1.160.6.39  raeburn   496:         'coursedefaults' => 
1.160.6.16  raeburn   497:                  {text => 'Course/Community defaults',
                    498:                   help => 'Domain_Configuration_Course_Defaults',
1.160.6.57  raeburn   499:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    500:                               col2 => 'Value',},
                    501:                              {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16  raeburn   502:                               col2 => 'Value',},],
1.160.6.37  raeburn   503:                   print => \&print_coursedefaults,
                    504:                   modify => \&modify_coursedefaults,
                    505:                  },
1.160.6.39  raeburn   506:         'selfenrollment' => 
1.160.6.37  raeburn   507:                  {text   => 'Self-enrollment in Course/Community',
                    508:                   help   => 'Domain_Configuration_Selfenrollment',
                    509:                   header => [{col1 => 'Configuration Rights',
                    510:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    511:                              {col1 => 'Defaults',
                    512:                               col2 => 'Value'},
                    513:                              {col1 => 'Self-enrollment validation (optional)',
                    514:                               col2 => 'Value'},],
                    515:                   print => \&print_selfenrollment,
                    516:                   modify => \&modify_selfenrollment,
1.160.6.16  raeburn   517:                  },
1.141     raeburn   518:         'usersessions' =>
1.145     raeburn   519:                  {text  => 'User session hosting/offloading',
1.137     raeburn   520:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   521:                   header => [{col1 => 'Domain server',
                    522:                               col2 => 'Servers to offload sessions to when busy'},
                    523:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   524:                               col2 => 'Rules'},
                    525:                              {col1 => "Hosting domain's own users elsewhere",
                    526:                               col2 => 'Rules'}],
1.160.6.37  raeburn   527:                   print => \&print_usersessions,
                    528:                   modify => \&modify_usersessions,
1.137     raeburn   529:                  },
1.160.6.78  raeburn   530:         'loadbalancing' =>
1.160.6.7  raeburn   531:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   532:                   help  => 'Domain_Configuration_Load_Balancing',
1.160.6.7  raeburn   533:                   header => [{col1 => 'Balancers',
1.150     raeburn   534:                               col2 => 'Default destinations',
1.160.6.13  raeburn   535:                               col3 => 'User affiliation',
1.150     raeburn   536:                               col4 => 'Overrides'},
                    537:                             ],
1.160.6.37  raeburn   538:                   print => \&print_loadbalancing,
                    539:                   modify => \&modify_loadbalancing,
1.150     raeburn   540:                  },
1.160.6.118.2  1(raebur  541:1):         'ltitools' =>
                    542:1):                  {text => 'External Tools (LTI)',
                    543:1):                   help => 'Domain_Configuration_LTI_Tools',
                    544:1):                   header => [{col1 => 'Setting',
                    545:1):                               col2 => 'Value',}],
                    546:1):                   print => \&print_ltitools,
                    547:1):                   modify => \&modify_ltitools,
                    548:1):                  },
          5(raebur  549:2):           'lti' =>
                    550:2):                  {text => 'LTI Link Protection and LTI Consumers',
                    551:2):                   help => 'Domain_Configuration_LTI_Provider',
                    552:2):                   header => [{col1 => 'Encryption of shared secrets',
                    553:2):                               col2 => 'Settings'},
                    554:2):                              {col1 => 'Rules for shared secrets',
                    555:2):                               col2 => 'Settings'},
                    556:2):                              {col1 => 'Link Protectors',
                    557:2):                               col2 => 'Settings'},],
                    558:2):                   print => \&print_lti,
                    559:2):                   modify => \&modify_lti,
                    560:2):                  },
1.160.6.113  raeburn   561:          'ipaccess' =>
                    562:                        {text => 'IP-based access control',
                    563:                         help => 'Domain_Configuration_IP_Access',
                    564:                         header => [{col1 => 'Setting',
                    565:                                     col2 => 'Value'},],
                    566:                         print  => \&print_ipaccess,
                    567:                         modify => \&modify_ipaccess,
                    568:                        },
1.3       raeburn   569:     );
1.110     raeburn   570:     if (keys(%servers) > 1) {
                    571:         $prefs{'login'}  = { text   => 'Log-in page options',
                    572:                              help   => 'Domain_Configuration_Login_Page',
                    573:                             header => [{col1 => 'Log-in Service',
                    574:                                         col2 => 'Server Setting',},
                    575:                                        {col1 => 'Log-in Page Items',
1.160.6.118.2  5(raebur  576:2):                                         col2 => 'Settings'},
1.160.6.5  raeburn   577:                                        {col1 => 'Log-in Help',
1.160.6.56  raeburn   578:                                         col2 => 'Value'},
                    579:                                        {col1 => 'Custom HTML in document head',
1.160.6.113  raeburn   580:                                         col2 => 'Value'},
                    581:                                        {col1 => 'SSO',
                    582:                                         col2 => 'Dual login: SSO and non-SSO options'},
                    583:                                       ],
1.160.6.37  raeburn   584:                             print => \&print_login,
                    585:                             modify => \&modify_login,
1.110     raeburn   586:                            };
                    587:     }
1.160.6.13  raeburn   588: 
1.6       raeburn   589:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   590:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   591:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   592:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   593:       text=>"Settings to display/modify"});
1.9       raeburn   594:     my $confname = $dom.'-domainconfig';
1.160.6.13  raeburn   595: 
1.3       raeburn   596:     if ($phase eq 'process') {
1.160.6.27  raeburn   597:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    598:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33  raeburn   599:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24  raeburn   600:             $r->rflush();
1.160.6.27  raeburn   601:             &devalidate_remote_domconfs($dom,$result);
1.160.6.24  raeburn   602:         }
1.30      raeburn   603:     } elsif ($phase eq 'display') {
1.160.6.16  raeburn   604:         my $js = &recaptcha_js().
1.160.6.40  raeburn   605:                  &toggle_display_js();
1.160.6.7  raeburn   606:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   607:             my ($othertitle,$usertypes,$types) =
                    608:                 &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7  raeburn   609:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    610:                                           $domconfig{'loadbalancing'}).
1.160.6.6  raeburn   611:                    &new_spares_js().
                    612:                    &common_domprefs_js().
                    613:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   614:         }
1.160.6.30  raeburn   615:         if (grep(/^requestcourses$/,@actions)) {
                    616:             my $javascript_validations;
                    617:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    618:             $js .= <<END;
                    619: <script type="text/javascript">
                    620: $javascript_validations
                    621: </script>
                    622: $coursebrowserjs
                    623: END
1.160.6.113  raeburn   624:         } elsif (grep(/^ipaccess$/,@actions)) {
                    625:             $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30  raeburn   626:         }
1.160.6.93  raeburn   627:         if (grep(/^selfcreation$/,@actions)) {
                    628:             $js .= &selfcreate_javascript();
                    629:         }
1.160.6.78  raeburn   630:         if (grep(/^contacts$/,@actions)) {
                    631:             $js .= &contacts_javascript();
                    632:         }
1.160.6.97  raeburn   633:         if (grep(/^scantron$/,@actions)) {
                    634:             $js .= &scantron_javascript();
                    635:         }
1.150     raeburn   636:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   637:     } else {
1.160.6.11  raeburn   638: # check if domconfig user exists for the domain.
                    639:         my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26  raeburn   640:         my ($configuserok,$author_ok,$switchserver) =
1.160.6.11  raeburn   641:             &config_check($dom,$confname,$servadm);
                    642:         unless ($configuserok eq 'ok') {
                    643:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    644:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    645:                           $confname).
                    646:                       '<br />'
                    647:             );
                    648:             if ($switchserver) {
                    649:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    650:                           '<br />'.
                    651:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    652:                           '<br />'.
                    653:                           &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).
                    654:                           '<br />'.
                    655:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    656:                 );
                    657:             } else {
                    658:                 $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.').
                    659:                           '<br />'.
                    660:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    661:                 );
                    662:             }
                    663:             $r->print(&Apache::loncommon::end_page());
                    664:             return OK;
                    665:         }
1.21      raeburn   666:         if (keys(%domconfig) == 0) {
                    667:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   668:             my @ids=&Apache::lonnet::current_machine_ids();
                    669:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   670:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   671:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   672:                 my $custom_img_count = 0;
                    673:                 foreach my $img (@loginimages) {
                    674:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    675:                         $custom_img_count ++;
                    676:                     }
                    677:                 }
                    678:                 foreach my $role (@roles) {
                    679:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    680:                         $custom_img_count ++;
                    681:                     }
                    682:                 }
                    683:                 if ($custom_img_count > 0) {
1.94      raeburn   684:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   685:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   686:                     $r->print(
                    687:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    688:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    689:     &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 />'.
                    690:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    691:                     if ($switch_server) {
1.30      raeburn   692:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   693:                     }
1.91      raeburn   694:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   695:                     return OK;
                    696:                 }
                    697:             }
                    698:         }
1.91      raeburn   699:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   700:     }
                    701:     return OK;
                    702: }
                    703: 
                    704: sub process_changes {
1.160.6.24  raeburn   705:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   706:     my %domconfig;
                    707:     if (ref($values) eq 'HASH') {
                    708:         %domconfig = %{$values};
                    709:     }
1.3       raeburn   710:     my $output;
                    711:     if ($action eq 'login') {
1.160.6.24  raeburn   712:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   713:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   714:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24  raeburn   715:                                      $lastactref,%domconfig);
1.3       raeburn   716:     } elsif ($action eq 'quotas') {
1.160.6.30  raeburn   717:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   718:     } elsif ($action eq 'autoenroll') {
1.160.6.24  raeburn   719:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   720:     } elsif ($action eq 'autoupdate') {
                    721:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   722:     } elsif ($action eq 'autocreate') {
                    723:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   724:     } elsif ($action eq 'directorysrch') {
1.160.6.81  raeburn   725:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   726:     } elsif ($action eq 'usercreation') {
1.28      raeburn   727:         $output = &modify_usercreation($dom,%domconfig);
1.160.6.34  raeburn   728:     } elsif ($action eq 'selfcreation') {
1.160.6.93  raeburn   729:         $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33      raeburn   730:     } elsif ($action eq 'usermodification') {
                    731:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   732:     } elsif ($action eq 'contacts') {
1.160.6.24  raeburn   733:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   734:     } elsif ($action eq 'defaults') {
1.160.6.27  raeburn   735:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   736:     } elsif ($action eq 'scantron') {
1.160.6.24  raeburn   737:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   738:     } elsif ($action eq 'coursecategories') {
1.160.6.43  raeburn   739:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   740:     } elsif ($action eq 'serverstatuses') {
                    741:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   742:     } elsif ($action eq 'requestcourses') {
1.160.6.30  raeburn   743:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5  raeburn   744:     } elsif ($action eq 'requestauthor') {
1.160.6.30  raeburn   745:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73  raeburn   746:     } elsif ($action eq 'helpsettings') {
1.160.6.77  raeburn   747:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16  raeburn   748:     } elsif ($action eq 'coursedefaults') {
1.160.6.27  raeburn   749:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37  raeburn   750:     } elsif ($action eq 'selfenrollment') {
                    751:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   752:     } elsif ($action eq 'usersessions') {
1.160.6.27  raeburn   753:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   754:     } elsif ($action eq 'loadbalancing') {
                    755:         $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2  5(raebur  756:2):     } elsif ($action eq 'lti') {
                    757:2):         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98  raeburn   758:     } elsif ($action eq 'passwords') {
                    759:         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.118.2  1(raebur  760:1):     } elsif ($action eq 'ltitools') {
                    761:1):         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.160.6.113  raeburn   762:     } elsif ($action eq 'wafproxy') {
                    763:         $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
                    764:     } elsif ($action eq 'ipaccess') {
                    765:         $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3       raeburn   766:     }
                    767:     return $output;
                    768: }
                    769: 
                    770: sub print_config_box {
1.9       raeburn   771:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   772:     my $rowtotal = 0;
1.49      raeburn   773:     my $output;
                    774:     if ($action eq 'coursecategories') {
                    775:         $output = &coursecategories_javascript($settings);
1.160.6.40  raeburn   776:     } elsif ($action eq 'defaults') {
                    777:         $output = &defaults_javascript($settings); 
1.160.6.98  raeburn   778:     } elsif ($action eq 'passwords') {
1.160.6.118.2  5(raebur  779:2):         $output = &passwords_javascript($action);
1.160.6.73  raeburn   780:     } elsif ($action eq 'helpsettings') {
                    781:         my (%privs,%levelscurrent);
                    782:         my %full=();
                    783:         my %levels=(
                    784:                      course => {},
                    785:                      domain => {},
                    786:                      system => {},
                    787:                    );
                    788:         my $context = 'domain';
                    789:         my $crstype = 'Course';
                    790:         my $formname = 'display';
                    791:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    792:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    793:         $output =
                    794:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
                    795:                                                       \@templateroles);
1.160.6.118.2  1(raebur  796:1):     } elsif ($action eq 'ltitools') {
                    797:1):         $output .= &ltitools_javascript($settings);
          5(raebur  798:2):     } elsif ($action eq 'lti') {
                    799:2):         $output .= &passwords_javascript('secrets')."\n".
                    800:2):                    &lti_javascript($dom,$settings);
1.160.6.113  raeburn   801:     } elsif ($action eq 'wafproxy') {
                    802:         $output .= &wafproxy_javascript($dom);
                    803:     } elsif ($action eq 'autoupdate') {
                    804:         $output .= &autoupdate_javascript();
1.160.6.116  raeburn   805:     } elsif ($action eq 'autoenroll') {
                    806:         $output .= &autoenroll_javascript();
1.160.6.113  raeburn   807:     } elsif ($action eq 'login') {
                    808:         $output .= &saml_javascript();
                    809:     } elsif ($action eq 'ipaccess') {
                    810:         $output .= &ipaccess_javascript($settings);
1.91      raeburn   811:     }
1.160.6.40  raeburn   812:     $output .=
1.30      raeburn   813:          '<table class="LC_nested_outer">
1.3       raeburn   814:           <tr>
1.160.6.113  raeburn   815:            <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66      raeburn   816:            &mt($item->{text}).'&nbsp;'.
                    817:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    818:           '</tr>';
1.30      raeburn   819:     $rowtotal ++;
1.110     raeburn   820:     my $numheaders = 1;
                    821:     if (ref($item->{'header'}) eq 'ARRAY') {
                    822:         $numheaders = scalar(@{$item->{'header'}});
                    823:     }
                    824:     if ($numheaders > 1) {
1.64      raeburn   825:         my $colspan = '';
1.145     raeburn   826:         my $rightcolspan = '';
1.160.6.104  raeburn   827:         my $leftnobr = '';  
1.160.6.42  raeburn   828:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72  raeburn   829:             ($action eq 'directorysrch') ||
1.160.6.113  raeburn   830:             (($action eq 'login') && ($numheaders < 5))) {
1.64      raeburn   831:             $colspan = ' colspan="2"';
                    832:         }
1.145     raeburn   833:         if ($action eq 'usersessions') {
                    834:             $rightcolspan = ' colspan="3"'; 
                    835:         }
1.160.6.104  raeburn   836:         if ($action eq 'passwords') {
                    837:             $leftnobr = ' LC_nobreak';
                    838:         }
1.30      raeburn   839:         $output .= '
1.3       raeburn   840:           <tr>
                    841:            <td>
                    842:             <table class="LC_nested">
                    843:              <tr class="LC_info_row">
1.160.6.104  raeburn   844:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   845:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   846:              </tr>';
1.69      raeburn   847:         $rowtotal ++;
1.160.6.37  raeburn   848:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57  raeburn   849:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   850:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2  5(raebur  851:2):             ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.160.6.37  raeburn   852:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98  raeburn   853:         } elsif ($action eq 'passwords') {
                    854:             $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57      raeburn   855:         } elsif ($action eq 'coursecategories') {
1.160.6.37  raeburn   856:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97  raeburn   857:         } elsif ($action eq 'scantron') {
                    858:             $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   859:         } elsif ($action eq 'login') {
1.160.6.113  raeburn   860:             if ($numheaders == 5) {
1.160.6.5  raeburn   861:                 $colspan = ' colspan="2"';
                    862:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    863:             } else {
                    864:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    865:             }
1.160.6.37  raeburn   866:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn   867:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       868:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   869:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2  raeburn   870:         }
1.30      raeburn   871:         $output .= '
1.6       raeburn   872:            </table>
                    873:           </td>
                    874:          </tr>
                    875:          <tr>
                    876:            <td>
                    877:             <table class="LC_nested">
                    878:              <tr class="LC_info_row">
1.160.6.37  raeburn   879:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    880:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   881:              </tr>';
                    882:             $rowtotal ++;
1.160.6.37  raeburn   883:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    884:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78  raeburn   885:             ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2  8(raebur  886:2):             ($action eq 'contacts') || ($action eq 'passwords') || 
                    887:2):             ($action eq 'defaults') || ($action eq 'lti')) {
1.160.6.42  raeburn   888:             if ($action eq 'coursecategories') {
                    889:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    890:                 $colspan = ' colspan="2"';
1.160.6.98  raeburn   891:             } elsif ($action eq 'passwords') {
                    892:                 $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42  raeburn   893:             } else {
                    894:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    895:             }
                    896:             $output .= '
1.63      raeburn   897:            </table>
                    898:           </td>
                    899:          </tr>
                    900:          <tr>
                    901:            <td>
                    902:             <table class="LC_nested">
                    903:              <tr class="LC_info_row">
1.160.6.113  raeburn   904:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34  raeburn   905:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42  raeburn   906:              </tr>'."\n";
                    907:             if ($action eq 'coursecategories') {
                    908:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108  raeburn   909:             } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107  raeburn   910:                 if ($action eq 'passwords') {
                    911:                     $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                    912:                 } else {
                    913:                     $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                    914:                 }
                    915:                 $output .= '
1.160.6.98  raeburn   916:              </tr>
                    917:             </table>
                    918:            </td>
                    919:           </tr>
                    920:           <tr>
                    921:            <td>
                    922:             <table class="LC_nested">
                    923:              <tr class="LC_info_row">
1.160.6.113  raeburn   924:               <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107  raeburn   925:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108  raeburn   926:                 if ($action eq 'passwords') {
                    927:                     $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                    928:                 } else {
                    929:                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    930:                 }
                    931:                 $output .= '
1.160.6.98  raeburn   932:             </table>
                    933:           </td>
                    934:          </tr>
                    935:          <tr>';
1.160.6.42  raeburn   936:             } else {
                    937:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    938:             }
1.63      raeburn   939:             $rowtotal ++;
1.160.6.57  raeburn   940:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.118.2  8(raebur  941:2):                  ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
                    942:2):                  ($action eq 'wafproxy')) {
1.160.6.37  raeburn   943:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97  raeburn   944:         } elsif ($action eq 'scantron') {
                    945:             $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110     raeburn   946:         } elsif ($action eq 'login') {
1.160.6.113  raeburn   947:             if ($numheaders == 5) {
1.160.6.5  raeburn   948:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    949:            </table>
                    950:           </td>
                    951:          </tr>
                    952:          <tr>
                    953:            <td>
                    954:             <table class="LC_nested">
                    955:              <tr class="LC_info_row">
                    956:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30  raeburn   957:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5  raeburn   958:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    959:                 $rowtotal ++;
                    960:             } else {
                    961:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    962:             }
1.160.6.56  raeburn   963:             $output .= '
                    964:            </table>
                    965:           </td>
                    966:          </tr>
                    967:          <tr>
                    968:            <td>
                    969:             <table class="LC_nested">
                    970:              <tr class="LC_info_row">';
1.160.6.113  raeburn   971:             if ($numheaders == 5) {
1.160.6.56  raeburn   972:                 $output .= '
                    973:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    974:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    975:              </tr>';
                    976:             } else {
                    977:                 $output .= '
                    978:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    979:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    980:              </tr>';
                    981:             }
                    982:             $rowtotal ++;
1.160.6.113  raeburn   983:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
                    984:            </table>
                    985:           </td>
                    986:          </tr>
                    987:          <tr>
                    988:            <td>
                    989:             <table class="LC_nested">
                    990:              <tr class="LC_info_row">';
                    991:             if ($numheaders == 5) {
                    992:                 $output .= '
                    993:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    994:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
                    995:              </tr>';
                    996:             } else {
                    997:                 $output .= '
                    998:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    999:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                   1000:              </tr>';
                   1001:             }
                   1002:             $rowtotal ++;
                   1003:             $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn  1004:         } elsif ($action eq 'requestcourses') {
1.160.6.50  raeburn  1005:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                   1006:             $rowtotal ++;
                   1007:             $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30  raeburn  1008:            </table>
                   1009:           </td>
                   1010:          </tr>
                   1011:          <tr>
                   1012:            <td>
                   1013:             <table class="LC_nested">
                   1014:              <tr class="LC_info_row">
                   1015:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1016:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46  raeburn  1017:                        &textbookcourses_javascript($settings).
                   1018:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                   1019:             </table>
                   1020:            </td>
                   1021:           </tr>
                   1022:          <tr>
                   1023:            <td>
                   1024:             <table class="LC_nested">
                   1025:              <tr class="LC_info_row">
                   1026:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1027:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                   1028:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39  raeburn  1029:             </table>
                   1030:            </td>
                   1031:           </tr>
                   1032:           <tr>
                   1033:            <td>
                   1034:             <table class="LC_nested">
                   1035:              <tr class="LC_info_row">
1.160.6.46  raeburn  1036:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                   1037:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39  raeburn  1038:              </tr>'.
                   1039:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5  raeburn  1040:         } elsif ($action eq 'requestauthor') {
                   1041:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50  raeburn  1042:             $rowtotal ++;
1.122     jms      1043:         } elsif ($action eq 'rolecolors') {
1.30      raeburn  1044:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn  1045:            </table>
                   1046:           </td>
                   1047:          </tr>
                   1048:          <tr>
                   1049:            <td>
                   1050:             <table class="LC_nested">
                   1051:              <tr class="LC_info_row">
1.69      raeburn  1052:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                   1053:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                   1054:               <td class="LC_right_item" valign="top">'.
                   1055:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn  1056:              </tr>'.
1.30      raeburn  1057:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn  1058:            </table>
                   1059:           </td>
                   1060:          </tr>
                   1061:          <tr>
                   1062:            <td>
                   1063:             <table class="LC_nested">
                   1064:              <tr class="LC_info_row">
1.59      bisitz   1065:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                   1066:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn  1067:              </tr>'.
1.30      raeburn  1068:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                   1069:             $rowtotal += 2;
1.6       raeburn  1070:         }
1.3       raeburn  1071:     } else {
1.30      raeburn  1072:         $output .= '
1.3       raeburn  1073:           <tr>
                   1074:            <td>
                   1075:             <table class="LC_nested">
1.30      raeburn  1076:              <tr class="LC_info_row">';
1.160.6.72  raeburn  1077:         if ($action eq 'login') {
1.30      raeburn  1078:             $output .= '  
1.59      bisitz   1079:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn  1080:         } elsif ($action eq 'serverstatuses') {
                   1081:             $output .= '
                   1082:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                   1083:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                   1084: 
1.6       raeburn  1085:         } else {
1.30      raeburn  1086:             $output .= '
1.69      raeburn  1087:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                   1088:         }
1.72      raeburn  1089:         if (defined($item->{'header'}->[0]->{'col3'})) {
                   1090:             $output .= '<td class="LC_left_item" valign="top">'.
                   1091:                        &mt($item->{'header'}->[0]->{'col2'});
                   1092:             if ($action eq 'serverstatuses') {
                   1093:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                   1094:             } 
1.69      raeburn  1095:         } else {
                   1096:             $output .= '<td class="LC_right_item" valign="top">'.
                   1097:                        &mt($item->{'header'}->[0]->{'col2'});
                   1098:         }
                   1099:         $output .= '</td>';
                   1100:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn  1101:             if (defined($item->{'header'}->[0]->{'col4'})) {
                   1102:                 $output .= '<td class="LC_left_item" valign="top">'.
                   1103:                             &mt($item->{'header'}->[0]->{'col3'});
                   1104:             } else {
                   1105:                 $output .= '<td class="LC_right_item" valign="top">'.
                   1106:                            &mt($item->{'header'}->[0]->{'col3'});
                   1107:             }
1.69      raeburn  1108:             if ($action eq 'serverstatuses') {
                   1109:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                   1110:             }
                   1111:             $output .= '</td>';
1.6       raeburn  1112:         }
1.150     raeburn  1113:         if ($item->{'header'}->[0]->{'col4'}) {
                   1114:             $output .= '<td class="LC_right_item" valign="top">'.
                   1115:                        &mt($item->{'header'}->[0]->{'col4'});
                   1116:         }
1.69      raeburn  1117:         $output .= '</tr>';
1.48      raeburn  1118:         $rowtotal ++;
1.160.6.5  raeburn  1119:         if ($action eq 'quotas') {
1.86      raeburn  1120:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72  raeburn  1121:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.160.6.113  raeburn  1122:                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2  1(raebur 1123:1):                  ($action eq 'ltitools') || ($action eq 'ipaccess')) {
1.160.6.37  raeburn  1124:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121     raeburn  1125:         }
1.3       raeburn  1126:     }
1.30      raeburn  1127:     $output .= '
1.3       raeburn  1128:    </table>
                   1129:   </td>
                   1130:  </tr>
1.30      raeburn  1131: </table><br />';
                   1132:     return ($output,$rowtotal);
1.1       raeburn  1133: }
                   1134: 
1.3       raeburn  1135: sub print_login {
1.160.6.5  raeburn  1136:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113  raeburn  1137:     my ($css_class,$datatable,$switchserver,%lt);
1.6       raeburn  1138:     my %choices = &login_choices();
1.160.6.113  raeburn  1139:     if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
                   1140:         %lt = &login_file_options();
                   1141:         $switchserver = &check_switchserver($dom,$confname);
                   1142:     }
1.110     raeburn  1143: 
1.160.6.5  raeburn  1144:     if ($caller eq 'service') {
1.149     raeburn  1145:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn  1146:         my $choice = $choices{'disallowlogin'};
                   1147:         $css_class = ' class="LC_odd_row"';
1.128     raeburn  1148:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn  1149:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn  1150:                       '<th>'.$choices{'server'}.'</th>'.
                   1151:                       '<th>'.$choices{'serverpath'}.'</th>'.
                   1152:                       '<th>'.$choices{'custompath'}.'</th>'.
                   1153:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn  1154:         my %disallowed;
                   1155:         if (ref($settings) eq 'HASH') {
                   1156:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                   1157:                %disallowed = %{$settings->{'loginvia'}};
                   1158:             }
                   1159:         }
                   1160:         foreach my $lonhost (sort(keys(%servers))) {
                   1161:             my $direct = 'selected="selected"';
1.128     raeburn  1162:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1163:                 if ($disallowed{$lonhost}{'server'} ne '') {
                   1164:                     $direct = '';
                   1165:                 }
1.110     raeburn  1166:             }
1.115     raeburn  1167:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1168:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1169:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1170:                           '</option>';
1.160.6.13  raeburn  1171:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1172:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1173:                 my $selected = '';
1.128     raeburn  1174:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1175:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1176:                         $selected = 'selected="selected"';
                   1177:                     }
1.110     raeburn  1178:                 }
                   1179:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1180:                               $servers{$hostid}.'</option>';
                   1181:             }
1.128     raeburn  1182:             $datatable .= '</select></td>'.
                   1183:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1184:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1185:                 my $pathname = $path;
                   1186:                 if ($path eq 'custom') {
                   1187:                     $pathname = &mt('Custom Path').' ->';
                   1188:                 }
                   1189:                 my $selected = '';
                   1190:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1191:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1192:                         $selected = 'selected="selected"';
                   1193:                     }
                   1194:                 } elsif ($path eq '') {
                   1195:                     $selected = 'selected="selected"';
                   1196:                 }
                   1197:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1198:             }
                   1199:             $datatable .= '</select></td>';
                   1200:             my ($custom,$exempt);
                   1201:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1202:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1203:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1204:             }
                   1205:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1206:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1207:                           '</tr>';
1.110     raeburn  1208:         }
                   1209:         $datatable .= '</table></td></tr>';
                   1210:         return $datatable;
1.160.6.5  raeburn  1211:     } elsif ($caller eq 'page') {
                   1212:         my %defaultchecked = ( 
                   1213:                                'coursecatalog' => 'on',
1.160.6.14  raeburn  1214:                                'helpdesk'      => 'on',
1.160.6.5  raeburn  1215:                                'adminmail'     => 'off',
                   1216:                                'newuser'       => 'off',
                   1217:                              );
1.160.6.14  raeburn  1218:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5  raeburn  1219:         my (%checkedon,%checkedoff);
1.42      raeburn  1220:         foreach my $item (@toggles) {
1.160.6.5  raeburn  1221:             if ($defaultchecked{$item} eq 'on') { 
                   1222:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1223:                 $checkedoff{$item} = ' ';
1.160.6.5  raeburn  1224:             } elsif ($defaultchecked{$item} eq 'off') {
                   1225:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1226:                 $checkedon{$item} = ' ';
                   1227:             }
1.1       raeburn  1228:         }
1.160.6.5  raeburn  1229:         my @images = ('img','logo','domlogo','login');
1.160.6.118.2  2(raebur 1230:2):         my @alttext = ('img','logo','domlogo');
1.160.6.5  raeburn  1231:         my @logintext = ('textcol','bgcol');
                   1232:         my @bgs = ('pgbg','mainbg','sidebg');
                   1233:         my @links = ('link','alink','vlink');
                   1234:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1235:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1236:         my (%is_custom,%designs);
                   1237:         my %defaults = (
                   1238:                        font => $defaultdesign{'login.font'},
                   1239:                        );
1.6       raeburn  1240:         foreach my $item (@images) {
1.160.6.5  raeburn  1241:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1242:             $defaults{'showlogo'}{$item} = 1;
                   1243:         }
                   1244:         foreach my $item (@bgs) {
                   1245:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1246:         }
1.41      raeburn  1247:         foreach my $item (@logintext) {
1.160.6.5  raeburn  1248:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1249:         }
1.160.6.5  raeburn  1250:         foreach my $item (@links) {
                   1251:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1252:         }
1.160.6.5  raeburn  1253:         if (ref($settings) eq 'HASH') {
                   1254:             foreach my $item (@toggles) {
                   1255:                 if ($settings->{$item} eq '1') {
                   1256:                     $checkedon{$item} =  ' checked="checked" ';
                   1257:                     $checkedoff{$item} = ' ';
                   1258:                 } elsif ($settings->{$item} eq '0') {
                   1259:                     $checkedoff{$item} =  ' checked="checked" ';
                   1260:                     $checkedon{$item} = ' ';
                   1261:                 }
1.6       raeburn  1262:             }
1.160.6.5  raeburn  1263:             foreach my $item (@images) {
                   1264:                 if (defined($settings->{$item})) {
                   1265:                     $designs{$item} = $settings->{$item};
                   1266:                     $is_custom{$item} = 1;
                   1267:                 }
                   1268:                 if (defined($settings->{'showlogo'}{$item})) {
                   1269:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1270:                 }
                   1271:             }
1.160.6.118.2  2(raebur 1272:2):             foreach my $item (@alttext) {
                   1273:2):                 if (ref($settings->{'alttext'}) eq 'HASH') {
                   1274:2):                     if ($settings->{'alttext'}->{$item} ne '') {
                   1275:2):                         $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
                   1276:2):                     }
                   1277:2):                 }
                   1278:2):             }
1.160.6.5  raeburn  1279:             foreach my $item (@logintext) {
                   1280:                 if ($settings->{$item} ne '') {
                   1281:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1282:                     $is_custom{$item} = 1;
                   1283:                 }
                   1284:             }
                   1285:             if ($settings->{'font'} ne '') {
                   1286:                 $designs{'font'} = $settings->{'font'};
                   1287:                 $is_custom{'font'} = 1;
                   1288:             }
                   1289:             foreach my $item (@bgs) {
                   1290:                 if ($settings->{$item} ne '') {
                   1291:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1292:                     $is_custom{$item} = 1;
                   1293:                 }
                   1294:             }
                   1295:             foreach my $item (@links) {
                   1296:                 if ($settings->{$item} ne '') {
                   1297:                     $designs{'links'}{$item} = $settings->{$item};
                   1298:                     $is_custom{$item} = 1;
                   1299:                 }
                   1300:             }
                   1301:         } else {
                   1302:             if ($designhash{$dom.'.login.font'} ne '') {
                   1303:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1304:                 $is_custom{'font'} = 1;
                   1305:             }
                   1306:             foreach my $item (@images) {
                   1307:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1308:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1309:                     $is_custom{$item} = 1;
                   1310:                 }
                   1311:             }
                   1312:             foreach my $item (@bgs) {
                   1313:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1314:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1315:                     $is_custom{$item} = 1;
                   1316:                 }
                   1317:             }
                   1318:             foreach my $item (@links) {
                   1319:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1320:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1321:                     $is_custom{$item} = 1;
                   1322:                 }
1.6       raeburn  1323:             }
                   1324:         }
1.160.6.5  raeburn  1325:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1326:                                                       logo => 'Institution Logo',
                   1327:                                                       domlogo => 'Domain Logo',
                   1328:                                                       login => 'Login box');
                   1329:         my $itemcount = 1;
                   1330:         foreach my $item (@toggles) {
                   1331:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1332:             $datatable .=  
                   1333:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1334:                 '</td><td>'.
                   1335:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1336:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1337:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1338:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1339:                 '</tr>';
                   1340:             $itemcount ++;
1.6       raeburn  1341:         }
1.160.6.5  raeburn  1342:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1343:         $datatable .= '</tr></table></td></tr>';
                   1344:     } elsif ($caller eq 'help') {
1.160.6.113  raeburn  1345:         my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5  raeburn  1346:         my $itemcount = 1;
                   1347:         $defaulturl = '/adm/loginproblems.html';
                   1348:         $defaulttype = 'default';
                   1349:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1350:         my @currlangs;
                   1351:         if (ref($settings) eq 'HASH') {
                   1352:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1353:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1354:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1355:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1356:                     $type{$key} = 'custom';
                   1357:                     unless ($key eq 'nolang') {
                   1358:                         push(@currlangs,$key);
                   1359:                     }
                   1360:                 }
                   1361:             } elsif ($settings->{'helpurl'} ne '') {
                   1362:                 $type{'nolang'} = 'custom';
                   1363:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1364:             }
                   1365:         }
1.160.6.5  raeburn  1366:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1367:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1368:             $datatable .= '<tr'.$css_class.'>';
                   1369:             if ($url{$lang} eq '') {
                   1370:                 $url{$lang} = $defaulturl;
                   1371:             }
                   1372:             if ($type{$lang} eq '') {
                   1373:                 $type{$lang} = $defaulttype;
                   1374:             }
                   1375:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1376:             if ($lang eq 'nolang') {
                   1377:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1378:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1379:             } else {
                   1380:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1381:                                   $langchoices{$lang},
                   1382:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1383:             }
                   1384:             $datatable .= '</span></td>'."\n".
                   1385:                           '<td class="LC_left_item">';
                   1386:             if ($type{$lang} eq 'custom') {
                   1387:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1388:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1389:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1390:             } else {
                   1391:                 $datatable .= $lt{'upl'};
                   1392:             }
                   1393:             $datatable .='<br />';
                   1394:             if ($switchserver) {
                   1395:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1396:             } else {
                   1397:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1398:             }
1.160.6.5  raeburn  1399:             $datatable .= '</td></tr>';
                   1400:             $itemcount ++;
1.6       raeburn  1401:         }
1.160.6.5  raeburn  1402:         my @addlangs;
                   1403:         foreach my $lang (sort(keys(%langchoices))) {
                   1404:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1405:             push(@addlangs,$lang);
                   1406:         }
                   1407:         if (@addlangs > 0) {
                   1408:             my %toadd;
                   1409:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1410:             $toadd{''} = &mt('Select');
                   1411:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1412:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1413:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1414:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1415:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1416:             if ($switchserver) {
                   1417:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1418:             } else {
                   1419:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1420:             }
1.160.6.5  raeburn  1421:             $datatable .= '</td></tr>';
                   1422:             $itemcount ++;
1.6       raeburn  1423:         }
1.160.6.5  raeburn  1424:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56  raeburn  1425:     } elsif ($caller eq 'headtag') {
                   1426:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1427:         my $choice = $choices{'headtag'};
                   1428:         $css_class = ' class="LC_odd_row"';
                   1429:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1430:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1431:                       '<th>'.$choices{'current'}.'</th>'.
                   1432:                       '<th>'.$choices{'action'}.'</th>'.
                   1433:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1434:         my (%currurls,%currexempt);
                   1435:         if (ref($settings) eq 'HASH') {
                   1436:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1437:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1438:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1439:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1440:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1441:                     }
                   1442:                 }
                   1443:             }
                   1444:         }
                   1445:         foreach my $lonhost (sort(keys(%domservers))) {
                   1446:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1447:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1448:             if ($currurls{$lonhost}) {
                   1449:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1450:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1451:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1452:                               '">'.$lt{'curr'}.'</a></td>'.
                   1453:                               '<td><span class="LC_nobreak"><label>'.
                   1454:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1455:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1456:             } else {
                   1457:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1458:             }
                   1459:             $datatable .='<br />';
                   1460:             if ($switchserver) {
                   1461:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1462:             } else {
                   1463:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1464:             }
1.160.6.87  raeburn  1465:             $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56  raeburn  1466:         }
                   1467:         $datatable .= '</table></td></tr>';
1.160.6.113  raeburn  1468:     } elsif ($caller eq 'saml') {
                   1469:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1470:         $datatable .= '<tr><td colspan="3" style="text-align: left">'.
                   1471:                       '<table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1472:                       '<th>'.$choices{'samllanding'}.'</th>'.
                   1473:                       '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2  9(raebur 1474:2):         my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113  raeburn  1475:         foreach my $lonhost (keys(%domservers)) {
                   1476:             $samlurl{$lonhost} = '/adm/sso';
                   1477:             $styleon{$lonhost} = 'display:none';
                   1478:             $styleoff{$lonhost} = '';
                   1479:         }
                   1480:         if (ref($settings->{'saml'}) eq 'HASH') {
                   1481:             foreach my $lonhost (keys(%{$settings->{'saml'}})) {
                   1482:                 if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
                   1483:                     $saml{$lonhost} = 1;
                   1484:                     $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
                   1485:                     $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
                   1486:                     $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
                   1487:                     $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
                   1488:                     $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2  9(raebur 1489:2):                     $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113  raeburn  1490:                     $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
                   1491:                     $styleon{$lonhost} = '';
                   1492:                     $styleoff{$lonhost} = 'display:none';
                   1493:                 } else {
                   1494:                     $styleon{$lonhost} = 'display:none';
                   1495:                     $styleoff{$lonhost} = '';
                   1496:                 }
                   1497:             }
                   1498:         }
                   1499:         my $itemcount = 1;
                   1500:         foreach my $lonhost (sort(keys(%domservers))) {
                   1501:             my $samlon = ' ';
                   1502:             my $samloff = ' checked="checked" ';
                   1503:             if ($saml{$lonhost}) {
                   1504:                 $samlon = $samloff;
                   1505:                 $samloff = ' ';
                   1506:             }
1.160.6.118.2  9(raebur 1507:2):             my $samlwinon = '';
                   1508:2):             my $samlwinoff = ' checked="checked"';
                   1509:2):             if ($samlwindow{$lonhost}) {
                   1510:2):                 $samlwinon = $samlwinoff;
                   1511:2):                 $samlwinoff = '';
                   1512:2):             }
1.160.6.113  raeburn  1513:             my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1514:             $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
                   1515:                           '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
                   1516:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
                   1517:                           &mt('No').'</label>'.('&nbsp;'x2).
                   1518:                           '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
                   1519:                           'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
                   1520:                           &mt('Yes').'</label></span></td>'.
                   1521:                           '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2  9(raebur 1522:2):                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113  raeburn  1523:                           '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2  9(raebur 1524:2):                           '<th>'.&mt('Alt Text').'</th></tr>'.
                   1525:2):                           '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113  raeburn  1526:                           $samltext{$lonhost}.'" /></td><td>';
                   1527:             if ($samlimg{$lonhost}) {
                   1528:                 $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
                   1529:                               '<span class="LC_nobreak"><label>'.
                   1530:                               '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
                   1531:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1532:             } else {
                   1533:                 $datatable .= $lt{'upl'};
                   1534:             }
                   1535:             $datatable .='<br />';
                   1536:             if ($switchserver) {
                   1537:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1538:             } else {
                   1539:                 $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
                   1540:             }
                   1541:             $datatable .= '</td>'.
1.160.6.118.2  9(raebur 1542:2):                           '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
                   1543:2):                           'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
                   1544:2):                           '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
                   1545:2):                           '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
                   1546:2):                           '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
                   1547:2):                           '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
                   1548:2):                           '<tr'.$css_class.'>'.
                   1549:2):                           '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113  raeburn  1550:                           'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2  9(raebur 1551:2):                           '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113  raeburn  1552:                           $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2  9(raebur 1553:2):                           '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
                   1554:2):                           &mt('No').'</label>'.('&nbsp;'x2).'<label><input type="radio" '.
                   1555:2):                           'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
                   1556:2):                           '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113  raeburn  1557:                           'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
                   1558:                           '</table></td>'.
                   1559:                           '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%">&nbsp;</td></tr>';
                   1560:            $itemcount ++;
                   1561:         }
                   1562:         $datatable .= '</table></td></tr>';
1.1       raeburn  1563:     }
1.6       raeburn  1564:     return $datatable;
                   1565: }
                   1566: 
                   1567: sub login_choices {
                   1568:     my %choices =
                   1569:         &Apache::lonlocal::texthash (
1.116     bisitz   1570:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1571:             adminmail     => "Display Administrator's E-mail Address?",
1.160.6.14  raeburn  1572:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1573:             disallowlogin => "Login page requests redirected",
                   1574:             hostid        => "Server",
1.128     raeburn  1575:             server        => "Redirect to:",
                   1576:             serverpath    => "Path",
                   1577:             custompath    => "Custom", 
                   1578:             exempt        => "Exempt IP(s)",
1.110     raeburn  1579:             directlogin   => "No redirect",
                   1580:             newuser       => "Link to create a user account",
                   1581:             img           => "Header",
                   1582:             logo          => "Main Logo",
                   1583:             domlogo       => "Domain Logo",
                   1584:             login         => "Log-in Header", 
                   1585:             textcol       => "Text color",
                   1586:             bgcol         => "Box color",
                   1587:             bgs           => "Background colors",
                   1588:             links         => "Link colors",
                   1589:             font          => "Font color",
                   1590:             pgbg          => "Header",
                   1591:             mainbg        => "Page",
                   1592:             sidebg        => "Login box",
                   1593:             link          => "Link",
                   1594:             alink         => "Active link",
                   1595:             vlink         => "Visited link",
1.160.6.56  raeburn  1596:             headtag       => "Custom markup",
                   1597:             action        => "Action",
                   1598:             current       => "Current",
1.160.6.113  raeburn  1599:             samllanding   => "Dual login?",
                   1600:             samloptions   => "Options",
1.160.6.118.2  2(raebur 1601:2):             alttext       => "Alt text",
1.6       raeburn  1602:         );
                   1603:     return %choices;
                   1604: }
                   1605: 
1.160.6.113  raeburn  1606: sub login_file_options {
                   1607:       return &Apache::lonlocal::texthash(
                   1608:                                            del     => 'Delete?',
                   1609:                                            rep     => 'Replace:',
                   1610:                                            upl     => 'Upload:',
                   1611:                                            curr    => 'View contents',
                   1612:                                            default => 'Default',
                   1613:                                            custom  => 'Custom',
                   1614:                                            none    => 'None',
                   1615:       );
                   1616: }
                   1617: 
                   1618: sub print_ipaccess {
                   1619:     my ($dom,$settings,$rowtotal) = @_;
                   1620:     my $css_class;
                   1621:     my $itemcount = 0;
                   1622:     my $datatable;
                   1623:     my %ordered;
                   1624:     if (ref($settings) eq 'HASH') {
                   1625:         foreach my $item (keys(%{$settings})) {
                   1626:             if (ref($settings->{$item}) eq 'HASH') {
                   1627:                 my $num = $settings->{$item}{'order'};
                   1628:                 if ($num eq '') {
                   1629:                     $num = scalar(keys(%{$settings}));
                   1630:                 }
                   1631:                 $ordered{$num} = $item;
                   1632:             }
                   1633:         }
                   1634:     }
                   1635:     my $maxnum = scalar(keys(%ordered));
                   1636:     if (keys(%ordered)) {
                   1637:         my @items = sort { $a <=> $b } keys(%ordered);
                   1638:         for (my $i=0; $i<@items; $i++) {
                   1639:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1640:             my $item = $ordered{$items[$i]};
                   1641:             my ($name,$ipranges,%commblocks,%courses);
                   1642:             if (ref($settings->{$item}) eq 'HASH') {
                   1643:                 $name = $settings->{$item}->{'name'};
                   1644:                 $ipranges = $settings->{$item}->{'ip'};
                   1645:                 if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
                   1646:                     %commblocks = %{$settings->{$item}->{'commblocks'}};
                   1647:                 }
                   1648:                 if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
                   1649:                     %courses = %{$settings->{$item}->{'courses'}};
                   1650:                 }
                   1651:             }
                   1652:             my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
                   1653:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   1654:                          .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
                   1655:             for (my $k=0; $k<=$maxnum; $k++) {
                   1656:                 my $vpos = $k+1;
                   1657:                 my $selstr;
                   1658:                 if ($k == $i) {
                   1659:                     $selstr = ' selected="selected" ';
                   1660:                 }
                   1661:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1662:             }
                   1663:             $datatable .= '</select>'.('&nbsp;'x2).
                   1664:                 '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
                   1665:                 &mt('Delete?').'</label></span></td>'.
                   1666:                 '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
                   1667:                 &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
                   1668:                 '</td></tr>';
                   1669:             $itemcount ++;
                   1670:         }
                   1671:     }
                   1672:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1673:     my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
                   1674:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   1675:                   '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
                   1676:                   '<select name="ipaccess_pos_add"'.$chgstr.'>';
                   1677:     for (my $k=0; $k<$maxnum+1; $k++) {
                   1678:         my $vpos = $k+1;
                   1679:         my $selstr;
                   1680:         if ($k == $maxnum) {
                   1681:             $selstr = ' selected="selected" ';
                   1682:         }
                   1683:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   1684:     }
                   1685:     $datatable .= '</select>&nbsp;'."\n".
                   1686:                   '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   1687:                   '<td colspan="2">'.
                   1688:                   &ipaccess_options('add',$itemcount,$dom).
                   1689:                   '</td>'."\n".
                   1690:                   '</tr>'."\n";
                   1691:     $$rowtotal ++;
                   1692:     return $datatable;
                   1693: }
                   1694: 
                   1695: sub ipaccess_options {
                   1696:     my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
                   1697:     my (%currblocks,%currcourses,$output);
                   1698:     if (ref($blocksref) eq 'HASH') {
                   1699:         %currblocks = %{$blocksref};
                   1700:     }
                   1701:     if (ref($coursesref) eq 'HASH') {
                   1702:         %currcourses = %{$coursesref};
                   1703:     }
                   1704:     $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
                   1705:               '<span class="LC_nobreak">'.&mt('Name').':&nbsp;'.
                   1706:               '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
                   1707:               '</span></fieldset>'.
                   1708:               '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
                   1709:               &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   1710:               &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
                   1711:               '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
                   1712:               $ipranges.'</textarea></fieldset>'.
                   1713:               '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
                   1714:               &blocker_checkboxes($num,$blocksref).'</fieldset>'.
                   1715:               '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
                   1716:               '<table>';
                   1717:     foreach my $cid (sort(keys(%currcourses))) {
                   1718:         my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   1719:         $output .= '<tr><td><span class="LC_nobreak">'.
                   1720:                    '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
                   1721:                    &mt('Delete?').'&nbsp;<span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
                   1722:                    ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
                   1723:     }
                   1724:     $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').':&nbsp;'.
                   1725:                '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
                   1726:                 &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
                   1727:                '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
                   1728:                '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
                   1729:                '</span></td></tr></table>'."\n".
                   1730:                '</fieldset>';
                   1731:     return $output;
                   1732: }
                   1733: 
                   1734: sub blocker_checkboxes {
                   1735:     my ($num,$blocks) = @_;
                   1736:     my ($typeorder,$types) = &commblocktype_text();
                   1737:     my $numinrow = 6;
                   1738:     my $output = '<table>';
                   1739:     for (my $i=0; $i<@{$typeorder}; $i++) {
                   1740:         my $block = $typeorder->[$i];
                   1741:         my $blockstatus;
                   1742:         if (ref($blocks) eq 'HASH') {
                   1743:             if ($blocks->{$block} eq 'on') {
                   1744:                 $blockstatus = 'checked="checked"';
                   1745:             }
                   1746:         }
                   1747:         my $rem = $i%($numinrow);
                   1748:         if ($rem == 0) {
                   1749:             if ($i > 0) {
                   1750:                 $output .= '</tr>';
                   1751:             }
                   1752:             $output .= '<tr>';
                   1753:         }
                   1754:         if ($i == scalar(@{$typeorder})-1) {
                   1755:             my $colsleft = $numinrow-$rem;
                   1756:             if ($colsleft > 1) {
                   1757:                 $output .= '<td colspan="'.$colsleft.'">';
                   1758:             } else {
                   1759:                 $output .= '<td>';
                   1760:             }
                   1761:         } else {
                   1762:             $output .= '<td>';
                   1763:         }
                   1764:         my $item = 'ipaccess_block_'.$num;
                   1765:         if ($blockstatus) {
                   1766:             $blockstatus = ' '.$blockstatus;
                   1767:         }
                   1768:         $output .= '<span class="LC_nobreak"><label>'."\n".
                   1769:                    '<input type="checkbox" name="'.$item.'"'.
                   1770:                    $blockstatus.' value="'.$block.'"'.' />'.
                   1771:                    $types->{$block}.'</label></span>'."\n".
                   1772:                    '<br /></td>';
                   1773:     }
                   1774:     $output .= '</tr></table>';
                   1775:     return $output;
                   1776: }
                   1777: 
                   1778: sub commblocktype_text {
                   1779:     my %types = &Apache::lonlocal::texthash(
                   1780:         'com' => 'Messaging',
                   1781:         'chat' => 'Chat Room',
                   1782:         'boards' => 'Discussion',
                   1783:         'port' => 'Portfolio',
                   1784:         'groups' => 'Groups',
                   1785:         'blogs' => 'Blogs',
                   1786:         'about' => 'User Information',
                   1787:         'printout' => 'Printouts',
                   1788:         'passwd' => 'Change Password',
                   1789:         'grades' => 'Gradebook',
1.160.6.115  raeburn  1790:         'search' => 'Course search',
                   1791:         'wishlist' => 'Stored links',
                   1792:         'annotate' => 'Annotations',
1.160.6.113  raeburn  1793:     );
1.160.6.115  raeburn  1794:     my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113  raeburn  1795:     return ($typeorder,\%types);
                   1796: }
                   1797: 
1.6       raeburn  1798: sub print_rolecolors {
1.30      raeburn  1799:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1800:     my %choices = &color_font_choices();
                   1801:     my @bgs = ('pgbg','tabbg','sidebg');
                   1802:     my @links = ('link','alink','vlink');
                   1803:     my @images = ('img');
                   1804:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1805:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1806:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1807:     my (%is_custom,%designs);
1.160.6.22  raeburn  1808:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1809:     if (ref($settings) eq 'HASH') {
                   1810:         if (ref($settings->{$role}) eq 'HASH') {
                   1811:             if ($settings->{$role}->{'img'} ne '') {
                   1812:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1813:                 $is_custom{'img'} = 1;
                   1814:             }
                   1815:             if ($settings->{$role}->{'font'} ne '') {
                   1816:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1817:                 $is_custom{'font'} = 1;
                   1818:             }
1.97      tempelho 1819:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1820:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1821:                 $is_custom{'fontmenu'} = 1;
                   1822:             }
1.6       raeburn  1823:             foreach my $item (@bgs) {
                   1824:                 if ($settings->{$role}->{$item} ne '') {
                   1825:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1826:                     $is_custom{$item} = 1;
                   1827:                 }
                   1828:             }
                   1829:             foreach my $item (@links) {
                   1830:                 if ($settings->{$role}->{$item} ne '') {
                   1831:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1832:                     $is_custom{$item} = 1;
                   1833:                 }
                   1834:             }
                   1835:         }
                   1836:     } else {
                   1837:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1838:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1839:             $is_custom{'img'} = 1;
                   1840:         }
1.97      tempelho 1841:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1842:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1843:             $is_custom{'fontmenu'} = 1; 
                   1844:         }
1.6       raeburn  1845:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1846:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1847:             $is_custom{'font'} = 1;
                   1848:         }
                   1849:         foreach my $item (@bgs) {
                   1850:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1851:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1852:                 $is_custom{$item} = 1;
                   1853:             
                   1854:             }
                   1855:         }
                   1856:         foreach my $item (@links) {
                   1857:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1858:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1859:                 $is_custom{$item} = 1;
                   1860:             }
                   1861:         }
                   1862:     }
                   1863:     my $itemcount = 1;
1.30      raeburn  1864:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1865:     $datatable .= '</tr></table></td></tr>';
                   1866:     return $datatable;
                   1867: }
                   1868: 
1.160.6.22  raeburn  1869: sub role_defaults {
                   1870:     my ($role,$bgs,$links,$images,$logintext) = @_;
                   1871:     my %defaults;
                   1872:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
                   1873:         return %defaults;
                   1874:     }
                   1875:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1876:     if ($role eq 'login') {
                   1877:         %defaults = (
                   1878:                        font => $defaultdesign{$role.'.font'},
                   1879:                     );
                   1880:         if (ref($logintext) eq 'ARRAY') {
                   1881:             foreach my $item (@{$logintext}) {
                   1882:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1883:             }
                   1884:         }
                   1885:         foreach my $item (@{$images}) {
                   1886:             $defaults{'showlogo'}{$item} = 1;
                   1887:         }
                   1888:     } else {
                   1889:         %defaults = (
                   1890:                        img => $defaultdesign{$role.'.img'},
                   1891:                        font => $defaultdesign{$role.'.font'},
                   1892:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1893:                     );
                   1894:     }
                   1895:     foreach my $item (@{$bgs}) {
                   1896:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1897:     }
                   1898:     foreach my $item (@{$links}) {
                   1899:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1900:     }
                   1901:     foreach my $item (@{$images}) {
                   1902:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1903:     }
                   1904:     return %defaults;
                   1905: }
                   1906: 
1.6       raeburn  1907: sub display_color_options {
1.9       raeburn  1908:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1909:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1910:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1911:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1912:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1913:         '<td>'.$choices->{'font'}.'</td>';
                   1914:     if (!$is_custom->{'font'}) {
1.160.6.87  raeburn  1915:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1916:     } else {
                   1917:         $datatable .= '<td>&nbsp;</td>';
                   1918:     }
1.160.6.9  raeburn  1919:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1920: 
1.8       raeburn  1921:     $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1922:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1923:                   ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1924:                   '&nbsp;</span></td></tr>';
1.107     raeburn  1925:     unless ($role eq 'login') { 
                   1926:         $datatable .= '<tr'.$css_class.'>'.
                   1927:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1928:         if (!$is_custom->{'fontmenu'}) {
1.160.6.87  raeburn  1929:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107     raeburn  1930:         } else {
                   1931:             $datatable .= '<td>&nbsp;</td>';
                   1932:         }
1.160.6.22  raeburn  1933: 	$current_color = $designs->{'fontmenu'} ?
                   1934: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1935:         $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1936:                       '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22  raeburn  1937: 		      .$role.'_fontmenu"'.
1.160.6.9  raeburn  1938:                       ' value="'.$current_color.'" />&nbsp;'.
1.160.6.87  raeburn  1939:                       '&nbsp;</span></td></tr>';
1.97      tempelho 1940:     }
1.9       raeburn  1941:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1942:     foreach my $img (@{$images}) {
1.18      albertel 1943: 	$itemcount ++;
1.6       raeburn  1944:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1945:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1946:                       '<td>'.$choices->{$img};
1.160.6.118.2  2(raebur 1947:2):         my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70      raeburn  1948:         if ($role eq 'login') {
                   1949:             if ($img eq 'login') {
                   1950:                 $login_hdr_pick =
1.135     bisitz   1951:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1952:                 $logincolors =
                   1953:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22  raeburn  1954:                                        $designs,$defaults);
1.160.6.118.2  2(raebur 1955:2):             } else {
                   1956:2):                 if ($img ne 'domlogo') {
                   1957:2):                     $datatable.= &logo_display_options($img,$defaults,$designs);
                   1958:2):                 }
                   1959:2):                 if (ref($designs->{'alttext'}) eq 'HASH') {
                   1960:2):                     $alttext = $designs->{'alttext'}{$img};
                   1961:2):                 }
1.70      raeburn  1962:             }
                   1963:         }
                   1964:         $datatable .= '</td>';
1.6       raeburn  1965:         if ($designs->{$img} ne '') {
                   1966:             $imgfile = $designs->{$img};
1.18      albertel 1967: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1968:         } else {
                   1969:             $imgfile = $defaults->{$img};
                   1970:         }
                   1971:         if ($imgfile) {
1.9       raeburn  1972:             my ($showfile,$fullsize);
                   1973:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1974:                 my $urldir = $1;
                   1975:                 my $filename = $2;
                   1976:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1977:                 if (@info) {
                   1978:                     my $thumbfile = 'tn-'.$filename;
                   1979:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1980:                     if (@thumb) {
                   1981:                         $showfile = $urldir.'/'.$thumbfile;
                   1982:                     } else {
                   1983:                         $showfile = $imgfile;
                   1984:                     }
                   1985:                 } else {
                   1986:                     $showfile = '';
                   1987:                 }
                   1988:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1989:                 $showfile = $imgfile;
1.6       raeburn  1990:                 my $imgdir = $1;
                   1991:                 my $filename = $2;
1.159     raeburn  1992:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1993:                     $showfile = "/$imgdir/tn-".$filename;
                   1994:                 } else {
1.159     raeburn  1995:                     my $input = $londocroot.$imgfile;
                   1996:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1997:                     if (!-e $output) {
1.9       raeburn  1998:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1999:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   2000:                         if ($fullwidth ne '' && $fullheight ne '') {
                   2001:                             if ($fullwidth > $width && $fullheight > $height) { 
                   2002:                                 my $size = $width.'x'.$height;
1.160.6.88  raeburn  2003:                                 my @args = ('convert','-sample',$size,$input,$output);
                   2004:                                 system({$args[0]} @args);
1.159     raeburn  2005:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  2006:                             }
                   2007:                         }
1.6       raeburn  2008:                     }
                   2009:                 }
1.16      raeburn  2010:             }
1.6       raeburn  2011:             if ($showfile) {
1.40      raeburn  2012:                 if ($showfile =~ m{^/(adm|res)/}) {
                   2013:                     if ($showfile =~ m{^/res/}) {
                   2014:                         my $local_showfile =
                   2015:                             &Apache::lonnet::filelocation('',$showfile);
                   2016:                         &Apache::lonnet::repcopy($local_showfile);
                   2017:                     }
                   2018:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   2019:                 }
                   2020:                 if ($imgfile) {
                   2021:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   2022:                         if ($imgfile =~ m{^/res/}) {
                   2023:                             my $local_imgfile =
                   2024:                                 &Apache::lonnet::filelocation('',$imgfile);
                   2025:                             &Apache::lonnet::repcopy($local_imgfile);
                   2026:                         }
                   2027:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   2028:                     } else {
                   2029:                         $fullsize = $imgfile;
                   2030:                     }
                   2031:                 }
1.41      raeburn  2032:                 $datatable .= '<td>';
                   2033:                 if ($img eq 'login') {
1.135     bisitz   2034:                     $datatable .= $login_hdr_pick;
                   2035:                 } 
1.41      raeburn  2036:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   2037:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  2038:             } else {
1.160.6.22  raeburn  2039:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2040:                               &mt('Upload:').'<br />';
1.6       raeburn  2041:             }
                   2042:         } else {
1.160.6.22  raeburn  2043:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   2044:                           &mt('Upload:').'<br />';
1.6       raeburn  2045:         }
1.9       raeburn  2046:         if ($switchserver) {
                   2047:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2048:         } else {
1.135     bisitz   2049:             if ($img ne 'login') { # suppress file selection for Log-in header
                   2050:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   2051:             }
1.9       raeburn  2052:         }
1.160.6.118.2  2(raebur 2053:2):         if (($role eq 'login') && ($img ne 'login')) {
                   2054:2):             $datatable .= ('&nbsp;' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
                   2055:2):                           '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
                   2056:2):                           '</label></span>';
                   2057:2):         }
1.9       raeburn  2058:         $datatable .= '</td></tr>';
1.6       raeburn  2059:     }
                   2060:     $itemcount ++;
                   2061:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2062:     $datatable .= '<tr'.$css_class.'>'.
                   2063:                   '<td>'.$choices->{'bgs'}.'</td>';
                   2064:     my $bgs_def;
                   2065:     foreach my $item (@{$bgs}) {
                   2066:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  2067:             $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  2068:         }
                   2069:     }
                   2070:     if ($bgs_def) {
1.8       raeburn  2071:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  2072:     } else {
                   2073:         $datatable .= '<td>&nbsp;</td>';
                   2074:     }
                   2075:     $datatable .= '<td class="LC_right_item">'.
                   2076:                   '<table border="0"><tr>';
1.160.6.13  raeburn  2077: 
1.6       raeburn  2078:     foreach my $item (@{$bgs}) {
1.160.6.22  raeburn  2079:         $datatable .= '<td align="center">'.$choices->{$item};
                   2080: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  2081:         if ($designs->{'bgs'}{$item}) {
1.160.6.9  raeburn  2082:             $datatable .= '&nbsp;';
1.6       raeburn  2083:         }
1.160.6.9  raeburn  2084:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  2085:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  2086:     }
                   2087:     $datatable .= '</tr></table></td></tr>';
                   2088:     $itemcount ++;
                   2089:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2090:     $datatable .= '<tr'.$css_class.'>'.
                   2091:                   '<td>'.$choices->{'links'}.'</td>';
                   2092:     my $links_def;
                   2093:     foreach my $item (@{$links}) {
                   2094:         if (!$is_custom->{$item}) {
1.160.6.87  raeburn  2095:             $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  2096:         }
                   2097:     }
                   2098:     if ($links_def) {
1.8       raeburn  2099:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  2100:     } else {
                   2101:         $datatable .= '<td>&nbsp;</td>';
                   2102:     }
                   2103:     $datatable .= '<td class="LC_right_item">'.
                   2104:                   '<table border="0"><tr>';
                   2105:     foreach my $item (@{$links}) {
1.160.6.39  raeburn  2106: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22  raeburn  2107:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  2108:         if ($designs->{'links'}{$item}) {
1.160.6.9  raeburn  2109:             $datatable.='&nbsp;';
1.6       raeburn  2110:         }
1.160.6.9  raeburn  2111:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  2112:                       '" /></td>';
                   2113:     }
1.30      raeburn  2114:     $$rowtotal += $itemcount;
1.3       raeburn  2115:     return $datatable;
                   2116: }
                   2117: 
1.70      raeburn  2118: sub logo_display_options {
                   2119:     my ($img,$defaults,$designs) = @_;
                   2120:     my $checkedon;
                   2121:     if (ref($defaults) eq 'HASH') {
                   2122:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   2123:             if ($defaults->{'showlogo'}{$img}) {
                   2124:                 $checkedon = 'checked="checked" ';     
                   2125:             }
                   2126:         } 
                   2127:     }
                   2128:     if (ref($designs) eq 'HASH') {
                   2129:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   2130:             if (defined($designs->{'showlogo'}{$img})) {
                   2131:                 if ($designs->{'showlogo'}{$img} == 0) {
                   2132:                     $checkedon = '';
                   2133:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   2134:                     $checkedon = 'checked="checked" ';
                   2135:                 }
                   2136:             }
                   2137:         }
                   2138:     }
                   2139:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   2140:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   2141:            &mt('show').'</label>'."\n";
                   2142: }
                   2143: 
1.41      raeburn  2144: sub login_header_options  {
1.135     bisitz   2145:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   2146:     my $output = '';
1.41      raeburn  2147:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   2148:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  2149:         if (!$is_custom->{'textcol'}) {
                   2150:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   2151:                        '&nbsp;&nbsp;&nbsp;';
                   2152:         }
                   2153:         if (!$is_custom->{'bgcol'}) {
                   2154:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   2155:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   2156:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   2157:         }
                   2158:         $output .= '<br />';
                   2159:     }
                   2160:     $output .='<br />';
                   2161:     return $output;
                   2162: }
                   2163: 
                   2164: sub login_text_colors {
1.160.6.22  raeburn  2165:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  2166:     my $color_menu = '<table border="0"><tr>';
                   2167:     foreach my $item (@{$logintext}) {
1.160.6.22  raeburn  2168:         $color_menu .= '<td align="center">'.$choices->{$item};
                   2169:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   2170:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   2171:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  2172:     }
                   2173:     $color_menu .= '</tr></table><br />';
                   2174:     return $color_menu;
                   2175: }
                   2176: 
                   2177: sub image_changes {
                   2178:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   2179:     my $output;
1.135     bisitz   2180:     if ($img eq 'login') {
1.160.6.87  raeburn  2181:         $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135     bisitz   2182:     } elsif (!$is_custom) {
1.70      raeburn  2183:         if ($img ne 'domlogo') {
1.160.6.87  raeburn  2184:             $output = &mt('Default image:').'<br />';
1.41      raeburn  2185:         } else {
1.160.6.87  raeburn  2186:             $output = &mt('Default in use:').'<br />';
1.41      raeburn  2187:         }
                   2188:     }
1.160.6.87  raeburn  2189:     if ($img ne 'login') {
1.135     bisitz   2190:         if ($img_import) {
                   2191:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   2192:         }
                   2193:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   2194:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   2195:         if ($is_custom) {
                   2196:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   2197:                        '<input type="checkbox" name="'.
                   2198:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   2199:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   2200:         } else {
1.160.6.22  raeburn  2201:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   2202:         }
1.41      raeburn  2203:     }
                   2204:     return $output;
                   2205: }
                   2206: 
1.3       raeburn  2207: sub print_quotas {
1.86      raeburn  2208:     my ($dom,$settings,$rowtotal,$action) = @_;
                   2209:     my $context;
                   2210:     if ($action eq 'quotas') {
                   2211:         $context = 'tools';
                   2212:     } else {
                   2213:         $context = $action;
                   2214:     }
1.160.6.20  raeburn  2215:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  2216:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  2217:     my $typecount = 0;
1.101     raeburn  2218:     my ($css_class,%titles);
1.86      raeburn  2219:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  2220:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  2221:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  2222:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   2223:         %titles = &courserequest_titles();
1.160.6.5  raeburn  2224:     } elsif ($context eq 'requestauthor') {
                   2225:         @usertools = ('author');
                   2226:         @options = ('norequest','approval','automatic');
                   2227:         %titles = &authorrequest_titles();
1.86      raeburn  2228:     } else {
1.160.6.4  raeburn  2229:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  2230:         %titles = &tool_titles();
1.86      raeburn  2231:     }
1.26      raeburn  2232:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  2233:         foreach my $type (@{$types}) {
1.160.6.20  raeburn  2234:             my ($currdefquota,$currauthorquota);
1.160.6.5  raeburn  2235:             unless (($context eq 'requestcourses') ||
                   2236:                     ($context eq 'requestauthor')) {
1.86      raeburn  2237:                 if (ref($settings) eq 'HASH') {
                   2238:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20  raeburn  2239:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  2240:                     } else {
                   2241:                         $currdefquota = $settings->{$type};
                   2242:                     }
1.160.6.20  raeburn  2243:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   2244:                         $currauthorquota = $settings->{authorquota}->{$type};
                   2245:                     }
1.78      raeburn  2246:                 }
1.72      raeburn  2247:             }
1.3       raeburn  2248:             if (defined($usertypes->{$type})) {
                   2249:                 $typecount ++;
                   2250:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  2251:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  2252:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  2253:                               '<td class="LC_left_item">';
1.101     raeburn  2254:                 if ($context eq 'requestcourses') {
                   2255:                     $datatable .= '<table><tr>';
                   2256:                 }
                   2257:                 my %cell;  
1.72      raeburn  2258:                 foreach my $item (@usertools) {
1.101     raeburn  2259:                     if ($context eq 'requestcourses') {
                   2260:                         my ($curroption,$currlimit);
                   2261:                         if (ref($settings) eq 'HASH') {
                   2262:                             if (ref($settings->{$item}) eq 'HASH') {
                   2263:                                 $curroption = $settings->{$item}->{$type};
                   2264:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   2265:                                     $currlimit = $1; 
                   2266:                                 }
                   2267:                             }
                   2268:                         }
                   2269:                         if (!$curroption) {
                   2270:                             $curroption = 'norequest';
                   2271:                         }
                   2272:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   2273:                         foreach my $option (@options) {
                   2274:                             my $val = $option;
                   2275:                             if ($option eq 'norequest') {
                   2276:                                 $val = 0;  
                   2277:                             }
                   2278:                             if ($option eq 'validate') {
                   2279:                                 my $canvalidate = 0;
                   2280:                                 if (ref($validations{$item}) eq 'HASH') { 
                   2281:                                     if ($validations{$item}{$type}) {
                   2282:                                         $canvalidate = 1;
                   2283:                                     }
                   2284:                                 }
                   2285:                                 next if (!$canvalidate);
                   2286:                             }
                   2287:                             my $checked = '';
                   2288:                             if ($option eq $curroption) {
                   2289:                                 $checked = ' checked="checked"';
                   2290:                             } elsif ($option eq 'autolimit') {
                   2291:                                 if ($curroption =~ /^autolimit/) {
                   2292:                                     $checked = ' checked="checked"';
                   2293:                                 }                       
                   2294:                             } 
                   2295:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   2296:                                   '<input type="radio" name="crsreq_'.$item.
                   2297:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  2298:                                   $titles{$option}.'</label>';
1.101     raeburn  2299:                             if ($option eq 'autolimit') {
1.127     raeburn  2300:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2301:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  2302:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  2303:                             }
1.127     raeburn  2304:                             $cell{$item} .= '</span> ';
1.103     raeburn  2305:                             if ($option eq 'autolimit') {
1.127     raeburn  2306:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  2307:                             }
1.101     raeburn  2308:                         }
1.160.6.5  raeburn  2309:                     } elsif ($context eq 'requestauthor') {
                   2310:                         my $curroption;
                   2311:                         if (ref($settings) eq 'HASH') {
                   2312:                             $curroption = $settings->{$type};
                   2313:                         }
                   2314:                         if (!$curroption) {
                   2315:                             $curroption = 'norequest';
                   2316:                         }
                   2317:                         foreach my $option (@options) {
                   2318:                             my $val = $option;
                   2319:                             if ($option eq 'norequest') {
                   2320:                                 $val = 0;
                   2321:                             }
                   2322:                             my $checked = '';
                   2323:                             if ($option eq $curroption) {
                   2324:                                 $checked = ' checked="checked"';
                   2325:                             }
                   2326:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   2327:                                   '<input type="radio" name="authorreq_'.$type.
                   2328:                                   '" value="'.$val.'"'.$checked.' />'.
                   2329:                                   $titles{$option}.'</label></span>&nbsp; ';
                   2330:                         }
1.101     raeburn  2331:                     } else {
                   2332:                         my $checked = 'checked="checked" ';
                   2333:                         if (ref($settings) eq 'HASH') {
                   2334:                             if (ref($settings->{$item}) eq 'HASH') {
                   2335:                                 if ($settings->{$item}->{$type} == 0) {
                   2336:                                     $checked = '';
                   2337:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   2338:                                     $checked =  'checked="checked" ';
                   2339:                                 }
1.78      raeburn  2340:                             }
1.72      raeburn  2341:                         }
1.101     raeburn  2342:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   2343:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   2344:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   2345:                                       '</label></span>&nbsp; ';
1.72      raeburn  2346:                     }
1.101     raeburn  2347:                 }
                   2348:                 if ($context eq 'requestcourses') {
                   2349:                     $datatable .= '</tr><tr>';
                   2350:                     foreach my $item (@usertools) {
1.106     raeburn  2351:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  2352:                     }
                   2353:                     $datatable .= '</tr></table>';
1.72      raeburn  2354:                 }
1.86      raeburn  2355:                 $datatable .= '</td>';
1.160.6.5  raeburn  2356:                 unless (($context eq 'requestcourses') ||
                   2357:                         ($context eq 'requestauthor')) {
1.86      raeburn  2358:                     $datatable .= 
1.160.6.20  raeburn  2359:                               '<td class="LC_right_item">'.
                   2360:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  2361:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  2362:                               '" value="'.$currdefquota.
1.160.6.20  raeburn  2363:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   2364:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2365:                               '<input type="text" name="authorquota_'.$type.
                   2366:                               '" value="'.$currauthorquota.
                   2367:                               '" size="5" /></span></td>';
1.86      raeburn  2368:                 }
                   2369:                 $datatable .= '</tr>';
1.3       raeburn  2370:             }
                   2371:         }
                   2372:     }
1.160.6.5  raeburn  2373:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  2374:         $defaultquota = '20';
1.160.6.20  raeburn  2375:         $authorquota = '500';
1.86      raeburn  2376:         if (ref($settings) eq 'HASH') {
                   2377:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   2378:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   2379:             } elsif (defined($settings->{'default'})) {
                   2380:                 $defaultquota = $settings->{'default'};
                   2381:             }
1.160.6.20  raeburn  2382:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   2383:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   2384:             }
1.3       raeburn  2385:         }
                   2386:     }
                   2387:     $typecount ++;
                   2388:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2389:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  2390:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  2391:                   '<td class="LC_left_item">';
1.101     raeburn  2392:     if ($context eq 'requestcourses') {
                   2393:         $datatable .= '<table><tr>';
                   2394:     }
                   2395:     my %defcell;
1.72      raeburn  2396:     foreach my $item (@usertools) {
1.101     raeburn  2397:         if ($context eq 'requestcourses') {
                   2398:             my ($curroption,$currlimit);
                   2399:             if (ref($settings) eq 'HASH') {
                   2400:                 if (ref($settings->{$item}) eq 'HASH') {
                   2401:                     $curroption = $settings->{$item}->{'default'};
                   2402:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2403:                         $currlimit = $1;
                   2404:                     }
                   2405:                 }
                   2406:             }
                   2407:             if (!$curroption) {
                   2408:                 $curroption = 'norequest';
                   2409:             }
                   2410:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   2411:             foreach my $option (@options) {
                   2412:                 my $val = $option;
                   2413:                 if ($option eq 'norequest') {
                   2414:                     $val = 0;
                   2415:                 }
                   2416:                 if ($option eq 'validate') {
                   2417:                     my $canvalidate = 0;
                   2418:                     if (ref($validations{$item}) eq 'HASH') {
                   2419:                         if ($validations{$item}{'default'}) {
                   2420:                             $canvalidate = 1;
                   2421:                         }
                   2422:                     }
                   2423:                     next if (!$canvalidate);
                   2424:                 }
                   2425:                 my $checked = '';
                   2426:                 if ($option eq $curroption) {
                   2427:                     $checked = ' checked="checked"';
                   2428:                 } elsif ($option eq 'autolimit') {
                   2429:                     if ($curroption =~ /^autolimit/) {
                   2430:                         $checked = ' checked="checked"';
                   2431:                     }
                   2432:                 }
                   2433:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2434:                                   '<input type="radio" name="crsreq_'.$item.
                   2435:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   2436:                                   $titles{$option}.'</label>';
                   2437:                 if ($option eq 'autolimit') {
1.127     raeburn  2438:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2439:                                        $item.'_limit_default" size="1" '.
                   2440:                                        'value="'.$currlimit.'" />';
                   2441:                 }
1.127     raeburn  2442:                 $defcell{$item} .= '</span> ';
1.104     raeburn  2443:                 if ($option eq 'autolimit') {
1.127     raeburn  2444:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2445:                 }
1.101     raeburn  2446:             }
1.160.6.5  raeburn  2447:         } elsif ($context eq 'requestauthor') {
                   2448:             my $curroption;
                   2449:             if (ref($settings) eq 'HASH') {
1.160.6.8  raeburn  2450:                 $curroption = $settings->{'default'};
1.160.6.5  raeburn  2451:             }
                   2452:             if (!$curroption) {
                   2453:                 $curroption = 'norequest';
                   2454:             }
                   2455:             foreach my $option (@options) {
                   2456:                 my $val = $option;
                   2457:                 if ($option eq 'norequest') {
                   2458:                     $val = 0;
                   2459:                 }
                   2460:                 my $checked = '';
                   2461:                 if ($option eq $curroption) {
                   2462:                     $checked = ' checked="checked"';
                   2463:                 }
                   2464:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2465:                               '<input type="radio" name="authorreq_default"'.
                   2466:                               ' value="'.$val.'"'.$checked.' />'.
                   2467:                               $titles{$option}.'</label></span>&nbsp; ';
                   2468:             }
1.101     raeburn  2469:         } else {
                   2470:             my $checked = 'checked="checked" ';
                   2471:             if (ref($settings) eq 'HASH') {
                   2472:                 if (ref($settings->{$item}) eq 'HASH') {
                   2473:                     if ($settings->{$item}->{'default'} == 0) {
                   2474:                         $checked = '';
                   2475:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2476:                         $checked = 'checked="checked" ';
                   2477:                     }
1.78      raeburn  2478:                 }
1.72      raeburn  2479:             }
1.101     raeburn  2480:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2481:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2482:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2483:                           '</label></span>&nbsp; ';
                   2484:         }
                   2485:     }
                   2486:     if ($context eq 'requestcourses') {
                   2487:         $datatable .= '</tr><tr>';
                   2488:         foreach my $item (@usertools) {
1.106     raeburn  2489:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2490:         }
1.101     raeburn  2491:         $datatable .= '</tr></table>';
1.72      raeburn  2492:     }
1.86      raeburn  2493:     $datatable .= '</td>';
1.160.6.5  raeburn  2494:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20  raeburn  2495:         $datatable .= '<td class="LC_right_item">'.
                   2496:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2497:                       '<input type="text" name="defaultquota" value="'.
1.160.6.20  raeburn  2498:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2499:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2500:                       '<input type="text" name="authorquota" value="'.
                   2501:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2502:     }
                   2503:     $datatable .= '</tr>';
1.72      raeburn  2504:     $typecount ++;
                   2505:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2506:     $datatable .= '<tr'.$css_class.'>'.
1.160.6.20  raeburn  2507:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2508:     if ($context eq 'requestcourses') {
1.109     raeburn  2509:         $datatable .= &mt('(overrides affiliation, if set)').
                   2510:                       '</td>'.
                   2511:                       '<td class="LC_left_item">'.
                   2512:                       '<table><tr>';
1.101     raeburn  2513:     } else {
1.109     raeburn  2514:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2515:                       '</td>'.
                   2516:                       '<td class="LC_left_item" colspan="2">'.
                   2517:                       '<br />';
1.101     raeburn  2518:     }
                   2519:     my %advcell;
1.72      raeburn  2520:     foreach my $item (@usertools) {
1.101     raeburn  2521:         if ($context eq 'requestcourses') {
                   2522:             my ($curroption,$currlimit);
                   2523:             if (ref($settings) eq 'HASH') {
                   2524:                 if (ref($settings->{$item}) eq 'HASH') {
                   2525:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2526:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2527:                         $currlimit = $1;
                   2528:                     }
                   2529:                 }
                   2530:             }
                   2531:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2532:             my $checked = '';
                   2533:             if ($curroption eq '') {
                   2534:                 $checked = ' checked="checked"';
                   2535:             }
                   2536:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2537:                                '<input type="radio" name="crsreq_'.$item.
                   2538:                                '__LC_adv" value=""'.$checked.' />'.
                   2539:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2540:             foreach my $option (@options) {
                   2541:                 my $val = $option;
                   2542:                 if ($option eq 'norequest') {
                   2543:                     $val = 0;
                   2544:                 }
                   2545:                 if ($option eq 'validate') {
                   2546:                     my $canvalidate = 0;
                   2547:                     if (ref($validations{$item}) eq 'HASH') {
                   2548:                         if ($validations{$item}{'_LC_adv'}) {
                   2549:                             $canvalidate = 1;
                   2550:                         }
                   2551:                     }
                   2552:                     next if (!$canvalidate);
                   2553:                 }
                   2554:                 my $checked = '';
1.104     raeburn  2555:                 if ($val eq $curroption) {
1.101     raeburn  2556:                     $checked = ' checked="checked"';
                   2557:                 } elsif ($option eq 'autolimit') {
                   2558:                     if ($curroption =~ /^autolimit/) {
                   2559:                         $checked = ' checked="checked"';
                   2560:                     }
                   2561:                 }
                   2562:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2563:                                   '<input type="radio" name="crsreq_'.$item.
                   2564:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2565:                                   $titles{$option}.'</label>';
                   2566:                 if ($option eq 'autolimit') {
1.127     raeburn  2567:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2568:                                        $item.'_limit__LC_adv" size="1" '.
                   2569:                                        'value="'.$currlimit.'" />';
                   2570:                 }
1.127     raeburn  2571:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2572:                 if ($option eq 'autolimit') {
1.127     raeburn  2573:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2574:                 }
1.101     raeburn  2575:             }
1.160.6.5  raeburn  2576:         } elsif ($context eq 'requestauthor') {
                   2577:             my $curroption;
                   2578:             if (ref($settings) eq 'HASH') {
                   2579:                 $curroption = $settings->{'_LC_adv'};
                   2580:             }
                   2581:             my $checked = '';
                   2582:             if ($curroption eq '') {
                   2583:                 $checked = ' checked="checked"';
                   2584:             }
                   2585:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2586:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2587:                           ' value=""'.$checked.' />'.
                   2588:                           &mt('No override set').'</label></span>&nbsp; ';
                   2589:             foreach my $option (@options) {
                   2590:                 my $val = $option;
                   2591:                 if ($option eq 'norequest') {
                   2592:                     $val = 0;
                   2593:                 }
                   2594:                 my $checked = '';
                   2595:                 if ($val eq $curroption) {
                   2596:                     $checked = ' checked="checked"';
                   2597:                 }
                   2598:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8  raeburn  2599:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2600:                               ' value="'.$val.'"'.$checked.' />'.
1.160.6.5  raeburn  2601:                               $titles{$option}.'</label></span>&nbsp; ';
                   2602:             }
1.101     raeburn  2603:         } else {
                   2604:             my $checked = 'checked="checked" ';
                   2605:             if (ref($settings) eq 'HASH') {
                   2606:                 if (ref($settings->{$item}) eq 'HASH') {
                   2607:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2608:                         $checked = '';
                   2609:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2610:                         $checked = 'checked="checked" ';
                   2611:                     }
1.79      raeburn  2612:                 }
1.72      raeburn  2613:             }
1.101     raeburn  2614:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2615:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2616:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2617:                           '</label></span>&nbsp; ';
                   2618:         }
                   2619:     }
                   2620:     if ($context eq 'requestcourses') {
                   2621:         $datatable .= '</tr><tr>';
                   2622:         foreach my $item (@usertools) {
1.106     raeburn  2623:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2624:         }
1.101     raeburn  2625:         $datatable .= '</tr></table>';
1.72      raeburn  2626:     }
1.98      raeburn  2627:     $datatable .= '</td></tr>';
1.30      raeburn  2628:     $$rowtotal += $typecount;
1.3       raeburn  2629:     return $datatable;
                   2630: }
                   2631: 
1.160.6.5  raeburn  2632: sub print_requestmail {
1.160.6.93  raeburn  2633:     my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25  raeburn  2634:     my ($now,$datatable,%currapp);
1.102     raeburn  2635:     $now = time;
                   2636:     if (ref($settings) eq 'HASH') {
                   2637:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2638:             if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34  raeburn  2639:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2640:             }
                   2641:         }
                   2642:     }
1.160.6.16  raeburn  2643:     my $numinrow = 2;
1.160.6.34  raeburn  2644:     my $css_class;
1.160.6.93  raeburn  2645:     if ($$rowtotal%2) {
                   2646:         $css_class = 'LC_odd_row';
                   2647:     }
                   2648:     if ($customcss) {
                   2649:         $css_class .= " $customcss";
                   2650:     }
                   2651:     $css_class =~ s/^\s+//;
                   2652:     if ($css_class) {
                   2653:         $css_class = ' class="'.$css_class.'"';
                   2654:     }
                   2655:     if ($rowstyle) {
                   2656:         $css_class .= ' style="'.$rowstyle.'"';
                   2657:     }
1.160.6.5  raeburn  2658:     my $text;
                   2659:     if ($action eq 'requestcourses') {
                   2660:         $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34  raeburn  2661:     } elsif ($action eq 'requestauthor') {
                   2662:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5  raeburn  2663:     } else {
1.160.6.34  raeburn  2664:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5  raeburn  2665:     }
1.160.6.34  raeburn  2666:     $datatable = '<tr'.$css_class.'>'.
1.160.6.5  raeburn  2667:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2668:                  ' <td class="LC_left_item">';
1.160.6.16  raeburn  2669:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34  raeburn  2670:                                                  $action.'notifyapproval',%currapp);
1.160.6.16  raeburn  2671:     if ($numdc > 0) {
                   2672:         $datatable .= $table;
1.102     raeburn  2673:     } else {
                   2674:         $datatable .= &mt('There are no active Domain Coordinators');
                   2675:     }
                   2676:     $datatable .='</td></tr>';
                   2677:     return $datatable;
                   2678: }
                   2679: 
1.160.6.30  raeburn  2680: sub print_studentcode {
                   2681:     my ($settings,$rowtotal) = @_;
                   2682:     my $rownum = 0; 
                   2683:     my ($output,%current);
                   2684:     my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51  raeburn  2685:     if (ref($settings) eq 'HASH') {
                   2686:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2687:             foreach my $type (@crstypes) {
                   2688:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2689:             }
1.160.6.30  raeburn  2690:         }
                   2691:     }
                   2692:     $output .= '<tr>'.
                   2693:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2694:                '<td class="LC_left_item">';
                   2695:     foreach my $type (@crstypes) {
                   2696:         my $check = ' ';
                   2697:         if ($current{$type}) {
                   2698:             $check = ' checked="checked" ';
                   2699:         }
                   2700:         $output .= '<span class="LC_nobreak"><label>'.
                   2701:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2702:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2703:     }
                   2704:     $output .= '</td></tr>';
                   2705:     $$rowtotal ++;
                   2706:     return $output;
                   2707: }
                   2708: 
                   2709: sub print_textbookcourses {
1.160.6.46  raeburn  2710:     my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30  raeburn  2711:     my $rownum = 0;
                   2712:     my $css_class;
                   2713:     my $itemcount = 1;
                   2714:     my $maxnum = 0;
                   2715:     my $bookshash;
                   2716:     if (ref($settings) eq 'HASH') {
1.160.6.46  raeburn  2717:         $bookshash = $settings->{$type};
1.160.6.30  raeburn  2718:     }
                   2719:     my %ordered;
                   2720:     if (ref($bookshash) eq 'HASH') {
                   2721:         foreach my $item (keys(%{$bookshash})) {
                   2722:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2723:                 my $num = $bookshash->{$item}{'order'};
                   2724:                 $ordered{$num} = $item;
                   2725:             }
                   2726:         }
                   2727:     }
                   2728:     my $confname = $dom.'-domainconfig';
                   2729:     my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46  raeburn  2730:     my $maxnum = scalar(keys(%ordered));
                   2731:     my $datatable;
1.160.6.30  raeburn  2732:     if (keys(%ordered)) {
                   2733:         my @items = sort { $a <=> $b } keys(%ordered);
                   2734:         for (my $i=0; $i<@items; $i++) {
                   2735:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2736:             my $key = $ordered{$items[$i]};
                   2737:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2738:             my $coursetitle = $coursehash{'description'};
1.160.6.47  raeburn  2739:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30  raeburn  2740:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2741:                 $subject = $bookshash->{$key}->{'subject'};
                   2742:                 $title = $bookshash->{$key}->{'title'};
1.160.6.46  raeburn  2743:                 if ($type eq 'textbooks') {
1.160.6.47  raeburn  2744:                     $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46  raeburn  2745:                     $author = $bookshash->{$key}->{'author'};
                   2746:                     $image = $bookshash->{$key}->{'image'};
                   2747:                     if ($image ne '') {
                   2748:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2749:                         my $imagethumb = "$path/tn-".$imagefile;
                   2750:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2751:                     }
1.160.6.30  raeburn  2752:                 }
                   2753:             }
1.160.6.46  raeburn  2754:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30  raeburn  2755:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46  raeburn  2756:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30  raeburn  2757:             for (my $k=0; $k<=$maxnum; $k++) {
                   2758:                 my $vpos = $k+1;
                   2759:                 my $selstr;
                   2760:                 if ($k == $i) {
                   2761:                     $selstr = ' selected="selected" ';
                   2762:                 }
                   2763:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2764:             }
                   2765:             $datatable .= '</select>'.('&nbsp;'x2).
1.160.6.46  raeburn  2766:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30  raeburn  2767:                 &mt('Delete?').'</label></span></td>'.
                   2768:                 '<td colspan="2">'.
1.160.6.46  raeburn  2769:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30  raeburn  2770:                 ('&nbsp;'x2).
1.160.6.46  raeburn  2771:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2772:             if ($type eq 'textbooks') {
                   2773:                 $datatable .= ('&nbsp;'x2).
1.160.6.47  raeburn  2774:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2775:                               ('&nbsp;'x2).
1.160.6.46  raeburn  2776:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2777:                               ('&nbsp;'x2).
                   2778:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2779:                 if ($image) {
1.160.6.114  raeburn  2780:                     $datatable .= $imgsrc.
1.160.6.46  raeburn  2781:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2782:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2783:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2784:                 }
                   2785:                 if ($switchserver) {
                   2786:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2787:                 } else {
                   2788:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2789:                 }
1.160.6.30  raeburn  2790:             }
1.160.6.46  raeburn  2791:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30  raeburn  2792:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2793:                           $coursetitle.'</span></td></tr>'."\n";
                   2794:             $itemcount ++;
                   2795:         }
                   2796:     }
                   2797:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46  raeburn  2798:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30  raeburn  2799:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46  raeburn  2800:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2801:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30  raeburn  2802:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2803:         my $vpos = $k+1;
                   2804:         my $selstr;
                   2805:         if ($k == $maxnum) {
                   2806:             $selstr = ' selected="selected" ';
                   2807:         }
                   2808:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2809:     }
                   2810:     $datatable .= '</select>&nbsp;'."\n".
1.160.6.87  raeburn  2811:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30  raeburn  2812:                   '<td colspan="2">'.
1.160.6.46  raeburn  2813:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30  raeburn  2814:                   ('&nbsp;'x2).
1.160.6.46  raeburn  2815:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2816:                   ('&nbsp;'x2);
                   2817:     if ($type eq 'textbooks') {
1.160.6.47  raeburn  2818:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2819:                       ('&nbsp;'x2).
                   2820:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46  raeburn  2821:                       ('&nbsp;'x2).
                   2822:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2823:         if ($switchserver) {
                   2824:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2825:         } else {
                   2826:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2827:         }
1.160.6.87  raeburn  2828:         $datatable .= '</span>'."\n";
1.160.6.30  raeburn  2829:     }
1.160.6.87  raeburn  2830:     $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.160.6.46  raeburn  2831:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2832:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30  raeburn  2833:                   &Apache::loncommon::selectcourse_link
1.160.6.87  raeburn  2834:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30  raeburn  2835:                   '</span></td>'."\n".
                   2836:                   '</tr>'."\n";
                   2837:     $itemcount ++;
                   2838:     return $datatable;
                   2839: }
                   2840: 
                   2841: sub textbookcourses_javascript {
1.160.6.46  raeburn  2842:     my ($settings) = @_;
                   2843:     return unless(ref($settings) eq 'HASH');
                   2844:     my (%ordered,%total,%jstext);
                   2845:     foreach my $type ('textbooks','templates') {
                   2846:         $total{$type} = 0;
                   2847:         if (ref($settings->{$type}) eq 'HASH') {
                   2848:             foreach my $item (keys(%{$settings->{$type}})) {
                   2849:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2850:                     my $num = $settings->{$type}->{$item}{'order'};
                   2851:                     $ordered{$type}{$num} = $item;
                   2852:                 }
                   2853:             }
                   2854:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2855:         }
                   2856:         my @jsarray = ();
                   2857:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2858:             push(@jsarray,$ordered{$type}{$item});
                   2859:         }
                   2860:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30  raeburn  2861:     }
                   2862:     return <<"ENDSCRIPT";
                   2863: <script type="text/javascript">
                   2864: // <![CDATA[
1.160.6.46  raeburn  2865: function reorderBooks(form,item,caller) {
1.160.6.30  raeburn  2866:     var changedVal;
1.160.6.46  raeburn  2867: $jstext{'textbooks'};
                   2868: $jstext{'templates'};
                   2869:     var newpos;
                   2870:     var maxh;
                   2871:     if (caller == 'textbooks') {  
                   2872:         newpos = 'textbooks_addbook_pos';
                   2873:         maxh = 1 + $total{'textbooks'};
                   2874:     } else {
                   2875:         newpos = 'templates_addbook_pos';
                   2876:         maxh = 1 + $total{'templates'};
                   2877:     }
1.160.6.30  raeburn  2878:     var current = new Array;
                   2879:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2880:     if (item == newpos) {
                   2881:         changedVal = newitemVal;
                   2882:     } else {
                   2883:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2884:         current[newitemVal] = newpos;
                   2885:     }
1.160.6.46  raeburn  2886:     if (caller == 'textbooks') {
                   2887:         for (var i=0; i<textbooks.length; i++) {
                   2888:             var elementName = 'textbooks_'+textbooks[i];
                   2889:             if (elementName != item) {
                   2890:                 if (form.elements[elementName]) {
                   2891:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2892:                     current[currVal] = elementName;
                   2893:                 }
                   2894:             }
                   2895:         }
                   2896:     }
                   2897:     if (caller == 'templates') {
                   2898:         for (var i=0; i<templates.length; i++) {
                   2899:             var elementName = 'templates_'+templates[i];
                   2900:             if (elementName != item) {
                   2901:                 if (form.elements[elementName]) {
                   2902:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2903:                     current[currVal] = elementName;
                   2904:                 }
1.160.6.30  raeburn  2905:             }
                   2906:         }
                   2907:     }
                   2908:     var oldVal;
                   2909:     for (var j=0; j<maxh; j++) {
                   2910:         if (current[j] == undefined) {
                   2911:             oldVal = j;
                   2912:         }
                   2913:     }
                   2914:     if (oldVal < changedVal) {
                   2915:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2916:            var elementName = current[k];
                   2917:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2918:         }
                   2919:     } else {
                   2920:         for (var k=changedVal; k<oldVal; k++) {
                   2921:             var elementName = current[k];
                   2922:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2923:         }
                   2924:     }
                   2925:     return;
                   2926: }
                   2927: 
                   2928: // ]]>
                   2929: </script>
                   2930: 
                   2931: ENDSCRIPT
                   2932: }
                   2933: 
1.160.6.118.2  1(raebur 2934:1): sub ltitools_javascript {
                   2935:1):     my ($settings) = @_;
                   2936:1):     my $togglejs = &ltitools_toggle_js();
                   2937:1):     unless (ref($settings) eq 'HASH') {
                   2938:1):         return $togglejs;
                   2939:1):     }
                   2940:1):     my (%ordered,$total,%jstext);
                   2941:1):     $total = 0;
                   2942:1):     foreach my $item (keys(%{$settings})) {
                   2943:1):         if (ref($settings->{$item}) eq 'HASH') {
                   2944:1):             my $num = $settings->{$item}{'order'};
                   2945:1):             $ordered{$num} = $item;
                   2946:1):         }
                   2947:1):     }
                   2948:1):     $total = scalar(keys(%{$settings}));
                   2949:1):     my @jsarray = ();
                   2950:1):     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2951:1):         push(@jsarray,$ordered{$item});
                   2952:1):     }
                   2953:1):     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2954:1):     return <<"ENDSCRIPT";
                   2955:1): <script type="text/javascript">
                   2956:1): // <![CDATA[
                   2957:1): function reorderLTITools(form,item) {
                   2958:1):     var changedVal;
                   2959:1): $jstext
                   2960:1):     var newpos = 'ltitools_add_pos';
                   2961:1):     var maxh = 1 + $total;
                   2962:1):     var current = new Array;
                   2963:1):     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2964:1):     if (item == newpos) {
                   2965:1):         changedVal = newitemVal;
                   2966:1):     } else {
                   2967:1):         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2968:1):         current[newitemVal] = newpos;
                   2969:1):     }
                   2970:1):     for (var i=0; i<ltitools.length; i++) {
                   2971:1):         var elementName = 'ltitools_'+ltitools[i];
                   2972:1):         if (elementName != item) {
                   2973:1):             if (form.elements[elementName]) {
                   2974:1):                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2975:1):                 current[currVal] = elementName;
                   2976:1):             }
                   2977:1):         }
                   2978:1):     }
                   2979:1):     var oldVal;
                   2980:1):     for (var j=0; j<maxh; j++) {
                   2981:1):         if (current[j] == undefined) {
                   2982:1):             oldVal = j;
                   2983:1):         }
                   2984:1):     }
                   2985:1):     if (oldVal < changedVal) {
                   2986:1):         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2987:1):            var elementName = current[k];
                   2988:1):            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2989:1):         }
                   2990:1):     } else {
                   2991:1):         for (var k=changedVal; k<oldVal; k++) {
                   2992:1):             var elementName = current[k];
                   2993:1):             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2994:1):         }
                   2995:1):     }
                   2996:1):     return;
                   2997:1): }
                   2998:1): 
                   2999:1): // ]]>
                   3000:1): </script>
                   3001:1): 
                   3002:1): $togglejs
                   3003:1): 
                   3004:1): ENDSCRIPT
                   3005:1): }
                   3006:1): 
                   3007:1): sub ltitools_toggle_js {
                   3008:1):     return <<"ENDSCRIPT";
                   3009:1): <script type="text/javascript">
                   3010:1): // <![CDATA[
                   3011:1): 
                   3012:1): function toggleLTITools(form,setting,item) {
                   3013:1):     var radioname = '';
                   3014:1):     var divid = '';
                   3015:1):     if (setting == 'user') {
                   3016:1):         divid = 'ltitools_'+setting+'_div_'+item;
                   3017:1):         var checkid = 'ltitools_'+setting+'_field_'+item;
                   3018:1):         if (document.getElementById(divid)) {
                   3019:1):             if (document.getElementById(checkid)) {
                   3020:1):                 if (document.getElementById(checkid).checked) {
                   3021:1):                     document.getElementById(divid).style.display = 'inline-block';
                   3022:1):                 } else {
                   3023:1):                     document.getElementById(divid).style.display = 'none';
                   3024:1):                 }
                   3025:1):             }
                   3026:1):         }
                   3027:1):     }
                   3028:1):     return;
                   3029:1): }
                   3030:1): // ]]>
                   3031:1): </script>
                   3032:1): 
                   3033:1): ENDSCRIPT
                   3034:1): }
                   3035:1): 
1.160.6.113  raeburn  3036: sub wafproxy_javascript {
                   3037:     my ($dom) = @_;
                   3038:     return <<"ENDSCRIPT";
                   3039: <script type="text/javascript">
                   3040: // <![CDATA[
                   3041: function updateWAF() {
                   3042:     if (document.getElementById('wafproxy_remoteip')) {
                   3043:         var wafremote = 0;
                   3044:         if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
                   3045:             wafremote = 1;
                   3046:         }
                   3047:         var fields = new Array('header','trust');
                   3048:         for (var i=0; i<fields.length; i++) {
                   3049:             if (document.getElementById('wafproxy_'+fields[i])) {
                   3050:                 if (wafremote == 1) {
                   3051:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
                   3052:                 }
                   3053:                 else {
                   3054:                     document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
                   3055:                 }
                   3056:             }
                   3057:         }
                   3058:         if (document.getElementById('wafproxyranges_$dom')) {
                   3059:             if (wafremote == 1) {
                   3060:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3061:             } else {
                   3062:                 for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3063:                     if (document.display.wafproxy_vpnaccess[i].checked) {
                   3064:                         if (document.display.wafproxy_vpnaccess[i].value == 0) {
                   3065:                             document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3066:                         }
                   3067:                     }
                   3068:                 }
                   3069:             }
                   3070:         }
                   3071:     }
                   3072:     return;
                   3073: }
                   3074: 
                   3075: function checkWAF() {
                   3076:     if (document.getElementById('wafproxy_remoteip')) {
                   3077:         var wafvpn = 0;
                   3078:         for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
                   3079:             if (document.display.wafproxy_vpnaccess[i].checked) {
                   3080:                 if (document.display.wafproxy_vpnaccess[i].value == 1) {
                   3081:                     wafvpn = 1;
                   3082:                 }
                   3083:                 break;
                   3084:             }
                   3085:         }
                   3086:         var vpn = new Array('vpnint','vpnext');
                   3087:         for (var i=0; i<vpn.length; i++) {
                   3088:             if (document.getElementById('wafproxy_show_'+vpn[i])) {
                   3089:                 if (wafvpn == 1) {
                   3090:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
                   3091:                 }
                   3092:                 else {
                   3093:                     document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
                   3094:                 }
                   3095:             }
                   3096:         }
                   3097:         if (document.getElementById('wafproxyranges_$dom')) {
                   3098:             if (wafvpn == 1) {
                   3099:                 document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
                   3100:             }
                   3101:             else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
                   3102:                 document.getElementById('wafproxyranges_$dom').style.display = 'none';
                   3103:             }
                   3104:         }
                   3105:     }
                   3106:     return;
                   3107: }
                   3108: 
                   3109: function toggleWAF() {
                   3110:     if (document.getElementById('wafproxy_table')) {
                   3111:         var wafproxy = 0;
                   3112:         for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
                   3113:              if (document.display.wafproxy_${dom}[i].checked) {
                   3114:                  if (document.display.wafproxy_${dom}[i].value == 1) {
                   3115:                      wafproxy = 1;
                   3116:                      break;
                   3117:                 }
                   3118:             }
                   3119:         }
                   3120:         if (wafproxy == 1) {
                   3121:             document.getElementById('wafproxy_table').style.display='inline';
                   3122:         }
                   3123:         else {
                   3124:            document.getElementById('wafproxy_table').style.display='none';
                   3125:         }
                   3126:         if (document.getElementById('wafproxyrow_${dom}')) {
                   3127:             if (wafproxy == 1) {
                   3128:                 document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
                   3129:             }
                   3130:             else {
                   3131:                 document.getElementById('wafproxyrow_${dom}').style.display = 'none';
                   3132:             }
                   3133:         }
                   3134:         if (document.getElementById('nowafproxyrow_$dom')) {
                   3135:             if (wafproxy == 1) {
                   3136:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
                   3137:             }
                   3138:             else {
                   3139:                 document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
                   3140:             }
                   3141:         }
                   3142:     }
                   3143:     return;
                   3144: }
                   3145: // ]]>
                   3146: </script>
                   3147: 
                   3148: ENDSCRIPT
                   3149: }
                   3150: 
1.160.6.118.2  5(raebur 3151:2): sub lti_javascript {
                   3152:2):     my ($dom,$settings) = @_;
                   3153:2):     my $togglejs = &lti_toggle_js($dom);
                   3154:2):     my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
                   3155:2):     return <<"ENDSCRIPT";
                   3156:2): <script type="text/javascript">
                   3157:2): // <![CDATA[
                   3158:2): 
                   3159:2): $linkprot_js
                   3160:2): 
                   3161:2): // ]]>
                   3162:2): </script>
                   3163:2): 
                   3164:2): $togglejs
                   3165:2): 
                   3166:2): ENDSCRIPT
                   3167:2): }
                   3168:2): 
                   3169:2): sub lti_toggle_js {
                   3170:2):     my ($dom) = @_;
                   3171:2):     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   3172:2):     my $primary = &Apache::lonnet::domain($dom,'primary');
                   3173:2):     my $course_servers = "'".join("','",keys(%servers))."'";
          6(raebur 3174:2):     return <<"ENDSCRIPT";
                   3175:2): <script type="text/javascript">
                   3176:2): // <![CDATA[
          5(raebur 3177:2): function toggleLTIEncKey(form) {
                   3178:2):     var shownhosts = new Array();
                   3179:2):     var hiddenhosts = new Array();
                   3180:2):     var forcourse = new Array($course_servers);
                   3181:2):     var fromdomain = '$primary';
                   3182:2):     var crsradio = form.elements['ltisec_crslinkprot'];
                   3183:2):     if (crsradio.length) {
                   3184:2):         for (var i=0; i<crsradio.length; i++) {
                   3185:2):             if (crsradio[i].checked) {
                   3186:2):                 if (crsradio[i].value == 1) {
                   3187:2):                     if (forcourse.length > 0) {
                   3188:2):                         for (var j=0; j<forcourse.length; j++) {
                   3189:2):                             if (!shownhosts.includes(forcourse[j])) {
                   3190:2):                                 shownhosts.push(forcourse[j]);
                   3191:2):                             }
                   3192:2):                         }
                   3193:2):                     }
                   3194:2):                 } else {
                   3195:2):                     if (forcourse.length > 0) {
                   3196:2):                         for (var j=0; j<forcourse.length; j++) {
                   3197:2):                             if (!hiddenhosts.includes(forcourse[j])) {
                   3198:2):                                 hiddenhosts.push(forcourse[j]);
                   3199:2):                             }
                   3200:2):                         }
                   3201:2):                     }
                   3202:2):                 }
                   3203:2):             }
                   3204:2):         }
                   3205:2):     }
                   3206:2):     var domradio = form.elements['ltisec_domlinkprot'];
                   3207:2):     if (domradio.length) {
                   3208:2):         for (var i=0; i<domradio.length; i++) {
                   3209:2):             if (domradio[i].checked) {
                   3210:2):                 if (domradio[i].value == 1) {
                   3211:2):                     if (!shownhosts.includes(fromdomain)) {
                   3212:2):                         shownhosts.push(fromdomain);
                   3213:2):                     }
                   3214:2):                 } else {
                   3215:2):                     if (!hiddenhosts.includes(fromdomain)) {
                   3216:2):                         hiddenhosts.push(fromdomain);
                   3217:2):                     }
                   3218:2):                 }
                   3219:2):             }
                   3220:2):         }
                   3221:2):     }
                   3222:2):     if (shownhosts.length > 0) {
                   3223:2):         for (var i=0; i<shownhosts.length; i++) {
                   3224:2):             if (document.getElementById('ltisec_info_'+shownhosts[i])) {
                   3225:2):                 document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
                   3226:2):             }
                   3227:2):         }
                   3228:2):         if (document.getElementById('ltisec_noprivkey')) {
                   3229:2):             document.getElementById('ltisec_noprivkey').style.display = 'none';
                   3230:2):         }
                   3231:2):     } else {
                   3232:2):         if (document.getElementById('ltisec_noprivkey')) {
                   3233:2):             document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
                   3234:2):         }
                   3235:2):     }
                   3236:2):     if (hiddenhosts.length > 0) {
                   3237:2):         for (var i=0; i<hiddenhosts.length; i++) {
                   3238:2):             if (!shownhosts.includes(hiddenhosts[i])) {
                   3239:2):                 if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
                   3240:2):                     document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
                   3241:2):                 }
                   3242:2):             }
                   3243:2):         }
                   3244:2):     }
                   3245:2):     return;
                   3246:2): }
                   3247:2): 
                   3248:2): function togglePrivKey(form,hostid) {
                   3249:2):     var radioname = '';
                   3250:2):     var currdivid = '';
                   3251:2):     var newdivid = '';
                   3252:2):     if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
                   3253:2):         (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
                   3254:2):         currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
                   3255:2):         newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
                   3256:2):         radioname = form.elements['ltisec_changeprivkey_'+hostid];
                   3257:2):         if (radioname) {
                   3258:2):             if (radioname.length > 0) {
                   3259:2):                 var setvis;
                   3260:2):                 for (var i=0; i<radioname.length; i++) {
                   3261:2):                     if (radioname[i].checked == true) {
                   3262:2):                         if (radioname[i].value == 1) {
                   3263:2):                             newdivid.style.display = 'inline-block';
                   3264:2):                             currdivid.style.display = 'none';
                   3265:2):                             setvis = 1;
                   3266:2):                         }
                   3267:2):                         break;
                   3268:2):                     }
                   3269:2):                 }
                   3270:2):                 if (!setvis) {
                   3271:2):                     newdivid.style.display = 'none';
                   3272:2):                     currdivid.style.display = 'inline-block';
                   3273:2):                 }
                   3274:2):             }
                   3275:2):         }
                   3276:2):     }
                   3277:2): }
                   3278:2): 
                   3279:2): // ]]>
                   3280:2): </script>
                   3281:2): 
                   3282:2): ENDSCRIPT
                   3283:2): }
                   3284:2): 
1.160.6.113  raeburn  3285: sub autoupdate_javascript {
                   3286:     return <<"ENDSCRIPT";
                   3287: <script type="text/javascript">
                   3288: // <![CDATA[
                   3289: function toggleLastActiveDays(form) {
                   3290:     var radioname = 'lastactive';
                   3291:     var divid = 'lastactive_div';
                   3292:     var num = form.elements[radioname].length;
                   3293:     if (num) {
                   3294:         var setvis = '';
                   3295:         for (var i=0; i<num; i++) {
                   3296:             if (form.elements[radioname][i].checked) {
                   3297:                 if (form.elements[radioname][i].value == '1') {
                   3298:                     if (document.getElementById(divid)) {
                   3299:                         document.getElementById(divid).style.display = 'inline-block';
                   3300:                     }
                   3301:                     setvis = 1;
                   3302:                 }
                   3303:                 break;
                   3304:             }
                   3305:         }
                   3306:         if (!setvis) {
                   3307:             if (document.getElementById(divid)) {
                   3308:                 document.getElementById(divid).style.display = 'none';
                   3309:             }
                   3310:         }
                   3311:     }
                   3312:     return;
                   3313: }
                   3314: // ]]>
                   3315: </script>
                   3316: 
                   3317: ENDSCRIPT
                   3318: }
                   3319: 
1.160.6.116  raeburn  3320: sub autoenroll_javascript {
                   3321:     return <<"ENDSCRIPT";
                   3322: <script type="text/javascript">
                   3323: // <![CDATA[
                   3324: function toggleFailsafe(form) {
                   3325:     var radioname = 'autoenroll_failsafe';
                   3326:     var divid = 'autoenroll_failsafe_div';
                   3327:     var num = form.elements[radioname].length;
                   3328:     if (num) {
                   3329:         var setvis = '';
                   3330:         for (var i=0; i<num; i++) {
                   3331:             if (form.elements[radioname][i].checked) {
                   3332:                 if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
                   3333:                     if (document.getElementById(divid)) {
                   3334:                         document.getElementById(divid).style.display = 'inline-block';
                   3335:                     }
                   3336:                     setvis = 1;
                   3337:                 }
                   3338:                 break;
                   3339:             }
                   3340:         }
                   3341:         if (!setvis) {
                   3342:             if (document.getElementById(divid)) {
                   3343:                 document.getElementById(divid).style.display = 'none';
                   3344:             }
                   3345:         }
                   3346:     }
                   3347:     return;
                   3348: }
                   3349: // ]]>
                   3350: </script>
                   3351: 
                   3352: ENDSCRIPT
                   3353: }
                   3354: 
1.160.6.113  raeburn  3355: sub saml_javascript {
                   3356:     return <<"ENDSCRIPT";
                   3357: <script type="text/javascript">
                   3358: // <![CDATA[
                   3359: function toggleSamlOptions(form,hostid) {
                   3360:     var radioname = 'saml_'+hostid;
                   3361:     var tablecellon = 'samloptionson_'+hostid;
                   3362:     var tablecelloff = 'samloptionsoff_'+hostid;
                   3363:     var num = form.elements[radioname].length;
                   3364:     if (num) {
                   3365:         var setvis = '';
                   3366:         for (var i=0; i<num; i++) {
                   3367:             if (form.elements[radioname][i].checked) {
                   3368:                 if (form.elements[radioname][i].value == '1') {
                   3369:                     if (document.getElementById(tablecellon)) {
                   3370:                         document.getElementById(tablecellon).style.display='';
                   3371:                     }
                   3372:                     if (document.getElementById(tablecelloff)) {
                   3373:                         document.getElementById(tablecelloff).style.display='none';
                   3374:                     }
                   3375:                     setvis = 1;
                   3376:                 }
                   3377:                 break;
                   3378:             }
                   3379:         }
                   3380:         if (!setvis) {
                   3381:             if (document.getElementById(tablecellon)) {
                   3382:                 document.getElementById(tablecellon).style.display='none';
                   3383:             }
                   3384:             if (document.getElementById(tablecelloff)) {
                   3385:                 document.getElementById(tablecelloff).style.display='';
                   3386:             }
                   3387:         }
                   3388:     }
                   3389:     return;
                   3390: }
                   3391: // ]]>
                   3392: </script>
                   3393: 
                   3394: ENDSCRIPT
                   3395: }
                   3396: 
                   3397: sub ipaccess_javascript {
                   3398:     my ($settings) = @_;
                   3399:     my (%ordered,$total,%jstext);
                   3400:     $total = 0;
                   3401:     if (ref($settings) eq 'HASH') {
                   3402:         foreach my $item (keys(%{$settings})) {
                   3403:             if (ref($settings->{$item}) eq 'HASH') {
                   3404:                 my $num = $settings->{$item}{'order'};
                   3405:                 $ordered{$num} = $item;
                   3406:             }
                   3407:         }
                   3408:         $total = scalar(keys(%{$settings}));
                   3409:     }
                   3410:     my @jsarray = ();
                   3411:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3412:         push(@jsarray,$ordered{$item});
                   3413:     }
                   3414:     my $jstext = '    var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
                   3415:     return <<"ENDSCRIPT";
                   3416: <script type="text/javascript">
                   3417: // <![CDATA[
                   3418: function reorderIPaccess(form,item) {
                   3419:     var changedVal;
                   3420: $jstext
                   3421:     var newpos = 'ipaccess_pos_add';
                   3422:     var maxh = 1 + $total;
                   3423:     var current = new Array;
                   3424:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3425:     if (item == newpos) {
                   3426:         changedVal = newitemVal;
                   3427:     } else {
                   3428:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3429:         current[newitemVal] = newpos;
                   3430:     }
                   3431:     for (var i=0; i<ipaccess.length; i++) {
                   3432:         var elementName = 'ipaccess_pos_'+ipaccess[i];
                   3433:         if (elementName != item) {
                   3434:             if (form.elements[elementName]) {
                   3435:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3436:                 current[currVal] = elementName;
                   3437:             }
                   3438:         }
                   3439:     }
                   3440:     var oldVal;
                   3441:     for (var j=0; j<maxh; j++) {
                   3442:         if (current[j] == undefined) {
                   3443:             oldVal = j;
                   3444:         }
                   3445:     }
                   3446:     if (oldVal < changedVal) {
                   3447:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3448:            var elementName = current[k];
                   3449:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3450:         }
                   3451:     } else {
                   3452:         for (var k=changedVal; k<oldVal; k++) {
                   3453:             var elementName = current[k];
                   3454:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3455:         }
                   3456:     }
                   3457:     return;
                   3458: }
                   3459: // ]]>
                   3460: </script>
                   3461: 
                   3462: ENDSCRIPT
                   3463: }
                   3464: 
1.3       raeburn  3465: sub print_autoenroll {
1.30      raeburn  3466:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  3467:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116  raeburn  3468:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
                   3469:         $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
                   3470:     $failsafesty = 'none';
                   3471:     %failsafechecked = (
                   3472:         off => ' checked="checked"',
                   3473:     );
1.3       raeburn  3474:     if (ref($settings) eq 'HASH') {
                   3475:         if (exists($settings->{'run'})) {
                   3476:             if ($settings->{'run'} eq '0') {
                   3477:                 $runoff = ' checked="checked" ';
                   3478:                 $runon = ' ';
                   3479:             } else {
                   3480:                 $runon = ' checked="checked" ';
                   3481:                 $runoff = ' ';
                   3482:             }
                   3483:         } else {
                   3484:             if ($autorun) {
                   3485:                 $runon = ' checked="checked" ';
                   3486:                 $runoff = ' ';
                   3487:             } else {
                   3488:                 $runoff = ' checked="checked" ';
                   3489:                 $runon = ' ';
                   3490:             }
                   3491:         }
1.129     raeburn  3492:         if (exists($settings->{'co-owners'})) {
                   3493:             if ($settings->{'co-owners'} eq '0') {
                   3494:                 $coownersoff = ' checked="checked" ';
                   3495:                 $coownerson = ' ';
                   3496:             } else {
                   3497:                 $coownerson = ' checked="checked" ';
                   3498:                 $coownersoff = ' ';
                   3499:             }
                   3500:         } else {
                   3501:             $coownersoff = ' checked="checked" ';
                   3502:             $coownerson = ' ';
                   3503:         }
1.3       raeburn  3504:         if (exists($settings->{'sender_domain'})) {
                   3505:             $defdom = $settings->{'sender_domain'};
                   3506:         }
1.160.6.116  raeburn  3507:         if (exists($settings->{'failsafe'})) {
                   3508:             $failsafe = $settings->{'failsafe'};
                   3509:             if ($failsafe eq 'zero') {
                   3510:                 $failsafechecked{'zero'} = ' checked="checked"';
                   3511:                 $failsafechecked{'off'} = '';
                   3512:                 $failsafesty = 'inline-block';
                   3513:             } elsif ($failsafe eq 'any') {
                   3514:                 $failsafechecked{'any'} = ' checked="checked"';
                   3515:                 $failsafechecked{'off'} = '';
                   3516:             }
                   3517:             $autofailsafe = $settings->{'autofailsafe'};
                   3518:         } elsif (exists($settings->{'autofailsafe'})) {
                   3519:             $autofailsafe = $settings->{'autofailsafe'};
                   3520:             if ($autofailsafe ne '') {
                   3521:                 $failsafechecked{'zero'} = ' checked="checked"';
                   3522:                 $failsafe = 'zero';
                   3523:                 $failsafechecked{'off'} = '';
                   3524:             }
1.160.6.68  raeburn  3525:         }
1.14      raeburn  3526:     } else {
                   3527:         if ($autorun) {
                   3528:             $runon = ' checked="checked" ';
                   3529:             $runoff = ' ';
                   3530:         } else {
                   3531:             $runoff = ' checked="checked" ';
                   3532:             $runon = ' ';
                   3533:         }
1.3       raeburn  3534:     }
                   3535:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  3536:     my $notif_sender;
                   3537:     if (ref($settings) eq 'HASH') {
                   3538:         $notif_sender = $settings->{'sender_uname'};
                   3539:     }
1.3       raeburn  3540:     my $datatable='<tr class="LC_odd_row">'.
                   3541:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  3542:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3543:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  3544:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3545:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  3546:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  3547:                   '</tr><tr>'.
                   3548:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  3549:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  3550:                   &mt('username').':&nbsp;'.
                   3551:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  3552:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  3553:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   3554:                   '<tr class="LC_odd_row">'.
                   3555:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   3556:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3557:                   '<input type="radio" name="autoassign_coowners"'.
                   3558:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3559:                   '<label><input type="radio" name="autoassign_coowners"'.
                   3560:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68  raeburn  3561:                   '</tr><tr>'.
                   3562:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116  raeburn  3563:                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   3564:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span>&nbsp;&nbsp;&nbsp; '.
                   3565:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
                   3566:                   '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
                   3567:                   '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
                   3568:                   '<span class="LC_nobreak">'.
                   3569:                   &mt('Threshold for number of students in section to drop: [_1]',
                   3570:                       '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
                   3571:                   '</span></div></td></tr>';
1.160.6.68  raeburn  3572:     $$rowtotal += 4;
1.3       raeburn  3573:     return $datatable;
                   3574: }
                   3575: 
                   3576: sub print_autoupdate {
1.30      raeburn  3577:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113  raeburn  3578:     my ($enable,$datatable);
1.3       raeburn  3579:     if ($position eq 'top') {
1.160.6.113  raeburn  3580:         my %choices = &Apache::lonlocal::texthash (
                   3581:                           run        => 'Auto-update active?',
                   3582:                           classlists => 'Update information in classlists?',
                   3583:                           unexpired  => 'Skip updates for users without active or future roles?',
                   3584:                           lastactive => 'Skip updates for inactive users?',
                   3585:         );
                   3586:         my $itemcount = 0;
1.3       raeburn  3587:         my $updateon = ' ';
                   3588:         my $updateoff = ' checked="checked" ';
                   3589:         if (ref($settings) eq 'HASH') {
                   3590:             if ($settings->{'run'} eq '1') {
                   3591:                 $updateon = $updateoff;
                   3592:                 $updateoff = ' ';
                   3593:             }
                   3594:         }
1.160.6.113  raeburn  3595:         $enable = '<tr class="LC_odd_row">'. 
                   3596:                   '<td>'.&mt($choices{'run'}).'</td>'.
                   3597:                   '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  3598:                   '<input type="radio" name="autoupdate_run"'.
1.160.6.113  raeburn  3599:                   $updateoff.'value="0" />'.&mt('No').'</label>&nbsp;'.
1.8       raeburn  3600:                   '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113  raeburn  3601:                   $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3       raeburn  3602:                   '</tr>';
1.160.6.113  raeburn  3603:         my @toggles = ('classlists','unexpired');
                   3604:         my %defaultchecked = ('classlists' => 'off',
                   3605:                               'unexpired'  => 'off'
                   3606:                               );
                   3607:         $$rowtotal ++;
                   3608:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3609:                                                      \%choices,$itemcount,'','','left','no');
                   3610:         $datatable = $enable.$datatable;
                   3611:         $$rowtotal += $itemcount;
                   3612:         my $lastactiveon = ' ';
                   3613:         my $lastactiveoff = ' checked="checked" ';
                   3614:         my $lastactivestyle = 'none';
                   3615:         my $lastactivedays;
                   3616:         my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
                   3617:         if (ref($settings) eq 'HASH') {
                   3618:             if ($settings->{'lastactive'} =~ /^\d+$/) {
                   3619:                 $lastactiveon = $lastactiveoff;
                   3620:                 $lastactiveoff = ' ';
                   3621:                 $lastactivestyle = 'inline-block';
                   3622:                 $lastactivedays = $settings->{'lastactive'};
                   3623:             }
                   3624:         }
                   3625:         my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3626:         $datatable .= '<tr'.$css_class.'>'.
                   3627:                       '<td>'.$choices{'lastactive'}.'</td>'.
                   3628:                       '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
                   3629:                       '<input type="radio" name="lastactive"'.
                   3630:                       $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3631:                       '&nbsp;<label>'.
                   3632:                       '<input type="radio" name="lastactive"'.
                   3633:                       $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
                   3634:                       '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
                   3635:                       ':&nbsp;'.&mt('inactive = no activity in last [_1] days',
                   3636:                           '<input type="text" size="5" name="lastactivedays" value="'.
                   3637:                           $lastactivedays.'" />').
                   3638:                       '</span></td>'.
                   3639:                       '</tr>';
                   3640:         $$rowtotal ++;
1.131     raeburn  3641:     } elsif ($position eq 'middle') {
                   3642:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   3643:         my $numinrow = 3;
                   3644:         my $locknamesettings;
                   3645:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   3646:                                      $dom,$numinrow,$othertitle,
1.160.6.93  raeburn  3647:                                     'lockablenames',$rowtotal);
1.131     raeburn  3648:         $$rowtotal ++;
1.3       raeburn  3649:     } else {
1.44      raeburn  3650:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  3651:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  3652:                       'permanentemail','id');
1.33      raeburn  3653:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  3654:         my $numrows = 0;
1.26      raeburn  3655:         if (ref($types) eq 'ARRAY') {
                   3656:             if (@{$types} > 0) {
                   3657:                 $datatable = 
                   3658:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   3659:                                          \@fields,$types,\$numrows);
1.30      raeburn  3660:                     $$rowtotal += @{$types}; 
1.26      raeburn  3661:             }
1.3       raeburn  3662:         }
                   3663:         $datatable .= 
                   3664:             &usertype_update_row($settings,{'default' => $othertitle},
                   3665:                                  \%fieldtitles,\@fields,['default'],
                   3666:                                  \$numrows);
1.30      raeburn  3667:         $$rowtotal ++;     
1.3       raeburn  3668:     }
                   3669:     return $datatable;
                   3670: }
                   3671: 
1.125     raeburn  3672: sub print_autocreate {
                   3673:     my ($dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  3674:     my (%createon,%createoff,%currhash);
1.125     raeburn  3675:     my @types = ('xml','req');
                   3676:     if (ref($settings) eq 'HASH') {
                   3677:         foreach my $item (@types) {
                   3678:             $createoff{$item} = ' checked="checked" ';
                   3679:             $createon{$item} = ' ';
                   3680:             if (exists($settings->{$item})) {
                   3681:                 if ($settings->{$item}) {
                   3682:                     $createon{$item} = ' checked="checked" ';
                   3683:                     $createoff{$item} = ' ';
                   3684:                 }
                   3685:             }
                   3686:         }
1.160.6.16  raeburn  3687:         if ($settings->{'xmldc'} ne '') {
                   3688:             $currhash{$settings->{'xmldc'}} = 1;
                   3689:         }
1.125     raeburn  3690:     } else {
                   3691:         foreach my $item (@types) {
                   3692:             $createoff{$item} = ' checked="checked" ';
                   3693:             $createon{$item} = ' ';
                   3694:         }
                   3695:     }
                   3696:     $$rowtotal += 2;
1.160.6.16  raeburn  3697:     my $numinrow = 2;
1.125     raeburn  3698:     my $datatable='<tr class="LC_odd_row">'.
                   3699:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   3700:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3701:                   '<input type="radio" name="autocreate_xml"'.
                   3702:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3703:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  3704:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   3705:                   '</td></tr><tr>'.
                   3706:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   3707:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3708:                   '<input type="radio" name="autocreate_req"'.
                   3709:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3710:                   '<label><input type="radio" name="autocreate_req"'.
                   3711:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16  raeburn  3712:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   3713:                                                    'autocreate_xmldc',%currhash);
1.160.6.50  raeburn  3714:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  3715:     if ($numdc > 1) {
1.160.6.50  raeburn  3716:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   3717:                       '</td><td class="LC_left_item">';
1.125     raeburn  3718:     } else {
1.160.6.50  raeburn  3719:         $datatable .= &mt('Course creation processed as:').
                   3720:                       '</td><td class="LC_right_item">';
1.125     raeburn  3721:     }
1.160.6.50  raeburn  3722:     $datatable .= $dctable.'</td></tr>';
1.160.6.16  raeburn  3723:     $$rowtotal += $rows;
1.125     raeburn  3724:     return $datatable;
                   3725: }
                   3726: 
1.23      raeburn  3727: sub print_directorysrch {
1.160.6.72  raeburn  3728:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3729:     my $datatable;
                   3730:     if ($position eq 'top') {
                   3731:         my $instsrchon = ' ';
                   3732:         my $instsrchoff = ' checked="checked" ';
                   3733:         my ($exacton,$containson,$beginson);
                   3734:         my $instlocalon = ' ';
                   3735:         my $instlocaloff = ' checked="checked" ';
                   3736:         if (ref($settings) eq 'HASH') {
                   3737:             if ($settings->{'available'} eq '1') {
                   3738:                 $instsrchon = $instsrchoff;
                   3739:                 $instsrchoff = ' ';
                   3740:             }
                   3741:             if ($settings->{'localonly'} eq '1') {
                   3742:                 $instlocalon = $instlocaloff;
                   3743:                 $instlocaloff = ' ';
                   3744:             }
                   3745:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   3746:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   3747:                     if ($type eq 'exact') {
                   3748:                         $exacton = ' checked="checked" ';
                   3749:                     } elsif ($type eq 'contains') {
                   3750:                         $containson = ' checked="checked" ';
                   3751:                     } elsif ($type eq 'begins') {
                   3752:                         $beginson = ' checked="checked" ';
                   3753:                     }
                   3754:                 }
                   3755:             } else {
                   3756:                 if ($settings->{'searchtypes'} eq 'exact') {
                   3757:                     $exacton = ' checked="checked" ';
                   3758:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   3759:                     $containson = ' checked="checked" ';
                   3760:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  3761:                     $exacton = ' checked="checked" ';
                   3762:                     $containson = ' checked="checked" ';
                   3763:                 }
                   3764:             }
1.23      raeburn  3765:         }
1.160.6.72  raeburn  3766:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   3767:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  3768: 
1.160.6.72  raeburn  3769:         my $numinrow = 4;
                   3770:         my $cansrchrow = 0;
                   3771:         $datatable='<tr class="LC_odd_row">'.
                   3772:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   3773:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3774:                    '<input type="radio" name="dirsrch_available"'.
                   3775:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3776:                    '<label><input type="radio" name="dirsrch_available"'.
                   3777:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3778:                    '</tr><tr>'.
                   3779:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   3780:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3781:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   3782:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3783:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   3784:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3785:                    '</tr>';
                   3786:         $$rowtotal += 2;
                   3787:         if (ref($usertypes) eq 'HASH') {
                   3788:             if (keys(%{$usertypes}) > 0) {
                   3789:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93  raeburn  3790:                                              $numinrow,$othertitle,'cansearch',
                   3791:                                              $rowtotal);
1.160.6.72  raeburn  3792:                 $cansrchrow = 1;
                   3793:             }
1.26      raeburn  3794:         }
1.160.6.72  raeburn  3795:         if ($cansrchrow) {
                   3796:             $$rowtotal ++;
                   3797:             $datatable .= '<tr>';
                   3798:         } else {
                   3799:             $datatable .= '<tr class="LC_odd_row">';
                   3800:         }
                   3801:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   3802:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   3803:         foreach my $title (@{$titleorder}) {
                   3804:             if (defined($searchtitles->{$title})) {
                   3805:                 my $check = ' ';
                   3806:                 if (ref($settings) eq 'HASH') {
                   3807:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   3808:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   3809:                             $check = ' checked="checked" ';
                   3810:                         }
1.39      raeburn  3811:                     }
1.25      raeburn  3812:                 }
1.160.6.72  raeburn  3813:                 $datatable .= '<td class="LC_left_item">'.
                   3814:                               '<span class="LC_nobreak"><label>'.
                   3815:                               '<input type="checkbox" name="searchby" '.
                   3816:                               'value="'.$title.'"'.$check.'/>'.
                   3817:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  3818:             }
                   3819:         }
1.160.6.72  raeburn  3820:         $datatable .= '</tr></table></td></tr>';
                   3821:         $$rowtotal ++;
                   3822:         if ($cansrchrow) {
                   3823:             $datatable .= '<tr class="LC_odd_row">';
                   3824:         } else {
                   3825:             $datatable .= '<tr>';
                   3826:         }
                   3827:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   3828:                       '<td class="LC_left_item" colspan="2">'.
                   3829:                       '<span class="LC_nobreak"><label>'.
                   3830:                       '<input type="checkbox" name="searchtypes" '.
                   3831:                       $exacton.' value="exact" />'.&mt('Exact match').
                   3832:                       '</label>&nbsp;'.
                   3833:                       '<label><input type="checkbox" name="searchtypes" '.
                   3834:                       $beginson.' value="begins" />'.&mt('Begins with').
                   3835:                       '</label>&nbsp;'.
                   3836:                       '<label><input type="checkbox" name="searchtypes" '.
                   3837:                       $containson.' value="contains" />'.&mt('Contains').
                   3838:                       '</label></span></td></tr>';
                   3839:         $$rowtotal ++;
1.26      raeburn  3840:     } else {
1.160.6.72  raeburn  3841:         my $domsrchon = ' checked="checked" ';
                   3842:         my $domsrchoff = ' ';
                   3843:         my $domlocalon = ' ';
                   3844:         my $domlocaloff = ' checked="checked" ';
                   3845:         if (ref($settings) eq 'HASH') {
                   3846:             if ($settings->{'lclocalonly'} eq '1') {
                   3847:                 $domlocalon = $domlocaloff;
                   3848:                 $domlocaloff = ' ';
                   3849:             }
                   3850:             if ($settings->{'lcavailable'} eq '0') {
                   3851:                 $domsrchoff = $domsrchon;
                   3852:                 $domsrchon = ' ';
                   3853:             }
                   3854:         }
                   3855:         $datatable='<tr class="LC_odd_row">'.
                   3856:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   3857:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3858:                       '<input type="radio" name="dirsrch_domavailable"'.
                   3859:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   3860:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   3861:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   3862:                       '</tr><tr>'.
                   3863:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   3864:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   3865:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   3866:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   3867:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   3868:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   3869:                       '</tr>';
                   3870:         $$rowtotal += 2;
1.26      raeburn  3871:     }
1.25      raeburn  3872:     return $datatable;
                   3873: }
                   3874: 
1.28      raeburn  3875: sub print_contacts {
1.160.6.78  raeburn  3876:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  3877:     my $datatable;
                   3878:     my @contacts = ('adminemail','supportemail');
1.160.6.78  raeburn  3879:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107  raeburn  3880:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78  raeburn  3881:     if ($position eq 'top') {
                   3882:         if (ref($settings) eq 'HASH') {
                   3883:             foreach my $item (@contacts) {
                   3884:                 if (exists($settings->{$item})) {
                   3885:                     $to{$item} = $settings->{$item};
                   3886:                 }
1.28      raeburn  3887:             }
                   3888:         }
1.160.6.78  raeburn  3889:     } elsif ($position eq 'middle') {
                   3890:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91  raeburn  3891:                      'updatesmail','idconflictsmail','hostipmail');
1.28      raeburn  3892:         foreach my $type (@mailings) {
1.160.6.78  raeburn  3893:             $otheremails{$type} = '';
                   3894:         }
1.160.6.107  raeburn  3895:     } elsif ($position eq 'lower') {
                   3896:         if (ref($settings) eq 'HASH') {
                   3897:             if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   3898:                 %lonstatus = %{$settings->{'lonstatus'}};
                   3899:             }
                   3900:         }
1.160.6.78  raeburn  3901:     } else {
                   3902:         @mailings = ('helpdeskmail','otherdomsmail');
                   3903:         foreach my $type (@mailings) {
                   3904:             $otheremails{$type} = '';
                   3905:         }
                   3906:         $bccemails{'helpdeskmail'} = '';
                   3907:         $bccemails{'otherdomsmail'} = '';
                   3908:         $includestr{'helpdeskmail'} = '';
                   3909:         $includestr{'otherdomsmail'} = '';
                   3910:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   3911:     }
                   3912:     if (ref($settings) eq 'HASH') {
1.160.6.107  raeburn  3913:         unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78  raeburn  3914:             foreach my $type (@mailings) {
                   3915:                 if (exists($settings->{$type})) {
                   3916:                     if (ref($settings->{$type}) eq 'HASH') {
                   3917:                         foreach my $item (@contacts) {
                   3918:                             if ($settings->{$type}{$item}) {
                   3919:                                 $checked{$type}{$item} = ' checked="checked" ';
                   3920:                             }
1.28      raeburn  3921:                         }
1.160.6.78  raeburn  3922:                         $otheremails{$type} = $settings->{$type}{'others'};
                   3923:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3924:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   3925:                             if ($settings->{$type}{'include'} ne '') {
                   3926:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3927:                                 $includestr{$type} = &unescape($includestr{$type});
                   3928:                             }
                   3929:                         }
                   3930:                     }
                   3931:                 } elsif ($type eq 'lonstatusmail') {
                   3932:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3933:                 }
                   3934:             }
                   3935:         }
                   3936:         if ($position eq 'bottom') {
                   3937:             foreach my $type (@mailings) {
                   3938:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   3939:                 if ($settings->{$type}{'include'} ne '') {
                   3940:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   3941:                     $includestr{$type} = &unescape($includestr{$type});
                   3942:                 }
                   3943:             }
                   3944:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   3945:                 if (ref($fields) eq 'ARRAY') {
                   3946:                     foreach my $field (@{$fields}) {
                   3947:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  3948:                     }
1.160.6.78  raeburn  3949:                 }
                   3950:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   3951:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   3952:                 } else {
                   3953:                     $maxsize = '1.0';
                   3954:                 }
                   3955:             } else {
                   3956:                 if (ref($fields) eq 'ARRAY') {
                   3957:                     foreach my $field (@{$fields}) {
                   3958:                         $currfield{$field} = 'yes';
1.134     raeburn  3959:                     }
1.28      raeburn  3960:                 }
1.160.6.78  raeburn  3961:                 $maxsize = '1.0';
1.28      raeburn  3962:             }
                   3963:         }
                   3964:     } else {
1.160.6.78  raeburn  3965:         if ($position eq 'top') {
                   3966:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   3967:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   3968:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   3969:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   3970:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   3971:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   3972:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   3973:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91  raeburn  3974:             $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78  raeburn  3975:         } elsif ($position eq 'bottom') {
                   3976:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   3977:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   3978:             if (ref($fields) eq 'ARRAY') {
                   3979:                 foreach my $field (@{$fields}) {
                   3980:                     $currfield{$field} = 'yes';
                   3981:                 }
                   3982:             }
                   3983:             $maxsize = '1.0';
                   3984:         }
1.28      raeburn  3985:     }
                   3986:     my ($titles,$short_titles) = &contact_titles();
                   3987:     my $rownum = 0;
                   3988:     my $css_class;
1.160.6.78  raeburn  3989:     if ($position eq 'top') {
                   3990:         foreach my $item (@contacts) {
                   3991:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3992:             $datatable .= '<tr'.$css_class.'>'. 
                   3993:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3994:                           '</span></td><td class="LC_right_item">'.
                   3995:                           '<input type="text" name="'.$item.'" value="'.
                   3996:                           $to{$item}.'" /></td></tr>';
                   3997:             $rownum ++;
                   3998:         }
1.160.6.101  raeburn  3999:     } elsif ($position eq 'bottom') {
                   4000:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4001:         $datatable .= '<tr'.$css_class.'>'.
                   4002:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   4003:                       &mt('(e-mail, subject, and description always shown)').
                   4004:                       '</td><td class="LC_left_item">';
                   4005:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   4006:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   4007:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   4008:             foreach my $field (@{$fields}) {
                   4009:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   4010:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   4011:                     $datatable .= ' '.&mt('(logged-in users)');
                   4012:                 }
                   4013:                 $datatable .='</td><td>';
                   4014:                 my $clickaction;
                   4015:                 if ($field eq 'screenshot') {
                   4016:                     $clickaction = ' onclick="screenshotSize(this);"';
                   4017:                 }
                   4018:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   4019:                     foreach my $option (@{$possoptions->{$field}}) {
                   4020:                         my $checked;
                   4021:                         if ($currfield{$field} eq $option) {
                   4022:                             $checked = ' checked="checked"';
                   4023:                         }
                   4024:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   4025:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   4026:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   4027:                                       '</label></span>'.('&nbsp;'x2);
                   4028:                     }
                   4029:                 }
                   4030:                 if ($field eq 'screenshot') {
                   4031:                     my $display;
                   4032:                     if ($currfield{$field} eq 'no') {
                   4033:                         $display = ' style="display:none"';
                   4034:                     }
                   4035:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
                   4036:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   4037:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   4038:                 }
                   4039:                 $datatable .= '</td></tr>';
                   4040:             }
                   4041:             $datatable .= '</table>';
                   4042:         }
                   4043:         $datatable .= '</td></tr>'."\n";
                   4044:         $rownum ++;
                   4045:     }
1.160.6.107  raeburn  4046:     unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78  raeburn  4047:         foreach my $type (@mailings) {
                   4048:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4049:             $datatable .= '<tr'.$css_class.'>'.
                   4050:                           '<td><span class="LC_nobreak">'.
                   4051:                           $titles->{$type}.': </span></td>'.
                   4052:                           '<td class="LC_left_item">';
                   4053:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4054:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   4055:             }
                   4056:             $datatable .= '<span class="LC_nobreak">';
                   4057:             foreach my $item (@contacts) {
                   4058:                 $datatable .= '<label>'.
                   4059:                               '<input type="checkbox" name="'.$type.'"'.
                   4060:                               $checked{$type}{$item}.
                   4061:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   4062:                               '</label>&nbsp;';
                   4063:             }
                   4064:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4065:                           '<input type="text" name="'.$type.'_others" '.
                   4066:                           'value="'.$otheremails{$type}.'"  />';
                   4067:             my %locchecked;
                   4068:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   4069:                 foreach my $loc ('s','b') {
                   4070:                     if ($includeloc{$type} eq $loc) {
                   4071:                         $locchecked{$loc} = ' checked="checked"';
                   4072:                         last;
                   4073:                     }
                   4074:                 }
                   4075:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4076:                               '<input type="text" name="'.$type.'_bcc" '.
                   4077:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   4078:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4079:                               &mt('Text automatically added to e-mail:').' '.
1.160.6.87  raeburn  4080:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78  raeburn  4081:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4082:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4083:                               ('&nbsp;'x2).
                   4084:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4085:                               '</span></fieldset>';
                   4086:             }
                   4087:             $datatable .= '</td></tr>'."\n";
                   4088:             $rownum ++;
                   4089:         }
1.28      raeburn  4090:     }
1.160.6.78  raeburn  4091:     if ($position eq 'middle') {
                   4092:         my %choices;
1.160.6.107  raeburn  4093:         my $corelink = &core_link_msu();
                   4094:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78  raeburn  4095:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107  raeburn  4096:                                         $corelink);
                   4097:         $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
                   4098:         my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78  raeburn  4099:         my %defaultchecked = ('reporterrors'  => 'on',
1.160.6.107  raeburn  4100:                               'reportupdates' => 'on',
                   4101:                               'reportstatus'  => 'on');
1.160.6.78  raeburn  4102:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4103:                                                    \%choices,$rownum);
                   4104:         $datatable .= $reports;
1.160.6.107  raeburn  4105:     } elsif ($position eq 'lower') {
1.160.6.109  raeburn  4106:         my (%current,%excluded,%weights);
1.160.6.107  raeburn  4107:         my ($defaults,$names) = &Apache::loncommon::lon_status_items();
                   4108:         if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109  raeburn  4109:             $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107  raeburn  4110:         } else {
1.160.6.109  raeburn  4111:             $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107  raeburn  4112:         }
                   4113:         if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109  raeburn  4114:             $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107  raeburn  4115:         } else {
1.160.6.109  raeburn  4116:             $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107  raeburn  4117:         }
                   4118:         if (ref($lonstatus{'weights'}) eq 'HASH') {
                   4119:             foreach my $type ('E','W','N','U') {
                   4120:                 if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                   4121:                     $weights{$type} = $lonstatus{'weights'}{$type};
                   4122:                 } else {
                   4123:                     $weights{$type} = $defaults->{$type};
                   4124:                 }
                   4125:             }
                   4126:         } else {
                   4127:             foreach my $type ('E','W','N','U') {
                   4128:                 $weights{$type} = $defaults->{$type};
                   4129:             }
                   4130:         }
                   4131:         if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
                   4132:             if (@{$lonstatus{'excluded'}} > 0) {
                   4133:                 map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
                   4134:             }
                   4135:         }
1.160.6.109  raeburn  4136:         foreach my $item ('errorthreshold','errorsysmail') {
                   4137:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4138:             $datatable .= '<tr'.$css_class.'>'.
                   4139:                           '<td class="LC_left_item"><span class="LC_nobreak">'.
                   4140:                           $titles->{$item}.
                   4141:                           '</span></td><td class="LC_left_item">'.
                   4142:                           '<input type="text" name="'.$item.'" value="'.
                   4143:                           $current{$item}.'" size="5" /></td></tr>';
                   4144:             $rownum ++;
                   4145:         }
1.160.6.107  raeburn  4146:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4147:         $datatable .= '<tr'.$css_class.'>'.
                   4148:                       '<td class="LC_left_item">'.
                   4149:                       '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                   4150:                       '</span></td><td class="LC_left_item"><table><tr>';
                   4151:         foreach my $type ('E','W','N','U') {
                   4152:             $datatable .= '<td>'.$names->{$type}.'<br />'.
                   4153:                           '<input type="text" name="errorweights_'.$type.'" value="'.
                   4154:                           $weights{$type}.'" size="5" /></td>';
                   4155:         }
                   4156:         $datatable .= '</tr></table></tr>';
                   4157:         $rownum ++;
                   4158:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   4159:         $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                   4160:                       $titles->{'errorexcluded'}.'</td>'.
                   4161:                       '<td class="LC_left_item"><table>';
                   4162:         my $numinrow = 4;
                   4163:         my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
                   4164:         for (my $i=0; $i<@ids; $i++) {
                   4165:             my $rem = $i%($numinrow);
                   4166:             if ($rem == 0) {
                   4167:                 if ($i > 0) {
                   4168:                     $datatable .= '</tr>';
                   4169:                 }
                   4170:                 $datatable .= '<tr>';
                   4171:             }
                   4172:             my $check;
                   4173:             if ($excluded{$ids[$i]}) {
                   4174:                 $check = ' checked="checked" ';
                   4175:             }
                   4176:             $datatable .= '<td class="LC_left_item">'.
                   4177:                           '<span class="LC_nobreak"><label>'.
                   4178:                           '<input type="checkbox" name="errorexcluded" '.
                   4179:                           'value="'.$ids[$i].'"'.$check.' />'.
                   4180:                           $ids[$i].'</label></span></td>';
                   4181:         }
                   4182:         my $colsleft = $numinrow - @ids%($numinrow);
                   4183:         if ($colsleft > 1 ) {
                   4184:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4185:                           '&nbsp;</td>';
                   4186:         } elsif ($colsleft == 1) {
                   4187:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4188:         }
                   4189:         $datatable .= '</tr></table></td></tr>';
                   4190:         $rownum ++;
1.160.6.78  raeburn  4191:     } elsif ($position eq 'bottom') {
1.160.6.101  raeburn  4192:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4193:         my (@posstypes,%usertypeshash);
                   4194:         if (ref($types) eq 'ARRAY') {
                   4195:             @posstypes = @{$types};
                   4196:         }
                   4197:         if (@posstypes) {
                   4198:             if (ref($usertypes) eq 'HASH') {
                   4199:                 %usertypeshash = %{$usertypes};
                   4200:             }
                   4201:             my @overridden;
                   4202:             my $numinrow = 4;
                   4203:             if (ref($settings) eq 'HASH') {
                   4204:                 if (ref($settings->{'overrides'}) eq 'HASH') {
                   4205:                     foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
                   4206:                         if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
                   4207:                             push(@overridden,$key);
                   4208:                             foreach my $item (@contacts) {
                   4209:                                 if ($settings->{'overrides'}{$key}{$item}) {
                   4210:                                     $checked{'override_'.$key}{$item} = ' checked="checked" ';
                   4211:                                 }
                   4212:                             }
                   4213:                             $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
                   4214:                             $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
                   4215:                             $includeloc{'override_'.$key} = '';
                   4216:                             $includestr{'override_'.$key} = '';
                   4217:                             if ($settings->{'overrides'}{$key}{'include'} ne '') {
                   4218:                                 ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
                   4219:                                     split(/:/,$settings->{'overrides'}{$key}{'include'},2);
                   4220:                                 $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
                   4221:                             }
1.160.6.78  raeburn  4222:                         }
                   4223:                     }
                   4224:                 }
1.160.6.101  raeburn  4225:             }
                   4226:             my $customclass = 'LC_helpdesk_override';
                   4227:             my $optionsprefix = 'LC_options_helpdesk_';
                   4228: 
                   4229:             my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
                   4230: 
                   4231:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   4232:                                          $numinrow,$othertitle,'overrides',
                   4233:                                          \$rownum,$onclicktypes,$customclass);
                   4234:             $rownum ++;
                   4235:             $usertypeshash{'default'} = $othertitle;
                   4236:             foreach my $status (@posstypes) {
                   4237:                 my $css_class;
                   4238:                 if ($rownum%2) {
                   4239:                     $css_class = 'LC_odd_row ';
                   4240:                 }
                   4241:                 $css_class .= $customclass;
                   4242:                 my $rowid = $optionsprefix.$status;
                   4243:                 my $hidden = 1;
                   4244:                 my $currstyle = 'display:none';
                   4245:                 if (grep(/^\Q$status\E$/,@overridden)) {
                   4246:                     $currstyle = 'display:table-row';
                   4247:                     $hidden = 0;
                   4248:                 }
                   4249:                 my $key = 'override_'.$status;
                   4250:                 $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
                   4251:                                                   $includeloc{$key},$includestr{$key},$status,$rowid,
                   4252:                                                   $usertypeshash{$status},$css_class,$currstyle,
                   4253:                                                   \@contacts,$short_titles);
                   4254:                 unless ($hidden) {
                   4255:                     $rownum ++;
1.160.6.78  raeburn  4256:                 }
                   4257:             }
1.134     raeburn  4258:         }
1.28      raeburn  4259:     }
1.30      raeburn  4260:     $$rowtotal += $rownum;
1.28      raeburn  4261:     return $datatable;
                   4262: }
                   4263: 
1.160.6.107  raeburn  4264: sub core_link_msu {
                   4265:     return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   4266:                                           &mt('LON-CAPA core group - MSU'),600,500);
                   4267: }
                   4268: 
1.160.6.101  raeburn  4269: sub overridden_helpdesk {
                   4270:     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
                   4271:         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
                   4272:     my $class = 'LC_left_item';
                   4273:     if ($css_class) {
                   4274:         $css_class = ' class="'.$css_class.'"';
                   4275:     }
                   4276:     if ($rowid) {
                   4277:         $rowid = ' id="'.$rowid.'"';
                   4278:     }
                   4279:     if ($rowstyle) {
                   4280:         $rowstyle = ' style="'.$rowstyle.'"';
                   4281:     }
                   4282:     my ($output,$description);
                   4283:     $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
                   4284:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   4285:               "<td>$description</td>\n".
                   4286:               '<td class="'.$class.'" colspan="2">'.
                   4287:               '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
                   4288:               '<span class="LC_nobreak">';
                   4289:     if (ref($contacts) eq 'ARRAY') {
                   4290:         foreach my $item (@{$contacts}) {
                   4291:             my $check;
                   4292:             if (ref($checked) eq 'HASH') {
                   4293:                $check = $checked->{$item};
                   4294:             }
                   4295:             my $title;
                   4296:             if (ref($short_titles) eq 'HASH') {
                   4297:                 $title = $short_titles->{$item};
                   4298:             }
                   4299:             $output .= '<label>'.
                   4300:                        '<input type="checkbox" name="override_'.$type.'"'.$check.
                   4301:                        ' value="'.$item.'" />'.$title.'</label>&nbsp;';
                   4302:         }
                   4303:     }
                   4304:     $output .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   4305:                '<input type="text" name="override_'.$type.'_others" '.
                   4306:                'value="'.$otheremails.'"  />';
                   4307:     my %locchecked;
                   4308:     foreach my $loc ('s','b') {
                   4309:         if ($includeloc eq $loc) {
                   4310:             $locchecked{$loc} = ' checked="checked"';
                   4311:             last;
                   4312:         }
                   4313:     }
                   4314:     $output .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   4315:                '<input type="text" name="override_'.$type.'_bcc" '.
                   4316:                'value="'.$bccemails.'"  /></fieldset>'.
                   4317:                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   4318:                &mt('Text automatically added to e-mail:').' '.
                   4319:                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
                   4320:                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   4321:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   4322:                ('&nbsp;'x2).
                   4323:                '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   4324:                '</span></fieldset>'.
                   4325:                '</td></tr>'."\n";
                   4326:     return $output;
                   4327: }
                   4328: 
1.160.6.78  raeburn  4329: sub contacts_javascript {
                   4330:     return <<"ENDSCRIPT";
                   4331: 
                   4332: <script type="text/javascript">
                   4333: // <![CDATA[
                   4334: 
                   4335: function screenshotSize(field) {
                   4336:     if (document.getElementById('help_screenshotsize')) {
                   4337:         if (field.value == 'no') {
                   4338:             document.getElementById('help_screenshotsize').style.display="none";
                   4339:         } else {
                   4340:             document.getElementById('help_screenshotsize').style.display="";
                   4341:         }
                   4342:     }
                   4343:     return;
                   4344: }
                   4345: 
1.160.6.101  raeburn  4346: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
                   4347:     if (form.elements[checkbox].length != undefined) {
                   4348:         var count = 0;
                   4349:         if (docount) {
                   4350:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   4351:                 if (form.elements[checkbox][i].checked) {
                   4352:                     count ++;
                   4353:                 }
                   4354:             }
                   4355:         }
                   4356:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   4357:             var type = form.elements[checkbox][i].value;
                   4358:             if (document.getElementById(prefix+type)) {
                   4359:                 if (form.elements[checkbox][i].checked) {
                   4360:                     document.getElementById(prefix+type).style.display = 'table-row';
                   4361:                     if (count % 2 == 1) {
                   4362:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   4363:                     } else {
                   4364:                         document.getElementById(prefix+type).className = target;
                   4365:                     }
                   4366:                     count ++;
                   4367:                 } else {
                   4368:                     document.getElementById(prefix+type).style.display = 'none';
                   4369:                 }
                   4370:             }
                   4371:         }
                   4372:     }
                   4373:     return;
                   4374: }
                   4375: 
1.160.6.78  raeburn  4376: // ]]>
                   4377: </script>
                   4378: 
                   4379: ENDSCRIPT
                   4380: }
                   4381: 
1.118     jms      4382: sub print_helpsettings {
1.160.6.73  raeburn  4383:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4384:     my $confname = $dom.'-domainconfig';
1.160.6.77  raeburn  4385:     my $formname = 'display';
1.160.6.5  raeburn  4386:     my ($datatable,$itemcount);
1.160.6.73  raeburn  4387:     if ($position eq 'top') {
                   4388:         $itemcount = 1;
                   4389:         my (%choices,%defaultchecked,@toggles);
                   4390:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   4391:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   4392:                                      &mt('LON-CAPA bug tracker'),600,500));
                   4393:         %defaultchecked = ('submitbugs' => 'on');
                   4394:         @toggles = ('submitbugs');
                   4395:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   4396:                                                      \%choices,$itemcount);
                   4397:         $$rowtotal ++;
                   4398:     } else {
                   4399:         my $css_class;
                   4400:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  4401:         my (%customroles,%ordered,%current);
1.160.6.84  raeburn  4402:         if (ref($settings) eq 'HASH') {
                   4403:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   4404:                 %current = %{$settings->{'adhoc'}};
                   4405:             }
1.160.6.77  raeburn  4406:         }
                   4407:         my $count = 0;
                   4408:         foreach my $key (sort(keys(%existing))) {
1.160.6.73  raeburn  4409:             if ($key=~/^rolesdef\_(\w+)$/) {
                   4410:                 my $rolename = $1;
1.160.6.77  raeburn  4411:                 my (%privs,$order);
1.160.6.73  raeburn  4412:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   4413:                 $customroles{$rolename} = \%privs;
1.160.6.77  raeburn  4414:                 if (ref($current{$rolename}) eq 'HASH') {
                   4415:                     $order = $current{$rolename}{'order'};
                   4416:                 }
                   4417:                 if ($order eq '') {
                   4418:                     $order = $count;
                   4419:                 }
                   4420:                 $ordered{$order} = $rolename;
                   4421:                 $count++;
1.160.6.73  raeburn  4422:             }
                   4423:         }
1.160.6.77  raeburn  4424:         my $maxnum = scalar(keys(%ordered));
                   4425:         my @roles_by_num = ();
                   4426:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   4427:             push(@roles_by_num,$item);
                   4428:         }
                   4429:         my $context = 'domprefs';
                   4430:         my $crstype = 'Course';
                   4431:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  4432:         my @accesstypes = ('all','dh','da','none');
1.160.6.77  raeburn  4433:         my ($numstatustypes,@jsarray);
                   4434:         if (ref($types) eq 'ARRAY') {
                   4435:             if (@{$types} > 0) {
                   4436:                 $numstatustypes = scalar(@{$types});
                   4437:                 push(@accesstypes,'status');
                   4438:                 @jsarray = ('bystatus');
                   4439:             }
                   4440:         }
1.160.6.86  raeburn  4441:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  4442:         if (keys(%domhelpdesk)) {
                   4443:             push(@accesstypes,('inc','exc'));
                   4444:             push(@jsarray,('notinc','notexc'));
                   4445:         }
                   4446:         my $hiddenstr = join("','",@jsarray);
                   4447:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73  raeburn  4448:         my $context = 'domprefs';
                   4449:         my $crstype = 'Course';
1.160.6.77  raeburn  4450:         my $prefix = 'helproles_';
                   4451:         my $add_class = 'LC_hidden';
                   4452:         foreach my $num (@roles_by_num) {
                   4453:             my $role = $ordered{$num};
                   4454:             my ($desc,$access,@statuses);
                   4455:             if (ref($current{$role}) eq 'HASH') {
                   4456:                 $desc = $current{$role}{'desc'};
                   4457:                 $access = $current{$role}{'access'};
                   4458:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   4459:                     @statuses = @{$current{$role}{'insttypes'}};
                   4460:                 }
                   4461:             }
                   4462:             if ($desc eq '') {
                   4463:                 $desc = $role;
                   4464:             }
                   4465:             my $identifier = 'custhelp'.$num;
1.160.6.73  raeburn  4466:             my %full=();
                   4467:             my %levels= (
                   4468:                          course => {},
                   4469:                          domain => {},
                   4470:                          system => {},
                   4471:                         );
                   4472:             my %levelscurrent=(
                   4473:                                course => {},
                   4474:                                domain => {},
                   4475:                                system => {},
                   4476:                               );
                   4477:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   4478:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   4479:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77  raeburn  4480:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
                   4481:             $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                   4482:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   4483:             for (my $k=0; $k<=$maxnum; $k++) {
                   4484:                 my $vpos = $k+1;
                   4485:                 my $selstr;
                   4486:                 if ($k == $num) {
                   4487:                     $selstr = ' selected="selected" ';
                   4488:                 }
                   4489:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4490:             }
                   4491:             $datatable .= '</select>'.('&nbsp;'x2).
                   4492:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   4493:                           '</td>'.
                   4494:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4495:                           &mt('Name shown to users:').
                   4496:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   4497:                           '</fieldset>'.
                   4498:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   4499:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   4500:                           '<fieldset>'.
                   4501:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73  raeburn  4502:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77  raeburn  4503:                                                                    \%levelscurrent,$identifier,
                   4504:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   4505:                           '</fieldset></td>';
1.160.6.73  raeburn  4506:             $itemcount ++;
                   4507:         }
                   4508:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4509:         my $newcust = 'custhelp'.$count;
                   4510:         my (%privs,%levelscurrent);
                   4511:         my %full=();
                   4512:         my %levels= (
                   4513:                      course => {},
                   4514:                      domain => {},
                   4515:                      system => {},
                   4516:                     );
                   4517:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   4518:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77  raeburn  4519:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
                   4520:         $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                   4521:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   4522:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   4523:         for (my $k=0; $k<$maxnum+1; $k++) {
                   4524:             my $vpos = $k+1;
                   4525:             my $selstr;
                   4526:             if ($k == $maxnum) {
                   4527:                 $selstr = ' selected="selected" ';
                   4528:             }
                   4529:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4530:         }
                   4531:         $datatable .= '</select>&nbsp;'."\n".
1.160.6.73  raeburn  4532:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   4533:                       '</label></span></td>'.
1.160.6.77  raeburn  4534:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   4535:                       '<span class="LC_nobreak">'.
                   4536:                       &mt('Internal name:').
                   4537:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   4538:                       '</span>'.('&nbsp;'x4).
                   4539:                       '<span class="LC_nobreak">'.
                   4540:                       &mt('Name shown to users:').
                   4541:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   4542:                       '</span></fieldset>'.
                   4543:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   4544:                                              $usertypes,$types,\%domhelpdesk).
                   4545:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73  raeburn  4546:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   4547:                                                                 \@templateroles,$newcust).
                   4548:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   4549:                                                                \%levelscurrent,$newcust).
1.160.6.87  raeburn  4550:                       '</fieldset>'.
                   4551:                       &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                   4552:                       '</td></tr>';
1.160.6.73  raeburn  4553:         $count ++;
                   4554:         $$rowtotal += $count;
                   4555:     }
1.160.6.5  raeburn  4556:     return $datatable;
1.121     raeburn  4557: }
                   4558: 
1.160.6.77  raeburn  4559: sub adhocbutton {
                   4560:     my ($prefix,$num,$field,$visibility) = @_;
                   4561:     my %lt = &Apache::lonlocal::texthash(
                   4562:                                           show => 'Show details',
                   4563:                                           hide => 'Hide details',
                   4564:                                         );
                   4565:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   4566:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   4567:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   4568:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   4569: }
                   4570: 
                   4571: sub helpsettings_javascript {
                   4572:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   4573:     return unless(ref($roles_by_num) eq 'ARRAY');
                   4574:     my %html_js_lt = &Apache::lonlocal::texthash(
                   4575:                                           show => 'Show details',
                   4576:                                           hide => 'Hide details',
                   4577:                                         );
                   4578:     &html_escape(\%html_js_lt);
                   4579:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   4580:     return <<"ENDSCRIPT";
                   4581: <script type="text/javascript">
                   4582: // <![CDATA[
                   4583: 
                   4584: function reorderHelpRoles(form,item) {
                   4585:     var changedVal;
                   4586: $jstext
                   4587:     var newpos = 'helproles_${total}_pos';
                   4588:     var maxh = 1 + $total;
                   4589:     var current = new Array();
                   4590:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   4591:     if (item == newpos) {
                   4592:         changedVal = newitemVal;
                   4593:     } else {
                   4594:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   4595:         current[newitemVal] = newpos;
                   4596:     }
                   4597:     for (var i=0; i<helproles.length; i++) {
                   4598:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   4599:         if (elementName != item) {
                   4600:             if (form.elements[elementName]) {
                   4601:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   4602:                 current[currVal] = elementName;
                   4603:             }
                   4604:         }
                   4605:     }
                   4606:     var oldVal;
                   4607:     for (var j=0; j<maxh; j++) {
                   4608:         if (current[j] == undefined) {
                   4609:             oldVal = j;
                   4610:         }
                   4611:     }
                   4612:     if (oldVal < changedVal) {
                   4613:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   4614:            var elementName = current[k];
                   4615:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   4616:         }
                   4617:     } else {
                   4618:         for (var k=changedVal; k<oldVal; k++) {
                   4619:             var elementName = current[k];
                   4620:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   4621:         }
                   4622:     }
                   4623:     return;
                   4624: }
                   4625: 
                   4626: function helpdeskAccess(num) {
                   4627:     var curraccess = null;
                   4628:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   4629:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   4630:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   4631:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   4632:             }
                   4633:         }
                   4634:     }
                   4635:     var shown = Array();
                   4636:     var hidden = Array();
                   4637:     if (curraccess == 'none') {
                   4638:         hidden = Array('$hiddenstr');
                   4639:     } else {
                   4640:         if (curraccess == 'status') {
                   4641:             shown = Array('bystatus');
                   4642:             hidden = Array('notinc','notexc');
                   4643:         } else {
                   4644:             if (curraccess == 'exc') {
                   4645:                 shown = Array('notexc');
                   4646:                 hidden = Array('notinc','bystatus');
                   4647:             }
                   4648:             if (curraccess == 'inc') {
                   4649:                 shown = Array('notinc');
                   4650:                 hidden = Array('notexc','bystatus');
                   4651:             }
1.160.6.79  raeburn  4652:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77  raeburn  4653:                 hidden = Array('notinc','notexc','bystatus');
                   4654:             }
                   4655:         }
                   4656:     }
                   4657:     if (hidden.length > 0) {
                   4658:         for (var i=0; i<hidden.length; i++) {
                   4659:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   4660:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   4661:             }
                   4662:         }
                   4663:     }
                   4664:     if (shown.length > 0) {
                   4665:         for (var i=0; i<shown.length; i++) {
                   4666:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   4667:                 if (shown[i] == 'privs') {
                   4668:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   4669:                 } else {
                   4670:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   4671:                 }
                   4672:             }
                   4673:         }
                   4674:     }
                   4675:     return;
                   4676: }
                   4677: 
                   4678: function toggleHelpdeskItem(num,field) {
                   4679:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   4680:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
                   4681:             document.getElementById('helproles_'+num+'_'+field).className =
                   4682:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   4683:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4684:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   4685:             }
                   4686:         } else {
                   4687:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   4688:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   4689:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   4690:             }
                   4691:         }
                   4692:     }
                   4693:     return;
                   4694: }
                   4695: 
                   4696: // ]]>
                   4697: </script>
                   4698: 
                   4699: ENDSCRIPT
                   4700: }
                   4701: 
                   4702: sub helpdeskroles_access {
                   4703:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   4704:         $usertypes,$types,$domhelpdesk) = @_;
                   4705:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   4706:     my %lt = &Apache::lonlocal::texthash(
                   4707:                     'rou'    => 'Role usage',
                   4708:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.160.6.79  raeburn  4709:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   4710:                     'dh'     => 'All with domain helpdesk role',
                   4711:                     'da'     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  4712:                     'none'   => 'None',
                   4713:                     'status' => 'Determined based on institutional status',
                   4714:                     'inc'    => 'Include all, but exclude specific personnel',
                   4715:                     'exc'    => 'Exclude all, but include specific personnel',
                   4716:                   );
                   4717:     my %usecheck = (
                   4718:                      all => ' checked="checked"',
                   4719:                    );
                   4720:     my %displaydiv = (
                   4721:                       status => 'none',
                   4722:                       inc    => 'none',
                   4723:                       exc    => 'none',
                   4724:                       priv   => 'block',
                   4725:                      );
                   4726:     my $output;
                   4727:     if (ref($current) eq 'HASH') {
                   4728:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   4729:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   4730:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   4731:                 delete($usecheck{'all'});
                   4732:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   4733:                     my $access = $1;
                   4734:                     $displaydiv{$access} = 'inline';
                   4735:                 } elsif ($current->{access} eq 'none') {
                   4736:                     $displaydiv{'priv'} = 'none';
                   4737:                 }
                   4738:             }
                   4739:         }
                   4740:     }
                   4741:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   4742:               '<p>'.$lt{'whi'}.'</p>';
                   4743:     foreach my $access (@{$accesstypes}) {
                   4744:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   4745:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   4746:                    $lt{$access}.'</label>';
                   4747:         if ($access eq 'status') {
                   4748:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   4749:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   4750:                                                                  $othertitle,$usertypes,$types).
                   4751:                        '</div>';
                   4752:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   4753:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   4754:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4755:                        '</div>';
                   4756:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   4757:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   4758:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   4759:                        '</div>';
                   4760:         }
                   4761:         $output .= '</p>';
                   4762:     }
                   4763:     $output .= '</fieldset>';
                   4764:     return $output;
                   4765: }
                   4766: 
1.121     raeburn  4767: sub radiobutton_prefs {
1.160.6.16  raeburn  4768:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113  raeburn  4769:         $additional,$align,$firstval) = @_;
1.121     raeburn  4770:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   4771:                    (ref($choices) eq 'HASH'));
                   4772: 
                   4773:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   4774: 
                   4775:     foreach my $item (@{$toggles}) {
                   4776:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      4777:             $checkedon{$item} = ' checked="checked" ';
                   4778:             $checkedoff{$item} = ' ';
1.121     raeburn  4779:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      4780:             $checkedoff{$item} = ' checked="checked" ';
                   4781:             $checkedon{$item} = ' ';
                   4782:         }
                   4783:     }
                   4784:     if (ref($settings) eq 'HASH') {
1.121     raeburn  4785:         foreach my $item (@{$toggles}) {
1.118     jms      4786:             if ($settings->{$item} eq '1') {
                   4787:                 $checkedon{$item} =  ' checked="checked" ';
                   4788:                 $checkedoff{$item} = ' ';
                   4789:             } elsif ($settings->{$item} eq '0') {
                   4790:                 $checkedoff{$item} =  ' checked="checked" ';
                   4791:                 $checkedon{$item} = ' ';
                   4792:             }
                   4793:         }
1.121     raeburn  4794:     }
1.160.6.16  raeburn  4795:     if ($onclick) {
                   4796:         $onclick = ' onclick="'.$onclick.'"';
                   4797:     }
1.121     raeburn  4798:     foreach my $item (@{$toggles}) {
1.118     jms      4799:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  4800:         $datatable .=
1.160.6.16  raeburn  4801:             '<tr'.$css_class.'><td valign="top">'.
                   4802:             '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57  raeburn  4803:             '</span></td>';
                   4804:         if ($align eq 'left') {
                   4805:             $datatable .= '<td class="LC_left_item">';
                   4806:         } else {
                   4807:             $datatable .= '<td class="LC_right_item">';
                   4808:         }
1.160.6.113  raeburn  4809:         $datatable .= '<span class="LC_nobreak">';
                   4810:         if ($firstval eq 'no') {
                   4811:             $datatable .=
                   4812:                 '<label><input type="radio" name="'.
                   4813:                 $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
                   4814:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
                   4815:                 $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
                   4816:         } else {
                   4817:             $datatable .=
1.118     jms      4818:             '<label><input type="radio" name="'.
1.160.6.16  raeburn  4819:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      4820:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.160.6.113  raeburn  4821:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
                   4822:         }
                   4823:         $datatable .= '</span>'.$additional.'</td></tr>';
1.118     jms      4824:         $itemcount ++;
1.121     raeburn  4825:     }
                   4826:     return ($datatable,$itemcount);
                   4827: }
                   4828: 
1.160.6.118.2  1(raebur 4829:1): sub print_ltitools {
                   4830:1):     my ($dom,$settings,$rowtotal) = @_;
                   4831:1):     my $rownum = 0;
                   4832:1):     my $css_class;
                   4833:1):     my $itemcount = 1;
                   4834:1):     my $maxnum = 0;
                   4835:1):     my %ordered;
                   4836:1):     if (ref($settings) eq 'HASH') {
                   4837:1):         foreach my $item (keys(%{$settings})) {
                   4838:1):             if (ref($settings->{$item}) eq 'HASH') {
                   4839:1):                 my $num = $settings->{$item}{'order'};
                   4840:1):                 $ordered{$num} = $item;
                   4841:1):             }
                   4842:1):         }
                   4843:1):     }
                   4844:1):     my $confname = $dom.'-domainconfig';
                   4845:1):     my $switchserver = &check_switchserver($dom,$confname);
                   4846:1):     my $maxnum = scalar(keys(%ordered));
                   4847:1):     my $datatable;
                   4848:1):     my %lt = &ltitools_names();
                   4849:1):     my @courseroles = ('cc','in','ta','ep','st');
                   4850:1):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   4851:1):     my @fields = ('fullname','firstname','lastname','email','roles','user');
                   4852:1):     if (keys(%ordered)) {
                   4853:1):         my @items = sort { $a <=> $b } keys(%ordered);
                   4854:1):         for (my $i=0; $i<@items; $i++) {
                   4855:1):             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4856:1):             my $item = $ordered{$items[$i]};
                   4857:1):             my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
                   4858:1):             if (ref($settings->{$item}) eq 'HASH') {
                   4859:1):                 $title = $settings->{$item}->{'title'};
                   4860:1):                 $url = $settings->{$item}->{'url'};
                   4861:1):                 $key = $settings->{$item}->{'key'};
                   4862:1):                 $secret = $settings->{$item}->{'secret'};
                   4863:1):                 $lifetime = $settings->{$item}->{'lifetime'};
                   4864:1):                 my $image = $settings->{$item}->{'image'};
                   4865:1):                 if ($image ne '') {
                   4866:1):                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   4867:1):                 }
                   4868:1):                 if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
                   4869:1):                     $sigsel{'HMAC-256'} = ' selected="selected"';
                   4870:1):                 } else {
                   4871:1):                     $sigsel{'HMAC-SHA1'} = ' selected="selected"';
                   4872:1):                 }
                   4873:1):             }
                   4874:1):             my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
                   4875:1):             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   4876:1):                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   4877:1):             for (my $k=0; $k<=$maxnum; $k++) {
                   4878:1):                 my $vpos = $k+1;
                   4879:1):                 my $selstr;
                   4880:1):                 if ($k == $i) {
                   4881:1):                     $selstr = ' selected="selected" ';
                   4882:1):                 }
                   4883:1):                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   4884:1):             }
                   4885:1):             $datatable .= '</select>'.('&nbsp;'x2).
                   4886:1):                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   4887:1):                 &mt('Delete?').'</label></span></td>'.
                   4888:1):                 '<td colspan="2">'.
                   4889:1):                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   4890:1):                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
                   4891:1):                 ('&nbsp;'x2).
                   4892:1):                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   4893:1):                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   4894:1):                 ('&nbsp;'x2).
                   4895:1):                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   4896:1):                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   4897:1):                 ('&nbsp;'x2).
                   4898:1):                 '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
                   4899:1):                 '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
                   4900:1):                 '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
                   4901:1):                 '<br /><br />'.
                   4902:1):                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
                   4903:1):                 ' value="'.$url.'" /></span>'.
                   4904:1):                 ('&nbsp;'x2).
                   4905:1):                 '<span class="LC_nobreak">'.$lt{'key'}.':'.
                   4906:1):                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   4907:1):                 ('&nbsp;'x2).
                   4908:1):                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
                   4909:1):                 '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
                   4910:1):                 ('&nbsp;'x2).
                   4911:1):                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   4912:1):                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   4913:1):                 '<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>'.
                   4914:1):                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   4915:1):                 '</fieldset>'.
                   4916:1):                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   4917:1):                 '<span class="LC_nobreak">'.&mt('Display target:');
                   4918:1):             my %currdisp;
                   4919:1):             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   4920:1):                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   4921:1):                     $currdisp{'window'} = ' checked="checked"';
                   4922:1):                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   4923:1):                     $currdisp{'tab'} = ' checked="checked"';
                   4924:1):                 } else {
                   4925:1):                     $currdisp{'iframe'} = ' checked="checked"';
                   4926:1):                 }
                   4927:1):                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   4928:1):                     $currdisp{'width'} = $1;
                   4929:1):                 }
                   4930:1):                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   4931:1):                      $currdisp{'height'} = $1;
                   4932:1):                 }
                   4933:1):                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   4934:1):                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
                   4935:1):             } else {
                   4936:1):                 $currdisp{'iframe'} = ' checked="checked"';
                   4937:1):             }
                   4938:1):             foreach my $disp ('iframe','tab','window') {
                   4939:1):                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   4940:1):                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   4941:1):             }
                   4942:1):             $datatable .= ('&nbsp;'x4);
                   4943:1):             foreach my $dimen ('width','height') {
                   4944:1):                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   4945:1):                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   4946:1):                               ('&nbsp;'x2);
                   4947:1):             }
                   4948:1):             $datatable .= '</span><br />'.
                   4949:1):                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   4950:1):                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
                   4951:1):                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   4952:1):                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   4953:1):                           '</textarea></div><div style=""></div>'.
                   4954:1):                           '<div style="padding:0;clear:both;margin:0;border:0"></div>';
                   4955:1):             $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   4956:1):             if ($imgsrc) {
                   4957:1):                 $datatable .= $imgsrc.
                   4958:1):                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   4959:1):                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   4960:1):                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   4961:1):             } else {
                   4962:1):                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   4963:1):             }
                   4964:1):             if ($switchserver) {
                   4965:1):                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   4966:1):             } else {
                   4967:1):                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   4968:1):             }
                   4969:1):             $datatable .= '</span></fieldset>';
                   4970:1):             my (%checkedfields,%rolemaps,$userincdom);
                   4971:1):             if (ref($settings->{$item}) eq 'HASH') {
                   4972:1):                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   4973:1):                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   4974:1):                 }
                   4975:1):                 $userincdom = $settings->{$item}->{'incdom'};
                   4976:1):                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   4977:1):                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   4978:1):                     $checkedfields{'roles'} = 1;
                   4979:1):                 }
                   4980:1):             }
                   4981:1):             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   4982:1):                           '<span class="LC_nobreak">';
                   4983:1):             my $userfieldstyle = 'display:none;';
                   4984:1):             my $seluserdom = '';
                   4985:1):             my $unseluserdom = ' selected="selected"';
                   4986:1):             foreach my $field (@fields) {
                   4987:1):                 my ($checked,$onclick,$id,$spacer);
                   4988:1):                 if ($checkedfields{$field}) {
                   4989:1):                     $checked = ' checked="checked"';
                   4990:1):                 }
                   4991:1):                 if ($field eq 'user') {
                   4992:1):                     $id = ' id="ltitools_user_field_'.$i.'"';
                   4993:1):                     $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
                   4994:1):                     if ($checked) {
                   4995:1):                         $userfieldstyle = 'display:inline-block';
                   4996:1):                         if ($userincdom) {
                   4997:1):                             $seluserdom = $unseluserdom;
                   4998:1):                             $unseluserdom = '';
                   4999:1):                         }
                   5000:1):                     }
                   5001:1):                 } else {
                   5002:1):                     $spacer = ('&nbsp;' x2);
                   5003:1):                 }
                   5004:1):                 $datatable .= '<label>'.
                   5005:1):                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
                   5006:1):                               $lt{$field}.'</label>'.$spacer;
                   5007:1):             }
                   5008:1):             $datatable .= '</span>';
                   5009:1):             $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
                   5010:1):                           '<span class="LC_nobreak"> : '.
                   5011:1):                           '<select name="ltitools_userincdom_'.$i.'">'.
                   5012:1):                           '<option value="">'.&mt('Select').'</option>'.
                   5013:1):                           '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
                   5014:1):                           '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
                   5015:1):                           '</select></span></div>';
                   5016:1):             $datatable .= '</fieldset>'.
                   5017:1):                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5018:1):             foreach my $role (@courseroles) {
                   5019:1):                 my ($selected,$selectnone);
                   5020:1):                 if (!$rolemaps{$role}) {
                   5021:1):                     $selectnone = ' selected="selected"';
                   5022:1):                 }
                   5023:1):                 $datatable .= '<td align="center">'.
                   5024:1):                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5025:1):                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   5026:1):                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   5027:1):                 foreach my $ltirole (@ltiroles) {
                   5028:1):                     unless ($selectnone) {
                   5029:1):                         if ($rolemaps{$role} eq $ltirole) {
                   5030:1):                             $selected = ' selected="selected"';
                   5031:1):                         } else {
                   5032:1):                             $selected = '';
                   5033:1):                         }
                   5034:1):                     }
                   5035:1):                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   5036:1):                 }
                   5037:1):                 $datatable .= '</select></td>';
                   5038:1):             }
                   5039:1):             $datatable .= '</tr></table></fieldset>';
                   5040:1):             my %courseconfig;
                   5041:1):             if (ref($settings->{$item}) eq 'HASH') {
                   5042:1):                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   5043:1):                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   5044:1):                 }
                   5045:1):             }
                   5046:1):             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   5047:1):             foreach my $item ('label','title','target','linktext','explanation','append') {
                   5048:1):                 my $checked;
                   5049:1):                 if ($courseconfig{$item}) {
                   5050:1):                     $checked = ' checked="checked"';
                   5051:1):                 }
                   5052:1):                 $datatable .= '<label>'.
                   5053:1):                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   5054:1):                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   5055:1):             }
                   5056:1):             $datatable .= '</span></fieldset>'.
                   5057:1):                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5058:1):                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   5059:1):             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   5060:1):                 my %custom = %{$settings->{$item}->{'custom'}};
                   5061:1):                 if (keys(%custom) > 0) {
                   5062:1):                     foreach my $key (sort(keys(%custom))) {
                   5063:1):                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5064:1):                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   5065:1):                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   5066:1):                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   5067:1):                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   5068:1):                     }
                   5069:1):                 }
                   5070:1):             }
                   5071:1):             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   5072:1):                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   5073:1):                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   5074:1):                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   5075:1):             $datatable .= '</table></fieldset></td></tr>'."\n";
                   5076:1):             $itemcount ++;
                   5077:1):         }
                   5078:1):     }
                   5079:1):     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5080:1):     my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
                   5081:1):     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   5082:1):                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   5083:1):                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   5084:1):     for (my $k=0; $k<$maxnum+1; $k++) {
                   5085:1):         my $vpos = $k+1;
                   5086:1):         my $selstr;
                   5087:1):         if ($k == $maxnum) {
                   5088:1):             $selstr = ' selected="selected" ';
                   5089:1):         }
                   5090:1):         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5091:1):     }
                   5092:1):     $datatable .= '</select>&nbsp;'."\n".
                   5093:1):                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   5094:1):                   '<td colspan="2">'.
                   5095:1):                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   5096:1):                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
                   5097:1):                   ('&nbsp;'x2).
                   5098:1):                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   5099:1):                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   5100:1):                   ('&nbsp;'x2).
                   5101:1):                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   5102:1):                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   5103:1):                   '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
                   5104:1):                   '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
                   5105:1):                   '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
                   5106:1):                   '<br />'.
                   5107:1):                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
                   5108:1):                   ('&nbsp;'x2).
                   5109:1):                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   5110:1):                   ('&nbsp;'x2).
                   5111:1):                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
                   5112:1):                   ('&nbsp;'x2).
                   5113:1):                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   5114:1):                   '<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".
                   5115:1):                   '</fieldset>'.
                   5116:1):                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   5117:1):                   '<span class="LC_nobreak">'.&mt('Display target:');
                   5118:1):     my %defaultdisp;
                   5119:1):     $defaultdisp{'iframe'} = ' checked="checked"';
                   5120:1):     foreach my $disp ('iframe','tab','window') {
                   5121:1):         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   5122:1):                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   5123:1):     }
                   5124:1):     $datatable .= ('&nbsp;'x4);
                   5125:1):     foreach my $dimen ('width','height') {
                   5126:1):         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   5127:1):                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   5128:1):                       ('&nbsp;'x2);
                   5129:1):     }
                   5130:1):     $datatable .= '</span><br />'.
                   5131:1):                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   5132:1):                   '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
                   5133:1):                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   5134:1):                   '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
                   5135:1):                   '</div><div style=""></div>'.
                   5136:1):                   '<div style="padding:0;clear:both;margin:0;border:0"></div>';
                   5137:1):     $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
                   5138:1):                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   5139:1):     if ($switchserver) {
                   5140:1):         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5141:1):     } else {
                   5142:1):         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   5143:1):     }
                   5144:1):     $datatable .= '</span></fieldset>'.
                   5145:1):                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   5146:1):                   '<span class="LC_nobreak">';
                   5147:1):     foreach my $field (@fields) {
                   5148:1):         my ($id,$onclick,$spacer);
                   5149:1):         if ($field eq 'user') {
                   5150:1):             $id = ' id="ltitools_user_field_add"';
                   5151:1):             $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
                   5152:1):         } else {
                   5153:1):             $spacer = ('&nbsp;' x2);
                   5154:1):         }
                   5155:1):         $datatable .= '<label>'.
                   5156:1):                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
                   5157:1):                       $lt{$field}.'</label>'.$spacer;
                   5158:1):     }
                   5159:1):     $datatable .= '</span>'.
                   5160:1):                   '<div style="display:none;" id="ltitools_user_div_add">'.
                   5161:1):                   '<span class="LC_nobreak"> : '.
                   5162:1):                   '<select name="ltitools_userincdom_add">'.
                   5163:1):                   '<option value="" selected="selected">'.&mt('Select').'</option>'.
                   5164:1):                   '<option value="0">'.&mt('username').'</option>'.
                   5165:1):                   '<option value="1">'.&mt('username:domain').'</option>'.
                   5166:1):                   '</select></span></div></fieldset>';
                   5167:1):     $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   5168:1):     foreach my $role (@courseroles) {
                   5169:1):         my ($checked,$checkednone);
                   5170:1):         $datatable .= '<td align="center">'.
                   5171:1):                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   5172:1):                       '<select name="ltitools_add_roles_'.$role.'">'.
                   5173:1):                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   5174:1):         foreach my $ltirole (@ltiroles) {
                   5175:1):             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   5176:1):         }
                   5177:1):         $datatable .= '</select></td>';
                   5178:1):     }
                   5179:1):     $datatable .= '</tr></table></fieldset>'.
                   5180:1):                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   5181:1):     foreach my $item ('label','title','target','linktext','explanation','append') {
                   5182:1):         $datatable .= '<label>'.
                   5183:1):                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   5184:1):                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   5185:1):     }
                   5186:1):     $datatable .= '</span></fieldset>'.
                   5187:1):                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   5188:1):                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   5189:1):                   '<tr><td><span class="LC_nobreak">'.
                   5190:1):                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   5191:1):                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   5192:1):                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   5193:1):                   '</table></fieldset>'."\n".
                   5194:1):                   '</td>'."\n".
                   5195:1):                   '</tr>'."\n";
                   5196:1):     $itemcount ++;
                   5197:1):     return $datatable;
                   5198:1): }
                   5199:1): 
                   5200:1): sub ltitools_names {
                   5201:1):     my %lt = &Apache::lonlocal::texthash(
                   5202:1):                                           'title'          => 'Title',
                   5203:1):                                           'version'        => 'Version',
                   5204:1):                                           'msgtype'        => 'Message Type',
                   5205:1):                                           'sigmethod'      => 'Signature Method',
                   5206:1):                                           'url'            => 'URL',
                   5207:1):                                           'key'            => 'Key',
                   5208:1):                                           'lifetime'       => 'Nonce lifetime (s)',
                   5209:1):                                           'secret'         => 'Secret',
                   5210:1):                                           'icon'           => 'Icon',
                   5211:1):                                           'user'           => 'User',
                   5212:1):                                           'fullname'       => 'Full Name',
                   5213:1):                                           'firstname'      => 'First Name',
                   5214:1):                                           'lastname'       => 'Last Name',
                   5215:1):                                           'email'          => 'E-mail',
                   5216:1):                                           'roles'          => 'Role',
                   5217:1):                                           'window'         => 'Window',
                   5218:1):                                           'tab'            => 'Tab',
                   5219:1):                                           'iframe'         => 'iFrame',
                   5220:1):                                           'height'         => 'Height',
                   5221:1):                                           'width'          => 'Width',
                   5222:1):                                           'linktext'       => 'Default Link Text',
                   5223:1):                                           'explanation'    => 'Default Explanation',
                   5224:1):                                           'crstarget'      => 'Display target',
                   5225:1):                                           'crslabel'       => 'Course label',
                   5226:1):                                           'crstitle'       => 'Course title',
                   5227:1):                                           'crslinktext'    => 'Link Text',
                   5228:1):                                           'crsexplanation' => 'Explanation',
                   5229:1):                                           'crsappend'      => 'Provider URL',
                   5230:1):                                         );
                   5231:1): 
                   5232:1):     return %lt;
                   5233:1): }
                   5234:1): 
          5(raebur 5235:2): sub print_lti {
                   5236:2):     my ($position,$dom,$settings,$rowtotal) = @_;
                   5237:2):     my $itemcount = 1;
                   5238:2):     my ($datatable,$css_class);
                   5239:2):     my (%rules,%encrypt,%privkeys,%linkprot);
                   5240:2):     if (ref($settings) eq 'HASH') {
                   5241:2):         if ($position eq 'top') {
                   5242:2):             if (exists($settings->{'encrypt'})) {
                   5243:2):                 if (ref($settings->{'encrypt'}) eq 'HASH') {
                   5244:2):                     foreach my $key (keys(%{$settings->{'encrypt'}})) {
                   5245:2):                         $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
                   5246:2):                     }
                   5247:2):                 }
                   5248:2):             }
                   5249:2):             if (exists($settings->{'private'})) {
                   5250:2):                 if (ref($settings->{'private'}) eq 'HASH') {
                   5251:2):                     if (ref($settings->{'private'}) eq 'HASH') {
                   5252:2):                         if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
                   5253:2):                             map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
                   5254:2):                         }
                   5255:2):                     }
                   5256:2):                 }
                   5257:2):             }
                   5258:2):         } elsif ($position eq 'middle') {
                   5259:2):             if (exists($settings->{'rules'})) {
                   5260:2):                 if (ref($settings->{'rules'}) eq 'HASH') {
                   5261:2):                     %rules = %{$settings->{'rules'}};
                   5262:2):                 }
                   5263:2):             }
                   5264:2):         } elsif ($position eq 'bottom') {
                   5265:2):             if (exists($settings->{'linkprot'})) {
                   5266:2):                 if (ref($settings->{'linkprot'}) eq 'HASH') {
                   5267:2):                     %linkprot = %{$settings->{'linkprot'}};
                   5268:2):                     if ($linkprot{'lock'}) {
                   5269:2):                         delete($linkprot{'lock'});
                   5270:2):                     }
                   5271:2):                 }
                   5272:2):             }
                   5273:2):         }
                   5274:2):     }
                   5275:2):     if ($position eq 'top') {
                   5276:2):         my @ids=&Apache::lonnet::current_machine_ids();
                   5277:2):         my %servers = &Apache::lonnet::get_servers($dom,'library');
                   5278:2):         my $primary = &Apache::lonnet::domain($dom,'primary');
                   5279:2):         my ($extra,$numshown);
                   5280:2):         foreach my $hostid (sort(keys(%servers))) {
                   5281:2):             my ($showextra,$divsty,$switch);
                   5282:2):             if ($hostid eq $primary) {
                   5283:2):                 if ($encrypt{'ltisec_domlinkprot'}) {
                   5284:2):                     $showextra = 1;
                   5285:2):                 }
                   5286:2):             }
                   5287:2):             if ($encrypt{'ltisec_crslinkprot'}) {
                   5288:2):                 $showextra = 1;
                   5289:2):             }
                   5290:2):             unless (grep(/^\Q$hostid\E$/,@ids)) {
                   5291:2):                 $switch = 1;
                   5292:2):             }
                   5293:2):             if ($showextra) {
                   5294:2):                 $numshown ++;
                   5295:2):                 $divsty = 'display:inline-block';
                   5296:2):             } else {
                   5297:2):                 $divsty = 'display:none';
                   5298:2):             }
                   5299:2):             $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
                   5300:2):                       '<legend>'.$hostid.'</legend>';
                   5301:2):             if ($switch) {
                   5302:2):                 my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&amp;role='.
                   5303:2):                                    &HTML::Entities::encode($env{'request.role'},'\'<>"&').
                   5304:2):                                    '&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
                   5305:2):                 if (exists($privkeys{$hostid})) {
                   5306:2):                     $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
                   5307:2):                               '<span class="LC_nobreak">'.
                   5308:2):                               &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   5309:2):                               '<span class="LC_nobreak">'.&mt('Change?').
                   5310:2):                               '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   5311:2):                               ('&nbsp;'x2).
                   5312:2):                               '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
                   5313:2):                               '</label>&nbsp;&nbsp;</span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   5314:2):                               '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   5315:2):                               '</span></div>';
                   5316:2):                 } else {
                   5317:2):                     $extra .= '<span class="LC_nobreak">'.
                   5318:2):                               &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
                   5319:2):                               '</span>'."\n";
                   5320:2):                 }
                   5321:2):             } elsif (exists($privkeys{$hostid})) {
                   5322:2):                 $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
                   5323:2):                           &mt('Encryption Key').': ['.&mt('not shown').'] '.('&nbsp;'x2).'</span></div>'.
                   5324:2):                           '<span class="LC_nobreak">'.&mt('Change?').
                   5325:2):                           '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
                   5326:2):                           ('&nbsp;'x2).
                   5327:2):                           '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
                   5328:2):                           '</label>&nbsp;&nbsp;</span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
                   5329:2):                           '<span class="LC_nobreak">'.&mt('New Key').':'.
                   5330:2):                           '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
                   5331:2):                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                   5332:2):                           '</span></div>';
                   5333:2):             } else {
                   5334:2):                 $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
                   5335:2):                           '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
                   5336:2):                           '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
                   5337:2):             }
                   5338:2):             $extra .= '</fieldset>';
                   5339:2):         }
                   5340:2):         my %choices = &Apache::lonlocal::texthash (
                   5341:2):                                                       ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
                   5342:2):                                                       ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
                   5343:2):                                                   );
                   5344:2):         my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot);
                   5345:2):         my %defaultchecked = (
                   5346:2):                                'ltisec_crslinkprot' => 'off',
                   5347:2):                                'ltisec_domlinkprot' => 'off',
                   5348:2):                              );
                   5349:2):         my ($onclick,$itemcount);
                   5350:2):         $onclick = 'javascript:toggleLTIEncKey(this.form);';
                   5351:2):         ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
                   5352:2):                                                      \%choices,$itemcount,$onclick,'','left','no');
                   5353:2): 
                   5354:2):         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5355:2):         my $noprivkeysty = 'display:inline-block';
                   5356:2):         if ($numshown) {
                   5357:2):             $noprivkeysty = 'display:none';
                   5358:2):         }
                   5359:2):         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
                   5360:2):                       '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
                   5361:2):                       '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
                   5362:2):                       $extra.
                   5363:2):                       '</td></tr>';
                   5364:2):         $itemcount ++;
                   5365:2):         $$rowtotal += $itemcount;
                   5366:2):     } elsif ($position eq 'middle') {
                   5367:2):         $datatable = &password_rules('secrets',\$itemcount,\%rules);
                   5368:2):         $$rowtotal += $itemcount;
                   5369:2):     } elsif ($position eq 'bottom') {
                   5370:2):          $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
                   5371:2):     }
                   5372:2):     return $datatable;
                   5373:2): }
                   5374:2): 
1.121     raeburn  5375: sub print_coursedefaults {
1.139     raeburn  5376:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  5377:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  5378:     my $itemcount = 1;
1.160.6.16  raeburn  5379:     my %choices =  &Apache::lonlocal::texthash (
1.160.6.21  raeburn  5380:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16  raeburn  5381:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   5382:         coursecredits        => 'Credits can be specified for courses',
1.160.6.57  raeburn  5383:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   5384:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115  raeburn  5385:         inline_chem          => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90  raeburn  5386:         texengine            => 'Default method to display mathematics',
1.160.6.57  raeburn  5387:         postsubmit           => 'Disable submit button/keypress following student submission',
1.160.6.64  raeburn  5388:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70  raeburn  5389:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2  5(raebur 5390:2):         ltiauth              => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
          7(raebur 5391:2):     );
1.160.6.21  raeburn  5392:     my %staticdefaults = (
                   5393:                            anonsurvey_threshold => 10,
                   5394:                            uploadquota          => 500,
1.160.6.57  raeburn  5395:                            postsubmit           => 60,
1.160.6.70  raeburn  5396:                            mysqltables          => 172800,
1.160.6.21  raeburn  5397:                          );
1.139     raeburn  5398:     if ($position eq 'top') {
1.160.6.57  raeburn  5399:         %defaultchecked = (
                   5400:                             'uselcmath'       => 'on',
                   5401:                             'usejsme'         => 'on',
1.160.6.115  raeburn  5402:                             'inline_chem'     => 'on',
1.160.6.64  raeburn  5403:                             'canclone'        => 'none',
1.160.6.57  raeburn  5404:                           );
1.160.6.115  raeburn  5405:         @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90  raeburn  5406:         my $deftex = $Apache::lonnet::deftex;
                   5407:         if (ref($settings) eq 'HASH') {
                   5408:             if ($settings->{'texengine'}) {
                   5409:                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   5410:                     $deftex = $settings->{'texengine'};
                   5411:                 }
                   5412:             }
                   5413:         }
                   5414:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5415:         my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
                   5416:                        '<span class="LC_nobreak">'.$choices{'texengine'}.
                   5417:                        '</span></td><td class="LC_right_item">'.
                   5418:                        '<select name="texengine">'."\n";
                   5419:         my %texoptions = (
                   5420:                             MathJax  => 'MathJax',
                   5421:                             mimetex  => &mt('Convert to Images'),
                   5422:                             tth      => &mt('TeX to HTML'),
                   5423:                          );
                   5424:         foreach my $renderer ('MathJax','mimetex','tth') {
                   5425:             my $selected = '';
                   5426:             if ($renderer eq $deftex) {
                   5427:                 $selected = ' selected="selected"';
                   5428:             }
                   5429:             $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
                   5430:         }
                   5431:         $mathdisp .= '</select></td></tr>'."\n";
                   5432:         $itemcount ++;
1.139     raeburn  5433:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  5434:                                                      \%choices,$itemcount);
1.160.6.90  raeburn  5435:         $datatable = $mathdisp.$datatable;
1.160.6.64  raeburn  5436:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5437:         $datatable .=
                   5438:             '<tr'.$css_class.'><td valign="top">'.
                   5439:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   5440:             '</span></td><td class="LC_left_item">';
                   5441:         my $currcanclone = 'none';
                   5442:         my $onclick;
                   5443:         my @cloneoptions = ('none','domain');
1.160.6.111  raeburn  5444:         my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64  raeburn  5445:                              none     => 'No additional course requesters',
                   5446:                              domain   => "Any course requester in course's domain",
                   5447:                              instcode => 'Course requests for official courses ...',
                   5448:                           );
                   5449:         my (%codedefaults,@code_order,@posscodes);
                   5450:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   5451:                                                     \@code_order) eq 'ok') {
                   5452:             if (@code_order > 0) {
                   5453:                 push(@cloneoptions,'instcode');
                   5454:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   5455:             }
                   5456:         }
                   5457:         if (ref($settings) eq 'HASH') {
                   5458:             if ($settings->{'canclone'}) {
                   5459:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   5460:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   5461:                         if (@code_order > 0) {
                   5462:                             $currcanclone = 'instcode';
                   5463:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   5464:                         }
                   5465:                     }
                   5466:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   5467:                     $currcanclone = $settings->{'canclone'};
                   5468:                 }
                   5469:             }
                   5470:         }
                   5471:         foreach my $option (@cloneoptions) {
                   5472:             my ($checked,$additional);
                   5473:             if ($currcanclone eq $option) {
                   5474:                 $checked = ' checked="checked"';
                   5475:             }
                   5476:             if ($option eq 'instcode') {
                   5477:                 if (@code_order) {
                   5478:                     my $show = 'none';
                   5479:                     if ($checked) {
                   5480:                         $show = 'block';
                   5481:                     }
                   5482:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   5483:                                   &mt('Institutional codes for new and cloned course have identical:').
                   5484:                                   '<br />';
                   5485:                     foreach my $item (@code_order) {
                   5486:                         my $codechk;
                   5487:                         if ($checked) {
                   5488:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   5489:                                 $codechk = ' checked="checked"';
                   5490:                             }
                   5491:                         }
                   5492:                         $additional .= '<label>'.
                   5493:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   5494:                                        $item.'</label>';
                   5495:                     }
                   5496:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   5497:                 }
                   5498:             }
                   5499:             $datatable .=
                   5500:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   5501:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   5502:                 '</label>&nbsp;'.$additional.'</span><br />';
                   5503:         }
                   5504:         $datatable .= '</td>'.
                   5505:                       '</tr>';
                   5506:         $itemcount ++;
1.139     raeburn  5507:     } else {
                   5508:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71  raeburn  5509:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16  raeburn  5510:         my $currusecredits = 0;
1.160.6.57  raeburn  5511:         my $postsubmitclient = 1;
1.160.6.118.2  4(raebur 5512:2):         my $ltiauth = 0;
1.160.6.30  raeburn  5513:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  5514:         if (ref($settings) eq 'HASH') {
1.160.6.118.2  4(raebur 5515:2):             if ($settings->{'ltiauth'}) {
                   5516:2):                 $ltiauth = 1;
                   5517:2):             }
1.139     raeburn  5518:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21  raeburn  5519:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   5520:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   5521:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   5522:                 }
                   5523:             }
1.160.6.16  raeburn  5524:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  5525:                 foreach my $type (@types) {
                   5526:                     next if ($type eq 'community');
                   5527:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   5528:                     if ($defcredits{$type} ne '') {
                   5529:                         $currusecredits = 1;
                   5530:                     }
                   5531:                 }
                   5532:             }
                   5533:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   5534:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   5535:                     $postsubmitclient = 0;
                   5536:                     foreach my $type (@types) {
                   5537:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5538:                     }
                   5539:                 } else {
                   5540:                     foreach my $type (@types) {
                   5541:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   5542:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   5543:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
                   5544:                             } else {
                   5545:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5546:                             }
                   5547:                         } else {
                   5548:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5549:                         }
                   5550:                     }
                   5551:                 }
                   5552:             } else {
                   5553:                 foreach my $type (@types) {
                   5554:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16  raeburn  5555:                 }
                   5556:             }
1.160.6.70  raeburn  5557:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   5558:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   5559:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   5560:                 }
                   5561:             } else {
                   5562:                 foreach my $type (@types) {
                   5563:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   5564:                 }
                   5565:             }
1.160.6.58  raeburn  5566:         } else {
                   5567:             foreach my $type (@types) {
                   5568:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   5569:             }
1.139     raeburn  5570:         }
                   5571:         if (!$currdefresponder) {
1.160.6.21  raeburn  5572:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  5573:         } elsif ($currdefresponder < 1) {
                   5574:             $currdefresponder = 1;
                   5575:         }
1.160.6.21  raeburn  5576:         foreach my $type (@types) {
                   5577:             if ($curruploadquota{$type} eq '') {
                   5578:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   5579:             }
                   5580:         }
1.139     raeburn  5581:         $datatable .=
1.160.6.16  raeburn  5582:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5583:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  5584:                 '</span></td>'.
                   5585:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5586:                 '<input type="text" name="anonsurvey_threshold"'.
                   5587:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37  raeburn  5588:                 '</td></tr>'."\n";
                   5589:         $itemcount ++;
                   5590:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5591:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5592:                       $choices{'uploadquota'}.
                   5593:                       '</span></td>'.
                   5594:                       '<td align="right" class="LC_right_item">'.
                   5595:                       '<table><tr>';
1.160.6.21  raeburn  5596:         foreach my $type (@types) {
                   5597:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   5598:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   5599:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   5600:         }
                   5601:         $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37  raeburn  5602:         $itemcount ++;
1.160.6.40  raeburn  5603:         my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16  raeburn  5604:         my $display = 'none';
                   5605:         if ($currusecredits) {
                   5606:             $display = 'block';
                   5607:         }
                   5608:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57  raeburn  5609:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   5610:         foreach my $type (@types) {
                   5611:             next if ($type eq 'community');
                   5612:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   5613:                            '<input type="text" name="'.$type.'_credits"'.
                   5614:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
                   5615:         }
                   5616:         $additional .= '</tr></table></div>'."\n";
1.160.6.16  raeburn  5617:         %defaultchecked = ('coursecredits' => 'off');
                   5618:         @toggles = ('coursecredits');
                   5619:         my $current = {
                   5620:                         'coursecredits' => $currusecredits,
                   5621:                       };
                   5622:         (my $table,$itemcount) =
                   5623:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  5624:                                \%choices,$itemcount,$onclick,$additional,'left');
                   5625:         $datatable .= $table;
                   5626:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   5627:         my $display = 'none';
                   5628:         if ($postsubmitclient) {
                   5629:             $display = 'block';
                   5630:         }
                   5631:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59  raeburn  5632:                       &mt('Number of seconds submit is disabled').'<br />'.
                   5633:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   5634:                       '<table><tr>';
1.160.6.57  raeburn  5635:         foreach my $type (@types) {
                   5636:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   5637:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   5638:                            $deftimeout{$type}.'" size="5" /></td>';
                   5639:         }
                   5640:         $additional .= '</tr></table></div>'."\n";
                   5641:         %defaultchecked = ('postsubmit' => 'on');
                   5642:         @toggles = ('postsubmit');
1.160.6.70  raeburn  5643:         $current = {
                   5644:                        'postsubmit' => $postsubmitclient,
                   5645:                    };
1.160.6.57  raeburn  5646:         ($table,$itemcount) =
                   5647:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   5648:                                \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16  raeburn  5649:         $datatable .= $table;
1.160.6.70  raeburn  5650:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5651:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5652:                       $choices{'mysqltables'}.
                   5653:                       '</span></td>'.
                   5654:                       '<td align="right" class="LC_right_item">'.
                   5655:                       '<table><tr>';
                   5656:         foreach my $type (@types) {
                   5657:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   5658:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81  raeburn  5659:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70  raeburn  5660:         }
                   5661:         $datatable .= '</tr></table></td></tr>'."\n";
                   5662:         $itemcount ++;
1.160.6.118.2  4(raebur 5663:2):         %defaultchecked = ('ltiauth' => 'off');
                   5664:2):         @toggles = ('ltiauth');
                   5665:2):         $current = {
                   5666:2):                        'ltiauth' => $ltiauth,
                   5667:2):                    };
                   5668:2):         ($table,$itemcount) =
                   5669:2):             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   5670:2):                                \%choices,$itemcount,undef,undef,'left');
                   5671:2):         $datatable .= $table;
                   5672:2):         $itemcount ++;
1.160.6.37  raeburn  5673:     }
                   5674:     $$rowtotal += $itemcount;
                   5675:     return $datatable;
                   5676: }
                   5677: 
                   5678: sub print_selfenrollment {
                   5679:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5680:     my ($css_class,$datatable);
                   5681:     my $itemcount = 1;
                   5682:     my @types = ('official','unofficial','community','textbook');
                   5683:     if (($position eq 'top') || ($position eq 'middle')) {
                   5684:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   5685:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   5686:         my @rows;
                   5687:         my $key;
                   5688:         if ($position eq 'top') {
                   5689:             $key = 'admin'; 
                   5690:             if (ref($rowsref) eq 'ARRAY') {
                   5691:                 @rows = @{$rowsref};
                   5692:             }
                   5693:         } elsif ($position eq 'middle') {
                   5694:             $key = 'default';
                   5695:             @rows = ('types','registered','approval','limit');
                   5696:         }
                   5697:         foreach my $row (@rows) {
                   5698:             if (defined($titlesref->{$row})) {
                   5699:                 $itemcount ++;
                   5700:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5701:                 $datatable .= '<tr'.$css_class.'>'.
                   5702:                               '<td>'.$titlesref->{$row}.'</td>'.
                   5703:                               '<td class="LC_left_item">'.
                   5704:                               '<table><tr>';
                   5705:                 my (%current,%currentcap);
                   5706:                 if (ref($settings) eq 'HASH') {
                   5707:                     if (ref($settings->{$key}) eq 'HASH') {
                   5708:                         foreach my $type (@types) {
                   5709:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5710:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   5711:                             }
                   5712:                             if (($row eq 'limit') && ($key eq 'default')) {
                   5713:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   5714:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   5715:                                 }
                   5716:                             }
                   5717:                         }
                   5718:                     }
                   5719:                 }
                   5720:                 my %roles = (
                   5721:                              '0' => &Apache::lonnet::plaintext('dc'),
                   5722:                             ); 
                   5723:             
                   5724:                 foreach my $type (@types) {
                   5725:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   5726:                         $datatable .= '<th>'.&mt($type).'</th>';
                   5727:                     }
                   5728:                 }
                   5729:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   5730:                     $datatable .= '</tr><tr>';
                   5731:                 }
                   5732:                 foreach my $type (@types) {
                   5733:                     if ($type eq 'community') {
                   5734:                         $roles{'1'} = &mt('Community personnel');
                   5735:                     } else {
                   5736:                         $roles{'1'} = &mt('Course personnel');
                   5737:                     }
                   5738:                     $datatable .= '<td style="vertical-align: top">';
                   5739:                     if ($position eq 'top') {
                   5740:                         my %checked;
                   5741:                         if ($current{$type} eq '0') {
                   5742:                             $checked{'0'} = ' checked="checked"';
                   5743:                         } else {
                   5744:                             $checked{'1'} = ' checked="checked"';
                   5745:                         }
                   5746:                         foreach my $role ('1','0') {
                   5747:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   5748:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   5749:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   5750:                                           $roles{$role}.'</label></span> ';
                   5751:                         }
                   5752:                     } else {
                   5753:                         if ($row eq 'types') {
                   5754:                             my %checked;
                   5755:                             if ($current{$type} =~ /^(all|dom)$/) {
                   5756:                                 $checked{$1} = ' checked="checked"';
                   5757:                             } else {
                   5758:                                 $checked{''} = ' checked="checked"';
                   5759:                             }
                   5760:                             foreach my $val ('','dom','all') {
                   5761:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5762:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5763:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5764:                             }
                   5765:                         } elsif ($row eq 'registered') {
                   5766:                             my %checked;
                   5767:                             if ($current{$type} eq '1') {
                   5768:                                 $checked{'1'} = ' checked="checked"';
                   5769:                             } else {
                   5770:                                 $checked{'0'} = ' checked="checked"';
                   5771:                             }
                   5772:                             foreach my $val ('0','1') {
                   5773:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5774:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5775:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5776:                             }
                   5777:                         } elsif ($row eq 'approval') {
                   5778:                             my %checked;
                   5779:                             if ($current{$type} =~ /^([12])$/) {
                   5780:                                 $checked{$1} = ' checked="checked"';
                   5781:                             } else {
                   5782:                                 $checked{'0'} = ' checked="checked"';
                   5783:                             }
                   5784:                             for my $val (0..2) {
                   5785:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5786:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5787:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5788:                             }
                   5789:                         } elsif ($row eq 'limit') {
                   5790:                             my %checked;
                   5791:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   5792:                                 $checked{$1} = ' checked="checked"';
                   5793:                             } else {
                   5794:                                 $checked{'none'} = ' checked="checked"';
                   5795:                             }
                   5796:                             my $cap;
                   5797:                             if ($currentcap{$type} =~ /^\d+$/) {
                   5798:                                 $cap = $currentcap{$type};
                   5799:                             }
                   5800:                             foreach my $val ('none','allstudents','selfenrolled') {
                   5801:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5802:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   5803:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   5804:                             }
                   5805:                             $datatable .= '<br />'.
                   5806:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   5807:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   5808:                                           '</span>'; 
                   5809:                         }
                   5810:                     }
                   5811:                     $datatable .= '</td>';
                   5812:                 }
                   5813:                 $datatable .= '</tr>';
                   5814:             }
                   5815:             $datatable .= '</table></td></tr>';
                   5816:         }
                   5817:     } elsif ($position eq 'bottom') {
1.160.6.39  raeburn  5818:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   5819:     }
                   5820:     $$rowtotal += $itemcount;
                   5821:     return $datatable;
                   5822: }
                   5823: 
                   5824: sub print_validation_rows {
                   5825:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   5826:     my ($itemsref,$namesref,$fieldsref);
                   5827:     if ($caller eq 'selfenroll') { 
                   5828:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   5829:     } elsif ($caller eq 'requestcourses') {
                   5830:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   5831:     }
                   5832:     my %currvalidation;
                   5833:     if (ref($settings) eq 'HASH') {
                   5834:         if (ref($settings->{'validation'}) eq 'HASH') {
                   5835:             %currvalidation = %{$settings->{'validation'}};
1.160.6.37  raeburn  5836:         }
1.160.6.39  raeburn  5837:     }
                   5838:     my $datatable;
                   5839:     my $itemcount = 0;
                   5840:     foreach my $item (@{$itemsref}) {
                   5841:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   5842:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   5843:                       $namesref->{$item}.
                   5844:                       '</span></td>'.
                   5845:                       '<td class="LC_left_item">';
                   5846:         if (($item eq 'url') || ($item eq 'button')) {
                   5847:             $datatable .= '<span class="LC_nobreak">'.
                   5848:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   5849:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   5850:         } elsif ($item eq 'fields') {
                   5851:             my @currfields;
                   5852:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   5853:                 @currfields = @{$currvalidation{$item}};
                   5854:             }
                   5855:             foreach my $field (@{$fieldsref}) {
                   5856:                 my $check = '';
                   5857:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   5858:                     $check = ' checked="checked"';
                   5859:                 }
                   5860:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5861:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   5862:                               ' value="'.$field.'"'.$check.' />'.$field.
                   5863:                               '</label></span> ';
                   5864:             }
                   5865:         } elsif ($item eq 'markup') {
1.160.6.87  raeburn  5866:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39  raeburn  5867:                            $currvalidation{$item}.
1.160.6.37  raeburn  5868:                               '</textarea>';
1.160.6.39  raeburn  5869:         }
                   5870:         $datatable .= '</td></tr>'."\n";
                   5871:         if (ref($rowtotal)) {
1.160.6.37  raeburn  5872:             $itemcount ++;
                   5873:         }
1.139     raeburn  5874:     }
1.160.6.39  raeburn  5875:     if ($caller eq 'requestcourses') {
                   5876:         my %currhash;
1.160.6.51  raeburn  5877:         if (ref($settings) eq 'HASH') {
                   5878:             if (ref($settings->{'validation'}) eq 'HASH') {
                   5879:                 if ($settings->{'validation'}{'dc'} ne '') {
                   5880:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   5881:                 }
1.160.6.39  raeburn  5882:             }
                   5883:         }
                   5884:         my $numinrow = 2;
                   5885:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   5886:                                                        'validationdc',%currhash);
1.160.6.50  raeburn  5887:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87  raeburn  5888:         $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39  raeburn  5889:         if ($numdc > 1) {
1.160.6.50  raeburn  5890:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39  raeburn  5891:         } else {
1.160.6.50  raeburn  5892:             $datatable .=  &mt('Course creation processed as: ');
1.160.6.39  raeburn  5893:         }
1.160.6.50  raeburn  5894:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39  raeburn  5895:         $itemcount ++;
                   5896:     }
                   5897:     if (ref($rowtotal)) {
                   5898:         $$rowtotal += $itemcount;
                   5899:     }
1.121     raeburn  5900:     return $datatable;
1.118     jms      5901: }
                   5902: 
1.160.6.98  raeburn  5903: sub print_passwords {
                   5904:     my ($position,$dom,$confname,$settings,$rowtotal) = @_;
                   5905:     my ($datatable,$css_class);
                   5906:     my $itemcount = 0;
                   5907:     my %titles = &Apache::lonlocal::texthash (
                   5908:         captcha        => '"Forgot Password" CAPTCHA validation',
                   5909:         link           => 'Reset link expiration (hours)',
                   5910:         case           => 'Case-sensitive usernames/e-mail',
                   5911:         prelink        => 'Information required (form 1)',
                   5912:         postlink       => 'Information required (form 2)',
                   5913:         emailsrc       => 'LON-CAPA e-mail address type(s)',
                   5914:         customtext     => 'Domain specific text (HTML)',
                   5915:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   5916:         intauth_check  => 'Check bcrypt cost if authenticated',
                   5917:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   5918:         permanent      => 'Permanent e-mail address',
                   5919:         critical       => 'Critical notification address',
                   5920:         notify         => 'Notification address',
                   5921:         min            => 'Minimum password length',
                   5922:         max            => 'Maximum password length',
                   5923:         chars          => 'Required characters',
                   5924:         numsaved       => 'Number of previous passwords to save and disallow reuse',
                   5925:     );
                   5926:     if ($position eq 'top') {
                   5927:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5928:         my $shownlinklife = 2;
                   5929:         my $prelink = 'both';
                   5930:         my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
                   5931:         if (ref($settings) eq 'HASH') {
                   5932:             if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   5933:                 $shownlinklife = $settings->{resetlink};
                   5934:             }
                   5935:             if (ref($settings->{resetcase}) eq 'ARRAY') {
                   5936:                 map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
                   5937:             }
                   5938:             if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   5939:                 $prelink = $settings->{resetprelink};
                   5940:             }
                   5941:             if (ref($settings->{resetpostlink}) eq 'HASH') {
                   5942:                 %postlink = %{$settings->{resetpostlink}};
                   5943:             }
                   5944:             if (ref($settings->{resetemail}) eq 'ARRAY') {
                   5945:                 map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
                   5946:             }
                   5947:             if ($settings->{resetremove}) {
                   5948:                 $nostdtext = 1;
                   5949:             }
                   5950:             if ($settings->{resetcustom}) {
                   5951:                 $customurl = $settings->{resetcustom};
                   5952:             }
                   5953:         } else {
                   5954:             if (ref($types) eq 'ARRAY') {
                   5955:                 foreach my $item (@{$types}) {
                   5956:                     $casesens{$item} = 1;
                   5957:                     $postlink{$item} = ['username','email'];
                   5958:                 }
                   5959:             }
                   5960:             $casesens{'default'} = 1;
                   5961:             $postlink{'default'} = ['username','email'];
                   5962:             $prelink = 'both';
                   5963:             %emailsrc = (
                   5964:                           permanent => 1,
                   5965:                           critical  => 1,
                   5966:                           notify    => 1,
                   5967:             );
                   5968:         }
                   5969:         $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
                   5970:         $itemcount ++;
                   5971:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5972:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                   5973:                       '<td class="LC_left_item">'.
                   5974:                       '<input type="textbox" value="'.$shownlinklife.'" '.
                   5975:                       'name="passwords_link" size="3" /></td></tr>';
                   5976:         $itemcount ++;
                   5977:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5978:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                   5979:                       '<td class="LC_left_item">';
                   5980:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   5981:             foreach my $item (@{$types}) {
                   5982:                 my $checkedcase;
                   5983:                 if ($casesens{$item}) {
                   5984:                     $checkedcase = ' checked="checked"';
                   5985:                 }
                   5986:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   5987:                               '<input type="checkbox" name="passwords_case_sensitive" value="'.
                   5988:                               $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104  raeburn  5989:                               '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  5990:             }
                   5991:         }
                   5992:         my $checkedcase;
                   5993:         if ($casesens{'default'}) {
                   5994:             $checkedcase = ' checked="checked"';
                   5995:         }
                   5996:         $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   5997:                       'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                   5998:                       $othertitle.'</label></span></td>';
                   5999:         $itemcount ++;
                   6000:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6001:         my %checkedpre = (
                   6002:                              both => ' checked="checked"',
                   6003:                              either => '',
                   6004:                          );
                   6005:         if ($prelink eq 'either') {
                   6006:             $checkedpre{either} = ' checked="checked"';
                   6007:             $checkedpre{both} = '';
                   6008:         }
                   6009:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                   6010:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6011:                       '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                   6012:                       &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                   6013:                       '<span class="LC_nobreak"><label>'.
                   6014:                       '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                   6015:                       &mt('Either username or e-mail address').'</label></span></td></tr>';
                   6016:         $itemcount ++;
                   6017:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6018:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                   6019:                       '<td class="LC_left_item">';
                   6020:         my %postlinked;
                   6021:         if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6022:             foreach my $item (@{$types}) {
                   6023:                 undef(%postlinked);
                   6024:                 $datatable .= '<fieldset style="display: inline-block;">'.
                   6025:                               '<legend>'.$usertypes->{$item}.'</legend>';
                   6026:                 if (ref($postlink{$item}) eq 'ARRAY') {
                   6027:                     map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   6028:                 }
                   6029:                 foreach my $field ('email','username') {
                   6030:                     my $checked;
                   6031:                     if ($postlinked{$field}) {
                   6032:                         $checked = ' checked="checked"';
                   6033:                     }
                   6034:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   6035:                                   '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                   6036:                                   $field.'"'.$checked.' />'.$field.'</label>'.
                   6037:                                   '<span>&nbsp;&nbsp; ';
                   6038:                 }
                   6039:                 $datatable .= '</fieldset>';
                   6040:             }
                   6041:         }
                   6042:         if (ref($postlink{'default'}) eq 'ARRAY') {
                   6043:             map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
                   6044:         }
                   6045:         $datatable .= '<fieldset style="display: inline-block;">'.
                   6046:                       '<legend>'.$othertitle.'</legend>';
                   6047:         foreach my $field ('email','username') {
                   6048:             my $checked;
                   6049:             if ($postlinked{$field}) {
                   6050:                 $checked = ' checked="checked"';
                   6051:             }
                   6052:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6053:                           '<input type="checkbox" name="passwords_postlink_default" value="'.
                   6054:                           $field.'"'.$checked.' />'.$field.'</label>'.
                   6055:                           '<span>&nbsp;&nbsp; ';
                   6056:         }
                   6057:         $datatable .= '</fieldset></td></tr>';
                   6058:         $itemcount ++;
                   6059:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6060:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                   6061:                       '<td class="LC_left_item">';
                   6062:         foreach my $type ('permanent','critical','notify') {
                   6063:             my $checkedemail;
                   6064:             if ($emailsrc{$type}) {
                   6065:                 $checkedemail = ' checked="checked"';
                   6066:             }
                   6067:             $datatable .= '<span class="LC_nobreak"><label>'.
                   6068:                           '<input type="checkbox" name="passwords_emailsrc" value="'.
                   6069:                           $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                   6070:                           '<span>&nbsp;&nbsp; ';
                   6071:         }
                   6072:         $datatable .= '</td></tr>';
                   6073:         $itemcount ++;
                   6074:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6075:         my $switchserver = &check_switchserver($dom,$confname);
                   6076:         my ($showstd,$noshowstd);
                   6077:         if ($nostdtext) {
                   6078:             $noshowstd = ' checked="checked"';
                   6079:         } else {
                   6080:             $showstd = ' checked="checked"';
                   6081:         }
                   6082:         $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                   6083:                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6084:                       &mt('Retain standard text:').
                   6085:                       '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                   6086:                       &mt('Yes').'</label>'.'&nbsp;'.
                   6087:                       '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                   6088:                       &mt('No').'</label></span><br />'.
                   6089:                       '<span class="LC_fontsize_small">'.
                   6090:                       &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                   6091:                       &mt('Include custom text:');
                   6092:         if ($customurl) {
1.160.6.104  raeburn  6093:             my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98  raeburn  6094:                                                        undef,undef,undef,undef,'background-color:#ffffff');
                   6095:             $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                   6096:                           '<label><input type="checkbox" name="passwords_custom_del"'.
                   6097:                           ' value="1" />'.&mt('Delete?').'</label></span>'.
                   6098:                           ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
                   6099:         }
                   6100:         if ($switchserver) {
                   6101:             $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
                   6102:         } else {
                   6103:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   6104:                          '<input type="file" name="passwords_customfile" /></span>';
                   6105:         }
                   6106:         $datatable .= '</td></tr>';
                   6107:     } elsif ($position eq 'middle') {
                   6108:         my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
                   6109:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   6110:         my %defaults;
                   6111:         if (ref($domconf{'defaults'}) eq 'HASH') {
                   6112:             %defaults = %{$domconf{'defaults'}};
                   6113:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   6114:                 $defaults{'intauth_cost'} = 10;
                   6115:             }
                   6116:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   6117:                 $defaults{'intauth_check'} = 0;
                   6118:             }
                   6119:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   6120:                 $defaults{'intauth_switch'} = 0;
                   6121:             }
                   6122:         } else {
                   6123:             %defaults = (
                   6124:                           'intauth_cost'   => 10,
                   6125:                           'intauth_check'  => 0,
                   6126:                           'intauth_switch' => 0,
                   6127:                         );
                   6128:         }
                   6129:         foreach my $item (@items) {
                   6130:             if ($itemcount%2) {
                   6131:                 $css_class = '';
                   6132:             } else {
                   6133:                 $css_class = ' class="LC_odd_row" ';
                   6134:             }
                   6135:             $datatable .= '<tr'.$css_class.'>'.
                   6136:                           '<td><span class="LC_nobreak">'.$titles{$item}.
                   6137:                           '</span></td><td class="LC_left_item" colspan="3">';
                   6138:             if ($item eq 'intauth_switch') {
                   6139:                 my @options = (0,1,2);
                   6140:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6141:                                    0 => 'No',
                   6142:                                    1 => 'Yes',
                   6143:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   6144:                                  );
                   6145:                 $datatable .= '<table width="100%">';
                   6146:                 foreach my $option (@options) {
                   6147:                     my $checked = ' ';
                   6148:                     if ($defaults{$item} eq $option) {
                   6149:                         $checked = ' checked="checked"';
                   6150:                     }
                   6151:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6152:                                   '<label><input type="radio" name="'.$item.
                   6153:                                   '" value="'.$option.'"'.$checked.' />'.
                   6154:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6155:                 }
                   6156:                 $datatable .= '</table>';
                   6157:             } elsif ($item eq 'intauth_check') {
                   6158:                 my @options = (0,1,2);
                   6159:                 my %optiondesc = &Apache::lonlocal::texthash (
                   6160:                                    0 => 'No',
                   6161:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   6162:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   6163:                                  );
                   6164:                 $datatable .= '<table width="100%">';
                   6165:                 foreach my $option (@options) {
                   6166:                     my $checked = ' ';
                   6167:                     my $onclick;
                   6168:                     if ($defaults{$item} eq $option) {
                   6169:                         $checked = ' checked="checked"';
                   6170:                     }
                   6171:                     if ($option == 2) {
                   6172:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   6173:                     }
                   6174:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   6175:                                   '<label><input type="radio" name="'.$item.
                   6176:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   6177:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6178:                 }
                   6179:                 $datatable .= '</table>';
                   6180:             } else {
                   6181:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6182:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   6183:             }
                   6184:             $datatable .= '</td></tr>';
                   6185:             $itemcount ++;
                   6186:         }
                   6187:     } elsif ($position eq 'lower') {
1.160.6.118.2  5(raebur 6188:2):         $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98  raeburn  6189:     } else {
                   6190:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   6191:         my %ownerchg = (
                   6192:                           by  => {},
                   6193:                           for => {},
                   6194:                        );
                   6195:         my %ownertitles = &Apache::lonlocal::texthash (
                   6196:                             by  => 'Course owner status(es) allowed',
                   6197:                             for => 'Student status(es) allowed',
                   6198:                           );
                   6199:         if (ref($settings) eq 'HASH') {
                   6200:             if (ref($settings->{crsownerchg}) eq 'HASH') {
                   6201:                 if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                   6202:                     map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   6203:                 }
                   6204:                 if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                   6205:                     map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   6206:                 }
                   6207:             }
                   6208:         }
                   6209:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6210:         $datatable .= '<tr '.$css_class.'>'.
                   6211:                       '<td>'.
                   6212:                       &mt('Requirements').'<ul>'.
                   6213:                       '<li>'.&mt("Course 'type' is not a Community").'</li>'.
                   6214:                       '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                   6215:                       '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
                   6216:                       '<li>'.&mt('User, course, and student share same domain').'</li>'.
                   6217:                       '</ul>'.
                   6218:                       '</td>'.
                   6219:                       '<td class="LC_left_item">';
                   6220:         foreach my $item ('by','for') {
                   6221:             $datatable .= '<fieldset style="display: inline-block;">'.
                   6222:                           '<legend>'.$ownertitles{$item}.'</legend>';
                   6223:             if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   6224:                 foreach my $type (@{$types}) {
                   6225:                     my $checked;
                   6226:                     if ($ownerchg{$item}{$type}) {
                   6227:                         $checked = ' checked="checked"';
                   6228:                     }
                   6229:                     $datatable .= '<span class="LC_nobreak"><label>'.
                   6230:                                   '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                   6231:                                   $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104  raeburn  6232:                                   '</span>&nbsp;&nbsp; ';
1.160.6.98  raeburn  6233:                 }
                   6234:             }
                   6235:             my $checked;
                   6236:             if ($ownerchg{$item}{'default'}) {
                   6237:                 $checked = ' checked="checked"';
                   6238:             }
                   6239:             $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                   6240:                           'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                   6241:                           $othertitle.'</label></span></fieldset>';
                   6242:         }
                   6243:         $datatable .= '</td></tr>';
                   6244:     }
                   6245:     return $datatable;
                   6246: }
                   6247: 
1.160.6.118.2  5(raebur 6248:2): sub password_rules {
                   6249:2):     my ($prefix,$itemcountref,$settings) = @_;
                   6250:2):     my ($min,$max,%chars,$numsaved,$numinrow);
                   6251:2):     my %titles;
                   6252:2):     if ($prefix eq 'passwords') {
                   6253:2):         %titles = &Apache::lonlocal::texthash (
                   6254:2):             min            => 'Minimum password length',
                   6255:2):             max            => 'Maximum password length',
                   6256:2):             chars          => 'Required characters',
                   6257:2):         );
                   6258:2):     } elsif ($prefix eq 'secrets') {
                   6259:2):         %titles = &Apache::lonlocal::texthash (
                   6260:2):             min            => 'Minimum secret length',
                   6261:2):             max            => 'Maximum secret length',
                   6262:2):             chars          => 'Required characters',
                   6263:2):         );
                   6264:2):     }
                   6265:2):     $min = $Apache::lonnet::passwdmin;
                   6266:2):     my $datatable;
                   6267:2):     my $itemcount;
                   6268:2):     if (ref($itemcountref)) {
                   6269:2):         $itemcount = $$itemcountref;
                   6270:2):     }
                   6271:2):     if (ref($settings) eq 'HASH') {
                   6272:2):         if ($settings->{min}) {
                   6273:2):             $min = $settings->{min};
                   6274:2):         }
                   6275:2):         if ($settings->{max}) {
                   6276:2):             $max = $settings->{max};
                   6277:2):         }
                   6278:2):         if (ref($settings->{chars}) eq 'ARRAY') {
                   6279:2):             map { $chars{$_} = 1; } (@{$settings->{chars}});
                   6280:2):         }
                   6281:2):         if ($prefix eq 'passwords') {
                   6282:2):             if ($settings->{numsaved}) {
                   6283:2):                 $numsaved = $settings->{numsaved};
                   6284:2):             }
                   6285:2):         }
                   6286:2):     }
                   6287:2):     my %rulenames = &Apache::lonlocal::texthash(
                   6288:2):                                                  uc => 'At least one upper case letter',
                   6289:2):                                                  lc => 'At least one lower case letter',
                   6290:2):                                                  num => 'At least one number',
                   6291:2):                                                  spec => 'At least one non-alphanumeric',
                   6292:2):                                                );
                   6293:2):     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6294:2):     $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                   6295:2):                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6296:2):                   '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
                   6297:2):                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   6298:2):                   '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
                   6299:2):                   '</span></td></tr>';
                   6300:2):     $itemcount ++;
                   6301:2):     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6302:2):     $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                   6303:2):                   '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6304:2):                   '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
                   6305:2):                   'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   6306:2):                   '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                   6307:2):                   '</span></td></tr>';
                   6308:2):     $itemcount ++;
                   6309:2):     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6310:2):     $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                   6311:2):                   '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                   6312:2):                   '</span></td>';
                   6313:2):     my $numinrow = 2;
                   6314:2):     my @possrules = ('uc','lc','num','spec');
                   6315:2):     $datatable .= '<td class="LC_left_item"><table>';
                   6316:2):     for (my $i=0; $i<@possrules; $i++) {
                   6317:2):         my ($rem,$checked);
                   6318:2):         if ($chars{$possrules[$i]}) {
                   6319:2):             $checked = ' checked="checked"';
                   6320:2):         }
                   6321:2):         $rem = $i%($numinrow);
                   6322:2):         if ($rem == 0) {
                   6323:2):             if ($i > 0) {
                   6324:2):                 $datatable .= '</tr>';
                   6325:2):             }
                   6326:2):             $datatable .= '<tr>';
                   6327:2):         }
                   6328:2):         $datatable .= '<td><span class="LC_nobreak"><label>'.
                   6329:2):                       '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                   6330:2):                       $rulenames{$possrules[$i]}.'</label></span></td>';
                   6331:2):     }
                   6332:2):     my $rem = @possrules%($numinrow);
                   6333:2):     my $colsleft = $numinrow - $rem;
                   6334:2):     if ($colsleft > 1 ) {
                   6335:2):         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6336:2):                       '&nbsp;</td>';
                   6337:2):     } elsif ($colsleft == 1) {
                   6338:2):         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   6339:2):     }
                   6340:2):     $datatable .='</table></td></tr>';
                   6341:2):     $itemcount ++;
                   6342:2):     if ($prefix eq 'passwords') {
                   6343:2):         $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
                   6344:2):         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6345:2):         $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                   6346:2):                       '<td class="LC_left_item"><span class="LC_nobreak">'.
                   6347:2):                       '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
                   6348:2):                       'onblur="javascript:warnInt'.$prefix.'(this);" />'.
                   6349:2):                       '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                   6350:2):                       '</span></td></tr>';
                   6351:2):         $itemcount ++;
                   6352:2):     }
                   6353:2):     if (ref($itemcountref)) {
                   6354:2):         $$itemcountref += $itemcount;
                   6355:2):     }
                   6356:2):     return $datatable;
                   6357:2): }
                   6358:2): 
1.160.6.113  raeburn  6359: sub print_wafproxy {
                   6360:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6361:     my $css_class;
                   6362:     my $itemcount = 0;
                   6363:     my $datatable;
                   6364:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   6365:     my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
                   6366:     my %lt = &wafproxy_titles();
                   6367:     foreach my $server (sort(keys(%servers))) {
                   6368:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   6369:         next if ($serverhome eq '');
                   6370:         my $serverdom;
                   6371:         if ($serverhome ne $server) {
                   6372:             $serverdom = &Apache::lonnet::host_domain($serverhome);
                   6373:             if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
                   6374:                 $othercontrol{$server} = $serverdom;
                   6375:             }
                   6376:         } else {
                   6377:             $serverdom = &Apache::lonnet::host_domain($server);
                   6378:             next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
                   6379:             if ($serverdom ne $dom) {
                   6380:                 $othercontrol{$server} = $serverdom;
                   6381:             } else {
                   6382:                 $setdom = 1;
                   6383:                 if (ref($settings) eq 'HASH') {
                   6384:                     if (ref($settings->{'alias'}) eq 'HASH') {
                   6385:                         $aliases{$dom} = $settings->{'alias'};
                   6386:                         if ($aliases{$dom} ne '') {
                   6387:                             $showdom = 1;
                   6388:                         }
                   6389:                     }
                   6390:                     if (ref($settings->{'saml'}) eq 'HASH') {
                   6391:                         $saml{$dom} = $settings->{'saml'};
                   6392:                     }
                   6393:                 }
                   6394:             }
                   6395:         }
                   6396:     }
                   6397:     if ($setdom) {
                   6398:         %{$values{$dom}} = ();
                   6399:         if (ref($settings) eq 'HASH') {
                   6400:             foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   6401:                 $values{$dom}{$item} = $settings->{$item};
                   6402:             }
                   6403:         }
                   6404:     }
                   6405:     if (keys(%othercontrol)) {
                   6406:         %otherdoms = reverse(%othercontrol);
                   6407:         foreach my $domain (keys(%otherdoms)) {
                   6408:             %{$values{$domain}} = ();
                   6409:             my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
                   6410:             if (ref($config{'wafproxy'}) eq 'HASH') {
                   6411:                 $aliases{$domain} = $config{'wafproxy'}{'alias'};
                   6412:                 if (exists($config{'wafproxy'}{'saml'})) {
                   6413:                     $saml{$domain} = $config{'wafproxy'}{'saml'};
                   6414:                 }
                   6415:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
                   6416:                     $values{$domain}{$item} = $config{'wafproxy'}{$item};
                   6417:                 }
                   6418:             }
                   6419:         }
                   6420:     }
                   6421:     if ($position eq 'top') {
                   6422:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   6423:         my %aliasinfo;
                   6424:         foreach my $server (sort(keys(%servers))) {
                   6425:             $itemcount ++;
                   6426:             my $dom_in_effect;
                   6427:             my $aliasrows = '<tr>'.
                   6428:                             '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   6429:                             &mt('Hostname').':&nbsp;'.
                   6430:                             '<i>'.&Apache::lonnet::hostname($server).'</i></td><td>&nbsp;</td>';
                   6431:             if ($othercontrol{$server}) {
                   6432:                 $dom_in_effect = $othercontrol{$server};
                   6433:                 my ($current,$forsaml);
                   6434:                 if (ref($aliases{$dom_in_effect}) eq 'HASH') {
                   6435:                     $current = $aliases{$dom_in_effect}{$server};
                   6436:                 }
                   6437:                 if (ref($saml{$dom_in_effect}) eq 'HASH') {
                   6438:                     if ($saml{$dom_in_effect}{$server}) {
                   6439:                         $forsaml = 1;
                   6440:                     }
                   6441:                 }
                   6442:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   6443:                               &mt('Alias').':&nbsp';
                   6444:                 if ($current) {
                   6445:                     $aliasrows .= $current;
                   6446:                     if ($forsaml) {
                   6447:                          $aliasrows .= '&nbsp;('.&mt('also for SSO Auth').')';
                   6448:                     }
                   6449:                 } else {
                   6450:                     $aliasrows .= &mt('None');
                   6451:                 }
                   6452:                 $aliasrows .= '&nbsp;<span class="LC_small">('.
                   6453:                               &mt('controlled by domain: [_1]',
                   6454:                                   '<b>'.$dom_in_effect.'</b>').')</span></td>';
                   6455:             } else {
                   6456:                 $dom_in_effect = $dom;
                   6457:                 my ($current,$samlon,$samloff);
                   6458:                 $samloff = ' checked="checked"';
                   6459:                 if (ref($aliases{$dom}) eq 'HASH') {
                   6460:                     if ($aliases{$dom}{$server}) {
                   6461:                         $current = $aliases{$dom}{$server};
                   6462:                     }
                   6463:                 }
                   6464:                 if (ref($saml{$dom}) eq 'HASH') {
                   6465:                     if ($saml{$dom}{$server}) {
                   6466:                         $samlon = $samloff;
                   6467:                         undef($samloff);
                   6468:                     }
                   6469:                 }
                   6470:                 $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
                   6471:                               &mt('Alias').':&nbsp;'.
                   6472:                               '<input type="text" name="wafproxy_alias_'.$server.'" '.
                   6473:                               'value="'.$current.'" size="30" />'.
                   6474:                               ('&nbsp;'x2).'<span class="LC_nobreak">'.
                   6475:                               &mt('Alias used for SSO Auth').':&nbsp;<label>'.
                   6476:                               '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
                   6477:                               &mt('No').'</label>&nbsp;<label>'.
                   6478:                               '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
                   6479:                               &mt('Yes').'</label></span>'.
                   6480:                               '</td>';
                   6481:             }
                   6482:             $aliasrows .= '</tr>';
                   6483:             $aliasinfo{$dom_in_effect} .= $aliasrows;
                   6484:         }
                   6485:         if ($aliasinfo{$dom}) {
                   6486:             my ($onclick,$wafon,$wafoff,$showtable);
                   6487:             $onclick = ' onclick="javascript:toggleWAF();"';
                   6488:             $wafoff = ' checked="checked"';
                   6489:             $showtable = ' style="display:none";';
                   6490:             if ($showdom) {
                   6491:                 $wafon = $wafoff;
                   6492:                 $wafoff = '';
                   6493:                 $showtable = ' style="display:inline;"';
                   6494:             }
                   6495:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6496:             $datatable = '<tr'.$css_class.'>'.
                   6497:                          '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
                   6498:                          '<span class="LC_nobreak">'.&mt('WAF in use?').'&nbsp;<label>'.
                   6499:                          '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
                   6500:                          &mt('Yes').'</label>'.('&nbsp;'x2).'<label>'.
                   6501:                          '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
                   6502:                          &mt('No').'</label></span></td>'.
                   6503:                          '<td class="LC_left_item">'.
                   6504:                          '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
                   6505:                          '</table></td></tr>';
                   6506:             $itemcount++;
                   6507:         }
                   6508:         if (keys(%otherdoms)) {
                   6509:             foreach my $key (sort(keys(%otherdoms))) {
                   6510:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6511:                 $datatable .= '<tr'.$css_class.'>'.
                   6512:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
                   6513:                               '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
                   6514:                               '</table></td></tr>';
                   6515:                 $itemcount++;
                   6516:             }
                   6517:         }
                   6518:     } else {
                   6519:         my %ip_methods = &remoteip_methods();
                   6520:         if ($setdom) {
                   6521:             $itemcount ++;
                   6522:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6523:             my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
                   6524:                 $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
                   6525:             $wafstyle = ' style="display:none;"';
                   6526:             $nowafstyle = ' style="display:table-row;"';
                   6527:             $currwafdisplay = ' style="display: none"';
                   6528:             $wafrangestyle = ' style="display: none"';
                   6529:             $curr_remotip = 'n';
                   6530:             $ssltossl = ' checked="checked"';
                   6531:             if ($showdom) {
                   6532:                 $wafstyle = ' style="display:table-row;"';
                   6533:                 $nowafstyle =  ' style="display:none;"';
                   6534:                 if (keys(%{$values{$dom}})) {
                   6535:                     if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
                   6536:                         $curr_remotip = $values{$dom}{remoteip};
                   6537:                     }
                   6538:                     if ($curr_remotip eq 'h') {
                   6539:                         $currwafdisplay = ' style="display:table-row"';
                   6540:                         $wafrangestyle = ' style="display:inline-block;"';
                   6541:                     }
                   6542:                     if ($values{$dom}{'sslopt'}) {
                   6543:                         $alltossl = ' checked="checked"';
                   6544:                         $ssltossl = '';
                   6545:                     }
                   6546:                 }
                   6547:                 if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
                   6548:                     $vpndircheck = ' checked="checked"';
                   6549:                     $currwafvpn = ' style="display:table-row;"';
                   6550:                     $wafrangestyle = ' style="display:inline-block;"';
                   6551:                 } else {
                   6552:                     $vpnaliascheck = ' checked="checked"';
                   6553:                     $currwafvpn = ' style="display:none;"';
                   6554:                 }
                   6555:             }
                   6556:             $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   6557:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
                   6558:                           '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
                   6559:                           '</tr>'.
                   6560:                           '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
                   6561:                           '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
                   6562:                           '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
                   6563:                           &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
                   6564:                           &mt('Range(s) stored in CIDR notation').'</div></td>'.
                   6565:                           '<td class="LC_left_item"><table>'.
                   6566:                           '<tr>'.
                   6567:                           '<td valign="top">'.$lt{'remoteip'}.':&nbsp;'.
                   6568:                           '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
                   6569:             foreach my $option ('m','h','n') {
                   6570:                 my $sel;
1.160.6.114  raeburn  6571:                 if ($option eq $curr_remotip) {
                   6572:                    $sel = ' selected="selected"';
                   6573:                 }
                   6574:                 $datatable .= '<option value="'.$option.'"'.$sel.'>'.
                   6575:                               $ip_methods{$option}.'</option>';
                   6576:             }
                   6577:             $datatable .= '</select></td></tr>'."\n".
                   6578:                           '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
                   6579:                           $lt{'ipheader'}.':&nbsp;'.
                   6580:                           '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
                   6581:                           'name="wafproxy_ipheader" />'.
                   6582:                           '</td></tr>'."\n".
                   6583:                           '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
                   6584:                           $lt{'trusted'}.':<br />'.
                   6585:                           '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
                   6586:                           $values{$dom}{'trusted'}.'</textarea>'.
                   6587:                           '</td></tr>'."\n".
                   6588:                           '<tr><td><hr /></td></tr>'."\n".
                   6589:                           '<tr>'.
1.160.6.113  raeburn  6590:                           '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
                   6591:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
                   6592:                           $lt{'vpndirect'}.'</label>'.('&nbsp;'x2).
                   6593:                           '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
                   6594:                           $lt{'vpnaliased'}.'</label></span></td></tr>';
                   6595:             foreach my $item ('vpnint','vpnext') {
                   6596:                 $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
                   6597:                               '<td valign="top">'.$lt{$item}.':<br />'.
                   6598:                               '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
                   6599:                               $values{$dom}{$item}.'</textarea>'.
                   6600:                               '</td></tr>'."\n";
                   6601:             }
                   6602:             $datatable .= '<tr><td><hr /></td></tr>'."\n".
                   6603:                           '<tr>'.
                   6604:                           '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
                   6605:                           '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
                   6606:                           $lt{'alltossl'}.'</label>'.('&nbsp;'x2).
                   6607:                           '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
                   6608:                           $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
                   6609:                           '</table></td></tr>';
                   6610:         }
                   6611:         if (keys(%otherdoms)) {
                   6612:             foreach my $domain (sort(keys(%otherdoms))) {
                   6613:                 $itemcount ++;
                   6614:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6615:                 $datatable .= '<tr'.$css_class.'>'.
                   6616:                               '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
                   6617:                               '<td class="LC_left_item"><table>';
                   6618:                 foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
                   6619:                     my $showval = &mt('None');
                   6620:                     if ($item eq 'ssl') {
                   6621:                         $showval = $lt{'ssltossl'};
                   6622:                     }
                   6623:                     if ($values{$domain}{$item}) {
                   6624:                         $showval = $values{$domain}{$item};
                   6625:                         if ($item eq 'ssl') {
                   6626:                             $showval = $lt{'alltossl'};
                   6627:                         } elsif ($item eq 'remoteip') {
                   6628:                             $showval = $ip_methods{$values{$domain}{$item}};
                   6629:                         }
                   6630:                     }
                   6631:                     $datatable .= '<tr>'.
                   6632:                                   '<td>'.$lt{$item}.':&nbsp;'.$showval.'</td></tr>';
                   6633:                 }
                   6634:                 $datatable .= '</table></td></tr>';
                   6635:             }
                   6636:         }
                   6637:     }
                   6638:     $$rowtotal += $itemcount;
                   6639:     return $datatable;
                   6640: }
                   6641: 
                   6642: sub wafproxy_titles {
                   6643:     return &Apache::lonlocal::texthash(
                   6644:                remoteip   => "Method for determining user's IP",
                   6645:                ipheader   => 'Request header containing remote IP',
                   6646:                trusted    => 'Trusted IP range(s)',
                   6647:                vpnaccess  => 'Access from institutional VPN',
                   6648:                vpndirect  => 'via regular hostname (no WAF)',
                   6649:                vpnaliased => 'via aliased hostname (WAF)',
                   6650:                vpnint     => 'Internal IP Range(s) for VPN sessions',
                   6651:                vpnext     => 'IP Range(s) for backend WAF connections',
                   6652:                sslopt     => 'Forwarding http/https',
                   6653:                alltossl   => 'WAF forwards both http and https requests to https',
                   6654:                ssltossl   => 'WAF forwards http requests to http and https to https',
                   6655:            );
                   6656: }
                   6657: 
                   6658: sub remoteip_methods {
                   6659:     return &Apache::lonlocal::texthash(
                   6660:               m => 'Use Apache mod_remoteip',
                   6661:               h => 'Use headers parsed by LON-CAPA',
                   6662:               n => 'Not in use',
                   6663:            );
                   6664: }
                   6665: 
1.137     raeburn  6666: sub print_usersessions {
                   6667:     my ($position,$dom,$settings,$rowtotal) = @_;
                   6668:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  6669:     my (%by_ip,%by_location,@intdoms);
                   6670:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  6671: 
                   6672:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  6673:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  6674:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  6675:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  6676:     my $itemcount = 1;
                   6677:     if ($position eq 'top') {
1.152     raeburn  6678:         if (keys(%serverhomes) > 1) {
1.145     raeburn  6679:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.160.6.105  raeburn  6680:             my ($curroffloadnow,$curroffloadoth);
1.160.6.61  raeburn  6681:             if (ref($settings) eq 'HASH') {
                   6682:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   6683:                     $curroffloadnow = $settings->{'offloadnow'};
                   6684:                 }
1.160.6.105  raeburn  6685:                 if (ref($settings->{'offloadoth'}) eq 'HASH') {
                   6686:                     $curroffloadoth = $settings->{'offloadoth'};
                   6687:                 }
1.160.6.61  raeburn  6688:             }
1.160.6.105  raeburn  6689:             my $other_insts = scalar(keys(%by_location));
                   6690:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
                   6691:                                       $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145     raeburn  6692:         } else {
1.140     raeburn  6693:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  6694:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  6695:         }
1.137     raeburn  6696:     } else {
1.145     raeburn  6697:         if (keys(%by_location) == 0) {
                   6698:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  6699:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  6700:         } else {
                   6701:             my %lt = &usersession_titles();
                   6702:             my $numinrow = 5;
                   6703:             my $prefix;
                   6704:             my @types;
                   6705:             if ($position eq 'bottom') {
                   6706:                 $prefix = 'remote';
                   6707:                 @types = ('version','excludedomain','includedomain');
                   6708:             } else {
                   6709:                 $prefix = 'hosted';
                   6710:                 @types = ('excludedomain','includedomain');
                   6711:             }
                   6712:             my (%current,%checkedon,%checkedoff);
                   6713:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   6714:             my @locations = sort(keys(%by_location));
                   6715:             foreach my $type (@types) {
                   6716:                 $checkedon{$type} = '';
                   6717:                 $checkedoff{$type} = ' checked="checked"';
                   6718:             }
                   6719:             if (ref($settings) eq 'HASH') {
                   6720:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   6721:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   6722:                         $current{$key} = $settings->{$prefix}{$key};
                   6723:                         if ($key eq 'version') {
                   6724:                             if ($current{$key} ne '') {
                   6725:                                 $checkedon{$key} = ' checked="checked"';
                   6726:                                 $checkedoff{$key} = '';
                   6727:                             }
                   6728:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   6729:                             $checkedon{$key} = ' checked="checked"';
                   6730:                             $checkedoff{$key} = '';
                   6731:                         }
1.137     raeburn  6732:                     }
                   6733:                 }
                   6734:             }
1.145     raeburn  6735:             foreach my $type (@types) {
                   6736:                 next if ($type ne 'version' && !@locations);
                   6737:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6738:                 $datatable .= '<tr'.$css_class.'>
                   6739:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   6740:                                <span class="LC_nobreak">&nbsp;
                   6741:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   6742:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   6743:                 if ($type eq 'version') {
                   6744:                     my $selector = '<select name="'.$prefix.'_version">';
                   6745:                     foreach my $version (@lcversions) {
                   6746:                         my $selected = '';
                   6747:                         if ($current{'version'} eq $version) {
                   6748:                             $selected = ' selected="selected"';
                   6749:                         }
                   6750:                         $selector .= ' <option value="'.$version.'"'.
                   6751:                                      $selected.'>'.$version.'</option>';
                   6752:                     }
                   6753:                     $selector .= '</select> ';
                   6754:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   6755:                 } else {
                   6756:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   6757:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   6758:                                  ' />'.('&nbsp;'x2).
                   6759:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   6760:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   6761:                                  "\n".
                   6762:                                  '</div><div><table>';
                   6763:                     my $rem;
                   6764:                     for (my $i=0; $i<@locations; $i++) {
                   6765:                         my ($showloc,$value,$checkedtype);
                   6766:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   6767:                             my $ip = $by_location{$locations[$i]}->[0];
                   6768:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   6769:                                  $value = join(':',@{$by_ip{$ip}});
                   6770:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   6771:                                 if (ref($current{$type}) eq 'ARRAY') {
                   6772:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   6773:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   6774:                                             $checkedtype = ' checked="checked"';
                   6775:                                             last;
                   6776:                                         }
                   6777:                                     }
1.138     raeburn  6778:                                 }
                   6779:                             }
                   6780:                         }
1.145     raeburn  6781:                         $rem = $i%($numinrow);
                   6782:                         if ($rem == 0) {
                   6783:                             if ($i > 0) {
                   6784:                                 $datatable .= '</tr>';
                   6785:                             }
                   6786:                             $datatable .= '<tr>';
                   6787:                         }
                   6788:                         $datatable .= '<td class="LC_left_item">'.
                   6789:                                       '<span class="LC_nobreak"><label>'.
                   6790:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   6791:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   6792:                                       '</label></span></td>';
1.137     raeburn  6793:                     }
1.145     raeburn  6794:                     $rem = @locations%($numinrow);
                   6795:                     my $colsleft = $numinrow - $rem;
                   6796:                     if ($colsleft > 1 ) {
                   6797:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6798:                                       '&nbsp;</td>';
                   6799:                     } elsif ($colsleft == 1) {
                   6800:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  6801:                     }
1.145     raeburn  6802:                     $datatable .= '</tr></table>';
1.137     raeburn  6803:                 }
1.145     raeburn  6804:                 $datatable .= '</td></tr>';
                   6805:                 $itemcount ++;
1.137     raeburn  6806:             }
                   6807:         }
                   6808:     }
                   6809:     $$rowtotal += $itemcount;
                   6810:     return $datatable;
                   6811: }
                   6812: 
1.138     raeburn  6813: sub build_location_hashes {
                   6814:     my ($intdoms,$by_ip,$by_location) = @_;
                   6815:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   6816:                   (ref($by_location) eq 'HASH')); 
                   6817:     my %iphost = &Apache::lonnet::get_iphost();
                   6818:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   6819:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   6820:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   6821:         foreach my $id (@{$iphost{$primary_ip}}) {
                   6822:             my $intdom = &Apache::lonnet::internet_dom($id);
                   6823:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   6824:                 push(@{$intdoms},$intdom);
                   6825:             }
                   6826:         }
                   6827:     }
                   6828:     foreach my $ip (keys(%iphost)) {
                   6829:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   6830:             foreach my $id (@{$iphost{$ip}}) {
                   6831:                 my $location = &Apache::lonnet::internet_dom($id);
                   6832:                 if ($location) {
                   6833:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   6834:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6835:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   6836:                             push(@{$by_ip->{$ip}},$location);
                   6837:                         }
                   6838:                     } else {
                   6839:                         $by_ip->{$ip} = [$location];
                   6840:                     }
                   6841:                 }
                   6842:             }
                   6843:         }
                   6844:     }
                   6845:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   6846:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   6847:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   6848:             my $first = $by_ip->{$ip}->[0];
                   6849:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   6850:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   6851:                     push(@{$by_location->{$first}},$ip);
                   6852:                 }
                   6853:             } else {
                   6854:                 $by_location->{$first} = [$ip];
                   6855:             }
                   6856:         }
                   6857:     }
                   6858:     return;
                   6859: }
                   6860: 
1.145     raeburn  6861: sub current_offloads_to {
                   6862:     my ($dom,$settings,$servers) = @_;
                   6863:     my (%spareid,%otherdomconfigs);
1.152     raeburn  6864:     if (ref($servers) eq 'HASH') {
1.145     raeburn  6865:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   6866:             my $gotspares;
1.152     raeburn  6867:             if (ref($settings) eq 'HASH') {
                   6868:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   6869:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   6870:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   6871:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   6872:                         $gotspares = 1;
                   6873:                     }
1.145     raeburn  6874:                 }
                   6875:             }
                   6876:             unless ($gotspares) {
                   6877:                 my $gotspares;
                   6878:                 my $serverhomeID =
                   6879:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   6880:                 my $serverhomedom =
                   6881:                     &Apache::lonnet::host_domain($serverhomeID);
                   6882:                 if ($serverhomedom ne $dom) {
                   6883:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   6884:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6885:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6886:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6887:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6888:                                 $gotspares = 1;
                   6889:                             }
                   6890:                         }
                   6891:                     } else {
                   6892:                         $otherdomconfigs{$serverhomedom} =
                   6893:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   6894:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   6895:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   6896:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   6897:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   6898:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   6899:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   6900:                                         $gotspares = 1;
                   6901:                                     }
                   6902:                                 }
                   6903:                             }
                   6904:                         }
                   6905:                     }
                   6906:                 }
                   6907:             }
                   6908:             unless ($gotspares) {
                   6909:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6910:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6911:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6912:                } else {
                   6913:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   6914:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   6915:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   6916:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   6917:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   6918:                     } else {
1.150     raeburn  6919:                         my %what = (
                   6920:                              spareid => 1,
                   6921:                         );
                   6922:                         my ($result,$returnhash) = 
                   6923:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   6924:                         if ($result eq 'ok') { 
                   6925:                             if (ref($returnhash) eq 'HASH') {
                   6926:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   6927:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   6928:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   6929:                                 }
                   6930:                             }
1.145     raeburn  6931:                         }
                   6932:                     }
                   6933:                 }
                   6934:             }
                   6935:         }
                   6936:     }
                   6937:     return %spareid;
                   6938: }
                   6939: 
                   6940: sub spares_row {
1.160.6.105  raeburn  6941:     my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
                   6942:         $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145     raeburn  6943:     my $css_class;
                   6944:     my $numinrow = 4;
                   6945:     my $itemcount = 1;
                   6946:     my $datatable;
1.152     raeburn  6947:     my %typetitles = &sparestype_titles();
                   6948:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  6949:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  6950:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   6951:             my ($othercontrol,$serverdom);
                   6952:             if ($serverhome ne $server) {
                   6953:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   6954:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6955:             } else {
                   6956:                 $serverdom = &Apache::lonnet::host_domain($server);
                   6957:                 if ($serverdom ne $dom) {
                   6958:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   6959:                 }
                   6960:             }
                   6961:             next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105  raeburn  6962:             my ($checkednow,$checkedoth);
1.160.6.61  raeburn  6963:             if (ref($curroffloadnow) eq 'HASH') {
                   6964:                 if ($curroffloadnow->{$server}) {
                   6965:                     $checkednow = ' checked="checked"';
                   6966:                 }
                   6967:             }
1.160.6.105  raeburn  6968:             if (ref($curroffloadoth) eq 'HASH') {
                   6969:                 if ($curroffloadoth->{$server}) {
                   6970:                     $checkedoth = ' checked="checked"';
                   6971:                 }
                   6972:             }
1.145     raeburn  6973:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   6974:             $datatable .= '<tr'.$css_class.'>
                   6975:                            <td rowspan="2">
1.160.6.13  raeburn  6976:                             <span class="LC_nobreak">'.
                   6977:                           &mt('[_1] when busy, offloads to:'
1.160.6.61  raeburn  6978:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   6979:                           '<span class="LC_nobreak">'."\n".
                   6980:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105  raeburn  6981:                           '&nbsp;'.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13  raeburn  6982:                           "\n";
1.160.6.105  raeburn  6983:             if ($other_insts) {
                   6984:                 $datatable .= '<br />'.
                   6985:                               '<span class="LC_nobreak">'."\n".
                   6986:                           '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
                   6987:                           '&nbsp;'.&mt('Switch other institutions on next access').'</label></span>'.
                   6988:                           "\n";
                   6989:             }
1.145     raeburn  6990:             my (%current,%canselect);
1.152     raeburn  6991:             my @choices = 
                   6992:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   6993:             foreach my $type ('primary','default') {
                   6994:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  6995:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   6996:                         my @spares = @{$spareid->{$server}{$type}};
                   6997:                         if (@spares > 0) {
1.152     raeburn  6998:                             if ($othercontrol) {
                   6999:                                 $current{$type} = join(', ',@spares);
                   7000:                             } else {
                   7001:                                 $current{$type} .= '<table>';
                   7002:                                 my $numspares = scalar(@spares);
                   7003:                                 for (my $i=0;  $i<@spares; $i++) {
                   7004:                                     my $rem = $i%($numinrow);
                   7005:                                     if ($rem == 0) {
                   7006:                                         if ($i > 0) {
                   7007:                                             $current{$type} .= '</tr>';
                   7008:                                         }
                   7009:                                         $current{$type} .= '<tr>';
1.145     raeburn  7010:                                     }
1.152     raeburn  7011:                                     $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;'.
                   7012:                                                        $spareid->{$server}{$type}[$i].
                   7013:                                                        '</label></td>'."\n";
                   7014:                                 }
                   7015:                                 my $rem = @spares%($numinrow);
                   7016:                                 my $colsleft = $numinrow - $rem;
                   7017:                                 if ($colsleft > 1 ) {
                   7018:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   7019:                                                        '" class="LC_left_item">'.
                   7020:                                                        '&nbsp;</td>';
                   7021:                                 } elsif ($colsleft == 1) {
                   7022:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  7023:                                 }
1.152     raeburn  7024:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  7025:                             }
1.145     raeburn  7026:                         }
                   7027:                     }
                   7028:                     if ($current{$type} eq '') {
                   7029:                         $current{$type} = &mt('None specified');
                   7030:                     }
1.152     raeburn  7031:                     if ($othercontrol) {
                   7032:                         if ($type eq 'primary') {
                   7033:                             $canselect{$type} = $othercontrol;
                   7034:                         }
                   7035:                     } else {
                   7036:                         $canselect{$type} = 
                   7037:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   7038:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   7039:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   7040:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   7041:                         if (@choices > 0) {
                   7042:                             foreach my $lonhost (@choices) {
                   7043:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   7044:                             }
                   7045:                         }
                   7046:                         $canselect{$type} .= '</select>'."\n";
                   7047:                     }
                   7048:                 } else {
                   7049:                     $current{$type} = &mt('Could not be determined');
                   7050:                     if ($type eq 'primary') {
                   7051:                         $canselect{$type} =  $othercontrol;
                   7052:                     }
1.145     raeburn  7053:                 }
1.152     raeburn  7054:                 if ($type eq 'default') {
                   7055:                     $datatable .= '<tr'.$css_class.'>';
                   7056:                 }
                   7057:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   7058:                               '<td>'.$current{$type}.'</td>'."\n".
                   7059:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  7060:             }
                   7061:             $itemcount ++;
                   7062:         }
                   7063:     }
                   7064:     $$rowtotal += $itemcount;
                   7065:     return $datatable;
                   7066: }
                   7067: 
1.152     raeburn  7068: sub possible_newspares {
                   7069:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   7070:     my $serverhostname = &Apache::lonnet::hostname($server);
                   7071:     my %excluded;
                   7072:     if ($serverhostname ne '') {
                   7073:         %excluded = (
                   7074:                        $serverhostname => 1,
                   7075:                     );
                   7076:     }
                   7077:     if (ref($currspares) eq 'HASH') {
                   7078:         foreach my $type (keys(%{$currspares})) {
                   7079:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   7080:                 if (@{$currspares->{$type}} > 0) {
                   7081:                     foreach my $curr (@{$currspares->{$type}}) {
                   7082:                         my $hostname = &Apache::lonnet::hostname($curr);
                   7083:                         $excluded{$hostname} = 1;
                   7084:                     }
                   7085:                 }
                   7086:             }
                   7087:         }
                   7088:     }
                   7089:     my @choices;
                   7090:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   7091:         if (keys(%{$serverhomes}) > 1) {
                   7092:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   7093:                 unless ($excluded{$name}) {
                   7094:                     if (exists($altids->{$serverhomes->{$name}})) {
                   7095:                         push(@choices,$altids->{$serverhomes->{$name}});
                   7096:                     } else {
                   7097:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  7098:                     }
                   7099:                 }
                   7100:             }
                   7101:         }
                   7102:     }
1.152     raeburn  7103:     return sort(@choices);
1.145     raeburn  7104: }
                   7105: 
1.150     raeburn  7106: sub print_loadbalancing {
                   7107:     my ($dom,$settings,$rowtotal) = @_;
                   7108:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7109:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7110:     my $numinrow = 1;
                   7111:     my $datatable;
                   7112:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94  raeburn  7113:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  7114:     if (ref($settings) eq 'HASH') {
                   7115:         %existing = %{$settings};
                   7116:     }
                   7117:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   7118:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  7119:                                   \%currtargets,\%currrules,\%currcookies);
1.150     raeburn  7120:     } else {
                   7121:         return;
                   7122:     }
                   7123:     my ($othertitle,$usertypes,$types) =
                   7124:         &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26  raeburn  7125:     my $rownum = 8;
1.150     raeburn  7126:     if (ref($types) eq 'ARRAY') {
                   7127:         $rownum += scalar(@{$types});
                   7128:     }
1.160.6.7  raeburn  7129:     my @css_class = ('LC_odd_row','LC_even_row');
                   7130:     my $balnum = 0;
                   7131:     my $islast;
                   7132:     my (@toshow,$disabledtext);
                   7133:     if (keys(%currbalancer) > 0) {
                   7134:         @toshow = sort(keys(%currbalancer));
                   7135:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   7136:             push(@toshow,'');
                   7137:         }
                   7138:     } else {
                   7139:         @toshow = ('');
                   7140:         $disabledtext = &mt('No existing load balancer');
                   7141:     }
                   7142:     foreach my $lonhost (@toshow) {
                   7143:         if ($balnum == scalar(@toshow)-1) {
                   7144:             $islast = 1;
                   7145:         } else {
                   7146:             $islast = 0;
                   7147:         }
                   7148:         my $cssidx = $balnum%2;
                   7149:         my $targets_div_style = 'display: none';
                   7150:         my $disabled_div_style = 'display: block';
                   7151:         my $homedom_div_style = 'display: none';
                   7152:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   7153:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   7154:                       '<p>';
                   7155:         if ($lonhost eq '') {
                   7156:             $datatable .= '<span class="LC_nobreak">';
                   7157:             if (keys(%currbalancer) > 0) {
                   7158:                 $datatable .= &mt('Add balancer:');
                   7159:             } else {
                   7160:                 $datatable .= &mt('Enable balancer:');
                   7161:             }
                   7162:             $datatable .= '&nbsp;'.
                   7163:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   7164:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   7165:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   7166:                           '<option value="" selected="selected">'.&mt('None').
                   7167:                           '</option>'."\n";
                   7168:             foreach my $server (sort(keys(%servers))) {
                   7169:                 next if ($currbalancer{$server});
                   7170:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   7171:             }
                   7172:             $datatable .=
                   7173:                 '</select>'."\n".
                   7174:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   7175:         } else {
                   7176:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   7177:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   7178:                            &mt('Stop balancing').'</label>'.
                   7179:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   7180:             $targets_div_style = 'display: block';
                   7181:             $disabled_div_style = 'display: none';
                   7182:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   7183:                 $homedom_div_style = 'display: block';
                   7184:             }
                   7185:         }
                   7186:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   7187:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   7188:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   7189:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   7190:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   7191:         my @sparestypes = ('primary','default');
                   7192:         my %typetitles = &sparestype_titles();
1.160.6.76  raeburn  7193:         my %hostherechecked = (
                   7194:                                   no => ' checked="checked"',
                   7195:                               );
1.160.6.94  raeburn  7196:         my %balcookiechecked = (
                   7197:                                   no => ' checked="checked"',
                   7198:                                );
1.160.6.7  raeburn  7199:         foreach my $sparetype (@sparestypes) {
                   7200:             my $targettable;
                   7201:             for (my $i=0; $i<$numspares; $i++) {
                   7202:                 my $checked;
                   7203:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7204:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7205:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7206:                             $checked = ' checked="checked"';
                   7207:                         }
                   7208:                     }
                   7209:                 }
                   7210:                 my ($chkboxval,$disabled);
                   7211:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   7212:                     $chkboxval = $spares[$i];
                   7213:                 }
                   7214:                 if (exists($currbalancer{$spares[$i]})) {
                   7215:                     $disabled = ' disabled="disabled"';
                   7216:                 }
                   7217:                 $targettable .=
1.160.6.55  raeburn  7218:                     '<td><span class="LC_nobreak"><label>'.
                   7219:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7  raeburn  7220:                     $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  7221:                     '</span></label></span></td>';
1.160.6.7  raeburn  7222:                 my $rem = $i%($numinrow);
                   7223:                 if ($rem == 0) {
                   7224:                     if (($i > 0) && ($i < $numspares-1)) {
                   7225:                         $targettable .= '</tr>';
                   7226:                     }
                   7227:                     if ($i < $numspares-1) {
                   7228:                         $targettable .= '<tr>';
1.150     raeburn  7229:                     }
                   7230:                 }
                   7231:             }
1.160.6.7  raeburn  7232:             if ($targettable ne '') {
                   7233:                 my $rem = $numspares%($numinrow);
                   7234:                 my $colsleft = $numinrow - $rem;
                   7235:                 if ($colsleft > 1 ) {
                   7236:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7237:                                     '&nbsp;</td>';
                   7238:                 } elsif ($colsleft == 1) {
                   7239:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   7240:                 }
                   7241:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   7242:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   7243:             }
1.160.6.76  raeburn  7244:             $hostherechecked{$sparetype} = '';
                   7245:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   7246:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   7247:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   7248:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   7249:                         $hostherechecked{'no'} = '';
                   7250:                     }
                   7251:                 }
                   7252:             }
                   7253:         }
1.160.6.94  raeburn  7254:         if ($currcookies{$lonhost}) {
                   7255:             %balcookiechecked = (
                   7256:                                     yes => ' checked="checked"',
                   7257:                                 );
                   7258:         }
1.160.6.76  raeburn  7259:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   7260:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   7261:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   7262:         foreach my $sparetype (@sparestypes) {
                   7263:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   7264:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   7265:                           '</i></label><br />';
1.160.6.7  raeburn  7266:         }
1.160.6.94  raeburn  7267:         $datatable .= &mt('Use balancer cookie').'<br />'.
                   7268:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                   7269:                       $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                   7270:                       '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                   7271:                       $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                   7272:                       '</div></td></tr>'.
1.160.6.7  raeburn  7273:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   7274:                                            $othertitle,$usertypes,$types,\%servers,
                   7275:                                            \%currbalancer,$lonhost,
                   7276:                                            $targets_div_style,$homedom_div_style,
                   7277:                                            $css_class[$cssidx],$balnum,$islast);
                   7278:         $$rowtotal += $rownum;
                   7279:         $balnum ++;
                   7280:     }
                   7281:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   7282:     return $datatable;
                   7283: }
                   7284: 
                   7285: sub get_loadbalancers_config {
1.160.6.94  raeburn  7286:     my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7  raeburn  7287:     return unless ((ref($servers) eq 'HASH') &&
                   7288:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94  raeburn  7289:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                   7290:                    (ref($currcookies) eq 'HASH'));
1.160.6.7  raeburn  7291:     if (keys(%{$existing}) > 0) {
                   7292:         my $oldlonhost;
                   7293:         foreach my $key (sort(keys(%{$existing}))) {
                   7294:             if ($key eq 'lonhost') {
                   7295:                 $oldlonhost = $existing->{'lonhost'};
                   7296:                 $currbalancer->{$oldlonhost} = 1;
                   7297:             } elsif ($key eq 'targets') {
                   7298:                 if ($oldlonhost) {
                   7299:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   7300:                 }
                   7301:             } elsif ($key eq 'rules') {
                   7302:                 if ($oldlonhost) {
                   7303:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   7304:                 }
                   7305:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   7306:                 $currbalancer->{$key} = 1;
                   7307:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   7308:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94  raeburn  7309:                 if ($existing->{$key}{'cookie'}) {
                   7310:                     $currcookies->{$key} = 1;
                   7311:                 }
1.150     raeburn  7312:             }
                   7313:         }
1.160.6.7  raeburn  7314:     } else {
                   7315:         my ($balancerref,$targetsref) =
                   7316:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   7317:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   7318:             foreach my $server (sort(keys(%{$balancerref}))) {
                   7319:                 $currbalancer->{$server} = 1;
                   7320:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  7321:             }
                   7322:         }
                   7323:     }
1.160.6.7  raeburn  7324:     return;
1.150     raeburn  7325: }
                   7326: 
                   7327: sub loadbalancing_rules {
                   7328:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7  raeburn  7329:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   7330:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  7331:     my $output;
1.160.6.7  raeburn  7332:     my $num = 0;
                   7333:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  7334:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   7335:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   7336:         foreach my $type (@{$alltypes}) {
1.160.6.7  raeburn  7337:             $num ++;
1.150     raeburn  7338:             my $current;
                   7339:             if (ref($currrules) eq 'HASH') {
                   7340:                 $current = $currrules->{$type};
                   7341:             }
1.160.6.55  raeburn  7342:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7  raeburn  7343:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  7344:                     $current = '';
                   7345:                 }
                   7346:             }
                   7347:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7  raeburn  7348:                                              $servers,$currbalancer,$lonhost,$dom,
                   7349:                                              $targets_div_style,$homedom_div_style,
                   7350:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  7351:         }
                   7352:     }
                   7353:     return $output;
                   7354: }
                   7355: 
                   7356: sub loadbalancing_titles {
                   7357:     my ($dom,$intdom,$usertypes,$types) = @_;
                   7358:     my %othertypes = (
                   7359:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   7360:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   7361:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   7362:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.160.6.26  raeburn  7363:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   7364:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  7365:                      );
1.160.6.26  raeburn  7366:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89  raeburn  7367:     my @available;
1.150     raeburn  7368:     if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  7369:         @available = @{$types};
1.150     raeburn  7370:     }
1.160.6.89  raeburn  7371:     unless (grep(/^default$/,@available)) {
                   7372:         push(@available,'default');
                   7373:     }
                   7374:     unshift(@alltypes,@available);
1.150     raeburn  7375:     my %titles;
                   7376:     foreach my $type (@alltypes) {
                   7377:         if ($type =~ /^_LC_/) {
                   7378:             $titles{$type} = $othertypes{$type};
                   7379:         } elsif ($type eq 'default') {
                   7380:             $titles{$type} = &mt('All users from [_1]',$dom);
                   7381:             if (ref($types) eq 'ARRAY') {
                   7382:                 if (@{$types} > 0) {
                   7383:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   7384:                 }
                   7385:             }
                   7386:         } elsif (ref($usertypes) eq 'HASH') {
                   7387:             $titles{$type} = $usertypes->{$type};
                   7388:         }
                   7389:     }
                   7390:     return (\@alltypes,\%othertypes,\%titles);
                   7391: }
                   7392: 
                   7393: sub loadbalance_rule_row {
1.160.6.7  raeburn  7394:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   7395:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26  raeburn  7396:     my @rulenames;
1.150     raeburn  7397:     my %ruletitles = &offloadtype_text();
1.160.6.26  raeburn  7398:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55  raeburn  7399:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  7400:     } else {
1.160.6.26  raeburn  7401:         @rulenames = ('default','homeserver');
                   7402:         if ($type eq '_LC_external') {
                   7403:             push(@rulenames,'externalbalancer');
                   7404:         } else {
                   7405:             push(@rulenames,'specific');
                   7406:         }
                   7407:         push(@rulenames,'none');
1.150     raeburn  7408:     }
                   7409:     my $style = $targets_div_style;
1.160.6.55  raeburn  7410:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  7411:         $style = $homedom_div_style;
                   7412:     }
1.160.6.7  raeburn  7413:     my $space;
                   7414:     if ($islast && $num == 1) {
                   7415:         $space = '<div display="inline-block">&nbsp;</div>';
                   7416:     }
                   7417:     my $output =
                   7418:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   7419:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   7420:         '<td valaign="top">'.$space.
                   7421:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  7422:     for (my $i=0; $i<@rulenames; $i++) {
                   7423:         my $rule = $rulenames[$i];
                   7424:         my ($checked,$extra);
                   7425:         if ($rulenames[$i] eq 'default') {
                   7426:             $rule = '';
                   7427:         }
                   7428:         if ($rulenames[$i] eq 'specific') {
                   7429:             if (ref($servers) eq 'HASH') {
                   7430:                 my $default;
                   7431:                 if (($current ne '') && (exists($servers->{$current}))) {
                   7432:                     $checked = ' checked="checked"';
                   7433:                 }
                   7434:                 unless ($checked) {
                   7435:                     $default = ' selected="selected"';
                   7436:                 }
1.160.6.7  raeburn  7437:                 $extra =
                   7438:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7439:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   7440:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   7441:                     '<option value=""'.$default.'></option>'."\n";
                   7442:                 foreach my $server (sort(keys(%{$servers}))) {
                   7443:                     if (ref($currbalancer) eq 'HASH') {
                   7444:                         next if (exists($currbalancer->{$server}));
                   7445:                     }
1.150     raeburn  7446:                     my $selected;
1.160.6.7  raeburn  7447:                     if ($server eq $current) {
1.150     raeburn  7448:                         $selected = ' selected="selected"';
                   7449:                     }
1.160.6.7  raeburn  7450:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  7451:                 }
                   7452:                 $extra .= '</select>';
                   7453:             }
                   7454:         } elsif ($rule eq $current) {
                   7455:             $checked = ' checked="checked"';
                   7456:         }
                   7457:         $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7  raeburn  7458:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   7459:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   7460:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55  raeburn  7461:                    ')"'.$checked.' />&nbsp;';
1.160.6.56  raeburn  7462:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55  raeburn  7463:             $output .= $ruletitles{'particular'};
                   7464:         } else {
                   7465:             $output .= $ruletitles{$rulenames[$i]};
                   7466:         }
                   7467:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  7468:     }
                   7469:     $output .= '</div></td></tr>'."\n";
                   7470:     return $output;
                   7471: }
                   7472: 
                   7473: sub offloadtype_text {
                   7474:     my %ruletitles = &Apache::lonlocal::texthash (
                   7475:            'default'          => 'Offloads to default destinations',
                   7476:            'homeserver'       => "Offloads to user's home server",
                   7477:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   7478:            'specific'         => 'Offloads to specific server',
1.160.6.3  raeburn  7479:            'none'             => 'No offload',
1.160.6.26  raeburn  7480:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   7481:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.160.6.55  raeburn  7482:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  7483:     );
                   7484:     return %ruletitles;
                   7485: }
                   7486: 
                   7487: sub sparestype_titles {
                   7488:     my %typestitles = &Apache::lonlocal::texthash (
                   7489:                           'primary' => 'primary',
                   7490:                           'default' => 'default',
                   7491:                       );
                   7492:     return %typestitles;
                   7493: }
                   7494: 
1.28      raeburn  7495: sub contact_titles {
                   7496:     my %titles = &Apache::lonlocal::texthash (
1.160.6.78  raeburn  7497:                    'supportemail'    => 'Support E-mail address',
                   7498:                    'adminemail'      => 'Default Server Admin E-mail address',
                   7499:                    'errormail'       => 'Error reports to be e-mailed to',
                   7500:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
1.160.6.101  raeburn  7501:                    'helpdeskmail'    => "Helpdesk requests from all users in this domain",
                   7502:                    'otherdomsmail'   => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78  raeburn  7503:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   7504:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   7505:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23  raeburn  7506:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91  raeburn  7507:                    'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109  raeburn  7508:                    'errorthreshold'  => 'Error count threshold for status e-mail to admin(s)',
                   7509:                    'errorsysmail'    => 'Error count threshold for e-mail to developer group',
1.160.6.107  raeburn  7510:                    'errorweights'    => 'Weights used to compute error count',
                   7511:                    'errorexcluded'   => 'Servers with unsent updates excluded from count',
1.28      raeburn  7512:                  );
                   7513:     my %short_titles = &Apache::lonlocal::texthash (
                   7514:                            adminemail   => 'Admin E-mail address',
                   7515:                            supportemail => 'Support E-mail',
                   7516:                        );   
                   7517:     return (\%titles,\%short_titles);
                   7518: }
                   7519: 
1.160.6.78  raeburn  7520: sub helpform_fields {
                   7521:     my %titles =  &Apache::lonlocal::texthash (
                   7522:                        'username'   => 'Name',
                   7523:                        'user'       => 'Username/domain',
                   7524:                        'phone'      => 'Phone',
                   7525:                        'cc'         => 'Cc e-mail',
                   7526:                        'course'     => 'Course Details',
                   7527:                        'section'    => 'Sections',
                   7528:                        'screenshot' => 'File upload',
                   7529:     );
                   7530:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   7531:     my %possoptions = (
                   7532:                         username     => ['yes','no','req'],
                   7533:                         phone        => ['yes','no','req'],
                   7534:                         user         => ['yes','no'],
                   7535:                         cc           => ['yes','no'],
                   7536:                         course       => ['yes','no'],
                   7537:                         section      => ['yes','no'],
                   7538:                         screenshot   => ['yes','no'],
                   7539:                       );
                   7540:     my %fieldoptions = &Apache::lonlocal::texthash (
                   7541:                          'yes'  => 'Optional',
                   7542:                          'req'  => 'Required',
                   7543:                          'no'   => "Not shown",
                   7544:     );
                   7545:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   7546: }
                   7547: 
1.72      raeburn  7548: sub tool_titles {
                   7549:     my %titles = &Apache::lonlocal::texthash (
1.160.6.4  raeburn  7550:                      aboutme    => 'Personal web page',
1.86      raeburn  7551:                      blog       => 'Blog',
1.160.6.4  raeburn  7552:                      webdav     => 'WebDAV',
1.86      raeburn  7553:                      portfolio  => 'Portfolio',
1.88      bisitz   7554:                      official   => 'Official courses (with institutional codes)',
                   7555:                      unofficial => 'Unofficial courses',
1.98      raeburn  7556:                      community  => 'Communities',
1.160.6.30  raeburn  7557:                      textbook   => 'Textbook courses',
1.86      raeburn  7558:                  );
1.72      raeburn  7559:     return %titles;
                   7560: }
                   7561: 
1.101     raeburn  7562: sub courserequest_titles {
                   7563:     my %titles = &Apache::lonlocal::texthash (
                   7564:                                    official   => 'Official',
                   7565:                                    unofficial => 'Unofficial',
                   7566:                                    community  => 'Communities',
1.160.6.30  raeburn  7567:                                    textbook   => 'Textbook',
1.101     raeburn  7568:                                    norequest  => 'Not allowed',
1.104     raeburn  7569:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  7570:                                    validate   => 'With validation',
                   7571:                                    autolimit  => 'Numerical limit',
1.103     raeburn  7572:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  7573:                  );
                   7574:     return %titles;
                   7575: }
                   7576: 
1.160.6.5  raeburn  7577: sub authorrequest_titles {
                   7578:     my %titles = &Apache::lonlocal::texthash (
                   7579:                                    norequest  => 'Not allowed',
                   7580:                                    approval   => 'Approval by Dom. Coord.',
                   7581:                                    automatic  => 'Automatic approval',
                   7582:                  );
                   7583:     return %titles;
                   7584: }
                   7585: 
1.101     raeburn  7586: sub courserequest_conditions {
                   7587:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  7588:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17  raeburn  7589:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  7590:                  );
                   7591:     return %conditions;
                   7592: }
                   7593: 
                   7594: 
1.27      raeburn  7595: sub print_usercreation {
1.30      raeburn  7596:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  7597:     my $numinrow = 4;
1.28      raeburn  7598:     my $datatable;
                   7599:     if ($position eq 'top') {
1.30      raeburn  7600:         $$rowtotal ++;
1.34      raeburn  7601:         my $rowcount = 0;
1.32      raeburn  7602:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  7603:         if (ref($rules) eq 'HASH') {
                   7604:             if (keys(%{$rules}) > 0) {
1.32      raeburn  7605:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   7606:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  7607:                 $$rowtotal ++;
1.32      raeburn  7608:                 $rowcount ++;
                   7609:             }
                   7610:         }
                   7611:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   7612:         if (ref($idrules) eq 'HASH') {
                   7613:             if (keys(%{$idrules}) > 0) {
                   7614:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   7615:                                                 $idruleorder,$numinrow,$rowcount);
                   7616:                 $$rowtotal ++;
                   7617:                 $rowcount ++;
1.28      raeburn  7618:             }
                   7619:         }
1.39      raeburn  7620:         if ($rowcount == 0) {
                   7621:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   7622:             $$rowtotal ++;
                   7623:             $rowcount ++;
                   7624:         }
1.34      raeburn  7625:     } elsif ($position eq 'middle') {
1.160.6.34  raeburn  7626:         my @creators = ('author','course','requestcrs');
1.37      raeburn  7627:         my ($rules,$ruleorder) =
                   7628:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  7629:         my %lt = &usercreation_types();
                   7630:         my %checked;
                   7631:         if (ref($settings) eq 'HASH') {
                   7632:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7633:                 foreach my $item (@creators) {
                   7634:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   7635:                 }
                   7636:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   7637:                 foreach my $item (@creators) {
                   7638:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   7639:                         $checked{$item} = 'none';
                   7640:                     }
                   7641:                 }
                   7642:             }
                   7643:         }
                   7644:         my $rownum = 0;
                   7645:         foreach my $item (@creators) {
                   7646:             $rownum ++;
1.160.6.34  raeburn  7647:             if ($checked{$item} eq '') {
                   7648:                 $checked{$item} = 'any';
1.34      raeburn  7649:             }
                   7650:             my $css_class;
                   7651:             if ($rownum%2) {
                   7652:                 $css_class = '';
                   7653:             } else {
                   7654:                 $css_class = ' class="LC_odd_row" ';
                   7655:             }
                   7656:             $datatable .= '<tr'.$css_class.'>'.
                   7657:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   7658:                          '</span></td><td align="right">';
1.160.6.34  raeburn  7659:             my @options = ('any');
                   7660:             if (ref($rules) eq 'HASH') {
                   7661:                 if (keys(%{$rules}) > 0) {
                   7662:                     push(@options,('official','unofficial'));
1.37      raeburn  7663:                 }
                   7664:             }
1.160.6.34  raeburn  7665:             push(@options,'none');
1.37      raeburn  7666:             foreach my $option (@options) {
1.50      raeburn  7667:                 my $type = 'radio';
1.34      raeburn  7668:                 my $check = ' ';
1.160.6.34  raeburn  7669:                 if ($checked{$item} eq $option) {
                   7670:                     $check = ' checked="checked" ';
1.34      raeburn  7671:                 } 
                   7672:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  7673:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  7674:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   7675:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   7676:             }
                   7677:             $datatable .= '</td></tr>';
                   7678:         }
1.28      raeburn  7679:     } else {
                   7680:         my @contexts = ('author','course','domain');
                   7681:         my @authtypes = ('int','krb4','krb5','loc');
                   7682:         my %checked;
                   7683:         if (ref($settings) eq 'HASH') {
                   7684:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   7685:                 foreach my $item (@contexts) {
                   7686:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   7687:                         foreach my $auth (@authtypes) {
                   7688:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   7689:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   7690:                             }
                   7691:                         }
                   7692:                     }
                   7693:                 }
1.27      raeburn  7694:             }
1.35      raeburn  7695:         } else {
                   7696:             foreach my $item (@contexts) {
1.36      raeburn  7697:                 foreach my $auth (@authtypes) {
1.35      raeburn  7698:                     $checked{$item}{$auth} = ' checked="checked" ';
                   7699:                 }
                   7700:             }
1.27      raeburn  7701:         }
1.28      raeburn  7702:         my %title = &context_names();
                   7703:         my %authname = &authtype_names();
                   7704:         my $rownum = 0;
                   7705:         my $css_class; 
                   7706:         foreach my $item (@contexts) {
                   7707:             if ($rownum%2) {
                   7708:                 $css_class = '';
                   7709:             } else {
                   7710:                 $css_class = ' class="LC_odd_row" ';
                   7711:             }
1.30      raeburn  7712:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  7713:                             '<td>'.$title{$item}.
                   7714:                             '</td><td class="LC_left_item">'.
                   7715:                             '<span class="LC_nobreak">';
                   7716:             foreach my $auth (@authtypes) {
                   7717:                 $datatable .= '<label>'. 
                   7718:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   7719:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   7720:                               $authname{$auth}.'</label>&nbsp;';
                   7721:             }
                   7722:             $datatable .= '</span></td></tr>';
                   7723:             $rownum ++;
1.27      raeburn  7724:         }
1.30      raeburn  7725:         $$rowtotal += $rownum;
1.27      raeburn  7726:     }
                   7727:     return $datatable;
                   7728: }
                   7729: 
1.160.6.34  raeburn  7730: sub print_selfcreation {
                   7731:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93  raeburn  7732:     my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
                   7733:         $emaildomain,$datatable);
1.160.6.34  raeburn  7734:     if (ref($settings) eq 'HASH') {
                   7735:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   7736:             $createsettings = $settings->{'cancreate'};
1.160.6.40  raeburn  7737:             if (ref($createsettings) eq 'HASH') {
                   7738:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   7739:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   7740:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   7741:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   7742:                         @selfcreate = ('email','login','sso');
                   7743:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   7744:                         @selfcreate = ($createsettings->{'selfcreate'});
                   7745:                     }
                   7746:                 }
                   7747:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   7748:                     $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34  raeburn  7749:                 }
1.160.6.93  raeburn  7750:                 if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
                   7751:                     $emailoptions = $createsettings->{'emailoptions'};
                   7752:                 }
                   7753:                 if (ref($createsettings->{'emailverified'}) eq 'HASH') {
                   7754:                     $emailverified = $createsettings->{'emailverified'};
                   7755:                 }
                   7756:                 if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
                   7757:                     $emaildomain = $createsettings->{'emaildomain'};
                   7758:                 }
1.160.6.34  raeburn  7759:             }
                   7760:         }
                   7761:     }
                   7762:     my %radiohash;
                   7763:     my $numinrow = 4;
                   7764:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89  raeburn  7765:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34  raeburn  7766:     if ($position eq 'top') {
                   7767:         my %choices = &Apache::lonlocal::texthash (
                   7768:                                                       cancreate_login      => 'Institutional Login',
                   7769:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   7770:                                                   );
                   7771:         my @toggles = sort(keys(%choices));
                   7772:         my %defaultchecked = (
                   7773:                                'cancreate_login' => 'off',
                   7774:                                'cancreate_sso'   => 'off',
                   7775:                              );
1.160.6.35  raeburn  7776:         my ($onclick,$itemcount);
1.160.6.34  raeburn  7777:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7778:                                                      \%choices,$itemcount,$onclick);
1.160.6.35  raeburn  7779:         $$rowtotal += $itemcount;
1.160.6.34  raeburn  7780: 
                   7781:         if (ref($usertypes) eq 'HASH') {
                   7782:             if (keys(%{$usertypes}) > 0) {
                   7783:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   7784:                                              $dom,$numinrow,$othertitle,
1.160.6.89  raeburn  7785:                                              'statustocreate',$rowtotal);
1.160.6.34  raeburn  7786:                 $$rowtotal ++;
                   7787:             }
                   7788:         }
1.160.6.44  raeburn  7789:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   7790:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   7791:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   7792:         my $rem;
                   7793:         my $numperrow = 2;
                   7794:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   7795:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.45  raeburn  7796:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44  raeburn  7797:                      '<td class="LC_left_item">'."\n".
1.160.6.87  raeburn  7798:                      '<table>'."\n";
1.160.6.44  raeburn  7799:         for (my $i=0; $i<@fields; $i++) {
                   7800:             $rem = $i%($numperrow);
                   7801:             if ($rem == 0) {
                   7802:                 if ($i > 0) {
                   7803:                     $datatable .= '</tr>';
                   7804:                 }
                   7805:                 $datatable .= '<tr>';
                   7806:             }
                   7807:             my $currval;
1.160.6.51  raeburn  7808:             if (ref($createsettings) eq 'HASH') {
                   7809:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   7810:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   7811:                 }
1.160.6.44  raeburn  7812:             }
                   7813:             $datatable .= '<td class="LC_left_item">'.
                   7814:                           '<span class="LC_nobreak">'.
                   7815:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   7816:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   7817:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   7818:         }
                   7819:         my $colsleft = $numperrow - $rem;
                   7820:         if ($colsleft > 1 ) {
                   7821:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7822:                          '&nbsp;</td>';
                   7823:         } elsif ($colsleft == 1) {
                   7824:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   7825:         }
                   7826:         $datatable .= '</tr></table></td></tr>';
                   7827:         $$rowtotal ++;
1.160.6.34  raeburn  7828:     } elsif ($position eq 'middle') {
                   7829:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89  raeburn  7830:         my @posstypes;
1.160.6.34  raeburn  7831:         if (ref($types) eq 'ARRAY') {
1.160.6.89  raeburn  7832:             @posstypes = @{$types};
                   7833:         }
                   7834:         unless (grep(/^default$/,@posstypes)) {
                   7835:             push(@posstypes,'default');
                   7836:         }
                   7837:         my %usertypeshash;
                   7838:         if (ref($usertypes) eq 'HASH') {
                   7839:             %usertypeshash = %{$usertypes};
                   7840:         }
                   7841:         $usertypeshash{'default'} = $othertitle;
                   7842:         foreach my $status (@posstypes) {
                   7843:             $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
                   7844:                                                    $numinrow,$$rowtotal,\%usertypeshash);
                   7845:             $$rowtotal ++;
1.160.6.34  raeburn  7846:         }
                   7847:     } else {
1.160.6.40  raeburn  7848:         my %choices = &Apache::lonlocal::texthash (
1.160.6.93  raeburn  7849:                           'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40  raeburn  7850:                                                   );
                   7851:         my @toggles = sort(keys(%choices));
                   7852:         my %defaultchecked = (
                   7853:                                'cancreate_email' => 'off',
                   7854:                              );
1.160.6.93  raeburn  7855:         my $customclass = 'LC_selfcreate_email';
                   7856:         my $classprefix = 'LC_canmodify_emailusername_';
                   7857:         my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40  raeburn  7858:         my $display = 'none';
1.160.6.93  raeburn  7859:         my $rowstyle = 'display:none';
1.160.6.40  raeburn  7860:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   7861:             $display = 'block';
1.160.6.93  raeburn  7862:             $rowstyle = 'display:table-row';
1.160.6.40  raeburn  7863:         }
1.160.6.93  raeburn  7864:         my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
                   7865:         ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   7866:                                                      \%choices,$$rowtotal,$onclick);
                   7867:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
                   7868:                                          $rowstyle);
                   7869:         $$rowtotal ++;
                   7870:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
                   7871:                                       $rowstyle);
                   7872:         $$rowtotal ++;
                   7873:         my (@ordered,@posstypes,%usertypeshash);
1.160.6.40  raeburn  7874:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93  raeburn  7875:         my ($emailrules,$emailruleorder) =
                   7876:             &Apache::lonnet::inst_userrules($dom,'email');
                   7877:         my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   7878:         my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   7879:         if (ref($types) eq 'ARRAY') {
                   7880:             @posstypes = @{$types};
                   7881:         }
                   7882:         if (@posstypes) {
                   7883:             unless (grep(/^default$/,@posstypes)) {
                   7884:                 push(@posstypes,'default');
1.160.6.89  raeburn  7885:             }
                   7886:             if (ref($usertypes) eq 'HASH') {
                   7887:                 %usertypeshash = %{$usertypes};
                   7888:             }
1.160.6.93  raeburn  7889:             my $currassign;
                   7890:             if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
                   7891:                 $currassign = {
                   7892:                                   selfassign => $domdefaults{'inststatusguest'},
                   7893:                               };
                   7894:                 @ordered = @{$domdefaults{'inststatusguest'}};
                   7895:             } else {
                   7896:                 $currassign = { selfassign => [] };
                   7897:             }
                   7898:             my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
                   7899:                                "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
                   7900:             $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
                   7901:                                          $numinrow,$othertitle,'selfassign',
                   7902:                                          $rowtotal,$onclicktypes,$customclass,
                   7903:                                          $rowstyle);
                   7904:             $$rowtotal ++;
1.160.6.89  raeburn  7905:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  7906:             foreach my $status (@posstypes) {
                   7907:                 my $css_class;
                   7908:                 if ($$rowtotal%2) {
                   7909:                     $css_class = 'LC_odd_row ';
                   7910:                 }
                   7911:                 $css_class .= $customclass;
                   7912:                 my $rowid = $optionsprefix.$status;
                   7913:                 my $hidden = 1;
                   7914:                 my $currstyle = 'display:none';
                   7915:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   7916:                     $currstyle = $rowstyle;
                   7917:                     $hidden = 0;
                   7918:                 }
                   7919:                 $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7920:                                              $emailrules,$emailruleorder,$settings,$status,$rowid,
                   7921:                                              $usertypeshash{$status},$css_class,$currstyle,$intdom);
                   7922:                 unless ($hidden) {
                   7923:                     $$rowtotal ++;
                   7924:                 }
1.160.6.89  raeburn  7925:             }
                   7926:         } else {
1.160.6.93  raeburn  7927:             my $css_class;
                   7928:             if ($$rowtotal%2) {
                   7929:                 $css_class = 'LC_odd_row ';
                   7930:             }
                   7931:             $css_class .= $customclass;
1.160.6.89  raeburn  7932:             $usertypeshash{'default'} = $othertitle;
1.160.6.93  raeburn  7933:             $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
                   7934:                                          $emailrules,$emailruleorder,$settings,'default','',
                   7935:                                          $othertitle,$css_class,$rowstyle,$intdom);
                   7936:             $$rowtotal ++;
1.160.6.34  raeburn  7937:         }
1.160.6.35  raeburn  7938:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   7939:         $numinrow = 1;
1.160.6.93  raeburn  7940:         if (@posstypes) {
                   7941:             foreach my $status (@posstypes) {
                   7942:                 my $rowid = $classprefix.$status;
                   7943:                 my $datarowstyle = 'display:none';
                   7944:                 if (grep(/^\Q$status\E$/,@ordered)) {
                   7945:                     $datarowstyle = $rowstyle;
                   7946:                 }
                   7947:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   7948:                                                        $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7949:                                                        $infotitles,$rowid,$customclass,$datarowstyle);
                   7950:                 unless ($datarowstyle eq 'display:none') {
                   7951:                     $$rowtotal ++;
                   7952:                 }
1.160.6.34  raeburn  7953:             }
1.160.6.93  raeburn  7954:         } else {
                   7955:             $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
                   7956:                                                    $numinrow,$$rowtotal,\%usertypeshash,$infofields,
                   7957:                                                    $infotitles,'',$customclass,$rowstyle);
1.160.6.34  raeburn  7958:         }
                   7959:     }
                   7960:     return $datatable;
                   7961: }
                   7962: 
1.160.6.93  raeburn  7963: sub selfcreate_javascript {
                   7964:     return <<"ENDSCRIPT";
                   7965: 
                   7966: <script type="text/javascript">
                   7967: // <![CDATA[
                   7968: 
                   7969: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
                   7970:     var x = document.getElementsByClassName(target);
                   7971:     var insttypes = 0;
                   7972:     var insttypeRegExp = new RegExp(prefix);
                   7973:     if ((x.length != undefined) && (x.length > 0)) {
                   7974:         if (form.elements[radio].length != undefined) {
                   7975:             for (var i=0; i<form.elements[radio].length; i++) {
                   7976:                 if (form.elements[radio][i].checked) {
                   7977:                     if (form.elements[radio][i].value == 1) {
                   7978:                         for (var j=0; j<x.length; j++) {
                   7979:                             if (x[j].id == 'undefined') {
                   7980:                                 x[j].style.display = 'table-row';
                   7981:                             } else if (insttypeRegExp.test(x[j].id)) {
                   7982:                                 insttypes ++;
                   7983:                             } else {
                   7984:                                 x[j].style.display = 'table-row';
                   7985:                             }
                   7986:                         }
                   7987:                     } else {
                   7988:                         for (var j=0; j<x.length; j++) {
                   7989:                             x[j].style.display = 'none';
                   7990:                         }
1.160.6.40  raeburn  7991:                     }
1.160.6.93  raeburn  7992:                     break;
                   7993:                 }
                   7994:             }
                   7995:             if (insttypes > 0) {
                   7996:                 toggleDataRow(form,checkbox,target,altprefix);
                   7997:                 toggleDataRow(form,checkbox,target,prefix,1);
                   7998:             }
                   7999:         }
                   8000:     }
                   8001:     return;
                   8002: }
                   8003: 
                   8004: function toggleDataRow(form,checkbox,target,prefix,docount) {
                   8005:     if (form.elements[checkbox].length != undefined) {
                   8006:         var count = 0;
                   8007:         if (docount) {
                   8008:             for (var i=0; i<form.elements[checkbox].length; i++) {
                   8009:                 if (form.elements[checkbox][i].checked) {
                   8010:                     count ++;
                   8011:                 }
                   8012:             }
                   8013:         }
                   8014:         for (var i=0; i<form.elements[checkbox].length; i++) {
                   8015:             var type = form.elements[checkbox][i].value;
                   8016:             if (document.getElementById(prefix+type)) {
                   8017:                 if (form.elements[checkbox][i].checked) {
                   8018:                     document.getElementById(prefix+type).style.display = 'table-row';
                   8019:                     if (count % 2 == 1) {
                   8020:                         document.getElementById(prefix+type).className = target+' LC_odd_row';
                   8021:                     } else {
                   8022:                         document.getElementById(prefix+type).className = target;
                   8023:                     }
                   8024:                     count ++;
1.160.6.40  raeburn  8025:                 } else {
1.160.6.93  raeburn  8026:                     document.getElementById(prefix+type).style.display = 'none';
                   8027:                 }
                   8028:             }
                   8029:         }
                   8030:     }
                   8031:     return;
                   8032: }
                   8033: 
                   8034: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
                   8035:     var caller = radio+'_'+status;
                   8036:     if (form.elements[caller].length != undefined) {
                   8037:         for (var i=0; i<form.elements[caller].length; i++) {
                   8038:             if (form.elements[caller][i].checked) {
                   8039:                 if (document.getElementById(altprefix+'_inst_'+status)) {
                   8040:                     var curr = form.elements[caller][i].value;
                   8041:                     if (prefix) {
                   8042:                         document.getElementById(prefix+'_'+status).style.display = 'none';
                   8043:                     }
                   8044:                     document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
                   8045:                     document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
                   8046:                     if (curr == 'custom') {
                   8047:                         if (prefix) {
                   8048:                             document.getElementById(prefix+'_'+status).style.display = 'inline';
                   8049:                         }
                   8050:                     } else if (curr == 'inst') {
                   8051:                         document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
                   8052:                     } else if (curr == 'noninst') {
                   8053:                         document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40  raeburn  8054:                     }
1.160.6.93  raeburn  8055:                     break;
1.160.6.40  raeburn  8056:                 }
1.160.6.93  raeburn  8057:             }
                   8058:         }
                   8059:     }
                   8060: }
                   8061: 
                   8062: // ]]>
                   8063: </script>
                   8064: 
                   8065: ENDSCRIPT
                   8066: }
                   8067: 
                   8068: sub noninst_users {
                   8069:     my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
                   8070:         $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
                   8071:     my $class = 'LC_left_item';
                   8072:     if ($css_class) {
                   8073:         $css_class = ' class="'.$css_class.'"';
                   8074:     }
                   8075:     if ($rowid) {
                   8076:         $rowid = ' id="'.$rowid.'"';
                   8077:     }
                   8078:     if ($rowstyle) {
                   8079:         $rowstyle = ' style="'.$rowstyle.'"';
                   8080:     }
                   8081:     my ($output,$description);
                   8082:     if ($type eq 'default') {
                   8083:         $description = &mt('Requests for: [_1]',$typetitle);
                   8084:     } else {
                   8085:         $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
                   8086:     }
                   8087:     $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
                   8088:               "<td>$description</td>\n".
                   8089:               '<td class="'.$class.'" colspan="2">'.
                   8090:               '<table><tr>';
                   8091:     my %headers = &Apache::lonlocal::texthash(
                   8092:               approve  => 'Processing',
                   8093:               email    => 'E-mail',
                   8094:               username => 'Username',
                   8095:     );
                   8096:     foreach my $item ('approve','email','username') {
                   8097:         $output .= '<th>'.$headers{$item}.'</th>';
                   8098:     }
                   8099:     $output .= '</tr><tr>';
                   8100:     foreach my $item ('approve','email','username') {
                   8101:         $output .= '<td valign="top">';
                   8102:         my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
                   8103:         if ($item eq 'approve') {
                   8104:             %choices = &Apache::lonlocal::texthash (
                   8105:                                                      automatic => 'Automatically approved',
                   8106:                                                      approval  => 'Queued for approval',
                   8107:                                                    );
                   8108:             @options = ('automatic','approval');
                   8109:             $hashref = $processing;
                   8110:             $defoption = 'automatic';
                   8111:             $name = 'cancreate_emailprocess_'.$type;
                   8112:         } elsif ($item eq 'email') {
                   8113:             %choices = &Apache::lonlocal::texthash (
                   8114:                                                      any     => 'Any e-mail',
                   8115:                                                      inst    => 'Institutional only',
                   8116:                                                      noninst => 'Non-institutional only',
                   8117:                                                      custom  => 'Custom restrictions',
                   8118:                                                    );
                   8119:             @options = ('any','inst','noninst');
                   8120:             my $showcustom;
                   8121:             if (ref($emailrules) eq 'HASH') {
                   8122:                 if (keys(%{$emailrules}) > 0) {
                   8123:                     push(@options,'custom');
                   8124:                     $showcustom = 'cancreate_emailrule';
                   8125:                     if (ref($settings) eq 'HASH') {
                   8126:                         if (ref($settings->{'email_rule'}) eq 'ARRAY') {
                   8127:                             foreach my $rule (@{$settings->{'email_rule'}}) {
                   8128:                                 if (exists($emailrules->{$rule})) {
                   8129:                                     $hascustom ++;
                   8130:                                 }
                   8131:                             }
                   8132:                         } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
                   8133:                             if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
                   8134:                                 foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
                   8135:                                     if (exists($emailrules->{$rule})) {
                   8136:                                         $hascustom ++;
                   8137:                                     }
                   8138:                                 }
                   8139:                             }
                   8140:                         }
                   8141:                     }
                   8142:                 }
                   8143:             }
                   8144:             $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
                   8145:                                                      "'cancreate_emaildomain','$type'".');"';
                   8146:             $hashref = $emailoptions;
                   8147:             $defoption = 'any';
                   8148:             $name = 'cancreate_emailoptions_'.$type;
                   8149:         } elsif ($item eq 'username') {
                   8150:             %choices = &Apache::lonlocal::texthash (
                   8151:                                                      all    => 'Same as e-mail',
                   8152:                                                      first  => 'Omit @domain',
                   8153:                                                      free   => 'Free to choose',
                   8154:                                                    );
                   8155:             @options = ('all','first','free');
                   8156:             $hashref = $emailverified;
                   8157:             $defoption = 'all';
                   8158:             $name = 'cancreate_usernameoptions_'.$type;
                   8159:         }
                   8160:         foreach my $option (@options) {
                   8161:             my $checked;
                   8162:             if (ref($hashref) eq 'HASH') {
                   8163:                 if ($type eq '') {
                   8164:                     if (!exists($hashref->{'default'})) {
                   8165:                         if ($option eq $defoption) {
                   8166:                             $checked = ' checked="checked"';
                   8167:                         }
                   8168:                     } else {
                   8169:                         if ($hashref->{'default'} eq $option) {
                   8170:                             $checked = ' checked="checked"';
                   8171:                         }
1.160.6.40  raeburn  8172:                     }
                   8173:                 } else {
1.160.6.93  raeburn  8174:                     if (!exists($hashref->{$type})) {
                   8175:                         if ($option eq $defoption) {
                   8176:                             $checked = ' checked="checked"';
                   8177:                         }
                   8178:                     } else {
                   8179:                         if ($hashref->{$type} eq $option) {
                   8180:                             $checked = ' checked="checked"';
                   8181:                         }
1.160.6.40  raeburn  8182:                     }
                   8183:                 }
1.160.6.93  raeburn  8184:             } elsif (($item eq 'email') && ($hascustom)) {
                   8185:                 if ($option eq 'custom') {
                   8186:                     $checked = ' checked="checked"';
                   8187:                 }
                   8188:             } elsif ($option eq $defoption) {
                   8189:                 $checked = ' checked="checked"';
                   8190:             }
                   8191:             $output .= '<span class="LC_nobreak"><label>'.
                   8192:                        '<input type="radio" name="'.$name.'"'.
                   8193:                        $checked.' value="'.$option.'"'.$onclick.' />'.
                   8194:                        $choices{$option}.'</label></span><br />';
                   8195:             if ($item eq 'email') {
                   8196:                 if ($option eq 'custom') {
                   8197:                     my $id = 'cancreate_emailrule_'.$type;
                   8198:                     my $display = 'none';
                   8199:                     if ($checked) {
                   8200:                         $display = 'inline';
                   8201:                     }
                   8202:                     my $numinrow = 2;
                   8203:                     $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
                   8204:                                '<legend>'.&mt('Disallow').'</legend><table>'.
                   8205:                                &user_formats_row('email',$settings,$emailrules,
                   8206:                                                  $emailruleorder,$numinrow,'',$type);
                   8207:                               '</table></fieldset>';
                   8208:                 } elsif (($option eq 'inst') || ($option eq 'noninst')) {
                   8209:                     my %text = &Apache::lonlocal::texthash (
                   8210:                                                              inst    => 'must end:',
                   8211:                                                              noninst => 'cannot end:',
                   8212:                                                            );
                   8213:                     my $value;
                   8214:                     if (ref($emaildomain) eq 'HASH') {
                   8215:                         if (ref($emaildomain->{$type}) eq 'HASH') {
                   8216:                             $value = $emaildomain->{$type}->{$option};
                   8217:                         }
                   8218:                     }
                   8219:                     if ($value eq '') {
                   8220:                         $value = '@'.$intdom;
                   8221:                     }
                   8222:                     my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
                   8223:                     my $display = 'none';
                   8224:                     if ($checked) {
                   8225:                         $display = 'inline';
                   8226:                     }
                   8227:                     $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
                   8228:                                '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
                   8229:                                '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
                   8230:                                '</div>';
                   8231:                 }
1.160.6.40  raeburn  8232:             }
                   8233:         }
1.160.6.93  raeburn  8234:         $output .= '</td>'."\n";
1.160.6.40  raeburn  8235:     }
1.160.6.93  raeburn  8236:     $output .= "</tr></table></td></tr>\n";
1.160.6.40  raeburn  8237:     return $output;
                   8238: }
                   8239: 
1.160.6.5  raeburn  8240: sub captcha_choice {
1.160.6.93  raeburn  8241:     my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69  raeburn  8242:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   8243:         $vertext,$currver); 
1.160.6.5  raeburn  8244:     my %lt = &captcha_phrases();
                   8245:     $keyentry = 'hidden';
1.160.6.98  raeburn  8246:     my $colspan=2;
1.160.6.5  raeburn  8247:     if ($context eq 'cancreate') {
1.160.6.34  raeburn  8248:         $rowname = &mt('CAPTCHA validation');
1.160.6.5  raeburn  8249:     } elsif ($context eq 'login') {
                   8250:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98  raeburn  8251:     } elsif ($context eq 'passwords') {
                   8252:         $rowname = &mt('"Forgot Password" CAPTCHA validation');
                   8253:         $colspan=1;
1.160.6.5  raeburn  8254:     }
                   8255:     if (ref($settings) eq 'HASH') {
                   8256:         if ($settings->{'captcha'}) {
                   8257:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   8258:         } else {
                   8259:             $checked{'original'} = ' checked="checked"';
                   8260:         }
                   8261:         if ($settings->{'captcha'} eq 'recaptcha') {
                   8262:             $pubtext = $lt{'pub'};
                   8263:             $privtext = $lt{'priv'};
                   8264:             $keyentry = 'text';
1.160.6.69  raeburn  8265:             $vertext = $lt{'ver'};
                   8266:             $currver = $settings->{'recaptchaversion'};
                   8267:             if ($currver ne '2') {
                   8268:                 $currver = 1;
                   8269:             }
1.160.6.5  raeburn  8270:         }
                   8271:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   8272:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   8273:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   8274:         }
                   8275:     } else {
                   8276:         $checked{'original'} = ' checked="checked"';
                   8277:     }
1.160.6.93  raeburn  8278:     my $css_class;
                   8279:     if ($itemcount%2) {
                   8280:         $css_class = 'LC_odd_row';
                   8281:     }
                   8282:     if ($customcss) {
                   8283:         $css_class .= " $customcss";
                   8284:     }
                   8285:     $css_class =~ s/^\s+//;
                   8286:     if ($css_class) {
                   8287:         $css_class = ' class="'.$css_class.'"';
                   8288:     }
                   8289:     if ($rowstyle) {
                   8290:         $css_class .= ' style="'.$rowstyle.'"';
                   8291:     }
1.160.6.5  raeburn  8292:     my $output = '<tr'.$css_class.'>'.
1.160.6.98  raeburn  8293:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5  raeburn  8294:                  '<table><tr><td>'."\n";
                   8295:     foreach my $option ('original','recaptcha','notused') {
                   8296:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   8297:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   8298:                    $lt{$option}.'</label></span>';
                   8299:         unless ($option eq 'notused') {
                   8300:             $output .= ('&nbsp;'x2)."\n";
                   8301:         }
                   8302:     }
                   8303: #
                   8304: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   8305: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   8306: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
                   8307: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   8308: #
                   8309:     $output .= '</td></tr>'."\n".
1.160.6.93  raeburn  8310:                '<tr><td class="LC_zero_height">'."\n".
1.160.6.5  raeburn  8311:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   8312:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   8313:                $currpub.'" size="40" /></span><br />'."\n".
                   8314:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   8315:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69  raeburn  8316:                $currpriv.'" size="40" /></span><br />'.
                   8317:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   8318:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   8319:                $currver.'" size="3" /></span><br />'.
                   8320:                '</td></tr></table>'."\n".
1.160.6.5  raeburn  8321:                '</td></tr>';
                   8322:     return $output;
                   8323: }
                   8324: 
1.32      raeburn  8325: sub user_formats_row {
1.160.6.93  raeburn  8326:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32      raeburn  8327:     my $output;
                   8328:     my %text = (
                   8329:                    'username' => 'new usernames',
                   8330:                    'id'       => 'IDs',
                   8331:                );
1.160.6.118.2  8(raebur 8332:2):     unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93  raeburn  8333:         my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   8334:         $output = '<tr '.$css_class.'>'.
                   8335:                   '<td><span class="LC_nobreak">'.
                   8336:                   &mt("Format rules to check for $text{$type}: ").
                   8337:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.63      raeburn  8338:     }
1.27      raeburn  8339:     my $rem;
                   8340:     if (ref($ruleorder) eq 'ARRAY') {
                   8341:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   8342:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   8343:                 my $rem = $i%($numinrow);
                   8344:                 if ($rem == 0) {
                   8345:                     if ($i > 0) {
                   8346:                         $output .= '</tr>';
                   8347:                     }
                   8348:                     $output .= '<tr>';
                   8349:                 }
                   8350:                 my $check = ' ';
1.39      raeburn  8351:                 if (ref($settings) eq 'HASH') {
                   8352:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   8353:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   8354:                             $check = ' checked="checked" ';
                   8355:                         }
1.160.6.93  raeburn  8356:                     } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
                   8357:                         if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
                   8358:                             if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
                   8359:                                 $check = ' checked="checked" ';
                   8360:                             }
                   8361:                         }
1.27      raeburn  8362:                     }
                   8363:                 }
1.160.6.93  raeburn  8364:                 my $name = $type.'_rule';
                   8365:                 if ($type eq 'email') {
                   8366:                     $name .= '_'.$status;
                   8367:                 }
1.27      raeburn  8368:                 $output .= '<td class="LC_left_item">'.
                   8369:                            '<span class="LC_nobreak"><label>'.
1.160.6.93  raeburn  8370:                            '<input type="checkbox" name="'.$name.'" '.
1.27      raeburn  8371:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   8372:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   8373:             }
                   8374:         }
                   8375:         $rem = @{$ruleorder}%($numinrow);
                   8376:     }
1.160.6.93  raeburn  8377:     my $colsleft;
                   8378:     if ($rem) {
                   8379:         $colsleft = $numinrow - $rem;
                   8380:     }
1.27      raeburn  8381:     if ($colsleft > 1 ) {
                   8382:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   8383:                    '&nbsp;</td>';
                   8384:     } elsif ($colsleft == 1) {
                   8385:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   8386:     }
1.160.6.118.2  8(raebur 8387:2):     $output .= '</tr>';
                   8388:2):     unless (($type eq 'email') || ($type eq 'unamemap')) {
                   8389:2):         $output .= '</table></td></tr>';
1.160.6.93  raeburn  8390:     }
1.27      raeburn  8391:     return $output;
                   8392: }
                   8393: 
1.34      raeburn  8394: sub usercreation_types {
                   8395:     my %lt = &Apache::lonlocal::texthash (
                   8396:                     author     => 'When adding a co-author',
                   8397:                     course     => 'When adding a user to a course',
1.100     raeburn  8398:                     requestcrs => 'When requesting a course',
1.34      raeburn  8399:                     any        => 'Any',
                   8400:                     official   => 'Institutional only ',
                   8401:                     unofficial => 'Non-institutional only',
                   8402:                     none       => 'None',
                   8403:     );
                   8404:     return %lt;
1.48      raeburn  8405: }
1.34      raeburn  8406: 
1.160.6.34  raeburn  8407: sub selfcreation_types {
                   8408:     my %lt = &Apache::lonlocal::texthash (
                   8409:                     selfcreate => 'User creates own account',
                   8410:                     any        => 'Any',
                   8411:                     official   => 'Institutional only ',
                   8412:                     unofficial => 'Non-institutional only',
                   8413:                     email      => 'E-mail address',
                   8414:                     login      => 'Institutional Login',
                   8415:                     sso        => 'SSO',
                   8416:              );
                   8417: }
                   8418: 
1.28      raeburn  8419: sub authtype_names {
                   8420:     my %lt = &Apache::lonlocal::texthash(
                   8421:                       int    => 'Internal',
                   8422:                       krb4   => 'Kerberos 4',
                   8423:                       krb5   => 'Kerberos 5',
                   8424:                       loc    => 'Local',
                   8425:                   );
                   8426:     return %lt;
                   8427: }
                   8428: 
                   8429: sub context_names {
                   8430:     my %context_title = &Apache::lonlocal::texthash(
                   8431:        author => 'Creating users when an Author',
                   8432:        course => 'Creating users when in a course',
                   8433:        domain => 'Creating users when a Domain Coordinator',
                   8434:     );
                   8435:     return %context_title;
                   8436: }
                   8437: 
1.33      raeburn  8438: sub print_usermodification {
                   8439:     my ($position,$dom,$settings,$rowtotal) = @_;
                   8440:     my $numinrow = 4;
                   8441:     my ($context,$datatable,$rowcount);
                   8442:     if ($position eq 'top') {
                   8443:         $rowcount = 0;
                   8444:         $context = 'author'; 
                   8445:         foreach my $role ('ca','aa') {
                   8446:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8447:                                                    $numinrow,$rowcount);
                   8448:             $$rowtotal ++;
                   8449:             $rowcount ++;
                   8450:         }
1.160.6.37  raeburn  8451:     } elsif ($position eq 'bottom') {
1.33      raeburn  8452:         $context = 'course';
                   8453:         $rowcount = 0;
                   8454:         foreach my $role ('st','ep','ta','in','cr') {
                   8455:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   8456:                                                    $numinrow,$rowcount);
                   8457:             $$rowtotal ++;
                   8458:             $rowcount ++;
                   8459:         }
                   8460:     }
                   8461:     return $datatable;
                   8462: }
                   8463: 
1.43      raeburn  8464: sub print_defaults {
1.160.6.40  raeburn  8465:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  8466:     my $rownum = 0;
1.160.6.80  raeburn  8467:     my ($datatable,$css_class,$titles);
                   8468:     unless ($position eq 'bottom') {
                   8469:         $titles = &defaults_titles($dom);
                   8470:     }
1.160.6.40  raeburn  8471:     if ($position eq 'top') {
                   8472:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   8473:                      'datelocale_def','portal_def');
                   8474:         my %defaults;
                   8475:         if (ref($settings) eq 'HASH') {
                   8476:             %defaults = %{$settings};
1.43      raeburn  8477:         } else {
1.160.6.40  raeburn  8478:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8479:             foreach my $item (@items) {
                   8480:                 $defaults{$item} = $domdefaults{$item};
                   8481:             }
1.43      raeburn  8482:         }
1.160.6.40  raeburn  8483:         foreach my $item (@items) {
                   8484:             if ($rownum%2) {
                   8485:                 $css_class = '';
                   8486:             } else {
                   8487:                 $css_class = ' class="LC_odd_row" ';
1.43      raeburn  8488:             }
1.160.6.40  raeburn  8489:             $datatable .= '<tr'.$css_class.'>'.
                   8490:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   8491:                           '</span></td><td class="LC_right_item" colspan="3">';
                   8492:             if ($item eq 'auth_def') {
                   8493:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   8494:                 my %shortauth = (
                   8495:                                  internal => 'int',
                   8496:                                  krb4 => 'krb4',
                   8497:                                  krb5 => 'krb5',
                   8498:                                  localauth  => 'loc'
                   8499:                                 );
                   8500:                 my %authnames = &authtype_names();
                   8501:                 foreach my $auth (@authtypes) {
                   8502:                     my $checked = ' ';
                   8503:                     if ($defaults{$item} eq $auth) {
                   8504:                         $checked = ' checked="checked" ';
                   8505:                     }
                   8506:                     $datatable .= '<label><input type="radio" name="'.$item.
                   8507:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   8508:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   8509:                 }
                   8510:             } elsif ($item eq 'timezone_def') {
                   8511:                 my $includeempty = 1;
                   8512:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   8513:             } elsif ($item eq 'datelocale_def') {
1.160.6.98  raeburn  8514:                 my $includeempty = 1;
                   8515:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   8516:             } elsif ($item eq 'lang_def') {
                   8517:                 my $includeempty = 1;
                   8518:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80  raeburn  8519:             } else {
1.160.6.98  raeburn  8520:                 my $size;
                   8521:                 if ($item eq 'portal_def') {
                   8522:                     $size = ' size="25"';
                   8523:                 }
1.160.6.80  raeburn  8524:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98  raeburn  8525:                               $defaults{$item}.'"'.$size.' />';
1.160.6.80  raeburn  8526:             }
                   8527:             $datatable .= '</td></tr>';
                   8528:             $rownum ++;
                   8529:         }
1.160.6.118.2  8(raebur 8530:2):     } elsif ($position eq 'middle') {
1.160.6.80  raeburn  8531:         my %defaults;
1.160.6.40  raeburn  8532:         if (ref($settings) eq 'HASH') {
1.160.6.93  raeburn  8533:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40  raeburn  8534:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   8535:                 for (my $i=0; $i<$maxnum; $i++) {
                   8536:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8537:                     my $item = $settings->{'inststatusorder'}->[$i];
                   8538:                     my $title = $settings->{'inststatustypes'}->{$item};
                   8539:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   8540:                     $datatable .= '<tr'.$css_class.'>'.
                   8541:                                   '<td><span class="LC_nobreak">'.
                   8542:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   8543:                     for (my $k=0; $k<=$maxnum; $k++) {
                   8544:                         my $vpos = $k+1;
                   8545:                         my $selstr;
                   8546:                         if ($k == $i) {
                   8547:                             $selstr = ' selected="selected" ';
                   8548:                         }
                   8549:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8550:                     }
                   8551:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   8552:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   8553:                                   &mt('delete').'</span></td>'.
1.160.6.112  raeburn  8554:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40  raeburn  8555:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93  raeburn  8556:                                   '</span></td></tr>';
1.160.6.40  raeburn  8557:                 }
                   8558:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8559:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   8560:                 $datatable .= '<tr '.$css_class.'>'.
                   8561:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   8562:                 for (my $k=0; $k<=$maxnum; $k++) {
                   8563:                     my $vpos = $k+1;
                   8564:                     my $selstr;
                   8565:                     if ($k == $maxnum) {
                   8566:                         $selstr = ' selected="selected" ';
                   8567:                     }
                   8568:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   8569:                 }
                   8570:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.160.6.63  raeburn  8571:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40  raeburn  8572:                               '&nbsp;'.&mt('(new)').
                   8573:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112  raeburn  8574:                               &mt('Name displayed').':'.
1.160.6.40  raeburn  8575:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   8576:                               '</tr>'."\n";
                   8577:                 $rownum ++;
1.141     raeburn  8578:             }
1.43      raeburn  8579:         }
1.160.6.118.2  8(raebur 8580:2):     } else {
                   8581:2):         my ($unamemaprules,$ruleorder) =
                   8582:2):             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   8583:2):         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   8584:2):         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8585:2):             my $numinrow = 2;
                   8586:2):             $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
                   8587:2):                           &user_formats_row('unamemap',$settings,$unamemaprules,
                   8588:2):                                             $ruleorder,$numinrow).
                   8589:2):                           '</table></td></tr>';
                   8590:2):         }
                   8591:2):         if ($datatable eq '') {
                   8592:2):             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
                   8593:2):                           &mt('No rules set for domain in customized localenroll.pm').
                   8594:2):                           '</td></tr>';
                   8595:2):         }
1.43      raeburn  8596:     }
                   8597:     $$rowtotal += $rownum;
                   8598:     return $datatable;
                   8599: }
                   8600: 
1.160.6.5  raeburn  8601: sub get_languages_hash {
                   8602:     my %langchoices;
                   8603:     foreach my $id (&Apache::loncommon::languageids()) {
                   8604:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   8605:         if ($code ne '') {
                   8606:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   8607:         }
                   8608:     }
                   8609:     return %langchoices;
                   8610: }
                   8611: 
1.43      raeburn  8612: sub defaults_titles {
1.141     raeburn  8613:     my ($dom) = @_;
1.43      raeburn  8614:     my %titles = &Apache::lonlocal::texthash (
                   8615:                    'auth_def'      => 'Default authentication type',
                   8616:                    'auth_arg_def'  => 'Default authentication argument',
                   8617:                    'lang_def'      => 'Default language',
1.54      raeburn  8618:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  8619:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  8620:                    'portal_def'     => 'Portal/Default URL',
1.160.6.80  raeburn  8621:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   8622:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   8623:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  8624:                  );
1.141     raeburn  8625:     if ($dom) {
                   8626:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   8627:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   8628:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   8629:         $protocol = 'http' if ($protocol ne 'https');
                   8630:         if ($uint_dom) {
                   8631:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   8632:                                          $uint_dom);
                   8633:         }
                   8634:     }
1.43      raeburn  8635:     return (\%titles);
                   8636: }
                   8637: 
1.160.6.97  raeburn  8638: sub print_scantron {
                   8639:     my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
                   8640:     if ($position eq 'top') {
                   8641:         return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
                   8642:     } else {
                   8643:         return &print_scantronconfig($dom,$settings,\$rowtotal);
                   8644:     }
                   8645: }
                   8646: 
                   8647: sub scantron_javascript {
                   8648:     return <<"ENDSCRIPT";
                   8649: 
                   8650: <script type="text/javascript">
                   8651: // <![CDATA[
                   8652: 
                   8653: function toggleScantron(form) {
                   8654:     var csvfieldset = new Array();
                   8655:     if (document.getElementById('scantroncsv_cols')) {
                   8656:         csvfieldset.push(document.getElementById('scantroncsv_cols'));
                   8657:     }
                   8658:     if (document.getElementById('scantroncsv_options')) {
                   8659:         csvfieldset.push(document.getElementById('scantroncsv_options'));
                   8660:     }
                   8661:     if (csvfieldset.length) {
                   8662:         if (document.getElementById('scantronconfcsv')) {
                   8663:             var scantroncsv = document.getElementById('scantronconfcsv');
                   8664:             if (scantroncsv.checked) {
                   8665:                 for (var i=0; i<csvfieldset.length; i++) {
                   8666:                     csvfieldset[i].style.display = 'block';
                   8667:                 }
                   8668:             } else {
                   8669:                 for (var i=0; i<csvfieldset.length; i++) {
                   8670:                     csvfieldset[i].style.display = 'none';
                   8671:                 }
                   8672:                 var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   8673:                 if (csvselects.length) {
                   8674:                     for (var j=0; j<csvselects.length; j++) {
                   8675:                         csvselects[j].selectedIndex = 0;
                   8676:                     }
                   8677:                 }
                   8678:             }
                   8679:         }
                   8680:     }
                   8681:     return;
                   8682: }
                   8683: // ]]>
                   8684: </script>
                   8685: 
                   8686: ENDSCRIPT
                   8687: 
                   8688: }
                   8689: 
1.46      raeburn  8690: sub print_scantronformat {
                   8691:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   8692:     my $itemcount = 1;
1.60      raeburn  8693:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   8694:         %confhash);
1.46      raeburn  8695:     my $switchserver = &check_switchserver($dom,$confname);
                   8696:     my %lt = &Apache::lonlocal::texthash (
1.95      www      8697:                 default => 'Default bubblesheet format file error',
                   8698:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  8699:              );
                   8700:     my %scantronfiles = (
                   8701:         default => 'default.tab',
                   8702:         custom => 'custom.tab',
                   8703:     );
                   8704:     foreach my $key (keys(%scantronfiles)) {
                   8705:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   8706:                               .$scantronfiles{$key};
                   8707:     }
                   8708:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   8709:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   8710:         if (!$switchserver) {
                   8711:             my $servadm = $r->dir_config('lonAdmEMail');
                   8712:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   8713:             if ($configuserok eq 'ok') {
                   8714:                 if ($author_ok eq 'ok') {
                   8715:                     my %legacyfile = (
1.160.6.97  raeburn  8716:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
                   8717:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46      raeburn  8718:                     );
                   8719:                     my %md5chk;
                   8720:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  8721:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   8722:                         chomp($md5chk{$type});
1.46      raeburn  8723:                     }
                   8724:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   8725:                         foreach my $type (keys(%legacyfile)) {
1.160.6.97  raeburn  8726:                             ($scantronurls{$type},my $error) =
1.46      raeburn  8727:                                 &legacy_scantronformat($r,$dom,$confname,
                   8728:                                                  $type,$legacyfile{$type},
                   8729:                                                  $scantronurls{$type},
                   8730:                                                  $scantronfiles{$type});
1.60      raeburn  8731:                             if ($error ne '') {
                   8732:                                 $error{$type} = $error;
                   8733:                             }
                   8734:                         }
                   8735:                         if (keys(%error) == 0) {
                   8736:                             $is_custom = 1;
1.160.6.97  raeburn  8737:                             $confhash{'scantron'}{'scantronformat'} =
1.60      raeburn  8738:                                 $scantronurls{'custom'};
1.160.6.97  raeburn  8739:                             my $putresult =
1.60      raeburn  8740:                                 &Apache::lonnet::put_dom('configuration',
                   8741:                                                          \%confhash,$dom);
                   8742:                             if ($putresult ne 'ok') {
1.160.6.97  raeburn  8743:                                 $error{'custom'} =
1.60      raeburn  8744:                                     '<span class="LC_error">'.
                   8745:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8746:                             }
1.46      raeburn  8747:                         }
                   8748:                     } else {
1.60      raeburn  8749:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  8750:                             &legacy_scantronformat($r,$dom,$confname,
                   8751:                                           'default',$legacyfile{'default'},
                   8752:                                           $scantronurls{'default'},
                   8753:                                           $scantronfiles{'default'});
1.60      raeburn  8754:                         if ($error eq '') {
                   8755:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   8756:                             my $putresult =
                   8757:                                 &Apache::lonnet::put_dom('configuration',
                   8758:                                                          \%confhash,$dom);
                   8759:                             if ($putresult ne 'ok') {
                   8760:                                 $error{'default'} =
                   8761:                                     '<span class="LC_error">'.
                   8762:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   8763:                             }
                   8764:                         } else {
                   8765:                             $error{'default'} = $error;
                   8766:                         }
1.46      raeburn  8767:                     }
                   8768:                 }
                   8769:             }
                   8770:         } else {
1.95      www      8771:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  8772:         }
                   8773:     }
                   8774:     if (ref($settings) eq 'HASH') {
                   8775:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   8776:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   8777:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   8778:                 $scantronurl = '';
                   8779:             } else {
                   8780:                 $scantronurl = $settings->{'scantronformat'};
                   8781:             }
                   8782:             $is_custom = 1;
                   8783:         } else {
                   8784:             $scantronurl = $scantronurls{'default'};
                   8785:         }
                   8786:     } else {
1.60      raeburn  8787:         if ($is_custom) {
                   8788:             $scantronurl = $scantronurls{'custom'};
                   8789:         } else {
                   8790:             $scantronurl = $scantronurls{'default'};
                   8791:         }
1.46      raeburn  8792:     }
                   8793:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   8794:     $datatable .= '<tr'.$css_class.'>';
                   8795:     if (!$is_custom) {
1.65      raeburn  8796:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   8797:                       '<span class="LC_nobreak">';
1.46      raeburn  8798:         if ($scantronurl) {
1.160.6.21  raeburn  8799:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   8800:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  8801:         } else {
                   8802:             $datatable = &mt('File unavailable for display');
                   8803:         }
1.65      raeburn  8804:         $datatable .= '</span></td>';
1.60      raeburn  8805:         if (keys(%error) == 0) { 
                   8806:             $datatable .= '<td valign="bottom">';
                   8807:             if (!$switchserver) {
                   8808:                 $datatable .= &mt('Upload:').'<br />';
                   8809:             }
                   8810:         } else {
                   8811:             my $errorstr;
                   8812:             foreach my $key (sort(keys(%error))) {
                   8813:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8814:             }
                   8815:             $datatable .= '<td>'.$errorstr;
                   8816:         }
1.46      raeburn  8817:     } else {
                   8818:         if (keys(%error) > 0) {
                   8819:             my $errorstr;
                   8820:             foreach my $key (sort(keys(%error))) {
                   8821:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   8822:             } 
1.60      raeburn  8823:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  8824:         } elsif ($scantronurl) {
1.160.6.26  raeburn  8825:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21  raeburn  8826:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  8827:             $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21  raeburn  8828:                           $link.
                   8829:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   8830:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  8831:                           '<td><span class="LC_nobreak">&nbsp;'.
                   8832:                           &mt('Replace:').'</span><br />';
1.46      raeburn  8833:         }
                   8834:     }
                   8835:     if (keys(%error) == 0) {
                   8836:         if ($switchserver) {
                   8837:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   8838:         } else {
1.65      raeburn  8839:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   8840:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  8841:         }
                   8842:     }
                   8843:     $datatable .= '</td></tr>';
                   8844:     $$rowtotal ++;
                   8845:     return $datatable;
                   8846: }
                   8847: 
                   8848: sub legacy_scantronformat {
                   8849:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   8850:     my ($url,$error);
                   8851:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   8852:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   8853:         (my $result,$url) =
                   8854:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   8855:                          '','',$newfile);
                   8856:         if ($result ne 'ok') {
1.130     raeburn  8857:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  8858:         }
                   8859:     }
                   8860:     return ($url,$error);
                   8861: }
1.43      raeburn  8862: 
1.160.6.97  raeburn  8863: sub print_scantronconfig {
                   8864:     my ($dom,$settings,$rowtotal) = @_;
                   8865:     my $itemcount = 2;
                   8866:     my $is_checked = ' checked="checked"';
                   8867:     my %optionson = (
                   8868:                      hdr => ' checked="checked"',
                   8869:                      pad => ' checked="checked"',
                   8870:                      rem => ' checked="checked"',
                   8871:                     );
                   8872:     my %optionsoff = (
                   8873:                       hdr => '',
                   8874:                       pad => '',
                   8875:                       rem => '',
                   8876:                      );
                   8877:     my $currcsvsty = 'none';
                   8878:     my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
                   8879:     my @fields = &scantroncsv_fields();
                   8880:     my %titles = &scantronconfig_titles();
                   8881:     if (ref($settings) eq 'HASH') {
                   8882:         if (ref($settings->{config}) eq 'HASH') {
                   8883:             if ($settings->{config}->{dat}) {
                   8884:                 $checked{'dat'} = $is_checked;
                   8885:             }
                   8886:             if (ref($settings->{config}->{csv}) eq 'HASH') {
                   8887:                 if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                   8888:                     %csvfields = %{$settings->{config}->{csv}->{fields}};
                   8889:                     if (keys(%csvfields) > 0) {
                   8890:                         $checked{'csv'} = $is_checked;
                   8891:                         $currcsvsty = 'block';
                   8892:                     }
                   8893:                 }
                   8894:                 if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                   8895:                     %csvoptions = %{$settings->{config}->{csv}->{options}};
                   8896:                     foreach my $option (keys(%optionson)) {
                   8897:                         unless ($csvoptions{$option}) {
                   8898:                             $optionsoff{$option} = $optionson{$option};
                   8899:                             $optionson{$option} = '';
                   8900:                         }
                   8901:                     }
                   8902:                 }
                   8903:             }
                   8904:         } else {
                   8905:             $checked{'dat'} = $is_checked;
                   8906:         }
                   8907:     } else {
                   8908:         $checked{'dat'} = $is_checked;
                   8909:     }
                   8910:     $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
                   8911:     my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   8912:     $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                   8913:                  '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
                   8914:     foreach my $item ('dat','csv') {
                   8915:         my $id;
                   8916:         if ($item eq 'csv') {
                   8917:             $id = 'id="scantronconfcsv" ';
                   8918:         }
                   8919:         $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                   8920:                       $titles{$item}.'</label>'.('&nbsp;'x3);
                   8921:         if ($item eq 'csv') {
                   8922:             $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                   8923:                           '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                   8924:                           '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
                   8925:             foreach my $col (@fields) {
                   8926:                 my $selnone;
                   8927:                 if ($csvfields{$col} eq '') {
                   8928:                     $selnone = ' selected="selected"';
                   8929:                 }
                   8930:                 $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                   8931:                               '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                   8932:                               '<option value=""'.$selnone.'></option>';
                   8933:                 for (my $i=0; $i<20; $i++) {
                   8934:                     my $shown = $i+1;
                   8935:                     my $sel;
                   8936:                     unless ($selnone) {
                   8937:                         if (exists($csvfields{$col})) {
                   8938:                             if ($csvfields{$col} == $i) {
                   8939:                                 $sel = ' selected="selected"';
                   8940:                             }
                   8941:                         }
                   8942:                     }
                   8943:                     $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   8944:                 }
                   8945:                 $datatable .= '</select></td></tr>';
                   8946:            }
                   8947:            $datatable .= '</table></fieldset>'.
                   8948:                          '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                   8949:                          '<legend>'.&mt('CSV Options').'</legend>';
                   8950:            foreach my $option ('hdr','pad','rem') {
                   8951:                $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                   8952:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                   8953:                          &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                   8954:                          '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
                   8955:            }
                   8956:            $datatable .= '</fieldset>';
                   8957:            $itemcount ++;
                   8958:         }
                   8959:     }
                   8960:     $datatable .= '</td></tr>';
                   8961:     $$rowtotal ++;
                   8962:     return $datatable;
                   8963: }
                   8964: 
                   8965: sub scantronconfig_titles {
                   8966:     return &Apache::lonlocal::texthash(
                   8967:                                           dat => 'Standard format (.dat)',
                   8968:                                           csv => 'Comma separated values (.csv)',
                   8969:                                           hdr => 'Remove first line in file (contains column titles)',
                   8970:                                           pad => 'Prepend 0s to PaperID',
                   8971:                                           rem => 'Remove leading spaces (except Question Response columns)',
                   8972:                                           CODE => 'CODE',
                   8973:                                           ID   => 'Student ID',
                   8974:                                           PaperID => 'Paper ID',
                   8975:                                           FirstName => 'First Name',
                   8976:                                           LastName => 'Last Name',
                   8977:                                           FirstQuestion => 'First Question Response',
                   8978:                                           Section => 'Section',
                   8979:     );
                   8980: }
                   8981: 
                   8982: sub scantroncsv_fields {
                   8983:     return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
                   8984: }
                   8985: 
1.49      raeburn  8986: sub print_coursecategories {
1.57      raeburn  8987:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   8988:     my $datatable;
                   8989:     if ($position eq 'top') {
1.160.6.42  raeburn  8990:         my (%checked);
                   8991:         my @catitems = ('unauth','auth');
                   8992:         my @cattypes = ('std','domonly','codesrch','none');
                   8993:         $checked{'unauth'} = 'std';
                   8994:         $checked{'auth'} = 'std';
                   8995:         if (ref($settings) eq 'HASH') {
                   8996:             foreach my $type (@cattypes) {
                   8997:                 if ($type eq $settings->{'unauth'}) {
                   8998:                     $checked{'unauth'} = $type;
                   8999:                 }
                   9000:                 if ($type eq $settings->{'auth'}) {
                   9001:                     $checked{'auth'} = $type;
                   9002:                 }
                   9003:             }
                   9004:         }
                   9005:         my %lt = &Apache::lonlocal::texthash (
                   9006:                                                unauth   => 'Catalog type for unauthenticated users',
                   9007:                                                auth     => 'Catalog type for authenticated users',
                   9008:                                                none     => 'No catalog',
                   9009:                                                std      => 'Standard catalog',
                   9010:                                                domonly  => 'Domain-only catalog',
                   9011:                                                codesrch => "Code search form",
                   9012:                                              );
                   9013:        my $itemcount = 0;
                   9014:        foreach my $item (@catitems) {
                   9015:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   9016:            $datatable .= '<tr '.$css_class.'>'.
                   9017:                          '<td>'.$lt{$item}.'</td>'.
                   9018:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   9019:            foreach my $type (@cattypes) {
                   9020:                my $ischecked;
                   9021:                if ($checked{$item} eq $type) {
                   9022:                    $ischecked=' checked="checked"';
                   9023:                }
                   9024:                $datatable .= '<label>'.
                   9025:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   9026:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   9027:            }
1.160.6.87  raeburn  9028:            $datatable .= '</span></td></tr>';
1.160.6.42  raeburn  9029:            $itemcount ++;
                   9030:         }
                   9031:         $$rowtotal += $itemcount;
                   9032:     } elsif ($position eq 'middle') {
1.57      raeburn  9033:         my $toggle_cats_crs = ' ';
                   9034:         my $toggle_cats_dom = ' checked="checked" ';
                   9035:         my $can_cat_crs = ' ';
                   9036:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  9037:         my $toggle_catscomm_comm = ' ';
                   9038:         my $toggle_catscomm_dom = ' checked="checked" ';
                   9039:         my $can_catcomm_comm = ' ';
                   9040:         my $can_catcomm_dom = ' checked="checked" ';
                   9041: 
1.57      raeburn  9042:         if (ref($settings) eq 'HASH') {
                   9043:             if ($settings->{'togglecats'} eq 'crs') {
                   9044:                 $toggle_cats_crs = $toggle_cats_dom;
                   9045:                 $toggle_cats_dom = ' ';
                   9046:             }
                   9047:             if ($settings->{'categorize'} eq 'crs') {
                   9048:                 $can_cat_crs = $can_cat_dom;
                   9049:                 $can_cat_dom = ' ';
                   9050:             }
1.120     raeburn  9051:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   9052:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   9053:                 $toggle_catscomm_dom = ' ';
                   9054:             }
                   9055:             if ($settings->{'categorizecomm'} eq 'comm') {
                   9056:                 $can_catcomm_comm = $can_catcomm_dom;
                   9057:                 $can_catcomm_dom = ' ';
                   9058:             }
1.57      raeburn  9059:         }
                   9060:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  9061:                      togglecats     => 'Show/Hide a course in catalog',
                   9062:                      togglecatscomm => 'Show/Hide a community in catalog',
                   9063:                      categorize     => 'Assign a category to a course',
                   9064:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  9065:                     );
                   9066:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  9067:                      dom  => 'Set in Domain',
                   9068:                      crs  => 'Set in Course',
                   9069:                      comm => 'Set in Community',
1.57      raeburn  9070:                     );
                   9071:         $datatable = '<tr class="LC_odd_row">'.
                   9072:                   '<td>'.$title{'togglecats'}.'</td>'.
                   9073:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   9074:                   '<input type="radio" name="togglecats"'.
                   9075:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9076:                   '<label><input type="radio" name="togglecats"'.
                   9077:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   9078:                   '</tr><tr>'.
                   9079:                   '<td>'.$title{'categorize'}.'</td>'.
                   9080:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   9081:                   '<label><input type="radio" name="categorize"'.
                   9082:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9083:                   '<label><input type="radio" name="categorize"'.
                   9084:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  9085:                   '</tr><tr class="LC_odd_row">'.
                   9086:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   9087:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   9088:                   '<input type="radio" name="togglecatscomm"'.
                   9089:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9090:                   '<label><input type="radio" name="togglecatscomm"'.
                   9091:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   9092:                   '</tr><tr>'.
                   9093:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   9094:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   9095:                   '<label><input type="radio" name="categorizecomm"'.
                   9096:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   9097:                   '<label><input type="radio" name="categorizecomm"'.
                   9098:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  9099:                   '</tr>';
1.120     raeburn  9100:         $$rowtotal += 4;
1.57      raeburn  9101:     } else {
                   9102:         my $css_class;
                   9103:         my $itemcount = 1;
                   9104:         my $cathash; 
                   9105:         if (ref($settings) eq 'HASH') {
                   9106:             $cathash = $settings->{'cats'};
                   9107:         }
                   9108:         if (ref($cathash) eq 'HASH') {
                   9109:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   9110:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   9111:                                                    \%allitems,\%idx,\@jsarray);
                   9112:             my $maxdepth = scalar(@cats);
                   9113:             my $colattrib = '';
                   9114:             if ($maxdepth > 2) {
                   9115:                 $colattrib = ' colspan="2" ';
                   9116:             }
                   9117:             my @path;
                   9118:             if (@cats > 0) {
                   9119:                 if (ref($cats[0]) eq 'ARRAY') {
                   9120:                     my $numtop = @{$cats[0]};
                   9121:                     my $maxnum = $numtop;
1.120     raeburn  9122:                     my %default_names = (
                   9123:                           instcode    => &mt('Official courses'),
                   9124:                           communities => &mt('Communities'),
                   9125:                     );
                   9126: 
                   9127:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   9128:                         ($cathash->{'instcode::0'} eq '') ||
                   9129:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   9130:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  9131:                         $maxnum ++;
                   9132:                     }
                   9133:                     my $lastidx;
                   9134:                     for (my $i=0; $i<$numtop; $i++) {
                   9135:                         my $parent = $cats[0][$i];
                   9136:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9137:                         my $item = &escape($parent).'::0';
                   9138:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   9139:                         $lastidx = $idx{$item};
                   9140:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   9141:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   9142:                         for (my $k=0; $k<=$maxnum; $k++) {
                   9143:                             my $vpos = $k+1;
                   9144:                             my $selstr;
                   9145:                             if ($k == $i) {
                   9146:                                 $selstr = ' selected="selected" ';
                   9147:                             }
                   9148:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9149:                         }
1.160.6.29  raeburn  9150:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  9151:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   9152:                             $datatable .=  '<span class="LC_nobreak">'
                   9153:                                            .$default_names{$parent}.'</span>';
                   9154:                             if ($parent eq 'instcode') {
                   9155:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   9156:                                               .&mt('with institutional codes')
                   9157:                                               .')</span></td><td'.$colattrib.'>';
                   9158:                             } else {
                   9159:                                 $datatable .= '<table><tr><td>';
                   9160:                             }
                   9161:                             $datatable .= '<span class="LC_nobreak">'
                   9162:                                           .'<label><input type="radio" name="'
                   9163:                                           .$parent.'" value="1" checked="checked" />'
                   9164:                                           .&mt('Display').'</label>';
                   9165:                             if ($parent eq 'instcode') {
                   9166:                                 $datatable .= '&nbsp;';
                   9167:                             } else {
                   9168:                                 $datatable .= '</span></td></tr><tr><td>'
                   9169:                                               .'<span class="LC_nobreak">';
                   9170:                             }
                   9171:                             $datatable .= '<label><input type="radio" name="'
                   9172:                                           .$parent.'" value="0" />'
                   9173:                                           .&mt('Do not display').'</label></span>';
                   9174:                             if ($parent eq 'communities') {
                   9175:                                 $datatable .= '</td></tr></table>';
                   9176:                             }
                   9177:                             $datatable .= '</td>';
1.57      raeburn  9178:                         } else {
                   9179:                             $datatable .= $parent
1.160.6.29  raeburn  9180:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   9181:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  9182:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   9183:                         }
                   9184:                         my $depth = 1;
                   9185:                         push(@path,$parent);
                   9186:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   9187:                         pop(@path);
                   9188:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9189:                         $itemcount ++;
                   9190:                     }
1.48      raeburn  9191:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  9192:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   9193:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  9194:                     for (my $k=0; $k<=$maxnum; $k++) {
                   9195:                         my $vpos = $k+1;
                   9196:                         my $selstr;
1.57      raeburn  9197:                         if ($k == $numtop) {
1.48      raeburn  9198:                             $selstr = ' selected="selected" ';
                   9199:                         }
                   9200:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   9201:                     }
1.59      bisitz   9202:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  9203:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   9204:                                   .'</tr>'."\n";
1.48      raeburn  9205:                     $itemcount ++;
1.120     raeburn  9206:                     foreach my $default ('instcode','communities') {
                   9207:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   9208:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9209:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   9210:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   9211:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   9212:                             for (my $k=0; $k<=$maxnum; $k++) {
                   9213:                                 my $vpos = $k+1;
                   9214:                                 my $selstr;
                   9215:                                 if ($k == $maxnum) {
                   9216:                                     $selstr = ' selected="selected" ';
                   9217:                                 }
                   9218:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  9219:                             }
1.120     raeburn  9220:                             $datatable .= '</select></span></td>'.
                   9221:                                           '<td><span class="LC_nobreak">'.
                   9222:                                           $default_names{$default}.'</span>';
                   9223:                             if ($default eq 'instcode') {
                   9224:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   9225:                                               .&mt('with institutional codes').')</span>';
                   9226:                             }
                   9227:                             $datatable .= '</td>'
                   9228:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   9229:                                           .&mt('Display').'</label>&nbsp;'
                   9230:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   9231:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  9232:                         }
                   9233:                     }
                   9234:                 }
1.57      raeburn  9235:             } else {
                   9236:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  9237:             }
                   9238:         } else {
1.160.6.87  raeburn  9239:             $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57      raeburn  9240:                           .&initialize_categories($itemcount);
1.48      raeburn  9241:         }
1.57      raeburn  9242:         $$rowtotal += $itemcount;
1.48      raeburn  9243:     }
                   9244:     return $datatable;
                   9245: }
                   9246: 
1.69      raeburn  9247: sub print_serverstatuses {
                   9248:     my ($dom,$settings,$rowtotal) = @_;
                   9249:     my $datatable;
                   9250:     my @pages = &serverstatus_pages();
                   9251:     my (%namedaccess,%machineaccess);
                   9252:     foreach my $type (@pages) {
                   9253:         $namedaccess{$type} = '';
                   9254:         $machineaccess{$type}= '';
                   9255:     }
                   9256:     if (ref($settings) eq 'HASH') {
                   9257:         foreach my $type (@pages) {
                   9258:             if (exists($settings->{$type})) {
                   9259:                 if (ref($settings->{$type}) eq 'HASH') {
                   9260:                     foreach my $key (keys(%{$settings->{$type}})) {
                   9261:                         if ($key eq 'namedusers') {
                   9262:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   9263:                         } elsif ($key eq 'machines') {
                   9264:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   9265:                         }
                   9266:                     }
                   9267:                 }
                   9268:             }
                   9269:         }
                   9270:     }
1.81      raeburn  9271:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  9272:     my $rownum = 0;
                   9273:     my $css_class;
                   9274:     foreach my $type (@pages) {
                   9275:         $rownum ++;
                   9276:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   9277:         $datatable .= '<tr'.$css_class.'>'.
                   9278:                       '<td><span class="LC_nobreak">'.
                   9279:                       $titles->{$type}.'</span></td>'.
                   9280:                       '<td class="LC_left_item">'.
                   9281:                       '<input type="text" name="'.$type.'_namedusers" '.
                   9282:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   9283:                       '<td class="LC_right_item">'.
                   9284:                       '<span class="LC_nobreak">'.
                   9285:                       '<input type="text" name="'.$type.'_machines" '.
                   9286:                       'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87  raeburn  9287:                       '</span></td></tr>'."\n";
1.69      raeburn  9288:     }
                   9289:     $$rowtotal += $rownum;
                   9290:     return $datatable;
                   9291: }
                   9292: 
                   9293: sub serverstatus_pages {
                   9294:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15  raeburn  9295:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31  raeburn  9296:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62  raeburn  9297:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  9298: }
                   9299: 
1.160.6.40  raeburn  9300: sub defaults_javascript {
                   9301:     my ($settings) = @_;
1.160.6.98  raeburn  9302:     return unless (ref($settings) eq 'HASH');
1.160.6.40  raeburn  9303:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   9304:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   9305:         if ($maxnum eq '') {
                   9306:             $maxnum = 0;
                   9307:         }
                   9308:         $maxnum ++;
1.160.6.51  raeburn  9309:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.160.6.40  raeburn  9310:         return <<"ENDSCRIPT";
                   9311: <script type="text/javascript">
                   9312: // <![CDATA[
                   9313: function reorderTypes(form,caller) {
                   9314:     var changedVal;
                   9315: $jstext 
                   9316:     var newpos = 'addinststatus_pos';
                   9317:     var current = new Array;
                   9318:     var maxh = $maxnum;
                   9319:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9320:     var oldVal;
                   9321:     if (caller == newpos) {
                   9322:         changedVal = newitemVal;
                   9323:     } else {
                   9324:         var curritem = 'inststatus_pos_'+caller;
                   9325:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   9326:         current[newitemVal] = newpos;
                   9327:     }
                   9328:     for (var i=0; i<inststatuses.length; i++) {
                   9329:         if (inststatuses[i] != caller) {
                   9330:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   9331:             if (form.elements[elementName]) {
                   9332:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9333:                 current[currVal] = elementName;
                   9334:             }
                   9335:         }
                   9336:     }
                   9337:     for (var j=0; j<maxh; j++) {
                   9338:         if (current[j] == undefined) {
                   9339:             oldVal = j;
                   9340:         }
                   9341:     }
                   9342:     if (oldVal < changedVal) {
                   9343:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9344:            var elementName = current[k];
                   9345:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9346:         }
                   9347:     } else {
                   9348:         for (var k=changedVal; k<oldVal; k++) {
                   9349:             var elementName = current[k];
                   9350:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9351:         }
                   9352:     }
                   9353:     return;
                   9354: }
                   9355: 
                   9356: // ]]>
                   9357: </script>
                   9358: 
                   9359: ENDSCRIPT
                   9360:     }
                   9361: }
                   9362: 
1.160.6.98  raeburn  9363: sub passwords_javascript {
1.160.6.118.2  5(raebur 9364:2):     my ($prefix) = @_;
                   9365:2):     my %intalert;
                   9366:2):     if ($prefix eq 'passwords') {
                   9367:2):         %intalert = &Apache::lonlocal::texthash (
                   9368:2):             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.',
                   9369:2):             authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
                   9370:2):             passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
                   9371:2):             passmax => 'Warning: maximum password length must be a positive integer (or blank).',
                   9372:2):             passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
                   9373:2):         );
                   9374:2):     } elsif ($prefix eq 'secrets') {
                   9375:2):         %intalert = &Apache::lonlocal::texthash (
                   9376:2):             passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
                   9377:2):             passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
                   9378:2):         );
                   9379:2):     }
1.160.6.99  raeburn  9380:     &js_escape(\%intalert);
                   9381:     my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2  5(raebur 9382:2):     my $intauthjs;
                   9383:2):     if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98  raeburn  9384: 
                   9385: function warnIntAuth(field) {
                   9386:     if (field.name == 'intauth_check') {
                   9387:         if (field.value == '2') {
1.160.6.99  raeburn  9388:             alert('$intalert{authcheck}');
1.160.6.98  raeburn  9389:         }
                   9390:     }
                   9391:     if (field.name == 'intauth_cost') {
                   9392:         field.value.replace(/\s/g,'');
                   9393:         if (field.value != '') {
                   9394:             var regexdigit=/^\\d+\$/;
                   9395:             if (!regexdigit.test(field.value)) {
1.160.6.99  raeburn  9396:                 alert('$intalert{authcost}');
                   9397:             }
                   9398:         }
                   9399:     }
                   9400:     return;
                   9401: }
                   9402: 
1.160.6.118.2  5(raebur 9403:2): ENDSCRIPT
                   9404:2): 
                   9405:2):      }
                   9406:2): 
                   9407:2):      $intauthjs .= <<"ENDSCRIPT";
                   9408:2): 
                   9409:2): function warnInt$prefix(field) {
1.160.6.99  raeburn  9410:     field.value.replace(/^\s+/,'');
                   9411:     field.value.replace(/\s+\$/,'');
                   9412:     var regexdigit=/^\\d+\$/;
1.160.6.118.2  5(raebur 9413:2):     if (field.name == '${prefix}_min') {
1.160.6.99  raeburn  9414:         if (field.value == '') {
                   9415:             alert('$intalert{passmin}');
                   9416:             field.value = '$defmin';
                   9417:         } else {
                   9418:             if (!regexdigit.test(field.value)) {
                   9419:                 alert('$intalert{passmin}');
                   9420:                 field.value = '$defmin';
                   9421:             }
                   9422:             var minval = parseInt(field.value,10);
                   9423:             if (minval < $defmin) {
                   9424:                 alert('$intalert{passmin}');
                   9425:                 field.value = '$defmin';
                   9426:             }
                   9427:         }
                   9428:     } else {
                   9429:         if (field.value == '0') {
                   9430:             field.value = '';
                   9431:         }
                   9432:         if (field.value != '') {
1.160.6.118.2  5(raebur 9433:2):             if (!regexdigit.test(field.value)) {
                   9434:2):                 if (field.name == '${prefix}_max') {
                   9435:2):                     alert('$intalert{passmax}');
1.160.6.99  raeburn  9436:                 } else {
1.160.6.118.2  5(raebur 9437:2):                     if (field.name == '${prefix}_numsaved') {
                   9438:2):                         alert('$intalert{passnum}');
1.160.6.99  raeburn  9439:                     }
                   9440:                 }
1.160.6.118.2  5(raebur 9441:2):                 field.value = '';
1.160.6.98  raeburn  9442:             }
                   9443:         }
                   9444:     }
                   9445:     return;
                   9446: }
                   9447: 
                   9448: ENDSCRIPT
                   9449:     return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   9450: }
                   9451: 
1.49      raeburn  9452: sub coursecategories_javascript {
                   9453:     my ($settings) = @_;
1.57      raeburn  9454:     my ($output,$jstext,$cathash);
1.49      raeburn  9455:     if (ref($settings) eq 'HASH') {
1.57      raeburn  9456:         $cathash = $settings->{'cats'};
                   9457:     }
                   9458:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  9459:         my (@cats,@jsarray,%idx);
1.57      raeburn  9460:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  9461:         if (@jsarray > 0) {
                   9462:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   9463:             for (my $i=0; $i<@jsarray; $i++) {
                   9464:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   9465:                     my $catstr = join('","',@{$jsarray[$i]});
                   9466:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   9467:                 }
                   9468:             }
                   9469:         }
                   9470:     } else {
                   9471:         $jstext  = '    var categories = Array(1);'."\n".
                   9472:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   9473:     }
1.160.6.42  raeburn  9474:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   9475:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66  raeburn  9476:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   9477:     &js_escape(\$instcode_reserved);
                   9478:     &js_escape(\$communities_reserved);
                   9479:     &js_escape(\$choose_again);
1.49      raeburn  9480:     $output = <<"ENDSCRIPT";
                   9481: <script type="text/javascript">
1.109     raeburn  9482: // <![CDATA[
1.49      raeburn  9483: function reorderCats(form,parent,item,idx) {
                   9484:     var changedVal;
                   9485: $jstext
                   9486:     var newpos = 'addcategory_pos';
                   9487:     if (parent == '') {
                   9488:         var has_instcode = 0;
                   9489:         var maxtop = categories[idx].length;
                   9490:         for (var j=0; j<maxtop; j++) {
                   9491:             if (categories[idx][j] == 'instcode::0') {
                   9492:                 has_instcode == 1;
                   9493:             }
                   9494:         }
                   9495:         if (has_instcode == 0) {
                   9496:             categories[idx][maxtop] = 'instcode_pos';
                   9497:         }
                   9498:     } else {
                   9499:         newpos += '_'+parent;
                   9500:     }
                   9501:     var maxh = 1 + categories[idx].length;
                   9502:     var current = new Array;
                   9503:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   9504:     if (item == newpos) {
                   9505:         changedVal = newitemVal;
                   9506:     } else {
                   9507:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   9508:         current[newitemVal] = newpos;
                   9509:     }
                   9510:     for (var i=0; i<categories[idx].length; i++) {
                   9511:         var elementName = categories[idx][i];
                   9512:         if (elementName != item) {
                   9513:             if (form.elements[elementName]) {
                   9514:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   9515:                 current[currVal] = elementName;
                   9516:             }
                   9517:         }
                   9518:     }
                   9519:     var oldVal;
                   9520:     for (var j=0; j<maxh; j++) {
                   9521:         if (current[j] == undefined) {
                   9522:             oldVal = j;
                   9523:         }
                   9524:     }
                   9525:     if (oldVal < changedVal) {
                   9526:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   9527:            var elementName = current[k];
                   9528:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   9529:         }
                   9530:     } else {
                   9531:         for (var k=changedVal; k<oldVal; k++) {
                   9532:             var elementName = current[k];
                   9533:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   9534:         }
                   9535:     }
                   9536:     return;
                   9537: }
1.120     raeburn  9538: 
                   9539: function categoryCheck(form) {
                   9540:     if (form.elements['addcategory_name'].value == 'instcode') {
                   9541:         alert('$instcode_reserved\\n$choose_again');
                   9542:         return false;
                   9543:     }
                   9544:     if (form.elements['addcategory_name'].value == 'communities') {
                   9545:         alert('$communities_reserved\\n$choose_again');
                   9546:         return false;
                   9547:     }
                   9548:     return true;
                   9549: }
                   9550: 
1.109     raeburn  9551: // ]]>
1.49      raeburn  9552: </script>
                   9553: 
                   9554: ENDSCRIPT
                   9555:     return $output;
                   9556: }
                   9557: 
1.48      raeburn  9558: sub initialize_categories {
                   9559:     my ($itemcount) = @_;
1.120     raeburn  9560:     my ($datatable,$css_class,$chgstr);
1.160.6.111  raeburn  9561:     my %default_names = &Apache::lonlocal::texthash (
1.120     raeburn  9562:                       instcode    => 'Official courses (with institutional codes)',
                   9563:                       communities => 'Communities',
                   9564:                         );
                   9565:     my $select0 = ' selected="selected"';
                   9566:     my $select1 = '';
                   9567:     foreach my $default ('instcode','communities') {
                   9568:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87  raeburn  9569:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120     raeburn  9570:         if ($default eq 'communities') {
                   9571:             $select1 = $select0;
                   9572:             $select0 = '';
                   9573:         }
                   9574:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   9575:                      .'<select name="'.$default.'_pos">'
                   9576:                      .'<option value="0"'.$select0.'>1</option>'
                   9577:                      .'<option value="1"'.$select1.'>2</option>'
                   9578:                      .'<option value="2">3</option></select>&nbsp;'
                   9579:                      .$default_names{$default}
                   9580:                      .'</span></td><td><span class="LC_nobreak">'
                   9581:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   9582:                      .&mt('Display').'</label>&nbsp;<label>'
                   9583:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  9584:                  .'</label></span></td></tr>';
1.120     raeburn  9585:         $itemcount ++;
                   9586:     }
1.48      raeburn  9587:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  9588:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  9589:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  9590:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   9591:                   .'<option value="0">1</option>'
                   9592:                   .'<option value="1">2</option>'
                   9593:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.160.6.103  raeburn  9594:                   .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87  raeburn  9595:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                   9596:                   .'</td></tr>';
1.48      raeburn  9597:     return $datatable;
                   9598: }
                   9599: 
                   9600: sub build_category_rows {
1.49      raeburn  9601:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   9602:     my ($text,$name,$item,$chgstr);
1.48      raeburn  9603:     if (ref($cats) eq 'ARRAY') {
                   9604:         my $maxdepth = scalar(@{$cats});
                   9605:         if (ref($cats->[$depth]) eq 'HASH') {
                   9606:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9607:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9608:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23  raeburn  9609:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  9610:                 my ($idxnum,$parent_name,$parent_item);
                   9611:                 my $higher = $depth - 1;
                   9612:                 if ($higher == 0) {
                   9613:                     $parent_name = &escape($parent).'::'.$higher;
                   9614:                 } else {
                   9615:                     if (ref($path) eq 'ARRAY') {
                   9616:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9617:                     }
                   9618:                 }
                   9619:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  9620:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  9621:                     if ($j < $numchildren) {
1.48      raeburn  9622:                         $name = $cats->[$depth]{$parent}[$j];
                   9623:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  9624:                         $idxnum = $idx->{$item};
                   9625:                     } else {
                   9626:                         $name = $parent_name;
                   9627:                         $item = $parent_item;
1.48      raeburn  9628:                     }
1.49      raeburn  9629:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   9630:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  9631:                     for (my $i=0; $i<=$numchildren; $i++) {
                   9632:                         my $vpos = $i+1;
                   9633:                         my $selstr;
                   9634:                         if ($j == $i) {
                   9635:                             $selstr = ' selected="selected" ';
                   9636:                         }
                   9637:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   9638:                     }
                   9639:                     $text .= '</select>&nbsp;';
                   9640:                     if ($j < $numchildren) {
                   9641:                         my $deeper = $depth+1;
                   9642:                         $text .= $name.'&nbsp;'
                   9643:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   9644:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   9645:                         if(ref($path) eq 'ARRAY') {
                   9646:                             push(@{$path},$name);
1.49      raeburn  9647:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  9648:                             pop(@{$path});
                   9649:                         }
                   9650:                     } else {
1.160.6.87  raeburn  9651:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
1.48      raeburn  9652:                         if ($j == $numchildren) {
                   9653:                             $text .= $name;
                   9654:                         } else {
                   9655:                             $text .= $item;
                   9656:                         }
                   9657:                         $text .= '" value="" />';
                   9658:                     }
                   9659:                     $text .= '</td></tr>';
                   9660:                 }
                   9661:                 $text .= '</table></td>';
                   9662:             } else {
                   9663:                 my $higher = $depth-1;
                   9664:                 if ($higher == 0) {
                   9665:                     $name = &escape($parent).'::'.$higher;
                   9666:                 } else {
                   9667:                     if (ref($path) eq 'ARRAY') {
                   9668:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   9669:                     }
                   9670:                 }
                   9671:                 my $colspan;
                   9672:                 if ($parent ne 'instcode') {
                   9673:                     $colspan = $maxdepth - $depth - 1;
1.160.6.87  raeburn  9674:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48      raeburn  9675:                 }
                   9676:             }
                   9677:         }
                   9678:     }
                   9679:     return $text;
                   9680: }
                   9681: 
1.33      raeburn  9682: sub modifiable_userdata_row {
1.160.6.93  raeburn  9683:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
                   9684:         $rowid,$customcss,$rowstyle) = @_;
1.160.6.35  raeburn  9685:     my ($role,$rolename,$statustype);
                   9686:     $role = $item;
1.160.6.34  raeburn  9687:     if ($context eq 'cancreate') {
1.160.6.93  raeburn  9688:         if ($item =~ /^(emailusername)_(.+)$/) {
                   9689:             $role = $1;
                   9690:             $statustype = $2;
1.160.6.35  raeburn  9691:             if (ref($usertypes) eq 'HASH') {
                   9692:                 if ($usertypes->{$statustype}) {
                   9693:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   9694:                 } else {
                   9695:                     $rolename = &mt('Data provided by user');
                   9696:                 }
                   9697:             }
1.160.6.34  raeburn  9698:         }
                   9699:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  9700:         if (ref($usertypes) eq 'HASH') {
                   9701:             $rolename = $usertypes->{$role};
                   9702:         } else {
                   9703:             $rolename = $role;
                   9704:         }
1.33      raeburn  9705:     } else {
1.63      raeburn  9706:         if ($role eq 'cr') {
                   9707:             $rolename = &mt('Custom role');
                   9708:         } else {
                   9709:             $rolename = &Apache::lonnet::plaintext($role);
                   9710:         }
1.33      raeburn  9711:     }
1.160.6.34  raeburn  9712:     my (@fields,%fieldtitles);
                   9713:     if (ref($fieldsref) eq 'ARRAY') {
                   9714:         @fields = @{$fieldsref};
                   9715:     } else {
                   9716:         @fields = ('lastname','firstname','middlename','generation',
                   9717:                    'permanentemail','id');
                   9718:     }
                   9719:     if ((ref($titlesref) eq 'HASH')) {
                   9720:         %fieldtitles = %{$titlesref};
                   9721:     } else {
                   9722:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9723:     }
1.33      raeburn  9724:     my $output;
1.160.6.93  raeburn  9725:     my $css_class;
                   9726:     if ($rowcount%2) {
                   9727:         $css_class = 'LC_odd_row';
                   9728:     }
                   9729:     if ($customcss) {
                   9730:         $css_class .= " $customcss";
                   9731:     }
                   9732:     $css_class =~ s/^\s+//;
                   9733:     if ($css_class) {
                   9734:         $css_class = ' class="'.$css_class.'"';
                   9735:     }
                   9736:     if ($rowstyle) {
                   9737:         $css_class .= ' style="'.$rowstyle.'"';
                   9738:     }
                   9739:     if ($rowid) {
                   9740:         $rowid = ' id="'.$rowid.'"';
                   9741:     }
                   9742: 
                   9743:     $output = '<tr '.$css_class.$rowid.'>'.
1.33      raeburn  9744:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   9745:               '<td class="LC_left_item" colspan="2"><table>';
                   9746:     my $rem;
                   9747:     my %checks;
                   9748:     if (ref($settings) eq 'HASH') {
                   9749:         if (ref($settings->{$context}) eq 'HASH') {
                   9750:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35  raeburn  9751:                 my $hashref = $settings->{$context}->{$role};
                   9752:                 if ($role eq 'emailusername') {
                   9753:                     if ($statustype) {
                   9754:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   9755:                             $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39  raeburn  9756:                             if (ref($hashref) eq 'HASH') { 
1.160.6.35  raeburn  9757:                                 foreach my $field (@fields) {
                   9758:                                     if ($hashref->{$field}) {
                   9759:                                         $checks{$field} = $hashref->{$field};
                   9760:                                     }
                   9761:                                 }
                   9762:                             }
                   9763:                         }
                   9764:                     }
                   9765:                 } else {
                   9766:                     if (ref($hashref) eq 'HASH') {
                   9767:                         foreach my $field (@fields) {
                   9768:                             if ($hashref->{$field}) {
                   9769:                                 $checks{$field} = ' checked="checked" ';
                   9770:                             }
                   9771:                         }
1.33      raeburn  9772:                     }
                   9773:                 }
                   9774:             }
                   9775:         }
                   9776:     }
1.160.6.93  raeburn  9777: 
                   9778:     my $total = scalar(@fields);
                   9779:     for (my $i=0; $i<$total; $i++) {
                   9780:         $rem = $i%($numinrow);
1.33      raeburn  9781:         if ($rem == 0) {
                   9782:             if ($i > 0) {
                   9783:                 $output .= '</tr>';
                   9784:             }
                   9785:             $output .= '<tr>';
                   9786:         }
                   9787:         my $check = ' ';
1.160.6.35  raeburn  9788:         unless ($role eq 'emailusername') {
                   9789:             if (exists($checks{$fields[$i]})) {
1.160.6.98  raeburn  9790:                 $check = $checks{$fields[$i]};
1.160.6.35  raeburn  9791:             } else {
                   9792:                 if ($role eq 'st') {
                   9793:                     if (ref($settings) ne 'HASH') {
1.160.6.39  raeburn  9794:                         $check = ' checked="checked" '; 
1.160.6.35  raeburn  9795:                     }
1.33      raeburn  9796:                 }
                   9797:             }
                   9798:         }
                   9799:         $output .= '<td class="LC_left_item">'.
1.160.6.35  raeburn  9800:                    '<span class="LC_nobreak">';
                   9801:         if ($role eq 'emailusername') {
                   9802:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   9803:                 $checks{$fields[$i]} = 'omit';
                   9804:             }
                   9805:             foreach my $option ('required','optional','omit') {
                   9806:                 my $checked='';
                   9807:                 if ($checks{$fields[$i]} eq $option) {
                   9808:                     $checked='checked="checked" ';
                   9809:                 }
                   9810:                 $output .= '<label>'.
                   9811:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   9812:                            &mt($option).'</label>'.('&nbsp;' x2);
                   9813:             }
                   9814:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   9815:         } else {
                   9816:             $output .= '<label>'.
                   9817:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   9818:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   9819:                        '</label>';
                   9820:         }
                   9821:         $output .= '</span></td>';
1.33      raeburn  9822:     }
1.160.6.93  raeburn  9823:     $rem = $total%$numinrow;
                   9824:     my $colsleft;
                   9825:     if ($rem) {
                   9826:         $colsleft = $numinrow - $rem;
                   9827:     }
                   9828:     if ($colsleft > 1) {
1.33      raeburn  9829:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   9830:                    '&nbsp;</td>';
                   9831:     } elsif ($colsleft == 1) {
                   9832:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   9833:     }
                   9834:     $output .= '</tr></table></td></tr>';
                   9835:     return $output;
                   9836: }
1.28      raeburn  9837: 
1.93      raeburn  9838: sub insttypes_row {
1.160.6.93  raeburn  9839:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
                   9840:         $customcss,$rowstyle) = @_;
1.93      raeburn  9841:     my %lt = &Apache::lonlocal::texthash (
                   9842:                       cansearch => 'Users allowed to search',
                   9843:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  9844:                       lockablenames => 'User preference to lock name',
1.160.6.93  raeburn  9845:                       selfassign    => 'Self-reportable affiliations',
1.160.6.101  raeburn  9846:                       overrides     => "Override domain's helpdesk settings based on requester's affiliation",
1.93      raeburn  9847:              );
                   9848:     my $showdom;
                   9849:     if ($context eq 'cansearch') {
                   9850:         $showdom = ' ('.$dom.')';
                   9851:     }
1.160.6.5  raeburn  9852:     my $class = 'LC_left_item';
                   9853:     if ($context eq 'statustocreate') {
                   9854:         $class = 'LC_right_item';
                   9855:     }
1.160.6.93  raeburn  9856:     my $css_class;
                   9857:     if ($$rowtotal%2) {
                   9858:         $css_class = 'LC_odd_row';
                   9859:     }
                   9860:     if ($customcss) {
                   9861:         $css_class .= ' '.$customcss;
                   9862:     }
                   9863:     $css_class =~ s/^\s+//;
                   9864:     if ($css_class) {
                   9865:         $css_class = ' class="'.$css_class.'"';
                   9866:     }
                   9867:     if ($rowstyle) {
                   9868:         $css_class .= ' style="'.$rowstyle.'"';
                   9869:     }
                   9870:     if ($onclick) {
                   9871:         $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34  raeburn  9872:     }
                   9873:     my $output = '<tr'.$css_class.'>'.
                   9874:                  '<td>'.$lt{$context}.$showdom.
                   9875:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  9876:     my $rem;
                   9877:     if (ref($types) eq 'ARRAY') {
                   9878:         for (my $i=0; $i<@{$types}; $i++) {
                   9879:             if (defined($usertypes->{$types->[$i]})) {
                   9880:                 my $rem = $i%($numinrow);
                   9881:                 if ($rem == 0) {
                   9882:                     if ($i > 0) {
                   9883:                         $output .= '</tr>';
                   9884:                     }
                   9885:                     $output .= '<tr>';
1.23      raeburn  9886:                 }
1.26      raeburn  9887:                 my $check = ' ';
1.99      raeburn  9888:                 if (ref($settings) eq 'HASH') {
                   9889:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   9890:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   9891:                             $check = ' checked="checked" ';
                   9892:                         }
1.160.6.101  raeburn  9893:                     } elsif (ref($settings->{$context}) eq 'HASH') {
                   9894:                         if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
                   9895:                             $check = ' checked="checked" ';
                   9896:                         }
1.99      raeburn  9897:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  9898:                         $check = ' checked="checked" ';
                   9899:                     }
1.23      raeburn  9900:                 }
1.26      raeburn  9901:                 $output .= '<td class="LC_left_item">'.
                   9902:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  9903:                            '<input type="checkbox" name="'.$context.'" '.
1.160.6.93  raeburn  9904:                            'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26      raeburn  9905:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  9906:             }
                   9907:         }
1.26      raeburn  9908:         $rem = @{$types}%($numinrow);
1.23      raeburn  9909:     }
                   9910:     my $colsleft = $numinrow - $rem;
1.160.6.101  raeburn  9911:     if ($context eq 'overrides') {
                   9912:         if ($colsleft > 1) {
                   9913:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9914:         } else {
                   9915:             $output .= '<td class="LC_left_item">';
                   9916:         }
                   9917:         $output .= '&nbsp;';
1.23      raeburn  9918:     } else {
1.160.6.101  raeburn  9919:         if ($rem == 0) {
                   9920:             $output .= '<tr>';
                   9921:         }
                   9922:         if ($colsleft > 1) {
                   9923:             $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
                   9924:         } else {
                   9925:             $output .= '<td class="LC_left_item">';
                   9926:         }
                   9927:         my $defcheck = ' ';
                   9928:         if (ref($settings) eq 'HASH') {  
                   9929:             if (ref($settings->{$context}) eq 'ARRAY') {
                   9930:                 if (grep(/^default$/,@{$settings->{$context}})) {
                   9931:                     $defcheck = ' checked="checked" ';
                   9932:                 }
                   9933:             } elsif ($context eq 'statustocreate') {
1.99      raeburn  9934:                 $defcheck = ' checked="checked" ';
                   9935:             }
1.26      raeburn  9936:         }
1.160.6.101  raeburn  9937:         $output .= '<span class="LC_nobreak"><label>'.
                   9938:                    '<input type="checkbox" name="'.$context.'" '.
                   9939:                    'value="default"'.$defcheck.$onclick.' />'.
                   9940:                    $othertitle.'</label></span>';
1.23      raeburn  9941:     }
1.160.6.101  raeburn  9942:     $output .= '</td></tr></table></td></tr>';
1.25      raeburn  9943:     return $output;
1.23      raeburn  9944: }
                   9945: 
                   9946: sub sorted_searchtitles {
                   9947:     my %searchtitles = &Apache::lonlocal::texthash(
                   9948:                          'uname' => 'username',
                   9949:                          'lastname' => 'last name',
                   9950:                          'lastfirst' => 'last name, first name',
                   9951:                      );
                   9952:     my @titleorder = ('uname','lastname','lastfirst');
                   9953:     return (\%searchtitles,\@titleorder);
                   9954: }
                   9955: 
1.25      raeburn  9956: sub sorted_searchtypes {
                   9957:     my %srchtypes_desc = (
                   9958:                            exact    => 'is exact match',
                   9959:                            contains => 'contains ..',
                   9960:                            begins   => 'begins with ..',
                   9961:                          );
                   9962:     my @srchtypeorder = ('exact','begins','contains');
                   9963:     return (\%srchtypes_desc,\@srchtypeorder);
                   9964: }
                   9965: 
1.3       raeburn  9966: sub usertype_update_row {
                   9967:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   9968:     my $datatable;
                   9969:     my $numinrow = 4;
                   9970:     foreach my $type (@{$types}) {
                   9971:         if (defined($usertypes->{$type})) {
                   9972:             $$rownums ++;
                   9973:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   9974:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   9975:                           '</td><td class="LC_left_item"><table>';
                   9976:             for (my $i=0; $i<@{$fields}; $i++) {
                   9977:                 my $rem = $i%($numinrow);
                   9978:                 if ($rem == 0) {
                   9979:                     if ($i > 0) {
                   9980:                         $datatable .= '</tr>';
                   9981:                     }
                   9982:                     $datatable .= '<tr>';
                   9983:                 }
                   9984:                 my $check = ' ';
1.39      raeburn  9985:                 if (ref($settings) eq 'HASH') {
                   9986:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   9987:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   9988:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   9989:                                 $check = ' checked="checked" ';
                   9990:                             }
1.3       raeburn  9991:                         }
                   9992:                     }
                   9993:                 }
                   9994: 
                   9995:                 if ($i == @{$fields}-1) {
                   9996:                     my $colsleft = $numinrow - $rem;
                   9997:                     if ($colsleft > 1) {
                   9998:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   9999:                     } else {
                   10000:                         $datatable .= '<td>';
                   10001:                     }
                   10002:                 } else {
                   10003:                     $datatable .= '<td>';
                   10004:                 }
1.8       raeburn  10005:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   10006:                               '<input type="checkbox" name="updateable_'.$type.
                   10007:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   10008:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  10009:             }
                   10010:             $datatable .= '</tr></table></td></tr>';
                   10011:         }
                   10012:     }
                   10013:     return $datatable;
1.1       raeburn  10014: }
                   10015: 
                   10016: sub modify_login {
1.160.6.24  raeburn  10017:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  10018:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113  raeburn  10019:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2  9(raebur 10020:2):         %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5  raeburn  10021:     %title = ( coursecatalog => 'Display course catalog',
                   10022:                adminmail => 'Display administrator E-mail address',
1.160.6.14  raeburn  10023:                helpdesk  => 'Display "Contact Helpdesk" link',
1.160.6.5  raeburn  10024:                newuser => 'Link for visitors to create a user account',
1.160.6.113  raeburn  10025:                loginheader => 'Log-in box header',
                   10026:                saml => 'Dual SSO and non-SSO login');
1.160.6.5  raeburn  10027:     @offon = ('off','on');
1.112     raeburn  10028:     if (ref($domconfig{login}) eq 'HASH') {
                   10029:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   10030:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   10031:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   10032:             }
                   10033:         }
1.160.6.113  raeburn  10034:         if (ref($domconfig{login}{'saml'}) eq 'HASH') {
                   10035:             foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
                   10036:                 if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
                   10037:                     $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
                   10038:                     $saml{$lonhost} = 1;
                   10039:                     $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
                   10040:                     $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
                   10041:                     $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
                   10042:                     $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
                   10043:                     $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2  9(raebur 10044:2):                     $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113  raeburn  10045:                     $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
                   10046:                 }
                   10047:             }
                   10048:         }
1.112     raeburn  10049:     }
1.9       raeburn  10050:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   10051:                                            \%domconfig,\%loginhash);
1.160.6.14  raeburn  10052:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  10053:     foreach my $item (@toggles) {
                   10054:         $loginhash{login}{$item} = $env{'form.'.$item};
                   10055:     }
1.41      raeburn  10056:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  10057:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   10058:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   10059:                                          \%loginhash);
                   10060:     }
1.110     raeburn  10061: 
1.149     raeburn  10062:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56  raeburn  10063:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  10064:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  10065:     if (keys(%servers) > 1) {
                   10066:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  10067:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   10068:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   10069:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   10070:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   10071:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   10072:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10073:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   10074:                         $changes{'loginvia'}{$lonhost} = 1;
                   10075:                     } else {
                   10076:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   10077:                         $changes{'loginvia'}{$lonhost} = 1;
                   10078:                     }
                   10079:                 } else {
                   10080:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10081:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   10082:                         $changes{'loginvia'}{$lonhost} = 1;
                   10083:                     }
                   10084:                 }
                   10085:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   10086:                     foreach my $item (@loginvia_attribs) {
                   10087:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   10088:                     }
                   10089:                 } else {
                   10090:                     foreach my $item (@loginvia_attribs) {
                   10091:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   10092:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   10093:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   10094:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   10095:                                 $new = '/';
                   10096:                             }
                   10097:                         }
                   10098:                         if (($item eq 'custompath') && 
                   10099:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   10100:                             $new = '';
                   10101:                         }
                   10102:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   10103:                             $changes{'loginvia'}{$lonhost} = 1;
                   10104:                         }
                   10105:                         if ($item eq 'exempt') {
1.160.6.56  raeburn  10106:                             $new = &check_exempt_addresses($new);
1.128     raeburn  10107:                         }
                   10108:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   10109:                     }
                   10110:                 }
1.112     raeburn  10111:             } else {
1.128     raeburn  10112:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   10113:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  10114:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  10115:                     foreach my $item (@loginvia_attribs) {
                   10116:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   10117:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   10118:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   10119:                                 $new = '/';
                   10120:                             }
                   10121:                         }
                   10122:                         if (($item eq 'custompath') && 
                   10123:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   10124:                             $new = '';
                   10125:                         }
                   10126:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   10127:                     }
1.110     raeburn  10128:                 }
                   10129:             }
                   10130:         }
                   10131:     }
1.119     raeburn  10132: 
1.160.6.5  raeburn  10133:     my $servadm = $r->dir_config('lonAdmEMail');
                   10134:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   10135:     if (ref($domconfig{'login'}) eq 'HASH') {
                   10136:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   10137:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   10138:                 if ($lang eq 'nolang') {
                   10139:                     push(@currlangs,$lang);
                   10140:                 } elsif (defined($langchoices{$lang})) {
                   10141:                     push(@currlangs,$lang);
                   10142:                 } else {
                   10143:                     next;
                   10144:                 }
                   10145:             }
                   10146:         }
                   10147:     }
                   10148:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   10149:     if (@currlangs > 0) {
                   10150:         foreach my $lang (@currlangs) {
                   10151:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   10152:                 $changes{'helpurl'}{$lang} = 1;
                   10153:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   10154:                 $changes{'helpurl'}{$lang} = 1;
                   10155:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   10156:                 push(@newlangs,$lang);
                   10157:             } else {
                   10158:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   10159:             }
                   10160:         }
                   10161:     }
                   10162:     unless (grep(/^nolang$/,@currlangs)) {
                   10163:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   10164:             $changes{'helpurl'}{'nolang'} = 1;
                   10165:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   10166:             push(@newlangs,'nolang');
                   10167:         }
                   10168:     }
                   10169:     if ($env{'form.loginhelpurl_add_lang'}) {
                   10170:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   10171:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   10172:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   10173:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   10174:         }
                   10175:     }
                   10176:     if ((@newlangs > 0) || ($addedfile)) {
                   10177:         my $error;
                   10178:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10179:         if ($configuserok eq 'ok') {
                   10180:             if ($switchserver) {
                   10181:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   10182:             } elsif ($author_ok eq 'ok') {
                   10183:                 my @allnew = @newlangs;
                   10184:                 if ($addedfile ne '') {
                   10185:                     push(@allnew,$addedfile);
                   10186:                 }
                   10187:                 foreach my $lang (@allnew) {
                   10188:                     my $formelem = 'loginhelpurl_'.$lang;
                   10189:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   10190:                         $formelem = 'loginhelpurl_add_file';
                   10191:                     }
                   10192:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10193:                                                                "help/$lang",'','',$newfile{$lang});
                   10194:                     if ($result eq 'ok') {
                   10195:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   10196:                         $changes{'helpurl'}{$lang} = 1;
                   10197:                     } else {
                   10198:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   10199:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   10200:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                   10201:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   10202:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   10203:                         }
                   10204:                     }
                   10205:                 }
                   10206:             } else {
                   10207:                 $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);
                   10208:             }
                   10209:         } else {
                   10210:             $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);
                   10211:         }
                   10212:         if ($error) {
                   10213:             &Apache::lonnet::logthis($error);
                   10214:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10215:         }
                   10216:     }
1.160.6.56  raeburn  10217: 
                   10218:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   10219:     if (ref($domconfig{'login'}) eq 'HASH') {
                   10220:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   10221:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   10222:                 if ($domservers{$lonhost}) {
                   10223:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10224:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73  raeburn  10225:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56  raeburn  10226:                     }
                   10227:                 }
                   10228:             }
                   10229:         }
                   10230:     }
                   10231:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   10232:     foreach my $lonhost (sort(keys(%domservers))) {
                   10233:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10234:             $changes{'headtag'}{$lonhost} = 1;
                   10235:         } else {
                   10236:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   10237:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   10238:             }
                   10239:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   10240:                 push(@newhosts,$lonhost);
                   10241:             } elsif ($currheadtagurls{$lonhost}) {
                   10242:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   10243:                 if ($currexempt{$lonhost}) {
                   10244:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
                   10245:                         $changes{'headtag'}{$lonhost} = 1;
                   10246:                     }
                   10247:                 } elsif ($possexempt{$lonhost}) {
                   10248:                     $changes{'headtag'}{$lonhost} = 1;
                   10249:                 }
                   10250:                 if ($possexempt{$lonhost}) {
                   10251:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10252:                 }
                   10253:             }
                   10254:         }
                   10255:     }
                   10256:     if (@newhosts) {
                   10257:         my $error;
                   10258:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10259:         if ($configuserok eq 'ok') {
                   10260:             if ($switchserver) {
                   10261:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   10262:             } elsif ($author_ok eq 'ok') {
                   10263:                 foreach my $lonhost (@newhosts) {
                   10264:                     my $formelem = 'loginheadtag_'.$lonhost;
                   10265:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10266:                                                                           "login/headtag/$lonhost",'','',
                   10267:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   10268:                     if ($result eq 'ok') {
1.160.6.113  raeburn  10269:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   10270:                         $changes{'headtag'}{$lonhost} = 1;
                   10271:                         if ($possexempt{$lonhost}) {
                   10272:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   10273:                         }
                   10274:                     } else {
                   10275:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   10276:                                            $newheadtagurls{$lonhost},$result);
                   10277:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   10278:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   10279:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   10280:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   10281:                         }
                   10282:                     }
                   10283:                 }
                   10284:             } else {
                   10285:                 $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);
                   10286:             }
                   10287:         } else {
                   10288:             $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);
                   10289:         }
                   10290:         if ($error) {
                   10291:             &Apache::lonnet::logthis($error);
                   10292:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10293:         }
                   10294:     }
                   10295:     my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
                   10296:     my @newsamlimgs;
                   10297:     foreach my $lonhost (keys(%domservers)) {
                   10298:         if ($env{'form.saml_'.$lonhost}) {
                   10299:             if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
                   10300:                 push(@newsamlimgs,$lonhost);
                   10301:             }
1.160.6.118.2  9(raebur 10302:2):             foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113  raeburn  10303:                 $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
                   10304:             }
                   10305:             if ($saml{$lonhost}) {
1.160.6.118.2  9(raebur 10306:2):                 if ($env{'form.saml_window_'.$lonhost} ne '1') {
                   10307:2):                     $env{'form.saml_window_'.$lonhost} = '';
                   10308:2):                 }
1.160.6.113  raeburn  10309:                 if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
                   10310: #FIXME Need to obsolete published image
                   10311:                     delete($currsaml{$lonhost}{'img'});
                   10312:                     $changes{'saml'}{$lonhost} = 1;
                   10313:                 }
                   10314:                 if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
                   10315:                     $changes{'saml'}{$lonhost} = 1;
                   10316:                 }
                   10317:                 if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
                   10318:                     $changes{'saml'}{$lonhost} = 1;
                   10319:                 }
                   10320:                 if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
                   10321:                     $changes{'saml'}{$lonhost} = 1;
                   10322:                 }
                   10323:                 if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
                   10324:                     $changes{'saml'}{$lonhost} = 1;
                   10325:                 }
1.160.6.118.2  9(raebur 10326:2):                 if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
                   10327:2):                     $changes{'saml'}{$lonhost} = 1;
                   10328:2):                 }
1.160.6.113  raeburn  10329:                 if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
                   10330:                     $changes{'saml'}{$lonhost} = 1;
                   10331:                 }
                   10332:             } else {
                   10333:                 $changes{'saml'}{$lonhost} = 1;
                   10334:             }
1.160.6.118.2  9(raebur 10335:2):             foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113  raeburn  10336:                 $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
                   10337:             }
                   10338:         } else {
                   10339:             if ($saml{$lonhost}) {
                   10340:                 $changes{'saml'}{$lonhost} = 1;
                   10341:                 delete($currsaml{$lonhost});
                   10342:             }
                   10343:         }
                   10344:     }
                   10345:     foreach my $posshost (keys(%currsaml)) {
                   10346:         unless (exists($domservers{$posshost})) {
                   10347:             delete($currsaml{$posshost});
                   10348:         }
                   10349:     }
                   10350:     %{$loginhash{'login'}{'saml'}} = %currsaml;
                   10351:     if (@newsamlimgs) {
                   10352:         my $error;
                   10353:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   10354:         if ($configuserok eq 'ok') {
                   10355:             if ($switchserver) {
                   10356:                 $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
                   10357:             } elsif ($author_ok eq 'ok') {
                   10358:                 foreach my $lonhost (@newsamlimgs) {
                   10359:                     my $formelem = 'saml_img_'.$lonhost;
                   10360:                     my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   10361:                                                         "login/saml/$lonhost",'','',
                   10362:                                                         $env{'form.saml_img_'.$lonhost.'.filename'});
                   10363:                     if ($result eq 'ok') {
                   10364:                         $currsaml{$lonhost}{'img'} = $imgurl;
                   10365:                         $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
                   10366:                         $changes{'saml'}{$lonhost} = 1;
1.160.6.56  raeburn  10367:                     } else {
1.160.6.113  raeburn  10368:                         my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
                   10369:                                            $lonhost,$result);
1.160.6.56  raeburn  10370:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   10371:                     }
                   10372:                 }
                   10373:             } else {
1.160.6.113  raeburn  10374:                 $error = &mt("Upload of SSO button image file(s) failed because an author role could not be assigned to a Domain Configuration user ([_1]) in domain: [_2].  Error was: [_3].",$confname,$dom,$author_ok);
1.160.6.56  raeburn  10375:             }
                   10376:         } else {
1.160.6.113  raeburn  10377:             $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2].  Error was: [_3].",$confname,$dom,$configuserok);
1.160.6.56  raeburn  10378:         }
                   10379:         if ($error) {
                   10380:             &Apache::lonnet::logthis($error);
                   10381:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10382:         }
                   10383:     }
1.160.6.5  raeburn  10384:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
                   10385: 
                   10386:     my $defaulthelpfile = '/adm/loginproblems.html';
                   10387:     my $defaulttext = &mt('Default in use');
                   10388: 
1.1       raeburn  10389:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   10390:                                              $dom);
                   10391:     if ($putresult eq 'ok') {
1.160.6.14  raeburn  10392:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  10393:         my %defaultchecked = (
                   10394:                     'coursecatalog' => 'on',
1.160.6.14  raeburn  10395:                     'helpdesk'      => 'on',
1.42      raeburn  10396:                     'adminmail'     => 'off',
1.43      raeburn  10397:                     'newuser'       => 'off',
1.42      raeburn  10398:         );
1.55      raeburn  10399:         if (ref($domconfig{'login'}) eq 'HASH') {
                   10400:             foreach my $item (@toggles) {
                   10401:                 if ($defaultchecked{$item} eq 'on') { 
                   10402:                     if (($domconfig{'login'}{$item} eq '0') &&
                   10403:                         ($env{'form.'.$item} eq '1')) {
                   10404:                         $changes{$item} = 1;
                   10405:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10406:                               $domconfig{'login'}{$item} eq '1') &&
                   10407:                              ($env{'form.'.$item} eq '0')) {
                   10408:                         $changes{$item} = 1;
                   10409:                     }
                   10410:                 } elsif ($defaultchecked{$item} eq 'off') {
                   10411:                     if (($domconfig{'login'}{$item} eq '1') &&
                   10412:                         ($env{'form.'.$item} eq '0')) {
                   10413:                         $changes{$item} = 1;
                   10414:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   10415:                               $domconfig{'login'}{$item} eq '0') &&
                   10416:                              ($env{'form.'.$item} eq '1')) {
                   10417:                         $changes{$item} = 1;
                   10418:                     }
1.42      raeburn  10419:                 }
                   10420:             }
1.41      raeburn  10421:         }
1.6       raeburn  10422:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  10423:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113  raeburn  10424:             if (exists($changes{'saml'})) {
                   10425:                 my $hostid_in_use;
                   10426:                 my @hosts = &Apache::lonnet::current_machine_ids();
                   10427:                 if (@hosts > 1) {
                   10428:                     foreach my $hostid (@hosts) {
                   10429:                         if (&Apache::lonnet::host_domain($hostid) eq $dom) {
                   10430:                             $hostid_in_use = $hostid;
                   10431:                             last;
                   10432:                         }
                   10433:                     }
                   10434:                 } else {
                   10435:                     $hostid_in_use = $r->dir_config('lonHostID');
                   10436:                 }
                   10437:                 if (($hostid_in_use) &&
                   10438:                     (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
                   10439:                     &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
                   10440:                 }
                   10441:                 if (ref($lastactref) eq 'HASH') {
                   10442:                     if (ref($changes{'saml'}) eq 'HASH') {
                   10443:                         my %updates;
                   10444:                         map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
                   10445:                         $lastactref->{'samllanding'} = \%updates;
                   10446:                     }
                   10447:                 }
                   10448:             }
1.160.6.27  raeburn  10449:             if (ref($lastactref) eq 'HASH') {
                   10450:                 $lastactref->{'domainconfig'} = 1;
                   10451:             }
1.1       raeburn  10452:             $resulttext = &mt('Changes made:').'<ul>';
                   10453:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   10454:                 if ($item eq 'loginvia') {
1.112     raeburn  10455:                     if (ref($changes{$item}) eq 'HASH') {
                   10456:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   10457:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  10458:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   10459:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   10460:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   10461:                                     $protocol = 'http' if ($protocol ne 'https');
                   10462:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   10463: 
                   10464:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   10465:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   10466:                                     } else {
                   10467:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   10468:                                     }
                   10469:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   10470:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   10471:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   10472:                                     }
                   10473:                                     $resulttext .= '</li>';
                   10474:                                 } else {
                   10475:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   10476:                                 }
1.112     raeburn  10477:                             } else {
1.128     raeburn  10478:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  10479:                             }
                   10480:                         }
1.128     raeburn  10481:                         $resulttext .= '</ul></li>';
1.112     raeburn  10482:                     }
1.160.6.5  raeburn  10483:                 } elsif ($item eq 'helpurl') {
                   10484:                     if (ref($changes{$item}) eq 'HASH') {
                   10485:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   10486:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   10487:                                 my ($chg,$link);
                   10488:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   10489:                                 if ($lang eq 'nolang') {
                   10490:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   10491:                                 } else {
                   10492:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   10493:                                 }
                   10494:                                 $resulttext .= '<li>'.$chg.'</li>';
                   10495:                             } else {
                   10496:                                 my $chg;
                   10497:                                 if ($lang eq 'nolang') {
                   10498:                                     $chg = &mt('custom log-in help file for no preferred language');
                   10499:                                 } else {
                   10500:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   10501:                                 }
                   10502:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   10503:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   10504:                                                       '?inhibitmenu=yes',$chg,600,500).
                   10505:                                                '</li>';
                   10506:                             }
                   10507:                         }
                   10508:                     }
1.160.6.56  raeburn  10509:                 } elsif ($item eq 'headtag') {
                   10510:                     if (ref($changes{$item}) eq 'HASH') {
                   10511:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   10512:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   10513:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   10514:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   10515:                                 $resulttext .= '<li><a href="'.
                   10516:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   10517:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   10518:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   10519:                                 if ($possexempt{$lonhost}) {
                   10520:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   10521:                                 } else {
                   10522:                                     $resulttext .= &mt('included for any client IP');
                   10523:                                 }
                   10524:                                 $resulttext .= '</li>';
                   10525:                             }
                   10526:                         }
                   10527:                     }
1.160.6.113  raeburn  10528:                 } elsif ($item eq 'saml') {
                   10529:                     if (ref($changes{$item}) eq 'HASH') {
                   10530:                         my %notlt = (
                   10531:                                        text   => 'Text for log-in by SSO',
                   10532:                                        img    => 'SSO button image',
                   10533:                                        alt    => 'Alt text for button image',
                   10534:                                        url    => 'SSO URL',
                   10535:                                        title  => 'Tooltip for SSO link',
1.160.6.118.2  9(raebur 10536:2):                                        window => 'Pop-up window if iframe',
1.160.6.113  raeburn  10537:                                        notsso => 'Text for non-SSO log-in',
                   10538:                                     );
                   10539:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   10540:                             if (ref($currsaml{$lonhost}) eq 'HASH') {
                   10541:                                 $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
                   10542:                                                '<ul>';
1.160.6.118.2  9(raebur 10543:2):                                 foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113  raeburn  10544:                                     if ($currsaml{$lonhost}{$key} eq '') {
                   10545:                                         $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
                   10546:                                     } else {
                   10547:                                         my $value = "'$currsaml{$lonhost}{$key}'";
                   10548:                                         if ($key eq 'img') {
                   10549:                                             $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2  9(raebur 10550:2):                                         } elsif ($key eq 'window') {
                   10551:2):                                             $value = 'On';
1.160.6.113  raeburn  10552:                                         }
                   10553:                                         $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
                   10554:                                                                   $value).'</li>';
                   10555:                                     }
                   10556:                                 }
                   10557:                                 $resulttext .= '</ul></li>';
                   10558:                             } else {
                   10559:                                 $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
                   10560:                             }
                   10561:                         }
                   10562:                     }
1.160.6.5  raeburn  10563:                 } elsif ($item eq 'captcha') {
                   10564:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10565:                         my $chgtxt;
                   10566:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   10567:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   10568:                         } else {
                   10569:                             my %captchas = &captcha_phrases();
                   10570:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   10571:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   10572:                             } else {
                   10573:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   10574:                             }
                   10575:                         }
                   10576:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10577:                     }
                   10578:                 } elsif ($item eq 'recaptchakeys') {
                   10579:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10580:                         my ($privkey,$pubkey);
                   10581:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   10582:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   10583:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   10584:                         }
                   10585:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10586:                         if (!$pubkey) {
                   10587:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   10588:                         } else {
                   10589:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10590:                         }
                   10591:                         if (!$privkey) {
                   10592:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   10593:                         } else {
1.160.6.53  raeburn  10594:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5  raeburn  10595:                         }
                   10596:                         $chgtxt .= '</ul>';
                   10597:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   10598:                     }
1.160.6.69  raeburn  10599:                 } elsif ($item eq 'recaptchaversion') {
                   10600:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   10601:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
                   10602:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                   10603:                                            '</li>';
                   10604:                         }
                   10605:                     }
1.41      raeburn  10606:                 } else {
                   10607:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   10608:                 }
1.1       raeburn  10609:             }
1.6       raeburn  10610:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  10611:         } else {
                   10612:             $resulttext = &mt('No changes made to log-in page settings');
                   10613:         }
                   10614:     } else {
1.11      albertel 10615:         $resulttext = '<span class="LC_error">'.
                   10616: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10617:     }
1.6       raeburn  10618:     if ($errors) {
1.9       raeburn  10619:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  10620:                        $errors.'</ul>';
                   10621:     }
                   10622:     return $resulttext;
                   10623: }
                   10624: 
1.160.6.56  raeburn  10625: sub check_exempt_addresses {
                   10626:     my ($iplist) = @_;
                   10627:     $iplist =~ s/^\s+//;
                   10628:     $iplist =~ s/\s+$//;
                   10629:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   10630:     my (@okips,$new);
                   10631:     foreach my $ip (@poss_ips) {
                   10632:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   10633:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   10634:                 push(@okips,$ip);
                   10635:             }
                   10636:         }
                   10637:     }
                   10638:     if (@okips > 0) {
                   10639:         $new = join(',',@okips);
                   10640:     } else {
                   10641:         $new = '';
                   10642:     }
                   10643:     return $new;
                   10644: }
                   10645: 
1.6       raeburn  10646: sub color_font_choices {
                   10647:     my %choices =
                   10648:         &Apache::lonlocal::texthash (
                   10649:             img => "Header",
                   10650:             bgs => "Background colors",
                   10651:             links => "Link colors",
1.55      raeburn  10652:             images => "Images",
1.6       raeburn  10653:             font => "Font color",
1.160.6.22  raeburn  10654:             fontmenu => "Font menu",
1.76      raeburn  10655:             pgbg => "Page",
1.6       raeburn  10656:             tabbg => "Header",
                   10657:             sidebg => "Border",
                   10658:             link => "Link",
                   10659:             alink => "Active link",
                   10660:             vlink => "Visited link",
                   10661:         );
                   10662:     return %choices;
                   10663: }
                   10664: 
1.160.6.113  raeburn  10665: sub modify_ipaccess {
                   10666:     my ($dom,$lastactref,%domconfig) = @_;
                   10667:     my (@allpos,%changes,%confhash,$errors,$resulttext);
                   10668:     my (@items,%deletions,%itemids,@warnings);
                   10669:     my ($typeorder,$types) = &commblocktype_text();
                   10670:     if ($env{'form.ipaccess_add'}) {
                   10671:         my $name = $env{'form.ipaccess_name_add'};
                   10672:         my ($newid,$error) = &get_ipaccess_id($dom,$name);
                   10673:         if ($newid) {
                   10674:             $itemids{'add'} = $newid;
                   10675:             push(@items,'add');
                   10676:             $changes{$newid} = 1;
                   10677:         } else {
                   10678:             $error = &mt('Failed to acquire unique ID for new IP access control item');
                   10679:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10680:         }
                   10681:     }
                   10682:     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   10683:         my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
                   10684:         if (@todelete) {
                   10685:             map { $deletions{$_} = 1; } @todelete;
                   10686:         }
                   10687:         my $maxnum = $env{'form.ipaccess_maxnum'};
                   10688:         for (my $i=0; $i<$maxnum; $i++) {
                   10689:             my $itemid = $env{'form.ipaccess_id_'.$i};
                   10690:             $itemid =~ s/\D+//g;
                   10691:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   10692:                 if ($deletions{$itemid}) {
                   10693:                     $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
                   10694:                 } else {
                   10695:                     push(@items,$i);
                   10696:                     $itemids{$i} = $itemid;
                   10697:                 }
                   10698:             }
                   10699:         }
                   10700:     }
                   10701:     foreach my $idx (@items) {
                   10702:         my $itemid = $itemids{$idx};
                   10703:         next unless ($itemid);
                   10704:         my %current;
                   10705:         unless ($idx eq 'add') {
                   10706:             if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   10707:                 %current = %{$domconfig{'ipaccess'}{$itemid}};
                   10708:             }
                   10709:         }
                   10710:         my $position = $env{'form.ipaccess_pos_'.$itemid};
                   10711:         $position =~ s/\D+//g;
                   10712:         if ($position ne '') {
                   10713:             $allpos[$position] = $itemid;
                   10714:         }
                   10715:         my $name = $env{'form.ipaccess_name_'.$idx};
                   10716:         $name =~ s/^\s+|\s+$//g;
                   10717:         $confhash{$itemid}{'name'} = $name;
                   10718:         my $possrange = $env{'form.ipaccess_range_'.$idx};
                   10719:         $possrange =~ s/^\s+|\s+$//g;
                   10720:         unless ($possrange eq '') {
                   10721:             $possrange =~ s/[\r\n]+/\s/g;
                   10722:             $possrange =~ s/\s*-\s*/-/g;
                   10723:             $possrange =~ s/\s+/,/g;
                   10724:             $possrange =~ s/,+/,/g;
                   10725:             if ($possrange ne '') {
                   10726:                 my (@ok,$count);
                   10727:                 $count = 0;
                   10728:                 foreach my $poss (split(/\,/,$possrange)) {
                   10729:                     $count ++;
                   10730:                     $poss = &validate_ip_pattern($poss);
                   10731:                     if ($poss ne '') {
                   10732:                         push(@ok,$poss);
                   10733:                     }
                   10734:                 }
                   10735:                 my $diff = $count - scalar(@ok);
                   10736:                 if ($diff) {
                   10737:                     $errors .= '<li><span class="LC_error">'.
                   10738:                                &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
                   10739:                                    $diff,$name).
                   10740:                                '</span></li>';
                   10741:                 }
                   10742:                 if (@ok) {
                   10743:                     my @cidr_list;
                   10744:                     foreach my $item (@ok) {
                   10745:                         @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   10746:                     }
                   10747:                     $confhash{$itemid}{'ip'} = join(',',@cidr_list);
                   10748:                 }
                   10749:             }
                   10750:         }
                   10751:         foreach my $field ('name','ip') {
                   10752:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   10753:                 if ($current{$field} ne $confhash{$itemid}{$field}) {
                   10754:                     $changes{$itemid} = 1;
                   10755:                     last;
                   10756:                 }
                   10757:             }
                   10758:         }
                   10759:         $confhash{$itemid}{'commblocks'} = {};
                   10760: 
                   10761:         my %commblocks;
                   10762:         map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
                   10763:         foreach my $type (@{$typeorder}) {
                   10764:             if ($commblocks{$type}) {
                   10765:                 $confhash{$itemid}{'commblocks'}{$type} = 'on';
                   10766:             }
                   10767:             unless (($idx eq 'add') || ($changes{$itemid})) {
                   10768:                 if (ref($current{'commblocks'}) eq 'HASH') {
                   10769:                     if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
                   10770:                         $changes{$itemid} = 1;
                   10771:                     }
                   10772:                 } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
                   10773:                     $changes{$itemid} = 1;
                   10774:                 }
                   10775:             }
                   10776:         }
                   10777:         $confhash{$itemid}{'courses'} = {};
                   10778:         my %crsdeletions;
                   10779:         my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
                   10780:         if (@delcrs) {
                   10781:             map { $crsdeletions{$_} = 1; } @delcrs;
                   10782:         }
                   10783:         if (ref($current{'courses'}) eq 'HASH') {
                   10784:             foreach my $cid (sort(keys(%{$current{'courses'}}))) {
                   10785:                 if ($crsdeletions{$cid}) {
                   10786:                     $changes{$itemid} = 1;
                   10787:                 } else {
                   10788:                     $confhash{$itemid}{'courses'}{$cid} = 1;
                   10789:                 }
                   10790:             }
                   10791:         }
                   10792:         $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
                   10793:         $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
                   10794:         if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
                   10795:             ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
                   10796:             if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
                   10797:                                             $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
                   10798:                 $errors .= '<li><span class="LC_error">'.
                   10799:                            &mt('Invalid courseID [_1] omitted from list of allowed courses',
                   10800:                                $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
                   10801:                            '</span></li>';
                   10802:             } else {
                   10803:                 $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
                   10804:                 $changes{$itemid} = 1;
                   10805:             }
                   10806:         }
                   10807:     }
                   10808:     if (@allpos > 0) {
                   10809:         my $idx = 0;
                   10810:         foreach my $itemid (@allpos) {
                   10811:             if ($itemid ne '') {
                   10812:                 $confhash{$itemid}{'order'} = $idx;
                   10813:                 unless ($changes{$itemid}) {
                   10814:                     if (ref($domconfig{'ipaccess'}) eq 'HASH') {
                   10815:                         if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
                   10816:                             if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
                   10817:                                 $changes{$itemid} = 1;
                   10818:                             }
                   10819:                         }
                   10820:                     }
                   10821:                 }
                   10822:                 $idx ++;
                   10823:             }
                   10824:         }
                   10825:     }
                   10826:     if (keys(%changes)) {
                   10827:         my %defaultshash = (
                   10828:                               ipaccess => \%confhash,
                   10829:                            );
                   10830:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   10831:                                                  $dom);
                   10832:         if ($putresult eq 'ok') {
                   10833:             my $cachetime = 1800;
                   10834:             &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
                   10835:             if (ref($lastactref) eq 'HASH') {
                   10836:                 $lastactref->{'ipaccess'} = 1;
                   10837:             }
                   10838:             $resulttext = &mt('Changes made:').'<ul>';
                   10839:             my %bynum;
                   10840:             foreach my $itemid (sort(keys(%changes))) {
                   10841:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   10842:                     my $position = $confhash{$itemid}{'order'};
                   10843:                     if ($position =~ /^\d+$/) {
                   10844:                         $bynum{$position} = $itemid;
                   10845:                     }
                   10846:                 }
                   10847:             }
                   10848:             if (keys(%deletions)) {
                   10849:                 foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
                   10850:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   10851:                 }
                   10852:             }
                   10853:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   10854:                 my $itemid = $bynum{$pos};
                   10855:                 if (ref($confhash{$itemid}) eq 'HASH') {
                   10856:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
                   10857:                     my $position = $pos + 1;
                   10858:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   10859:                     if ($confhash{$itemid}{'ip'} eq '') {
                   10860:                         $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
                   10861:                     } else {
                   10862:                         $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
                   10863:                     }
                   10864:                     if (keys(%{$confhash{$itemid}{'commblocks'}})) {
                   10865:                         $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
                   10866:                                                   join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
                   10867:                                        '</li>';
                   10868:                     } else {
                   10869:                         $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
                   10870:                     }
                   10871:                     if (keys(%{$confhash{$itemid}{'courses'}})) {
                   10872:                         my @courses;
                   10873:                         foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
                   10874:                             my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
                   10875:                             push(@courses,$courseinfo{'description'}.' ('.$cid.')');
                   10876:                         }
                   10877:                         $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
                   10878:                                              join('</li><li>',@courses).'</li></ul>';
                   10879:                     } else {
                   10880:                         $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
                   10881:                     }
                   10882:                     $resulttext .= '</ul></li>';
                   10883:                 }
                   10884:             }
                   10885:             $resulttext .= '</ul>';
                   10886:         } else {
                   10887:             $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   10888:         }
                   10889:     } else {
                   10890:         $resulttext = &mt('No changes made');
                   10891:     }
                   10892:     if ($errors) {
                   10893:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   10894:                        $errors.'</ul></p>';
                   10895:     }
                   10896:     return $resulttext;
                   10897: }
                   10898: 
                   10899: sub get_ipaccess_id {
                   10900:     my ($domain,$location) = @_;
                   10901:     # get lock on ipaccess db
                   10902:     my $lockhash = {
                   10903:                       lock => $env{'user.name'}.
                   10904:                               ':'.$env{'user.domain'},
                   10905:                    };
                   10906:     my $tries = 0;
                   10907:     my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   10908:     my ($id,$error);
                   10909: 
                   10910:     while (($gotlock ne 'ok') && ($tries<10)) {
                   10911:         $tries ++;
                   10912:         sleep (0.1);
                   10913:         $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
                   10914:     }
                   10915:     if ($gotlock eq 'ok') {
                   10916:         my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
                   10917:         if ($currids{'lock'}) {
                   10918:             delete($currids{'lock'});
                   10919:             if (keys(%currids)) {
                   10920:                 my @curr = sort { $a <=> $b } keys(%currids);
                   10921:                 if ($curr[-1] =~ /^\d+$/) {
                   10922:                     $id = 1 + $curr[-1];
                   10923:                 }
                   10924:             } else {
                   10925:                 $id = 1;
                   10926:             }
                   10927:             if ($id) {
                   10928:                 unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
                   10929:                     $error = 'nostore';
                   10930:                 }
                   10931:             } else {
                   10932:                 $error = 'nonumber';
                   10933:             }
                   10934:         }
                   10935:         my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
                   10936:     } else {
                   10937:         $error = 'nolock';
                   10938:     }
                   10939:     return ($id,$error);
                   10940: }
                   10941: 
1.6       raeburn  10942: sub modify_rolecolors {
1.160.6.24  raeburn  10943:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  10944:     my ($resulttext,%rolehash);
                   10945:     $rolehash{'rolecolors'} = {};
1.55      raeburn  10946:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   10947:         if ($domconfig{'rolecolors'} eq '') {
                   10948:             $domconfig{'rolecolors'} = {};
                   10949:         }
                   10950:     }
1.9       raeburn  10951:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  10952:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   10953:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   10954:                                              $dom);
                   10955:     if ($putresult eq 'ok') {
                   10956:         if (keys(%changes) > 0) {
1.41      raeburn  10957:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  10958:             if (ref($lastactref) eq 'HASH') {
                   10959:                 $lastactref->{'domainconfig'} = 1;
                   10960:             }
1.6       raeburn  10961:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   10962:                                              $rolehash{'rolecolors'});
                   10963:         } else {
                   10964:             $resulttext = &mt('No changes made to default color schemes');
                   10965:         }
                   10966:     } else {
1.11      albertel 10967:         $resulttext = '<span class="LC_error">'.
                   10968: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  10969:     }
                   10970:     if ($errors) {
                   10971:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10972:                        $errors.'</ul>';
                   10973:     }
                   10974:     return $resulttext;
                   10975: }
                   10976: 
                   10977: sub modify_colors {
1.9       raeburn  10978:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  10979:     my (%changes,%choices);
1.51      raeburn  10980:     my @bgs;
1.6       raeburn  10981:     my @links = ('link','alink','vlink');
1.41      raeburn  10982:     my @logintext;
1.6       raeburn  10983:     my @images;
                   10984:     my $servadm = $r->dir_config('lonAdmEMail');
                   10985:     my $errors;
1.160.6.22  raeburn  10986:     my %defaults;
1.6       raeburn  10987:     foreach my $role (@{$roles}) {
                   10988:         if ($role eq 'login') {
1.12      raeburn  10989:             %choices = &login_choices();
1.41      raeburn  10990:             @logintext = ('textcol','bgcol');
1.12      raeburn  10991:         } else {
                   10992:             %choices = &color_font_choices();
                   10993:         }
                   10994:         if ($role eq 'login') {
1.41      raeburn  10995:             @images = ('img','logo','domlogo','login');
1.51      raeburn  10996:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  10997:         } else {
                   10998:             @images = ('img');
1.160.6.22  raeburn  10999:             @bgs = ('pgbg','tabbg','sidebg');
                   11000:         }
                   11001:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   11002:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   11003:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   11004:         }
                   11005:         if ($role eq 'login') {
                   11006:             foreach my $item (@logintext) {
1.160.6.39  raeburn  11007:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   11008:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   11009:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   11010:                 }
                   11011:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22  raeburn  11012:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   11013:                 }
                   11014:             }
                   11015:         } else {
1.160.6.39  raeburn  11016:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   11017:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   11018:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   11019:             }
                   11020:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22  raeburn  11021:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   11022:             }
1.6       raeburn  11023:         }
1.160.6.22  raeburn  11024:         foreach my $item (@bgs) {
1.160.6.39  raeburn  11025:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   11026:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   11027:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   11028:             }
                   11029:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22  raeburn  11030:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   11031:             }
                   11032:         }
                   11033:         foreach my $item (@links) {
1.160.6.39  raeburn  11034:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   11035:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   11036:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   11037:             }
                   11038:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22  raeburn  11039:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   11040:             }
1.6       raeburn  11041:         }
1.46      raeburn  11042:         my ($configuserok,$author_ok,$switchserver) = 
                   11043:             &config_check($dom,$confname,$servadm);
1.9       raeburn  11044:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  11045:         if (ref($domconfig->{$role}) ne 'HASH') {
                   11046:             $domconfig->{$role} = {};
                   11047:         }
1.8       raeburn  11048:         foreach my $img (@images) {
1.160.6.118.2  2(raebur 11049:2):             if ($role eq 'login') {
                   11050:2):                 if (($img eq 'img') || ($img eq 'logo')) {  
                   11051:2):                     if (defined($env{'form.login_showlogo_'.$img})) {
                   11052:2):                         $confhash->{$role}{'showlogo'}{$img} = 1;
                   11053:2):                     } else { 
                   11054:2):                         $confhash->{$role}{'showlogo'}{$img} = 0;
                   11055:2):                     }
1.70      raeburn  11056:                 }
1.160.6.118.2  2(raebur 11057:2):                 if ($env{'form.login_alt_'.$img} ne '') {
                   11058:2):                     $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
                   11059:2):                 }
                   11060:2):             }
1.18      albertel 11061: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   11062: 		 && !defined($domconfig->{$role}{$img})
                   11063: 		 && !$env{'form.'.$role.'_del_'.$img}
                   11064: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   11065: 		# import the old configured image from the .tab setting
                   11066: 		# if they haven't provided a new one 
                   11067: 		$domconfig->{$role}{$img} = 
                   11068: 		    $env{'form.'.$role.'_import_'.$img};
                   11069: 	    }
1.6       raeburn  11070:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  11071:                 my $error;
1.6       raeburn  11072:                 if ($configuserok eq 'ok') {
1.9       raeburn  11073:                     if ($switchserver) {
1.12      raeburn  11074:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  11075:                     } else {
                   11076:                         if ($author_ok eq 'ok') {
                   11077:                             my ($result,$logourl) = 
                   11078:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   11079:                                            $dom,$confname,$img,$width,$height);
                   11080:                             if ($result eq 'ok') {
                   11081:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  11082:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  11083:                             } else {
1.12      raeburn  11084:                                 $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  11085:                             }
                   11086:                         } else {
1.46      raeburn  11087:                             $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  11088:                         }
                   11089:                     }
                   11090:                 } else {
1.46      raeburn  11091:                     $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  11092:                 }
                   11093:                 if ($error) {
1.8       raeburn  11094:                     &Apache::lonnet::logthis($error);
1.11      albertel 11095:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  11096:                 }
                   11097:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  11098:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   11099:                     my $error;
                   11100:                     if ($configuserok eq 'ok') {
                   11101: # is confname an author?
                   11102:                         if ($switchserver eq '') {
                   11103:                             if ($author_ok eq 'ok') {
                   11104:                                 my ($result,$logourl) = 
                   11105:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   11106:                                             $dom,$confname,$img,$width,$height);
                   11107:                                 if ($result eq 'ok') {
                   11108:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 11109: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  11110:                                 }
                   11111:                             }
                   11112:                         }
                   11113:                     }
1.6       raeburn  11114:                 }
                   11115:             }
                   11116:         }
                   11117:         if (ref($domconfig) eq 'HASH') {
                   11118:             if (ref($domconfig->{$role}) eq 'HASH') {
                   11119:                 foreach my $img (@images) {
                   11120:                     if ($domconfig->{$role}{$img} ne '') {
                   11121:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   11122:                             $confhash->{$role}{$img} = '';
1.12      raeburn  11123:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  11124:                         } else {
1.9       raeburn  11125:                             if ($confhash->{$role}{$img} eq '') {
                   11126:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   11127:                             }
1.6       raeburn  11128:                         }
                   11129:                     } else {
                   11130:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   11131:                             $confhash->{$role}{$img} = '';
1.12      raeburn  11132:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  11133:                         } 
                   11134:                     }
1.160.6.118.2  2(raebur 11135:2):                     if ($role eq 'login') {
                   11136:2):                         if (($img eq 'logo') || ($img eq 'img')) {
                   11137:2):                             if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   11138:2):                                 if ($confhash->{$role}{'showlogo'}{$img} ne 
                   11139:2):                                     $domconfig->{$role}{'showlogo'}{$img}) {
                   11140:2):                                     $changes{$role}{'showlogo'}{$img} = 1; 
                   11141:2):                                 }
                   11142:2):                             } else {
                   11143:2):                                 if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   11144:2):                                     $changes{$role}{'showlogo'}{$img} = 1;
                   11145:2):                                 }
1.70      raeburn  11146:                             }
1.160.6.118.2  2(raebur 11147:2):                         }
                   11148:2):                         if ($img ne 'login') {
                   11149:2):                             if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
                   11150:2):                                 if ($confhash->{$role}{'alttext'}{$img} ne
                   11151:2):                                     $domconfig->{$role}{'alttext'}{$img}) {
                   11152:2):                                     $changes{$role}{'alttext'}{$img} = 1;
                   11153:2):                                 }
                   11154:2):                             } else {
                   11155:2):                                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   11156:2):                                     $changes{$role}{'alttext'}{$img} = 1;
                   11157:2):                                 }
1.70      raeburn  11158:                             }
                   11159:                         }
                   11160:                     }
                   11161:                 }
1.6       raeburn  11162:                 if ($domconfig->{$role}{'font'} ne '') {
                   11163:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   11164:                         $changes{$role}{'font'} = 1;
                   11165:                     }
                   11166:                 } else {
                   11167:                     if ($confhash->{$role}{'font'}) {
                   11168:                         $changes{$role}{'font'} = 1;
                   11169:                     }
                   11170:                 }
1.107     raeburn  11171:                 if ($role ne 'login') {
                   11172:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   11173:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   11174:                             $changes{$role}{'fontmenu'} = 1;
                   11175:                         }
                   11176:                     } else {
                   11177:                         if ($confhash->{$role}{'fontmenu'}) {
                   11178:                             $changes{$role}{'fontmenu'} = 1;
                   11179:                         }
1.97      tempelho 11180:                     }
                   11181:                 }
1.6       raeburn  11182:                 foreach my $item (@bgs) {
                   11183:                     if ($domconfig->{$role}{$item} ne '') {
                   11184:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   11185:                             $changes{$role}{'bgs'}{$item} = 1;
                   11186:                         } 
                   11187:                     } else {
                   11188:                         if ($confhash->{$role}{$item}) {
                   11189:                             $changes{$role}{'bgs'}{$item} = 1;
                   11190:                         }
                   11191:                     }
                   11192:                 }
                   11193:                 foreach my $item (@links) {
                   11194:                     if ($domconfig->{$role}{$item} ne '') {
                   11195:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   11196:                             $changes{$role}{'links'}{$item} = 1;
                   11197:                         }
                   11198:                     } else {
                   11199:                         if ($confhash->{$role}{$item}) {
                   11200:                             $changes{$role}{'links'}{$item} = 1;
                   11201:                         }
                   11202:                     }
                   11203:                 }
1.41      raeburn  11204:                 foreach my $item (@logintext) {
                   11205:                     if ($domconfig->{$role}{$item} ne '') {
                   11206:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   11207:                             $changes{$role}{'logintext'}{$item} = 1;
                   11208:                         }
                   11209:                     } else {
                   11210:                         if ($confhash->{$role}{$item}) {
                   11211:                             $changes{$role}{'logintext'}{$item} = 1;
                   11212:                         }
                   11213:                     }
                   11214:                 }
1.6       raeburn  11215:             } else {
                   11216:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  11217:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  11218:             }
                   11219:         } else {
                   11220:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  11221:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  11222:         }
                   11223:     }
                   11224:     return ($errors,%changes);
                   11225: }
                   11226: 
1.46      raeburn  11227: sub config_check {
                   11228:     my ($dom,$confname,$servadm) = @_;
                   11229:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   11230:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   11231:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   11232:                                                    $confname,$servadm);
                   11233:     if ($configuserok eq 'ok') {
                   11234:         $switchserver = &check_switchserver($dom,$confname);
                   11235:         if ($switchserver eq '') {
                   11236:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   11237:         }
                   11238:     }
                   11239:     return ($configuserok,$author_ok,$switchserver);
                   11240: }
                   11241: 
1.6       raeburn  11242: sub default_change_checker {
1.41      raeburn  11243:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  11244:     foreach my $item (@{$links}) {
                   11245:         if ($confhash->{$role}{$item}) {
                   11246:             $changes->{$role}{'links'}{$item} = 1;
                   11247:         }
                   11248:     }
                   11249:     foreach my $item (@{$bgs}) {
                   11250:         if ($confhash->{$role}{$item}) {
                   11251:             $changes->{$role}{'bgs'}{$item} = 1;
                   11252:         }
                   11253:     }
1.41      raeburn  11254:     foreach my $item (@{$logintext}) {
                   11255:         if ($confhash->{$role}{$item}) {
                   11256:             $changes->{$role}{'logintext'}{$item} = 1;
                   11257:         }
                   11258:     }
1.6       raeburn  11259:     foreach my $img (@{$images}) {
                   11260:         if ($env{'form.'.$role.'_del_'.$img}) {
                   11261:             $confhash->{$role}{$img} = '';
1.12      raeburn  11262:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  11263:         }
1.70      raeburn  11264:         if ($role eq 'login') {
                   11265:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   11266:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   11267:             }
1.160.6.118.2  2(raebur 11268:2):             if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
                   11269:2):                 if ($confhash->{$role}{'alttext'}{$img} ne '') {
                   11270:2):                     $changes->{$role}{'alttext'}{$img} = 1;
                   11271:2):                 }
                   11272:2):             }
1.70      raeburn  11273:         }
1.6       raeburn  11274:     }
                   11275:     if ($confhash->{$role}{'font'}) {
                   11276:         $changes->{$role}{'font'} = 1;
                   11277:     }
1.48      raeburn  11278: }
1.6       raeburn  11279: 
                   11280: sub display_colorchgs {
                   11281:     my ($dom,$changes,$roles,$confhash) = @_;
                   11282:     my (%choices,$resulttext);
                   11283:     if (!grep(/^login$/,@{$roles})) {
                   11284:         $resulttext = &mt('Changes made:').'<br />';
                   11285:     }
                   11286:     foreach my $role (@{$roles}) {
                   11287:         if ($role eq 'login') {
                   11288:             %choices = &login_choices();
                   11289:         } else {
                   11290:             %choices = &color_font_choices();
                   11291:         }
                   11292:         if (ref($changes->{$role}) eq 'HASH') {
                   11293:             if ($role ne 'login') {
                   11294:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   11295:             }
                   11296:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   11297:                 if ($role ne 'login') {
                   11298:                     $resulttext .= '<ul>';
                   11299:                 }
                   11300:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   11301:                     if ($role ne 'login') {
                   11302:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   11303:                     }
                   11304:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  11305:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   11306:                             if ($confhash->{$role}{$key}{$item}) {
                   11307:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   11308:                             } else {
                   11309:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   11310:                             }
1.160.6.118.2  2(raebur 11311:2):                         } elsif (($role eq 'login') && ($key eq 'alttext')) {
                   11312:2):                             if ($confhash->{$role}{$key}{$item} ne '') {
          3(raebur 11313:2):                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
          2(raebur 11314:2):                                                $confhash->{$role}{$key}{$item}).'</li>';
                   11315:2):                             } else {
                   11316:2):                                 $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
                   11317:2):                             }
1.70      raeburn  11318:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  11319:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   11320:                         } else {
1.12      raeburn  11321:                             my $newitem = $confhash->{$role}{$item};
                   11322:                             if ($key eq 'images') {
                   11323:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   11324:                             }
                   11325:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  11326:                         }
                   11327:                     }
                   11328:                     if ($role ne 'login') {
                   11329:                         $resulttext .= '</ul></li>';
                   11330:                     }
                   11331:                 } else {
                   11332:                     if ($confhash->{$role}{$key} eq '') {
                   11333:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   11334:                     } else {
                   11335:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   11336:                     }
                   11337:                 }
                   11338:                 if ($role ne 'login') {
                   11339:                     $resulttext .= '</ul>';
                   11340:                 }
                   11341:             }
                   11342:         }
                   11343:     }
1.3       raeburn  11344:     return $resulttext;
1.1       raeburn  11345: }
                   11346: 
1.9       raeburn  11347: sub thumb_dimensions {
                   11348:     return ('200','50');
                   11349: }
                   11350: 
1.16      raeburn  11351: sub check_dimensions {
                   11352:     my ($inputfile) = @_;
                   11353:     my ($fullwidth,$fullheight);
                   11354:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   11355:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   11356:             my $imageinfo = <PIPE>;
                   11357:             if (!close(PIPE)) {
                   11358:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   11359:             }
                   11360:             chomp($imageinfo);
                   11361:             my ($fullsize) = 
1.21      raeburn  11362:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  11363:             if ($fullsize) {
                   11364:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   11365:             }
                   11366:         }
                   11367:     }
                   11368:     return ($fullwidth,$fullheight);
                   11369: }
                   11370: 
1.9       raeburn  11371: sub check_configuser {
                   11372:     my ($uhome,$dom,$confname,$servadm) = @_;
                   11373:     my ($configuserok,%currroles);
                   11374:     if ($uhome eq 'no_host') {
                   11375:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
1.160.6.98  raeburn  11376:         my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9       raeburn  11377:         $configuserok = 
                   11378:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   11379:                              $configpass,'','','','','',undef,$servadm);
                   11380:     } else {
                   11381:         $configuserok = 'ok';
                   11382:         %currroles = 
                   11383:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   11384:     }
                   11385:     return ($configuserok,%currroles);
                   11386: }
                   11387: 
                   11388: sub check_authorstatus {
                   11389:     my ($dom,$confname,%currroles) = @_;
                   11390:     my $author_ok;
1.40      raeburn  11391:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  11392:         my $start = time;
                   11393:         my $end = 0;
                   11394:         $author_ok = 
                   11395:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  11396:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  11397:     } else {
                   11398:         $author_ok = 'ok';
                   11399:     }
                   11400:     return $author_ok;
                   11401: }
                   11402: 
                   11403: sub publishlogo {
1.46      raeburn  11404:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  11405:     my ($output,$fname,$logourl);
                   11406:     if ($action eq 'upload') {
                   11407:         $fname=$env{'form.'.$formname.'.filename'};
                   11408:         chop($env{'form.'.$formname});
                   11409:     } else {
                   11410:         ($fname) = ($formname =~ /([^\/]+)$/);
                   11411:     }
1.46      raeburn  11412:     if ($savefileas ne '') {
                   11413:         $fname = $savefileas;
                   11414:     }
1.9       raeburn  11415:     $fname=&Apache::lonnet::clean_filename($fname);
                   11416: # See if there is anything left
                   11417:     unless ($fname) { return ('error: no uploaded file'); }
                   11418:     $fname="$subdir/$fname";
1.160.6.5  raeburn  11419:     my $docroot=$r->dir_config('lonDocRoot');
                   11420:     my $filepath="$docroot/priv";
                   11421:     my $relpath = "$dom/$confname";
1.9       raeburn  11422:     my ($fnamepath,$file,$fetchthumb);
                   11423:     $file=$fname;
                   11424:     if ($fname=~m|/|) {
                   11425:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   11426:     }
1.160.6.26  raeburn  11427:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  11428:     my $count;
1.160.6.5  raeburn  11429:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  11430:         $filepath.="/$parts[$count]";
                   11431:         if ((-e $filepath)!=1) {
                   11432:             mkdir($filepath,02770);
                   11433:         }
                   11434:     }
                   11435:     # Check for bad extension and disallow upload
                   11436:     if ($file=~/\.(\w+)$/ &&
                   11437:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   11438:         $output = 
1.160.6.25  raeburn  11439:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  11440:     } elsif ($file=~/\.(\w+)$/ &&
                   11441:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   11442:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   11443:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18  raeburn  11444:         $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  11445:     } elsif (-d "$filepath/$file") {
1.160.6.18  raeburn  11446:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  11447:     } else {
                   11448:         my $source = $filepath.'/'.$file;
                   11449:         my $logfile;
1.160.6.88  raeburn  11450:         if (!open($logfile,">>",$source.'.log')) {
1.160.6.19  raeburn  11451:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  11452:         }
                   11453:         print $logfile
                   11454: "\n================= Publish ".localtime()." ================\n".
                   11455: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   11456: # Save the file
1.160.6.88  raeburn  11457:         if (!open(FH,">",$source)) {
1.9       raeburn  11458:             &Apache::lonnet::logthis('Failed to create '.$source);
                   11459:             return (&mt('Failed to create file'));
                   11460:         }
                   11461:         if ($action eq 'upload') {
                   11462:             if (!print FH ($env{'form.'.$formname})) {
                   11463:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   11464:                 return (&mt('Failed to write file'));
                   11465:             }
                   11466:         } else {
                   11467:             my $original = &Apache::lonnet::filelocation('',$formname);
                   11468:             if(!copy($original,$source)) {
                   11469:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   11470:                 return (&mt('Failed to write file'));
                   11471:             }
                   11472:         }
                   11473:         close(FH);
                   11474:         chmod(0660, $source); # Permissions to rw-rw---.
                   11475: 
                   11476:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   11477:         my $copyfile=$targetdir.'/'.$file;
                   11478: 
                   11479:         my @parts=split(/\//,$targetdir);
                   11480:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   11481:         for (my $count=5;$count<=$#parts;$count++) {
                   11482:             $path.="/$parts[$count]";
                   11483:             if (!-e $path) {
                   11484:                 print $logfile "\nCreating directory ".$path;
                   11485:                 mkdir($path,02770);
                   11486:             }
                   11487:         }
                   11488:         my $versionresult;
                   11489:         if (-e $copyfile) {
                   11490:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   11491:         } else {
                   11492:             $versionresult = 'ok';
                   11493:         }
                   11494:         if ($versionresult eq 'ok') {
                   11495:             if (copy($source,$copyfile)) {
                   11496:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   11497:                 $output = 'ok';
                   11498:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  11499:                 push(@{$modified_urls},[$copyfile,$source]);
                   11500:                 my $metaoutput = 
                   11501:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   11502:                 unless ($registered_cleanup) {
                   11503:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   11504:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   11505:                     $registered_cleanup=1;
                   11506:                 }
1.9       raeburn  11507:             } else {
                   11508:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   11509:                 $output = &mt('Failed to copy file to RES space').", $!";
                   11510:             }
                   11511:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   11512:                 my $inputfile = $filepath.'/'.$file;
                   11513:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  11514:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   11515:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   11516:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   11517:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88  raeburn  11518:                         my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
                   11519:                         system({$args[0]} @args);
1.16      raeburn  11520:                         chmod(0660, $filepath.'/tn-'.$file);
                   11521:                         if (-e $outfile) {
                   11522:                             my $copyfile=$targetdir.'/tn-'.$file;
                   11523:                             if (copy($outfile,$copyfile)) {
                   11524:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  11525:                                 my $thumb_metaoutput = 
                   11526:                                     &write_metadata($dom,$confname,$formname,
                   11527:                                                     $targetdir,'tn-'.$file,$logfile);
                   11528:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   11529:                                 unless ($registered_cleanup) {
                   11530:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   11531:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   11532:                                     $registered_cleanup=1;
                   11533:                                 }
1.16      raeburn  11534:                             } else {
                   11535:                                 print $logfile "\nUnable to write ".$copyfile.
                   11536:                                                ':'.$!."\n";
                   11537:                             }
                   11538:                         }
1.9       raeburn  11539:                     }
                   11540:                 }
                   11541:             }
                   11542:         } else {
                   11543:             $output = $versionresult;
                   11544:         }
                   11545:     }
                   11546:     return ($output,$logourl);
                   11547: }
                   11548: 
                   11549: sub logo_versioning {
                   11550:     my ($targetdir,$file,$logfile) = @_;
                   11551:     my $target = $targetdir.'/'.$file;
                   11552:     my ($maxversion,$fn,$extn,$output);
                   11553:     $maxversion = 0;
                   11554:     if ($file =~ /^(.+)\.(\w+)$/) {
                   11555:         $fn=$1;
                   11556:         $extn=$2;
                   11557:     }
                   11558:     opendir(DIR,$targetdir);
                   11559:     while (my $filename=readdir(DIR)) {
                   11560:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   11561:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   11562:         }
                   11563:     }
                   11564:     $maxversion++;
                   11565:     print $logfile "\nCreating old version ".$maxversion."\n";
                   11566:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   11567:     if (copy($target,$copyfile)) {
                   11568:         print $logfile "Copied old target to ".$copyfile."\n";
                   11569:         $copyfile=$copyfile.'.meta';
                   11570:         if (copy($target.'.meta',$copyfile)) {
                   11571:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   11572:             $output = 'ok';
                   11573:         } else {
                   11574:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   11575:             $output = &mt('Failed to copy old meta').", $!, ";
                   11576:         }
                   11577:     } else {
                   11578:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   11579:         $output = &mt('Failed to copy old target').", $!, ";
                   11580:     }
                   11581:     return $output;
                   11582: }
                   11583: 
                   11584: sub write_metadata {
                   11585:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   11586:     my (%metadatafields,%metadatakeys,$output);
                   11587:     $metadatafields{'title'}=$formname;
                   11588:     $metadatafields{'creationdate'}=time;
                   11589:     $metadatafields{'lastrevisiondate'}=time;
                   11590:     $metadatafields{'copyright'}='public';
                   11591:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   11592:                                          $env{'user.domain'};
                   11593:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   11594:     $metadatafields{'domain'}=$dom;
                   11595:     {
                   11596:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   11597:         my $mfh;
1.160.6.88  raeburn  11598:         if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13  raeburn  11599:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  11600:                 unless ($_=~/\./) {
                   11601:                     my $unikey=$_;
                   11602:                     $unikey=~/^([A-Za-z]+)/;
                   11603:                     my $tag=$1;
                   11604:                     $tag=~tr/A-Z/a-z/;
                   11605:                     print $mfh "\n\<$tag";
                   11606:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   11607:                         my $value=$metadatafields{$unikey.'.'.$_};
                   11608:                         $value=~s/\"/\'\'/g;
                   11609:                         print $mfh ' '.$_.'="'.$value.'"';
                   11610:                     }
                   11611:                     print $mfh '>'.
                   11612:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   11613:                             .'</'.$tag.'>';
                   11614:                 }
                   11615:             }
                   11616:             $output = 'ok';
                   11617:             print $logfile "\nWrote metadata";
                   11618:             close($mfh);
                   11619:         } else {
                   11620:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  11621:             $output = &mt('Could not write metadata');
                   11622:         }
                   11623:     }
1.155     raeburn  11624:     return $output;
                   11625: }
                   11626: 
                   11627: sub notifysubscribed {
                   11628:     foreach my $targetsource (@{$modified_urls}){
                   11629:         next unless (ref($targetsource) eq 'ARRAY');
                   11630:         my ($target,$source)=@{$targetsource};
                   11631:         if ($source ne '') {
1.160.6.88  raeburn  11632:             if (open(my $logfh,">>",$source.'.log')) {
1.155     raeburn  11633:                 print $logfh "\nCleanup phase: Notifications\n";
                   11634:                 my @subscribed=&subscribed_hosts($target);
                   11635:                 foreach my $subhost (@subscribed) {
                   11636:                     print $logfh "\nNotifying host ".$subhost.':';
                   11637:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   11638:                     print $logfh $reply;
                   11639:                 }
                   11640:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   11641:                 foreach my $subhost (@subscribedmeta) {
                   11642:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   11643:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   11644:                                                         $subhost);
                   11645:                     print $logfh $reply;
                   11646:                 }
                   11647:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  11648:                 close($logfh);
1.155     raeburn  11649:             }
                   11650:         }
                   11651:     }
                   11652:     return OK;
                   11653: }
                   11654: 
                   11655: sub subscribed_hosts {
                   11656:     my ($target) = @_;
                   11657:     my @subscribed;
1.160.6.88  raeburn  11658:     if (open(my $fh,"<","$target.subscription")) {
1.155     raeburn  11659:         while (my $subline=<$fh>) {
                   11660:             if ($subline =~ /^($match_lonid):/) {
                   11661:                 my $host = $1;
                   11662:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   11663:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   11664:                         push(@subscribed,$host);
                   11665:                     }
                   11666:                 }
                   11667:             }
                   11668:         }
                   11669:     }
                   11670:     return @subscribed;
1.9       raeburn  11671: }
                   11672: 
                   11673: sub check_switchserver {
                   11674:     my ($dom,$confname) = @_;
                   11675:     my ($allowed,$switchserver);
                   11676:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   11677:     if ($home eq 'no_host') {
                   11678:         $home = &Apache::lonnet::domain($dom,'primary');
                   11679:     }
                   11680:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 11681:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   11682:     if (!$allowed) {
1.160.6.11  raeburn  11683: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  11684:     }
                   11685:     return $switchserver;
                   11686: }
                   11687: 
1.1       raeburn  11688: sub modify_quotas {
1.160.6.30  raeburn  11689:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  11690:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30  raeburn  11691:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39  raeburn  11692:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   11693:         $validationfieldsref);
1.86      raeburn  11694:     if ($action eq 'quotas') {
                   11695:         $context = 'tools'; 
1.160.6.26  raeburn  11696:     } else {
1.86      raeburn  11697:         $context = $action;
                   11698:     }
                   11699:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  11700:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  11701:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  11702:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   11703:         %titles = &courserequest_titles();
                   11704:         $toolregexp = join('|',@usertools);
                   11705:         %conditions = &courserequest_conditions();
1.160.6.30  raeburn  11706:         $confname = $dom.'-domainconfig';
                   11707:         my $servadm = $r->dir_config('lonAdmEMail');
                   11708:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39  raeburn  11709:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   11710:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5  raeburn  11711:     } elsif ($context eq 'requestauthor') {
                   11712:         @usertools = ('author');
                   11713:         %titles = &authorrequest_titles();
1.86      raeburn  11714:     } else {
1.160.6.4  raeburn  11715:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  11716:         %titles = &tool_titles();
1.86      raeburn  11717:     }
1.160.6.27  raeburn  11718:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  11719:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  11720:     foreach my $key (keys(%env)) {
1.101     raeburn  11721:         if ($context eq 'requestcourses') {
                   11722:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   11723:                 my $item = $1;
                   11724:                 my $type = $2;
                   11725:                 if ($type =~ /^limit_(.+)/) {
                   11726:                     $limithash{$item}{$1} = $env{$key};
                   11727:                 } else {
                   11728:                     $confhash{$item}{$type} = $env{$key};
                   11729:                 }
                   11730:             }
1.160.6.5  raeburn  11731:         } elsif ($context eq 'requestauthor') {
                   11732:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   11733:                 $confhash{$1} = $env{$key};
                   11734:             }
1.101     raeburn  11735:         } else {
1.86      raeburn  11736:             if ($key =~ /^form\.quota_(.+)$/) {
                   11737:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20  raeburn  11738:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   11739:                 $confhash{'authorquota'}{$1} = $env{$key};
                   11740:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  11741:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   11742:             }
1.72      raeburn  11743:         }
                   11744:     }
1.160.6.5  raeburn  11745:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34  raeburn  11746:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  11747:         @approvalnotify = sort(@approvalnotify);
                   11748:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30  raeburn  11749:         my @crstypes = ('official','unofficial','community','textbook');
                   11750:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   11751:         foreach my $type (@hasuniquecode) {
                   11752:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   11753:                 $confhash{'uniquecode'}{$type} = 1;
                   11754:             }
                   11755:         }
1.160.6.46  raeburn  11756:         my (%newbook,%allpos);
1.160.6.30  raeburn  11757:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  11758:             foreach my $type ('textbooks','templates') {
                   11759:                 @{$allpos{$type}} = (); 
                   11760:                 my $invalid;
                   11761:                 if ($type eq 'textbooks') {
                   11762:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   11763:                 } else {
                   11764:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   11765:                 }
                   11766:                 if ($env{'form.'.$type.'_addbook'}) {
                   11767:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   11768:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   11769:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   11770:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   11771:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   11772:                         } else {
                   11773:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   11774:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   11775:                             $position =~ s/\D+//g;
                   11776:                             if ($position ne '') {
                   11777:                                 $allpos{$type}[$position] = $newbook{$type};
                   11778:                             }
1.160.6.30  raeburn  11779:                         }
1.160.6.46  raeburn  11780:                     } else {
                   11781:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30  raeburn  11782:                     }
                   11783:                 }
1.160.6.46  raeburn  11784:             } 
1.160.6.30  raeburn  11785:         }
1.102     raeburn  11786:         if (ref($domconfig{$action}) eq 'HASH') {
                   11787:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   11788:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   11789:                     $changes{'notify'}{'approval'} = 1;
                   11790:                 }
                   11791:             } else {
1.144     raeburn  11792:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11793:                     $changes{'notify'}{'approval'} = 1;
                   11794:                 }
                   11795:             }
1.160.6.30  raeburn  11796:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   11797:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11798:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   11799:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   11800:                             $changes{'uniquecode'} = 1;
                   11801:                         }
                   11802:                     }
                   11803:                     unless ($changes{'uniquecode'}) {
                   11804:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   11805:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   11806:                                 $changes{'uniquecode'} = 1;
                   11807:                             }
                   11808:                         }
                   11809:                     }
                   11810:                } else {
                   11811:                    $changes{'uniquecode'} = 1;
                   11812:                }
                   11813:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   11814:                 $changes{'uniquecode'} = 1;
                   11815:             }
                   11816:             if ($context eq 'requestcourses') {
1.160.6.46  raeburn  11817:                 foreach my $type ('textbooks','templates') {
                   11818:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11819:                         my %deletions;
                   11820:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   11821:                         if (@todelete) {
                   11822:                             map { $deletions{$_} = 1; } @todelete;
                   11823:                         }
                   11824:                         my %imgdeletions;
                   11825:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   11826:                         if (@todeleteimages) {
                   11827:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   11828:                         }
                   11829:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   11830:                         for (my $i=0; $i<=$maxnum; $i++) {
                   11831:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   11832:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   11833:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   11834:                                 if ($deletions{$key}) {
                   11835:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   11836:                                         #FIXME need to obsolete item in RES space
                   11837:                                     }
                   11838:                                     next;
                   11839:                                 } else {
                   11840:                                     my $newpos = $env{'form.'.$itemid};
                   11841:                                     $newpos =~ s/\D+//g;
1.160.6.47  raeburn  11842:                                     foreach my $item ('subject','title','publisher','author') {
                   11843:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11844:                                                  ($type eq 'templates'));
1.160.6.46  raeburn  11845:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   11846:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   11847:                                             $changes{$type}{$key} = 1;
                   11848:                                         }
                   11849:                                     }
                   11850:                                     $allpos{$type}[$newpos] = $key;
1.160.6.30  raeburn  11851:                                 }
1.160.6.46  raeburn  11852:                                 if ($imgdeletions{$key}) {
                   11853:                                     $changes{$type}{$key} = 1;
                   11854:                                     #FIXME need to obsolete item in RES space
                   11855:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   11856:                                     my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88  raeburn  11857:                                     if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11858:                                         $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11859:                                     } else {
                   11860:                                         my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   11861:                                                                                       $cdom,$cnum,$type,$configuserok,
                   11862:                                                                                       $switchserver,$author_ok);
                   11863:                                         if ($imgurl) {
                   11864:                                             $confhash{$type}{$key}{'image'} = $imgurl;
                   11865:                                             $changes{$type}{$key} = 1; 
                   11866:                                         }
                   11867:                                         if ($error) {
                   11868:                                             &Apache::lonnet::logthis($error);
                   11869:                                             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11870:                                         }
1.160.6.46  raeburn  11871:                                     } 
                   11872:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   11873:                                     $confhash{$type}{$key}{'image'} = 
                   11874:                                         $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30  raeburn  11875:                                 }
                   11876:                             }
                   11877:                         }
                   11878:                     }
                   11879:                 }
                   11880:             }
1.102     raeburn  11881:         } else {
1.144     raeburn  11882:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  11883:                 $changes{'notify'}{'approval'} = 1;
                   11884:             }
1.160.6.30  raeburn  11885:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
                   11886:                 $changes{'uniquecode'} = 1;
                   11887:             }
                   11888:         }
                   11889:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  11890:             foreach my $type ('textbooks','templates') {
                   11891:                 if ($newbook{$type}) {
                   11892:                     $changes{$type}{$newbook{$type}} = 1;
1.160.6.47  raeburn  11893:                     foreach my $item ('subject','title','publisher','author') {
                   11894:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   11895:                                  ($type eq 'template'));
1.160.6.46  raeburn  11896:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   11897:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   11898:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   11899:                         }
                   11900:                     }
                   11901:                     if ($type eq 'textbooks') {
                   11902:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   11903:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88  raeburn  11904:                             if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
                   11905:                                 $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
                   11906:                             } else {
                   11907:                                 my ($imageurl,$error) =
                   11908:                                     &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   11909:                                                             $configuserok,$switchserver,$author_ok);
                   11910:                                 if ($imageurl) {
                   11911:                                     $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   11912:                                 }
                   11913:                                 if ($error) {
                   11914:                                     &Apache::lonnet::logthis($error);
                   11915:                                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11916:                                 }
1.160.6.46  raeburn  11917:                             }
                   11918:                         }
1.160.6.30  raeburn  11919:                     }
                   11920:                 }
1.160.6.46  raeburn  11921:                 if (@{$allpos{$type}} > 0) {
                   11922:                     my $idx = 0;
                   11923:                     foreach my $item (@{$allpos{$type}}) {
                   11924:                         if ($item ne '') {
                   11925:                             $confhash{$type}{$item}{'order'} = $idx;
                   11926:                             if (ref($domconfig{$action}) eq 'HASH') {
                   11927:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   11928:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   11929:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   11930:                                             $changes{$type}{$item} = 1;
                   11931:                                         }
1.160.6.30  raeburn  11932:                                     }
                   11933:                                 }
                   11934:                             }
1.160.6.46  raeburn  11935:                             $idx ++;
1.160.6.30  raeburn  11936:                         }
                   11937:                     }
                   11938:                 }
                   11939:             }
1.160.6.39  raeburn  11940:             if (ref($validationitemsref) eq 'ARRAY') {
                   11941:                 foreach my $item (@{$validationitemsref}) {
                   11942:                     if ($item eq 'fields') {
                   11943:                         my @changed;
                   11944:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   11945:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   11946:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   11947:                         }
1.160.6.65  raeburn  11948:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11949:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11950:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   11951:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   11952:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   11953:                                 } else {
                   11954:                                     @changed = @{$confhash{'validation'}{$item}};
                   11955:                                 }
1.160.6.39  raeburn  11956:                             } else {
                   11957:                                 @changed = @{$confhash{'validation'}{$item}};
                   11958:                             }
                   11959:                         } else {
                   11960:                             @changed = @{$confhash{'validation'}{$item}};
                   11961:                         }
                   11962:                         if (@changed) {
                   11963:                             if ($confhash{'validation'}{$item}) {
                   11964:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   11965:                             } else {
                   11966:                                 $changes{'validation'}{$item} = &mt('None');
                   11967:                             }
                   11968:                         }
                   11969:                     } else {
                   11970:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   11971:                         if ($item eq 'markup') {
                   11972:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   11973:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   11974:                             }
                   11975:                         }
1.160.6.65  raeburn  11976:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   11977:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   11978:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   11979:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11980:                                 }
                   11981:                             } else {
                   11982:                                 if ($confhash{'validation'}{$item} ne '') {
                   11983:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11984:                                 }
1.160.6.39  raeburn  11985:                             }
                   11986:                         } else {
                   11987:                             if ($confhash{'validation'}{$item} ne '') {
                   11988:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   11989:                             }
                   11990:                         }
                   11991:                     }
                   11992:                 }
                   11993:             }
                   11994:             if ($env{'form.validationdc'}) {
                   11995:                 my $newval = $env{'form.validationdc'};
1.160.6.77  raeburn  11996:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39  raeburn  11997:                 if (exists($domcoords{$newval})) {
                   11998:                     $confhash{'validation'}{'dc'} = $newval;
                   11999:                 }
                   12000:             }
                   12001:             if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65  raeburn  12002:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   12003:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   12004:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   12005:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   12006:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   12007:                                     $changes{'validation'}{'dc'} = &mt('None');
                   12008:                                 } else {
                   12009:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   12010:                                 }
1.160.6.39  raeburn  12011:                             }
1.160.6.65  raeburn  12012:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   12013:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39  raeburn  12014:                         }
                   12015:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   12016:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   12017:                     }
                   12018:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   12019:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   12020:                 }
1.160.6.65  raeburn  12021:             } else {
                   12022:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   12023:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   12024:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   12025:                             $changes{'validation'}{'dc'} = &mt('None');
                   12026:                         }
                   12027:                     }
1.160.6.39  raeburn  12028:                 }
                   12029:             }
1.102     raeburn  12030:         }
                   12031:     } else {
1.86      raeburn  12032:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20  raeburn  12033:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  12034:     }
1.72      raeburn  12035:     foreach my $item (@usertools) {
                   12036:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  12037:             my $unset; 
1.101     raeburn  12038:             if ($context eq 'requestcourses') {
1.104     raeburn  12039:                 $unset = '0';
                   12040:                 if ($type eq '_LC_adv') {
                   12041:                     $unset = '';
                   12042:                 }
1.101     raeburn  12043:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   12044:                     $confhash{$item}{$type} .= '=';
                   12045:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   12046:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   12047:                     }
                   12048:                 }
1.160.6.5  raeburn  12049:             } elsif ($context eq 'requestauthor') {
                   12050:                 $unset = '0';
                   12051:                 if ($type eq '_LC_adv') {
                   12052:                     $unset = '';
                   12053:                 }
1.72      raeburn  12054:             } else {
1.101     raeburn  12055:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   12056:                     $confhash{$item}{$type} = 1;
                   12057:                 } else {
                   12058:                     $confhash{$item}{$type} = 0;
                   12059:                 }
1.72      raeburn  12060:             }
1.86      raeburn  12061:             if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5  raeburn  12062:                 if ($action eq 'requestauthor') {
                   12063:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   12064:                         $changes{$type} = 1;
                   12065:                     }
                   12066:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  12067:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   12068:                         $changes{$item}{$type} = 1;
                   12069:                     }
                   12070:                 } else {
                   12071:                     if ($context eq 'requestcourses') {
1.104     raeburn  12072:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  12073:                             $changes{$item}{$type} = 1;
                   12074:                         }
                   12075:                     } else {
                   12076:                         if (!$confhash{$item}{$type}) {
                   12077:                             $changes{$item}{$type} = 1;
                   12078:                         }
                   12079:                     }
                   12080:                 }
                   12081:             } else {
                   12082:                 if ($context eq 'requestcourses') {
1.104     raeburn  12083:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  12084:                         $changes{$item}{$type} = 1;
                   12085:                     }
1.160.6.5  raeburn  12086:                 } elsif ($context eq 'requestauthor') {
                   12087:                     if ($confhash{$type} ne $unset) {
                   12088:                         $changes{$type} = 1;
                   12089:                     }
1.72      raeburn  12090:                 } else {
                   12091:                     if (!$confhash{$item}{$type}) {
                   12092:                         $changes{$item}{$type} = 1;
                   12093:                     }
                   12094:                 }
                   12095:             }
1.1       raeburn  12096:         }
                   12097:     }
1.160.6.5  raeburn  12098:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  12099:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   12100:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   12101:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   12102:                     if (exists($confhash{'defaultquota'}{$key})) {
                   12103:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   12104:                             $changes{'defaultquota'}{$key} = 1;
                   12105:                         }
                   12106:                     } else {
                   12107:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  12108:                     }
                   12109:                 }
1.86      raeburn  12110:             } else {
                   12111:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   12112:                     if (exists($confhash{'defaultquota'}{$key})) {
                   12113:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   12114:                             $changes{'defaultquota'}{$key} = 1;
                   12115:                         }
                   12116:                     } else {
                   12117:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  12118:                     }
1.1       raeburn  12119:                 }
                   12120:             }
1.160.6.20  raeburn  12121:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   12122:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   12123:                     if (exists($confhash{'authorquota'}{$key})) {
                   12124:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   12125:                             $changes{'authorquota'}{$key} = 1;
                   12126:                         }
                   12127:                     } else {
                   12128:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   12129:                     }
                   12130:                 }
                   12131:             }
1.1       raeburn  12132:         }
1.86      raeburn  12133:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   12134:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   12135:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   12136:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   12137:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   12138:                             $changes{'defaultquota'}{$key} = 1;
                   12139:                         }
                   12140:                     } else {
                   12141:                         if (!exists($domconfig{'quotas'}{$key})) {
                   12142:                             $changes{'defaultquota'}{$key} = 1;
                   12143:                         }
1.72      raeburn  12144:                     }
                   12145:                 } else {
1.86      raeburn  12146:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  12147:                 }
1.1       raeburn  12148:             }
                   12149:         }
1.160.6.20  raeburn  12150:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   12151:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   12152:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   12153:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   12154:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   12155:                             $changes{'authorquota'}{$key} = 1;
                   12156:                         }
                   12157:                     } else {
                   12158:                         $changes{'authorquota'}{$key} = 1;
                   12159:                     }
                   12160:                 } else {
                   12161:                     $changes{'authorquota'}{$key} = 1;
                   12162:                 }
                   12163:             }
                   12164:         }
1.1       raeburn  12165:     }
1.72      raeburn  12166: 
1.160.6.5  raeburn  12167:     if ($context eq 'requestauthor') {
                   12168:         $domdefaults{'requestauthor'} = \%confhash;
                   12169:     } else {
                   12170:         foreach my $key (keys(%confhash)) {
1.160.6.46  raeburn  12171:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30  raeburn  12172:                 $domdefaults{$key} = $confhash{$key};
                   12173:             }
1.160.6.5  raeburn  12174:         }
1.72      raeburn  12175:     }
1.160.6.5  raeburn  12176: 
1.1       raeburn  12177:     my %quotahash = (
1.86      raeburn  12178:                       $action => { %confhash }
1.1       raeburn  12179:                     );
                   12180:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   12181:                                              $dom);
                   12182:     if ($putresult eq 'ok') {
                   12183:         if (keys(%changes) > 0) {
1.72      raeburn  12184:             my $cachetime = 24*60*60;
                   12185:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  12186:             if (ref($lastactref) eq 'HASH') {
                   12187:                 $lastactref->{'domdefaults'} = 1;
                   12188:             }
1.1       raeburn  12189:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5  raeburn  12190:             unless (($context eq 'requestcourses') ||
                   12191:                     ($context eq 'requestauthor')) {
1.86      raeburn  12192:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   12193:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   12194:                     foreach my $type (@{$types},'default') {
                   12195:                         if (defined($changes{'defaultquota'}{$type})) {
                   12196:                             my $typetitle = $usertypes->{$type};
                   12197:                             if ($type eq 'default') {
                   12198:                                 $typetitle = $othertitle;
                   12199:                             }
1.160.6.28  raeburn  12200:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  12201:                         }
                   12202:                     }
1.86      raeburn  12203:                     $resulttext .= '</ul></li>';
1.72      raeburn  12204:                 }
1.160.6.20  raeburn  12205:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34  raeburn  12206:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20  raeburn  12207:                     foreach my $type (@{$types},'default') {
                   12208:                         if (defined($changes{'authorquota'}{$type})) {
                   12209:                             my $typetitle = $usertypes->{$type};
                   12210:                             if ($type eq 'default') {
                   12211:                                 $typetitle = $othertitle;
                   12212:                             }
1.160.6.28  raeburn  12213:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20  raeburn  12214:                         }
                   12215:                     }
                   12216:                     $resulttext .= '</ul></li>';
                   12217:                 }
1.72      raeburn  12218:             }
1.80      raeburn  12219:             my %newenv;
1.72      raeburn  12220:             foreach my $item (@usertools) {
1.160.6.5  raeburn  12221:                 my (%haschgs,%inconf);
                   12222:                 if ($context eq 'requestauthor') {
                   12223:                     %haschgs = %changes;
                   12224:                     %inconf = %confhash;
                   12225:                 } else {
                   12226:                     if (ref($changes{$item}) eq 'HASH') {
                   12227:                         %haschgs = %{$changes{$item}};
                   12228:                     }
                   12229:                     if (ref($confhash{$item}) eq 'HASH') {
                   12230:                         %inconf = %{$confhash{$item}};
                   12231:                     }
                   12232:                 }
                   12233:                 if (keys(%haschgs) > 0) {
1.80      raeburn  12234:                     my $newacc = 
                   12235:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   12236:                                                           $env{'user.domain'},
1.86      raeburn  12237:                                                           $item,'reload',$context);
1.160.6.5  raeburn  12238:                     if (($context eq 'requestcourses') ||
                   12239:                         ($context eq 'requestauthor')) {
1.108     raeburn  12240:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   12241:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  12242:                         }
                   12243:                     } else {
                   12244:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   12245:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   12246:                         }
1.80      raeburn  12247:                     }
1.160.6.5  raeburn  12248:                     unless ($context eq 'requestauthor') {
                   12249:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   12250:                     }
1.72      raeburn  12251:                     foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5  raeburn  12252:                         if ($haschgs{$type}) {
1.72      raeburn  12253:                             my $typetitle = $usertypes->{$type};
                   12254:                             if ($type eq 'default') {
                   12255:                                 $typetitle = $othertitle;
                   12256:                             } elsif ($type eq '_LC_adv') {
                   12257:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   12258:                             }
1.160.6.5  raeburn  12259:                             if ($inconf{$type}) {
1.101     raeburn  12260:                                 if ($context eq 'requestcourses') {
                   12261:                                     my $cond;
1.160.6.5  raeburn  12262:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  12263:                                         if ($1 eq '') {
                   12264:                                             $cond = &mt('(Automatic processing of any request).');
                   12265:                                         } else {
                   12266:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   12267:                                         }
                   12268:                                     } else { 
1.160.6.5  raeburn  12269:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  12270:                                     }
                   12271:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8  raeburn  12272:                                 } elsif ($context eq 'requestauthor') {
                   12273:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   12274:                                                              $titles{$inconf{$type}},$typetitle);
                   12275: 
1.101     raeburn  12276:                                 } else {
                   12277:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   12278:                                 }
1.72      raeburn  12279:                             } else {
1.104     raeburn  12280:                                 if ($type eq '_LC_adv') {
1.160.6.5  raeburn  12281:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  12282:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   12283:                                     } else { 
                   12284:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   12285:                                     }
                   12286:                                 } else {
                   12287:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   12288:                                 }
1.72      raeburn  12289:                             }
                   12290:                         }
1.26      raeburn  12291:                     }
1.160.6.5  raeburn  12292:                     unless ($context eq 'requestauthor') {
                   12293:                         $resulttext .= '</ul></li>';
                   12294:                     }
1.26      raeburn  12295:                 }
1.1       raeburn  12296:             }
1.160.6.5  raeburn  12297:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  12298:                 if (ref($changes{'notify'}) eq 'HASH') {
                   12299:                     if ($changes{'notify'}{'approval'}) {
                   12300:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   12301:                             if ($confhash{'notify'}{'approval'}) {
                   12302:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   12303:                             } else {
1.160.6.5  raeburn  12304:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  12305:                             }
                   12306:                         }
                   12307:                     }
                   12308:                 }
                   12309:             }
1.160.6.30  raeburn  12310:             if ($action eq 'requestcourses') {
                   12311:                 my @offon = ('off','on');
                   12312:                 if ($changes{'uniquecode'}) {
                   12313:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   12314:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   12315:                         $resulttext .= '<li>'.
                   12316:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   12317:                                        '</li>';
                   12318:                     } else {
                   12319:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   12320:                                        '</li>';
                   12321:                     }
                   12322:                 }
1.160.6.46  raeburn  12323:                 foreach my $type ('textbooks','templates') {
                   12324:                     if (ref($changes{$type}) eq 'HASH') {
                   12325:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   12326:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   12327:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   12328:                             my $coursetitle = $coursehash{'description'};
                   12329:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   12330:                             $resulttext .= '<li>';
1.160.6.47  raeburn  12331:                             foreach my $item ('subject','title','publisher','author') {
                   12332:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   12333:                                          ($type eq 'templates'));
1.160.6.46  raeburn  12334:                                 my $name = $item.':';
                   12335:                                 $name =~ s/^(\w)/\U$1/;
                   12336:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   12337:                             }
                   12338:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   12339:                             if ($type eq 'textbooks') {
                   12340:                                 if ($confhash{$type}{$key}{'image'}) {
                   12341:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   12342:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   12343:                                                    ' alt="Textbook cover" />').'<br />';
                   12344:                                 }
                   12345:                             }
                   12346:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30  raeburn  12347:                         }
1.160.6.46  raeburn  12348:                         $resulttext .= '</ul></li>';
1.160.6.30  raeburn  12349:                     }
                   12350:                 }
1.160.6.39  raeburn  12351:                 if (ref($changes{'validation'}) eq 'HASH') {
                   12352:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   12353:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   12354:                         foreach my $item (@{$validationitemsref}) {
                   12355:                             if (exists($changes{'validation'}{$item})) {
                   12356:                                 if ($item eq 'markup') {
                   12357:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   12358:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   12359:                                 } else {
                   12360:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   12361:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   12362:                                 }
                   12363:                             }
                   12364:                         }
                   12365:                         if (exists($changes{'validation'}{'dc'})) {
                   12366:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   12367:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   12368:                         }
                   12369:                     }
                   12370:                 }
1.160.6.30  raeburn  12371:             }
1.1       raeburn  12372:             $resulttext .= '</ul>';
1.80      raeburn  12373:             if (keys(%newenv)) {
                   12374:                 &Apache::lonnet::appenv(\%newenv);
                   12375:             }
1.1       raeburn  12376:         } else {
1.86      raeburn  12377:             if ($context eq 'requestcourses') {
                   12378:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5  raeburn  12379:             } elsif ($context eq 'requestauthor') {
                   12380:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  12381:             } else {
1.90      weissno  12382:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  12383:             }
1.1       raeburn  12384:         }
                   12385:     } else {
1.11      albertel 12386:         $resulttext = '<span class="LC_error">'.
                   12387: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  12388:     }
1.160.6.30  raeburn  12389:     if ($errors) {
                   12390:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   12391:                        '<ul>'.$errors.'</ul></p>';
                   12392:     }
1.3       raeburn  12393:     return $resulttext;
1.1       raeburn  12394: }
                   12395: 
1.160.6.30  raeburn  12396: sub process_textbook_image {
1.160.6.46  raeburn  12397:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30  raeburn  12398:     my $filename = $env{'form.'.$caller.'.filename'};
                   12399:     my ($error,$url);
                   12400:     my ($width,$height) = (50,50);
                   12401:     if ($configuserok eq 'ok') {
                   12402:         if ($switchserver) {
                   12403:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   12404:                          $switchserver);
                   12405:         } elsif ($author_ok eq 'ok') {
                   12406:             my ($result,$imageurl) =
                   12407:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88  raeburn  12408:                              "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30  raeburn  12409:             if ($result eq 'ok') {
                   12410:                 $url = $imageurl;
                   12411:             } else {
                   12412:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   12413:             }
                   12414:         } else {
                   12415:             $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);
                   12416:         }
                   12417:     } else {
                   12418:         $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);
                   12419:     }
                   12420:     return ($url,$error);
                   12421: }
                   12422: 
1.160.6.118.2  1(raebur 12423:1): sub modify_ltitools {
                   12424:1):     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   12425:1):     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   12426:1):     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   12427:1):     my $confname = $dom.'-domainconfig';
                   12428:1):     my $servadm = $r->dir_config('lonAdmEMail');
                   12429:1):     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   12430:1):     my (%posslti,%possfield);
                   12431:1):     my @courseroles = ('cc','in','ta','ep','st');
                   12432:1):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   12433:1):     map { $posslti{$_} = 1; } @ltiroles;
                   12434:1):     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   12435:1):     map { $possfield{$_} = 1; } @allfields;
                   12436:1):     my %lt = &ltitools_names();
                   12437:1):     if ($env{'form.ltitools_add'}) {
                   12438:1):         my $title = $env{'form.ltitools_add_title'};
                   12439:1):         $title =~ s/(`)/'/g;
                   12440:1):         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   12441:1):         if ($newid) {
                   12442:1):             my $position = $env{'form.ltitools_add_pos'};
                   12443:1):             $position =~ s/\D+//g;
                   12444:1):             if ($position ne '') {
                   12445:1):                 $allpos[$position] = $newid;
                   12446:1):             }
                   12447:1):             $changes{$newid} = 1;
                   12448:1):             foreach my $item ('title','url','key','secret','lifetime') {
                   12449:1):                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
                   12450:1):                 if ($item eq 'lifetime') {
                   12451:1):                     $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
                   12452:1):                 }
                   12453:1):                 if ($env{'form.ltitools_add_'.$item}) {
                   12454:1):                     if (($item eq 'key') || ($item eq 'secret')) {
                   12455:1):                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   12456:1):                     } else {
                   12457:1):                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   12458:1):                     }
                   12459:1):                 }
                   12460:1):             }
                   12461:1):             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   12462:1):                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   12463:1):             }
                   12464:1):             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   12465:1):                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   12466:1):             }
                   12467:1):             if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
                   12468:1):                 $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
                   12469:1):             } else {
                   12470:1):                 $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
                   12471:1):             }
                   12472:1):             foreach my $item ('width','height','linktext','explanation') {
                   12473:1):                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   12474:1):                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
                   12475:1):                 if (($item eq 'width') || ($item eq 'height')) {
                   12476:1):                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   12477:1):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   12478:1):                     }
                   12479:1):                 } else {
                   12480:1):                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   12481:1):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   12482:1):                     }
                   12483:1):                 }
                   12484:1):             }
                   12485:1):             if ($env{'form.ltitools_add_target'} eq 'window') {
                   12486:1):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   12487:1):             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   12488:1):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   12489:1):             } else {
                   12490:1):                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   12491:1):             }
                   12492:1):             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   12493:1):                 my ($imageurl,$error) =
                   12494:1):                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
                   12495:1):                                             $configuserok,$switchserver,$author_ok);
                   12496:1):                 if ($imageurl) {
                   12497:1):                     $confhash{$newid}{'image'} = $imageurl;
                   12498:1):                 }
                   12499:1):                 if ($error) {
                   12500:1):                     &Apache::lonnet::logthis($error);
                   12501:1):                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12502:1):                 }
                   12503:1):             }
                   12504:1):             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   12505:1):             foreach my $field (@fields) {
                   12506:1):                 if ($possfield{$field}) {
                   12507:1):                     if ($field eq 'roles') {
                   12508:1):                         foreach my $role (@courseroles) {
                   12509:1):                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   12510:1):                             if (($choice ne '') && ($posslti{$choice})) {
                   12511:1):                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   12512:1):                                 if ($role eq 'cc') {
                   12513:1):                                     $confhash{$newid}{'roles'}{'co'} = $choice;
                   12514:1):                                 }
                   12515:1):                             }
                   12516:1):                         }
                   12517:1):                     } else {
                   12518:1):                         $confhash{$newid}{'fields'}{$field} = 1;
                   12519:1):                     }
                   12520:1):                 }
                   12521:1):             }
                   12522:1):             if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
                   12523:1):                 if ($confhash{$newid}{'fields'}{'user'}) {
                   12524:1):                     if ($env{'form.ltitools_userincdom_add'}) {
                   12525:1):                         $confhash{$newid}{'incdom'} = 1;
                   12526:1):                     }
                   12527:1):                 }
                   12528:1):             }
                   12529:1):             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   12530:1):             foreach my $item (@courseconfig) {
                   12531:1):                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   12532:1):             }
                   12533:1):             if ($env{'form.ltitools_add_custom'}) {
                   12534:1):                 my $name = $env{'form.ltitools_add_custom_name'};
                   12535:1):                 my $value = $env{'form.ltitools_add_custom_value'};
                   12536:1):                 $value =~ s/(`)/'/g;
                   12537:1):                 $name =~ s/(`)/'/g;
                   12538:1):                 $confhash{$newid}{'custom'}{$name} = $value;
                   12539:1):             }
                   12540:1):         } else {
                   12541:1):             my $error = &mt('Failed to acquire unique ID for new external tool');
                   12542:1):             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12543:1):         }
                   12544:1):     }
                   12545:1):     if (ref($domconfig{$action}) eq 'HASH') {
                   12546:1):         my %deletions;
                   12547:1):         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   12548:1):         if (@todelete) {
                   12549:1):             map { $deletions{$_} = 1; } @todelete;
                   12550:1):         }
                   12551:1):         my %customadds;
                   12552:1):         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   12553:1):         if (@newcustom) {
                   12554:1):             map { $customadds{$_} = 1; } @newcustom;
                   12555:1):         }
                   12556:1):         my %imgdeletions;
                   12557:1):         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   12558:1):         if (@todeleteimages) {
                   12559:1):             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   12560:1):         }
                   12561:1):         my $maxnum = $env{'form.ltitools_maxnum'};
                   12562:1):         for (my $i=0; $i<=$maxnum; $i++) {
                   12563:1):             my $itemid = $env{'form.ltitools_id_'.$i};
                   12564:1):             $itemid =~ s/\D+//g;
                   12565:1):             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12566:1):                 if ($deletions{$itemid}) {
                   12567:1):                     if ($domconfig{$action}{$itemid}{'image'}) {
                   12568:1):                         #FIXME need to obsolete item in RES space
                   12569:1):                     }
                   12570:1):                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   12571:1):                     next;
                   12572:1):                 } else {
                   12573:1):                     my $newpos = $env{'form.ltitools_'.$itemid};
                   12574:1):                     $newpos =~ s/\D+//g;
                   12575:1):                     foreach my $item ('title','url','lifetime') {
                   12576:1):                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12577:1):                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   12578:1):                             $changes{$itemid} = 1;
                   12579:1):                         }
                   12580:1):                     }
                   12581:1):                     foreach my $item ('key','secret') {
                   12582:1):                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12583:1):                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   12584:1):                             $changes{$itemid} = 1;
                   12585:1):                         }
                   12586:1):                     }
                   12587:1):                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   12588:1):                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   12589:1):                     }
                   12590:1):                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   12591:1):                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   12592:1):                     }
                   12593:1):                     if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
                   12594:1):                         $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
                   12595:1):                     } else {
                   12596:1):                         $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
                   12597:1):                     }
                   12598:1):                     if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
                   12599:1):                         if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
                   12600:1):                             $changes{$itemid} = 1;
                   12601:1):                         }
                   12602:1):                     } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
                   12603:1):                         $changes{$itemid} = 1;
                   12604:1):                     }
                   12605:1):                     foreach my $size ('width','height') {
                   12606:1):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   12607:1):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   12608:1):                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   12609:1):                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   12610:1):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12611:1):                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   12612:1):                                     $changes{$itemid} = 1;
                   12613:1):                                 }
                   12614:1):                             } else {
                   12615:1):                                 $changes{$itemid} = 1;
                   12616:1):                             }
                   12617:1):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12618:1):                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   12619:1):                                 $changes{$itemid} = 1;
                   12620:1):                             }
                   12621:1):                         }
                   12622:1):                     }
                   12623:1):                     foreach my $item ('linktext','explanation') {
                   12624:1):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   12625:1):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   12626:1):                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   12627:1):                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   12628:1):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12629:1):                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   12630:1):                                     $changes{$itemid} = 1;
                   12631:1):                                 }
                   12632:1):                             } else {
                   12633:1):                                 $changes{$itemid} = 1;
                   12634:1):                             }
                   12635:1):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12636:1):                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   12637:1):                                 $changes{$itemid} = 1;
                   12638:1):                             }
                   12639:1):                         }
                   12640:1):                     }
                   12641:1):                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   12642:1):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   12643:1):                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   12644:1):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   12645:1):                     } else {
                   12646:1):                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   12647:1):                     }
                   12648:1):                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   12649:1):                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   12650:1):                             $changes{$itemid} = 1;
                   12651:1):                         }
                   12652:1):                     } else {
                   12653:1):                         $changes{$itemid} = 1;
                   12654:1):                     }
                   12655:1):                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
                   12656:1):                     foreach my $item ('label','title','target','linktext','explanation','append') {
                   12657:1):                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   12658:1):                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   12659:1):                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   12660:1):                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   12661:1):                                     $changes{$itemid} = 1;
                   12662:1):                                 }
                   12663:1):                             } else {
                   12664:1):                                 $changes{$itemid} = 1;
                   12665:1):                             }
                   12666:1):                         }
                   12667:1):                     }
                   12668:1):                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   12669:1):                     foreach my $field (@fields) {
                   12670:1):                         if ($possfield{$field}) {
                   12671:1):                             if ($field eq 'roles') {
                   12672:1):                                 foreach my $role (@courseroles) {
                   12673:1):                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   12674:1):                                     if (($choice ne '') && ($posslti{$choice})) {
                   12675:1):                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   12676:1):                                         if ($role eq 'cc') {
                   12677:1):                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   12678:1):                                         }
                   12679:1):                                     }
                   12680:1):                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   12681:1):                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   12682:1):                                             $changes{$itemid} = 1;
                   12683:1):                                         }
                   12684:1):                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   12685:1):                                         $changes{$itemid} = 1;
                   12686:1):                                     }
                   12687:1):                                 }
                   12688:1):                             } else {
                   12689:1):                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   12690:1):                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   12691:1):                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   12692:1):                                         $changes{$itemid} = 1;
                   12693:1):                                     }
                   12694:1):                                 } else {
                   12695:1):                                     $changes{$itemid} = 1;
                   12696:1):                                 }
                   12697:1):                             }
                   12698:1):                         }
                   12699:1):                     }
                   12700:1):                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12701:1):                         if ($confhash{$itemid}{'fields'}{'user'}) {
                   12702:1):                             if ($env{'form.ltitools_userincdom_'.$i}) {
                   12703:1):                                 $confhash{$itemid}{'incdom'} = 1;
                   12704:1):                             }
                   12705:1):                             if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
                   12706:1):                                 $changes{$itemid} = 1;
                   12707:1):                             }
                   12708:1):                         }
                   12709:1):                     }
                   12710:1):                     $allpos[$newpos] = $itemid;
                   12711:1):                 }
                   12712:1):                 if ($imgdeletions{$itemid}) {
                   12713:1):                     $changes{$itemid} = 1;
                   12714:1):                     #FIXME need to obsolete item in RES space
                   12715:1):                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   12716:1):                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   12717:1):                                                                  $itemid,$configuserok,$switchserver,
                   12718:1):                                                                  $author_ok);
                   12719:1):                     if ($imgurl) {
                   12720:1):                         $confhash{$itemid}{'image'} = $imgurl;
                   12721:1):                         $changes{$itemid} = 1;
                   12722:1):                     }
                   12723:1):                     if ($error) {
                   12724:1):                         &Apache::lonnet::logthis($error);
                   12725:1):                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   12726:1):                     }
                   12727:1):                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   12728:1):                     $confhash{$itemid}{'image'} =
                   12729:1):                        $domconfig{$action}{$itemid}{'image'};
                   12730:1):                 }
                   12731:1):                 if ($customadds{$i}) {
                   12732:1):                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   12733:1):                     $name =~ s/(`)/'/g;
                   12734:1):                     $name =~ s/^\s+//;
                   12735:1):                     $name =~ s/\s+$//;
                   12736:1):                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   12737:1):                     $value =~ s/(`)/'/g;
                   12738:1):                     $value =~ s/^\s+//;
                   12739:1):                     $value =~ s/\s+$//;
                   12740:1):                     if ($name ne '') {
                   12741:1):                         $confhash{$itemid}{'custom'}{$name} = $value;
                   12742:1):                         $changes{$itemid} = 1;
                   12743:1):                     }
                   12744:1):                 }
                   12745:1):                 my %customdels;
                   12746:1):                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
                   12747:1):                 if (@customdeletions) {
                   12748:1):                     $changes{$itemid} = 1;
                   12749:1):                 }
                   12750:1):                 map { $customdels{$_} = 1; } @customdeletions;
                   12751:1):                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   12752:1):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   12753:1):                         unless ($customdels{$key}) {
                   12754:1):                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   12755:1):                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
                   12756:1):                             }
                   12757:1):                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   12758:1):                                 $changes{$itemid} = 1;
                   12759:1):                             }
                   12760:1):                         }
                   12761:1):                     }
                   12762:1):                 }
                   12763:1):                 unless ($changes{$itemid}) {
                   12764:1):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   12765:1):                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   12766:1):                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   12767:1):                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   12768:1):                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   12769:1):                                         $changes{$itemid} = 1;
                   12770:1):                                         last;
                   12771:1):                                     }
                   12772:1):                                 }
                   12773:1):                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   12774:1):                                 $changes{$itemid} = 1;
                   12775:1):                             }
                   12776:1):                         }
                   12777:1):                         last if ($changes{$itemid});
                   12778:1):                     }
                   12779:1):                 }
                   12780:1):             }
                   12781:1):         }
                   12782:1):     }
                   12783:1):     if (@allpos > 0) {
                   12784:1):         my $idx = 0;
                   12785:1):         foreach my $itemid (@allpos) {
                   12786:1):             if ($itemid ne '') {
                   12787:1):                 $confhash{$itemid}{'order'} = $idx;
                   12788:1):                 if (ref($domconfig{$action}) eq 'HASH') {
                   12789:1):                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   12790:1):                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   12791:1):                             $changes{$itemid} = 1;
                   12792:1):                         }
                   12793:1):                     }
                   12794:1):                 }
                   12795:1):                 $idx ++;
                   12796:1):             }
                   12797:1):         }
                   12798:1):     }
                   12799:1):     my %ltitoolshash = (
                   12800:1):                           $action => { %confhash }
                   12801:1):                        );
                   12802:1):     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   12803:1):                                              $dom);
                   12804:1):     if ($putresult eq 'ok') {
                   12805:1):         my %ltienchash = (
                   12806:1):                              $action => { %encconfig }
                   12807:1):                          );
                   12808:1):         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
                   12809:1):         if (keys(%changes) > 0) {
                   12810:1):             my $cachetime = 24*60*60;
                   12811:1):             my %ltiall = %confhash;
                   12812:1):             foreach my $id (keys(%ltiall)) {
                   12813:1):                 if (ref($encconfig{$id}) eq 'HASH') {
                   12814:1):                     foreach my $item ('key','secret') {
                   12815:1):                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   12816:1):                     }
                   12817:1):                 }
                   12818:1):             }
                   12819:1):             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
                   12820:1):             if (ref($lastactref) eq 'HASH') {
                   12821:1):                 $lastactref->{'ltitools'} = 1;
                   12822:1):             }
                   12823:1):             $resulttext = &mt('Changes made:').'<ul>';
                   12824:1):             my %bynum;
                   12825:1):             foreach my $itemid (sort(keys(%changes))) {
                   12826:1):                 my $position = $confhash{$itemid}{'order'};
                   12827:1):                 $bynum{$position} = $itemid;
                   12828:1):             }
                   12829:1):             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   12830:1):                 my $itemid = $bynum{$pos};
                   12831:1):                 if (ref($confhash{$itemid}) ne 'HASH') {
                   12832:1):                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   12833:1):                 } else {
                   12834:1):                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   12835:1):                     if ($confhash{$itemid}{'image'}) {
                   12836:1):                         $resulttext .= '&nbsp;'.
                   12837:1):                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   12838:1):                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   12839:1):                     }
                   12840:1):                     $resulttext .= '</li><ul>';
                   12841:1):                     my $position = $pos + 1;
                   12842:1):                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   12843:1):                     foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
                   12844:1):                         if ($confhash{$itemid}{$item} ne '') {
                   12845:1):                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   12846:1):                         }
                   12847:1):                     }
                   12848:1):                     if ($encconfig{$itemid}{'key'} ne '') {
                   12849:1):                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   12850:1):                     }
                   12851:1):                     if ($encconfig{$itemid}{'secret'} ne '') {
                   12852:1):                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   12853:1):                         my $num = length($encconfig{$itemid}{'secret'});
                   12854:1):                         $resulttext .= ('*'x$num).'</li>';
                   12855:1):                     }
                   12856:1):                     $resulttext .= '<li>'.&mt('Configurable in course:');
                   12857:1):                     my @possconfig = ('label','title','target','linktext','explanation','append');
                   12858:1):                     my $numconfig = 0;
                   12859:1):                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
                   12860:1):                         foreach my $item (@possconfig) {
                   12861:1):                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   12862:1):                                 $numconfig ++;
                   12863:1):                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
                   12864:1):                             }
                   12865:1):                         }
                   12866:1):                     }
                   12867:1):                     if (!$numconfig) {
                   12868:1):                         $resulttext .= &mt('None');
                   12869:1):                     }
                   12870:1):                     $resulttext .= '</li>';
                   12871:1):                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   12872:1):                         my $displaylist;
                   12873:1):                         if ($confhash{$itemid}{'display'}{'target'}) {
                   12874:1):                             $displaylist = &mt('Display target').':&nbsp;'.
                   12875:1):                                            $confhash{$itemid}{'display'}{'target'}.',';
                   12876:1):                         }
                   12877:1):                         foreach my $size ('width','height') {
                   12878:1):                             if ($confhash{$itemid}{'display'}{$size}) {
                   12879:1):                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   12880:1):                                                 $confhash{$itemid}{'display'}{$size}.',';
                   12881:1):                             }
                   12882:1):                         }
                   12883:1):                         if ($displaylist) {
                   12884:1):                             $displaylist =~ s/,$//;
                   12885:1):                             $resulttext .= '<li>'.$displaylist.'</li>';
                   12886:1):                         }
                   12887:1):                         foreach my $item ('linktext','explanation') {
                   12888:1):                             if ($confhash{$itemid}{'display'}{$item}) {
                   12889:1):                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   12890:1):                             }
                   12891:1):                         }
                   12892:1):                     }
                   12893:1):                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   12894:1):                         my $fieldlist;
                   12895:1):                         foreach my $field (@allfields) {
                   12896:1):                             if ($confhash{$itemid}{'fields'}{$field}) {
                   12897:1):                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   12898:1):                             }
                   12899:1):                         }
                   12900:1):                         if ($fieldlist) {
                   12901:1):                             $fieldlist =~ s/,$//;
                   12902:1):                             if ($confhash{$itemid}{'fields'}{'user'}) {
                   12903:1):                                 if ($confhash{$itemid}{'incdom'}) {
                   12904:1):                                     $fieldlist .= ' ('.&mt('username:domain').')';
                   12905:1):                                 } else {
                   12906:1):                                     $fieldlist .= ' ('.&mt('username').')';
                   12907:1):                                 }
                   12908:1):                             }
                   12909:1):                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   12910:1):                         }
                   12911:1):                     }
                   12912:1):                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   12913:1):                         my $rolemaps;
                   12914:1):                         foreach my $role (@courseroles) {
                   12915:1):                             if ($confhash{$itemid}{'roles'}{$role}) {
                   12916:1):                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   12917:1):                                              $confhash{$itemid}{'roles'}{$role}.',';
                   12918:1):                             }
                   12919:1):                         }
                   12920:1):                         if ($rolemaps) {
                   12921:1):                             $rolemaps =~ s/,$//;
                   12922:1):                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   12923:1):                         }
                   12924:1):                     }
                   12925:1):                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   12926:1):                         my $customlist;
                   12927:1):                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   12928:1):                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   12929:1):                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   12930:1):                             }
                   12931:1):                         }
                   12932:1):                         if ($customlist) {
                   12933:1):                             $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
                   12934:1):                         }
                   12935:1):                     }
                   12936:1):                     $resulttext .= '</ul></li>';
                   12937:1):                 }
                   12938:1):             }
                   12939:1):             $resulttext .= '</ul>';
                   12940:1):         } else {
                   12941:1):             $resulttext = &mt('No changes made.');
                   12942:1):         }
                   12943:1):     } else {
                   12944:1):         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   12945:1):     }
                   12946:1):     if ($errors) {
                   12947:1):         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   12948:1):                        $errors.'</ul>';
                   12949:1):     }
                   12950:1):     return $resulttext;
                   12951:1): }
                   12952:1): 
                   12953:1): sub process_ltitools_image {
                   12954:1):     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   12955:1):     my $filename = $env{'form.'.$caller.'.filename'};
                   12956:1):     my ($error,$url);
                   12957:1):     my ($width,$height) = (21,21);
                   12958:1):     if ($configuserok eq 'ok') {
                   12959:1):         if ($switchserver) {
                   12960:1):             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   12961:1):                          $switchserver);
                   12962:1):         } elsif ($author_ok eq 'ok') {
                   12963:1):             my ($result,$imageurl,$madethumb) =
                   12964:1):                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   12965:1):                              "ltitools/$itemid/icon",$width,$height);
                   12966:1):             if ($result eq 'ok') {
                   12967:1):                 if ($madethumb) {
                   12968:1):                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   12969:1):                     my $imagethumb = "$path/tn-".$imagefile;
                   12970:1):                     $url = $imagethumb;
                   12971:1):                 } else {
                   12972:1):                     $url = $imageurl;
                   12973:1):                 }
                   12974:1):             } else {
                   12975:1):                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   12976:1):             }
                   12977:1):         } else {
                   12978:1):             $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);
                   12979:1):         }
                   12980:1):     } else {
                   12981:1):         $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);
                   12982:1):     }
                   12983:1):     return ($url,$error);
                   12984:1): }
                   12985:1): 
                   12986:1): sub get_ltitools_id {
                   12987:1):     my ($cdom,$title) = @_;
                   12988:1):     # get lock on ltitools db
                   12989:1):     my $lockhash = {
                   12990:1):                       lock => $env{'user.name'}.
                   12991:1):                               ':'.$env{'user.domain'},
                   12992:1):                    };
                   12993:1):     my $tries = 0;
                   12994:1):     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   12995:1):     my ($id,$error);
                   12996:1): 
                   12997:1):     while (($gotlock ne 'ok') && ($tries<10)) {
                   12998:1):         $tries ++;
                   12999:1):         sleep (0.1);
                   13000:1):         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   13001:1):     }
                   13002:1):     if ($gotlock eq 'ok') {
                   13003:1):         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   13004:1):         if ($currids{'lock'}) {
                   13005:1):             delete($currids{'lock'});
                   13006:1):             if (keys(%currids)) {
                   13007:1):                 my @curr = sort { $a <=> $b } keys(%currids);
                   13008:1):                 if ($curr[-1] =~ /^\d+$/) {
                   13009:1):                     $id = 1 + $curr[-1];
                   13010:1):                 }
                   13011:1):             } else {
                   13012:1):                 $id = 1;
                   13013:1):             }
                   13014:1):             if ($id) {
                   13015:1):                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   13016:1):                     $error = 'nostore';
                   13017:1):                 }
                   13018:1):             } else {
                   13019:1):                 $error = 'nonumber';
                   13020:1):             }
                   13021:1):         }
                   13022:1):         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   13023:1):     } else {
                   13024:1):         $error = 'nolock';
                   13025:1):     }
                   13026:1):     return ($id,$error);
                   13027:1): }
                   13028:1): 
          5(raebur 13029:2): sub modify_lti {
                   13030:2):     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   13031:2):     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   13032:2):     my (%encconfig,$errors,$resulttext);
                   13033:2): 
                   13034:2):     my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
                   13035:2):     $newltisec{'private'}{'keys'} = [];
                   13036:2):     $newltisec{'encrypt'} = {};
                   13037:2):     $newltisec{'rules'} = {};
                   13038:2):     $newltisec{'linkprot'} = {};
                   13039:2):     if (ref($domconfig{'ltisec'}) eq 'HASH') {
                   13040:2):         %currltisec = %{$domconfig{'ltisec'}};
                   13041:2):         if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   13042:2):             foreach my $id (keys(%{$currltisec{'linkprot'}})) {
                   13043:2):                 unless ($id =~ /^\d+$/) {
                   13044:2):                     delete($currltisec{'linkprot'}{$id});
                   13045:2):                 }
                   13046:2):             }
                   13047:2):         }
                   13048:2):         if (ref($currltisec{'private'}) eq 'HASH') {
                   13049:2):             if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
                   13050:2):                 $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
                   13051:2):                 map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
                   13052:2):             }
                   13053:2):         }
                   13054:2):     }
                   13055:2):     foreach my $item ('crs','dom') {
                   13056:2):         my $formelement = 'form.ltisec_'.$item.'linkprot';
                   13057:2):         if ($env{$formelement}) {
                   13058:2):             $newltisec{'encrypt'}{$item} = 1;
                   13059:2):             if (ref($currltisec{'encrypt'}) eq 'HASH') {
                   13060:2):                 unless ($currltisec{'encrypt'}{$item}) {
                   13061:2):                     $secchanges{'encrypt'} = 1;
                   13062:2):                 }
                   13063:2):             } else {
                   13064:2):                 $secchanges{'encrypt'} = 1;
                   13065:2):             }
                   13066:2):         } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
                   13067:2):             if ($currltisec{'encrypt'}{$item}) {
                   13068:2):                 $secchanges{'encrypt'} = 1;
                   13069:2):             }
                   13070:2):         }
                   13071:2):     }
                   13072:2):     unless (exists($currltisec{'rules'})) {
                   13073:2):         $currltisec{'rules'} = {};
                   13074:2):     }
                   13075:2):     &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
                   13076:2): 
                   13077:2):     my @ids=&Apache::lonnet::current_machine_ids();
                   13078:2):     my %servers = &Apache::lonnet::get_servers($dom,'library');
                   13079:2): 
                   13080:2):     foreach my $hostid (keys(%servers)) {
                   13081:2):         if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
                   13082:2):             my $newkey;
                   13083:2):             my $keyitem = 'form.ltisec_privkey_'.$hostid;
                   13084:2):             if (exists($env{$keyitem})) {
                   13085:2):                 $env{$keyitem} =~ s/(`)/'/g;
                   13086:2):                 if ($keyset{$hostid}) {
                   13087:2):                     if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
                   13088:2):                         if ($env{$keyitem} ne '') {
                   13089:2):                             $secchanges{'private'} = 1;
                   13090:2):                             $newkeyset{$hostid} = $env{$keyitem};
                   13091:2):                         }
                   13092:2):                     }
                   13093:2):                 } elsif ($env{$keyitem} ne '') {
                   13094:2):                     unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
                   13095:2):                         push(@{$newltisec{'private'}{'keys'}},$hostid);
                   13096:2):                     }
                   13097:2):                     $secchanges{'private'} = 1;
                   13098:2):                     $newkeyset{$hostid} = $env{$keyitem};
                   13099:2):                 }
                   13100:2):             }
                   13101:2):         }
                   13102:2):     }
                   13103:2): 
                   13104:2):     my (%linkprotchg,$linkprotoutput,$is_home);
                   13105:2):     my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
                   13106:2):                                                            \%linkprotchg,'domain');
                   13107:2):     my $home = &Apache::lonnet::domain($dom,'primary');
                   13108:2):     unless (($home eq 'no_host') || ($home eq '')) {
                   13109:2):         my @ids=&Apache::lonnet::current_machine_ids();
                   13110:2):         foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
                   13111:2):     }
                   13112:2): 
                   13113:2):     if (keys(%linkprotchg)) {
                   13114:2):         $secchanges{'linkprot'} = 1;
                   13115:2):         my %oldlinkprot;
                   13116:2):         if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   13117:2):             %oldlinkprot = %{$currltisec{'linkprot'}};
                   13118:2):         }
                   13119:2):         foreach my $id (keys(%linkprotchg)) {
                   13120:2):             if (ref($linkprotchg{$id}) eq 'HASH') {
                   13121:2):                 foreach my $inner (keys(%{$linkprotchg{$id}})) {
                   13122:2):                     if (($inner eq 'secret') || ($inner eq 'key')) {
                   13123:2):                         if ($is_home) {
                   13124:2):                             $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
                   13125:2):                         }
                   13126:2):                     }
                   13127:2):                 }
                   13128:2):             } else {
                   13129:2):                 $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
                   13130:2):             }
                   13131:2):         }
                   13132:2):         $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
                   13133:2):         if (keys(%linkprotchg)) {
                   13134:2):             %{$newltisec{'linkprot'}} = %linkprotchg;
                   13135:2):         }
                   13136:2):     }
                   13137:2):     if (ref($currltisec{'linkprot'}) eq 'HASH') {
                   13138:2):         foreach my $id (%{$currltisec{'linkprot'}}) {
                   13139:2):             next if ($id !~ /^\d+$/);
                   13140:2):             unless (exists($linkprotchg{$id})) {
                   13141:2):                 if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
                   13142:2):                     foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
                   13143:2):                         if (($inner eq 'secret') || ($inner eq 'key')) {
                   13144:2):                             if ($is_home) {
                   13145:2):                                 $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   13146:2):                             }
                   13147:2):                         } else {
                   13148:2):                             $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
                   13149:2):                         }
                   13150:2):                     }
                   13151:2):                 } else {
                   13152:2):                     $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
                   13153:2):                 }
                   13154:2):             }
                   13155:2):         }
                   13156:2):     }
                   13157:2):     if ($proterror) {
                   13158:2):         $errors .= '<li>'.$proterror.'</li>';
                   13159:2):     }
                   13160:2): 
          6(raebur 13161:2):     my ($putresult,%keystore);
          5(raebur 13162:2):     if (keys(%secchanges)) {
                   13163:2):         my %ltienchash;
                   13164:2):         my %ltihash = (
                   13165:2):                           'ltisec' => { %newltisec }
                   13166:2):                       );
                   13167:2):         $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
                   13168:2):         if ($putresult eq 'ok') {
                   13169:2):             if ($secchanges{'private'}) {
                   13170:2):                 my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
                   13171:2):                 foreach my $hostid (keys(%newkeyset)) {
                   13172:2):                     my $storehash = {
                   13173:2):                                        key => $newkeyset{$hostid},
                   13174:2):                                        who => $env{'user.name'}.':'.$env{'user.domain'},
                   13175:2):                                     };
                   13176:2):                     $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
                   13177:2):                                                                     $dom,$hostid);
                   13178:2):                 }
                   13179:2):             }
                   13180:2):             if (ref($lastactref) eq 'HASH') {
                   13181:2):                 if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
                   13182:2):                     $lastactref->{'domdefaults'} = 1;
                   13183:2):                 }
                   13184:2):             }
                   13185:2):             if (($secchanges{'linkprot'}) && ($is_home)) {
                   13186:2):                 my %ltienchash = (
                   13187:2):                                      'linkprot' =>  { %newltienc }
                   13188:2):                                  );
                   13189:2):                 &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
                   13190:2):             }
                   13191:2):         }
                   13192:2):     } else {
                   13193:2):         return &mt('No changes made.');
                   13194:2):     }
                   13195:2):     if ($putresult eq 'ok') {
                   13196:2):         $resulttext = &mt('Changes made:').'<ul>';
                   13197:2):         foreach my $item (keys(%secchanges)) {
                   13198:2):             if ($item eq 'encrypt') {
                   13199:2):                 my %encrypted = (
                   13200:2):                           crs  => {
                   13201:2):                                     on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
                   13202:2):                                     off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
                   13203:2):                                   },
                   13204:2):                           dom => {
                   13205:2):                                    on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
                   13206:2):                                    off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
                   13207:2):                                  },
                   13208:2):                 );
                   13209:2):                 foreach my $type ('crs','dom') {
                   13210:2):                     my $shown = $encrypted{$type}{'off'};
                   13211:2):                     if (ref($newltisec{$item}) eq 'HASH') {
                   13212:2):                         if ($newltisec{$item}{$type}) {
                   13213:2):                             $shown = $encrypted{$type}{'on'};
                   13214:2):                         }
                   13215:2):                     }
                   13216:2):                     $resulttext .= '<li>'.$shown.'</li>';
                   13217:2):                 }
                   13218:2):             } elsif ($item eq 'rules') {
                   13219:2):                 my %titles = &Apache::lonlocal::texthash(
                   13220:2):                                   min   => 'Minimum password length',
                   13221:2):                                   max   => 'Maximum password length',
                   13222:2):                                   chars => 'Required characters',
                   13223:2):                 );
                   13224:2):                 foreach my $rule ('min','max') {
                   13225:2):                     if ($newltisec{rules}{$rule} eq '') {
                   13226:2):                         if ($rule eq 'min') {
                   13227:2):                             $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
                   13228:2):                                            ' '.&mt('Default of [_1] will be used',
                   13229:2):                                                        $Apache::lonnet::passwdmin).'</li>';
                   13230:2):                         } else {
                   13231:2):                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   13232:2):                         }
                   13233:2):                     } else {
                   13234:2):                         $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
                   13235:2):                     }
                   13236:2):                 }
                   13237:2):                 if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
                   13238:2):                     if (@{$newltisec{'rules'}{'chars'}} > 0) {
                   13239:2):                         my %rulenames = &Apache::lonlocal::texthash(
                   13240:2):                                             uc => 'At least one upper case letter',
                   13241:2):                                             lc => 'At least one lower case letter',
                   13242:2):                                             num => 'At least one number',
                   13243:2):                                             spec => 'At least one non-alphanumeric',
                   13244:2):                                             );
                   13245:2):                         my $needed = '<ul><li>'.
                   13246:2):                                      join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
                   13247:2):                                      '</li></ul>';
                   13248:2):                         $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   13249:2):                     } else {
                   13250:2):                         $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   13251:2):                     }
                   13252:2):                 } else {
                   13253:2):                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   13254:2):                 }
                   13255:2):             } elsif ($item eq 'private') {
                   13256:2):                 if (keys(%newkeyset)) {
                   13257:2):                     foreach my $hostid (sort(keys(%newkeyset))) {
                   13258:2):                         if ($keystore{$hostid} eq 'ok') {
                   13259:2):                             $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
                   13260:2):                         }
                   13261:2):                     }
                   13262:2):                 }
                   13263:2):             } elsif ($item eq 'linkprot') {
                   13264:2):                 $resulttext .= $linkprotoutput;
                   13265:2):             }
                   13266:2):         }
                   13267:2):         $resulttext .= '</ul>';
                   13268:2):     } else {
                   13269:2):         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   13270:2):     }
                   13271:2):     if ($errors) {
                   13272:2):         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   13273:2):                        $errors.'</ul>';
                   13274:2):     }
                   13275:2):     return $resulttext;
                   13276:2): }
                   13277:2): 
1.3       raeburn  13278: sub modify_autoenroll {
1.160.6.24  raeburn  13279:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  13280:     my ($resulttext,%changes);
                   13281:     my %currautoenroll;
                   13282:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   13283:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   13284:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   13285:         }
                   13286:     }
                   13287:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   13288:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  13289:                   sender => 'Sender for notification messages',
1.160.6.68  raeburn  13290:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116  raeburn  13291:                   autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  13292:     my @offon = ('off','on');
1.17      raeburn  13293:     my $sender_uname = $env{'form.sender_uname'};
                   13294:     my $sender_domain = $env{'form.sender_domain'};
                   13295:     if ($sender_domain eq '') {
                   13296:         $sender_uname = '';
                   13297:     } elsif ($sender_uname eq '') {
                   13298:         $sender_domain = '';
                   13299:     }
1.129     raeburn  13300:     my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116  raeburn  13301:     my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
                   13302:     $autofailsafe =~ s{^\s+|\s+$}{}g;
                   13303:     if ($autofailsafe =~ /\D/) {
                   13304:         undef($autofailsafe);
                   13305:     }
1.160.6.68  raeburn  13306:     my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116  raeburn  13307:     unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
                   13308:         $failsafe = 'off';
                   13309:         undef($autofailsafe);
1.160.6.68  raeburn  13310:     }
1.1       raeburn  13311:     my %autoenrollhash =  (
1.129     raeburn  13312:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   13313:                                        'sender_uname' => $sender_uname,
                   13314:                                        'sender_domain' => $sender_domain,
                   13315:                                        'co-owners' => $coowners,
1.160.6.116  raeburn  13316:                                        'autofailsafe' => $autofailsafe,
                   13317:                                        'failsafe' => $failsafe,
1.1       raeburn  13318:                                 }
                   13319:                      );
1.4       raeburn  13320:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   13321:                                              $dom);
1.1       raeburn  13322:     if ($putresult eq 'ok') {
                   13323:         if (exists($currautoenroll{'run'})) {
                   13324:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   13325:                  $changes{'run'} = 1;
                   13326:              }
                   13327:         } elsif ($autorun) {
                   13328:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  13329:                  $changes{'run'} = 1;
1.1       raeburn  13330:             }
                   13331:         }
1.17      raeburn  13332:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  13333:             $changes{'sender'} = 1;
                   13334:         }
1.17      raeburn  13335:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  13336:             $changes{'sender'} = 1;
                   13337:         }
1.129     raeburn  13338:         if ($currautoenroll{'co-owners'} ne '') {
                   13339:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   13340:                 $changes{'coowners'} = 1;
                   13341:             }
                   13342:         } elsif ($coowners) {
                   13343:             $changes{'coowners'} = 1;
1.160.6.68  raeburn  13344:         }
1.160.6.116  raeburn  13345:         if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68  raeburn  13346:             $changes{'autofailsafe'} = 1;
                   13347:         }
1.160.6.116  raeburn  13348:         if ($currautoenroll{'failsafe'} ne $failsafe) {
                   13349:             $changes{'failsafe'} = 1;
                   13350:         }
1.1       raeburn  13351:         if (keys(%changes) > 0) {
                   13352:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  13353:             if ($changes{'run'}) {
1.1       raeburn  13354:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   13355:             }
                   13356:             if ($changes{'sender'}) {
1.17      raeburn  13357:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   13358:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   13359:                 } else {
                   13360:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   13361:                 }
1.1       raeburn  13362:             }
1.129     raeburn  13363:             if ($changes{'coowners'}) {
                   13364:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   13365:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  13366:                 if (ref($lastactref) eq 'HASH') {
                   13367:                     $lastactref->{'domainconfig'} = 1;
                   13368:                 }
1.129     raeburn  13369:             }
1.160.6.68  raeburn  13370:             if ($changes{'autofailsafe'}) {
1.160.6.116  raeburn  13371:                 if ($autofailsafe ne '') {
                   13372:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68  raeburn  13373:                 } else {
1.160.6.116  raeburn  13374:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68  raeburn  13375:                 }
1.160.6.116  raeburn  13376:             }
                   13377:             if ($changes{'failsafe'}) {
                   13378:                 if ($failsafe eq 'off') {
                   13379:                     unless ($changes{'autofailsafe'}) {
                   13380:                         $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
                   13381:                     }
                   13382:                 } elsif ($failsafe eq 'zero') {
                   13383:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
                   13384:                 } else {
                   13385:                     $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
                   13386:                 }
                   13387:             }
                   13388:             if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68  raeburn  13389:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   13390:                 if (ref($lastactref) eq 'HASH') {
                   13391:                     $lastactref->{'domdefaults'} = 1;
                   13392:                 }
                   13393:             }
1.1       raeburn  13394:             $resulttext .= '</ul>';
                   13395:         } else {
                   13396:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   13397:         }
                   13398:     } else {
1.11      albertel 13399:         $resulttext = '<span class="LC_error">'.
                   13400: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13401:     }
1.3       raeburn  13402:     return $resulttext;
1.1       raeburn  13403: }
                   13404: 
                   13405: sub modify_autoupdate {
1.3       raeburn  13406:     my ($dom,%domconfig) = @_;
1.1       raeburn  13407:     my ($resulttext,%currautoupdate,%fields,%changes);
                   13408:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   13409:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   13410:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   13411:         }
                   13412:     }
                   13413:     my @offon = ('off','on');
                   13414:     my %title = &Apache::lonlocal::texthash (
1.160.6.113  raeburn  13415:                     run        => 'Auto-update:',
                   13416:                     classlists => 'Updates to user information in classlists?',
                   13417:                     unexpired  => 'Skip updates for users without active or future roles?',
                   13418:                     lastactive => 'Skip updates for inactive users?',
1.1       raeburn  13419:                 );
1.44      raeburn  13420:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  13421:     my %fieldtitles = &Apache::lonlocal::texthash (
                   13422:                         id => 'Student/Employee ID',
1.20      raeburn  13423:                         permanentemail => 'E-mail address',
1.1       raeburn  13424:                         lastname => 'Last Name',
                   13425:                         firstname => 'First Name',
                   13426:                         middlename => 'Middle Name',
1.132     raeburn  13427:                         generation => 'Generation',
1.1       raeburn  13428:                       );
1.142     raeburn  13429:     $othertitle = &mt('All users');
1.1       raeburn  13430:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  13431:         $othertitle = &mt('Other users');
1.1       raeburn  13432:     }
                   13433:     foreach my $key (keys(%env)) {
                   13434:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  13435:             my ($usertype,$item) = ($1,$2);
                   13436:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   13437:                 if ($usertype eq 'default') {   
                   13438:                     push(@{$fields{$1}},$2);
                   13439:                 } elsif (ref($types) eq 'ARRAY') {
                   13440:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   13441:                         push(@{$fields{$1}},$2);
                   13442:                     }
                   13443:                 }
                   13444:             }
1.1       raeburn  13445:         }
                   13446:     }
1.131     raeburn  13447:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   13448:     @lockablenames = sort(@lockablenames);
                   13449:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   13450:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13451:         if (@changed) {
                   13452:             $changes{'lockablenames'} = 1;
                   13453:         }
                   13454:     } else {
                   13455:         if (@lockablenames) {
                   13456:             $changes{'lockablenames'} = 1;
                   13457:         }
                   13458:     }
1.1       raeburn  13459:     my %updatehash = (
                   13460:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   13461:                                       classlists => $env{'form.classlists'},
1.160.6.113  raeburn  13462:                                       unexpired  => $env{'form.unexpired'},
1.1       raeburn  13463:                                       fields => {%fields},
1.131     raeburn  13464:                                       lockablenames => \@lockablenames,
1.1       raeburn  13465:                                     }
                   13466:                      );
1.160.6.113  raeburn  13467:     my $lastactivedays;
                   13468:     if ($env{'form.lastactive'}) {
                   13469:         $lastactivedays = $env{'form.lastactivedays'};
                   13470:         $lastactivedays =~ s/^\s+|\s+$//g;
                   13471:         unless ($lastactivedays =~ /^\d+$/) {
                   13472:             undef($lastactivedays);
                   13473:             $env{'form.lastactive'} = 0;
                   13474:         }
                   13475:     }
                   13476:     $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1       raeburn  13477:     foreach my $key (keys(%currautoupdate)) {
1.160.6.113  raeburn  13478:         if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1       raeburn  13479:             if (exists($updatehash{autoupdate}{$key})) {
                   13480:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   13481:                     $changes{$key} = 1;
                   13482:                 }
                   13483:             }
                   13484:         } elsif ($key eq 'fields') {
                   13485:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  13486:                 foreach my $item (@{$types},'default') {
1.1       raeburn  13487:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   13488:                         my $change = 0;
                   13489:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   13490:                             if (!exists($fields{$item})) {
                   13491:                                 $change = 1;
1.132     raeburn  13492:                                 last;
1.1       raeburn  13493:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  13494:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  13495:                                     $change = 1;
1.132     raeburn  13496:                                     last;
1.1       raeburn  13497:                                 }
                   13498:                             }
                   13499:                         }
                   13500:                         if ($change) {
                   13501:                             push(@{$changes{$key}},$item);
                   13502:                         }
1.26      raeburn  13503:                     } 
1.1       raeburn  13504:                 }
                   13505:             }
1.131     raeburn  13506:         } elsif ($key eq 'lockablenames') {
                   13507:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   13508:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   13509:                 if (@changed) {
                   13510:                     $changes{'lockablenames'} = 1;
                   13511:                 }
                   13512:             } else {
                   13513:                 if (@lockablenames) {
                   13514:                     $changes{'lockablenames'} = 1;
                   13515:                 }
                   13516:             }
                   13517:         }
                   13518:     }
                   13519:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   13520:         if (@lockablenames) {
                   13521:             $changes{'lockablenames'} = 1;
1.1       raeburn  13522:         }
                   13523:     }
1.160.6.113  raeburn  13524:     unless (grep(/^unexpired$/,keys(%currautoupdate))) {
                   13525:         if ($updatehash{'autoupdate'}{'unexpired'}) {
                   13526:             $changes{'unexpired'} = 1;
                   13527:         }
                   13528:     }
                   13529:     unless (grep(/^lastactive$/,keys(%currautoupdate))) {
                   13530:         if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
                   13531:             $changes{'lastactive'} = 1;
                   13532:         }
                   13533:     }
1.26      raeburn  13534:     foreach my $item (@{$types},'default') {
                   13535:         if (defined($fields{$item})) {
                   13536:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  13537:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   13538:                     my $change = 0;
                   13539:                     if (ref($fields{$item}) eq 'ARRAY') {
                   13540:                         foreach my $type (@{$fields{$item}}) {
                   13541:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   13542:                                 $change = 1;
                   13543:                                 last;
                   13544:                             }
                   13545:                         }
                   13546:                     }
                   13547:                     if ($change) {
                   13548:                         push(@{$changes{'fields'}},$item);
                   13549:                     }
                   13550:                 } else {
1.26      raeburn  13551:                     push(@{$changes{'fields'}},$item);
                   13552:                 }
                   13553:             } else {
                   13554:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  13555:             }
                   13556:         }
                   13557:     }
                   13558:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   13559:                                              $dom);
                   13560:     if ($putresult eq 'ok') {
                   13561:         if (keys(%changes) > 0) {
                   13562:             $resulttext = &mt('Changes made:').'<ul>';
                   13563:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  13564:                 if ($key eq 'lockablenames') {
                   13565:                     $resulttext .= '<li>';
                   13566:                     if (@lockablenames) {
                   13567:                         $usertypes->{'default'} = $othertitle;
                   13568:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   13569:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   13570:                     } else {
                   13571:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   13572:                     }
                   13573:                     $resulttext .= '</li>';
                   13574:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  13575:                     foreach my $item (@{$changes{$key}}) {
                   13576:                         my @newvalues;
                   13577:                         foreach my $type (@{$fields{$item}}) {
                   13578:                             push(@newvalues,$fieldtitles{$type});
                   13579:                         }
1.3       raeburn  13580:                         my $newvaluestr;
                   13581:                         if (@newvalues > 0) {
                   13582:                             $newvaluestr = join(', ',@newvalues);
                   13583:                         } else {
                   13584:                             $newvaluestr = &mt('none');
1.6       raeburn  13585:                         }
1.1       raeburn  13586:                         if ($item eq 'default') {
1.26      raeburn  13587:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  13588:                         } else {
1.26      raeburn  13589:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  13590:                         }
                   13591:                     }
                   13592:                 } else {
                   13593:                     my $newvalue;
                   13594:                     if ($key eq 'run') {
                   13595:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113  raeburn  13596:                     } elsif ($key eq 'lastactive') {
                   13597:                         $newvalue = $offon[$env{'form.lastactive'}];
                   13598:                         unless ($lastactivedays eq '') {
                   13599:                             $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
                   13600:                         }
1.1       raeburn  13601:                     } else {
                   13602:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  13603:                     }
1.1       raeburn  13604:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   13605:                 }
                   13606:             }
                   13607:             $resulttext .= '</ul>';
                   13608:         } else {
1.3       raeburn  13609:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  13610:         }
                   13611:     } else {
1.11      albertel 13612:         $resulttext = '<span class="LC_error">'.
                   13613: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  13614:     }
1.3       raeburn  13615:     return $resulttext;
1.1       raeburn  13616: }
                   13617: 
1.125     raeburn  13618: sub modify_autocreate {
                   13619:     my ($dom,%domconfig) = @_;
                   13620:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   13621:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   13622:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   13623:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   13624:         }
                   13625:     }
                   13626:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   13627:                  req => 'Auto-creation of validated requests for official courses',
                   13628:                  xmldc => 'Identity of course creator of courses from XML files',
                   13629:                );
                   13630:     my @types = ('xml','req');
                   13631:     foreach my $item (@types) {
                   13632:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   13633:         $newvals{$item} =~ s/\D//g;
                   13634:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   13635:     }
                   13636:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77  raeburn  13637:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  13638:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   13639:         $newvals{'xmldc'} = '';
                   13640:     } 
                   13641:     %autocreatehash =  (
                   13642:                         autocreate => { xml => $newvals{'xml'},
                   13643:                                         req => $newvals{'req'},
                   13644:                                       }
                   13645:                        );
                   13646:     if ($newvals{'xmldc'} ne '') {
                   13647:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   13648:     }
                   13649:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   13650:                                              $dom);
                   13651:     if ($putresult eq 'ok') {
                   13652:         my @items = @types;
                   13653:         if ($newvals{'xml'}) {
                   13654:             push(@items,'xmldc');
                   13655:         }
                   13656:         foreach my $item (@items) {
                   13657:             if (exists($currautocreate{$item})) {
                   13658:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   13659:                     $changes{$item} = 1;
                   13660:                 }
                   13661:             } elsif ($newvals{$item}) {
                   13662:                 $changes{$item} = 1;
                   13663:             }
                   13664:         }
                   13665:         if (keys(%changes) > 0) {
                   13666:             my @offon = ('off','on'); 
                   13667:             $resulttext = &mt('Changes made:').'<ul>';
                   13668:             foreach my $item (@types) {
                   13669:                 if ($changes{$item}) {
                   13670:                     my $newtxt = $offon[$newvals{$item}];
1.160.6.13  raeburn  13671:                     $resulttext .= '<li>'.
                   13672:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   13673:                                        '<b>','</b>').
                   13674:                                    '</li>';
1.125     raeburn  13675:                 }
                   13676:             }
                   13677:             if ($changes{'xmldc'}) {
                   13678:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   13679:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13  raeburn  13680:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  13681:             }
                   13682:             $resulttext .= '</ul>';
                   13683:         } else {
                   13684:             $resulttext = &mt('No changes made to auto-creation settings');
                   13685:         }
                   13686:     } else {
                   13687:         $resulttext = '<span class="LC_error">'.
                   13688:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13689:     }
                   13690:     return $resulttext;
                   13691: }
                   13692: 
1.23      raeburn  13693: sub modify_directorysrch {
1.160.6.81  raeburn  13694:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  13695:     my ($resulttext,%changes);
                   13696:     my %currdirsrch;
                   13697:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   13698:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   13699:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   13700:         }
                   13701:     }
1.160.6.72  raeburn  13702:     my %title = ( available => 'Institutional directory search available',
                   13703:                   localonly => 'Other domains can search institution',
                   13704:                   lcavailable => 'LON-CAPA directory search available',
                   13705:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  13706:                   searchby => 'Search types',
                   13707:                   searchtypes => 'Search latitude');
                   13708:     my @offon = ('off','on');
1.24      raeburn  13709:     my @otherdoms = ('Yes','No');
1.23      raeburn  13710: 
1.25      raeburn  13711:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  13712:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   13713:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   13714: 
1.44      raeburn  13715:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  13716:     if (keys(%{$usertypes}) == 0) {
                   13717:         @cansearch = ('default');
                   13718:     } else {
                   13719:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   13720:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   13721:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   13722:                     push(@{$changes{'cansearch'}},$type);
                   13723:                 }
1.23      raeburn  13724:             }
1.26      raeburn  13725:             foreach my $type (@cansearch) {
                   13726:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   13727:                     push(@{$changes{'cansearch'}},$type);
                   13728:                 }
1.23      raeburn  13729:             }
1.26      raeburn  13730:         } else {
                   13731:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  13732:         }
                   13733:     }
                   13734: 
                   13735:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   13736:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   13737:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   13738:                 push(@{$changes{'searchby'}},$by);
                   13739:             }
                   13740:         }
                   13741:         foreach my $by (@searchby) {
                   13742:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   13743:                 push(@{$changes{'searchby'}},$by);
                   13744:             }
                   13745:         }
                   13746:     } else {
                   13747:         push(@{$changes{'searchby'}},@searchby);
                   13748:     }
1.25      raeburn  13749: 
                   13750:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   13751:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   13752:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   13753:                 push(@{$changes{'searchtypes'}},$type);
                   13754:             }
                   13755:         }
                   13756:         foreach my $type (@searchtypes) {
                   13757:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   13758:                 push(@{$changes{'searchtypes'}},$type);
                   13759:             }
                   13760:         }
                   13761:     } else {
                   13762:         if (exists($currdirsrch{'searchtypes'})) {
                   13763:             foreach my $type (@searchtypes) {  
                   13764:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   13765:                     push(@{$changes{'searchtypes'}},$type);
                   13766:                 }
                   13767:             }
                   13768:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   13769:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   13770:             }   
                   13771:         } else {
                   13772:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   13773:         }
                   13774:     }
                   13775: 
1.23      raeburn  13776:     my %dirsrch_hash =  (
                   13777:             directorysrch => { available => $env{'form.dirsrch_available'},
                   13778:                                cansearch => \@cansearch,
1.160.6.72  raeburn  13779:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   13780:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   13781:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  13782:                                searchby => \@searchby,
1.25      raeburn  13783:                                searchtypes => \@searchtypes,
1.23      raeburn  13784:                              }
                   13785:             );
                   13786:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   13787:                                              $dom);
                   13788:     if ($putresult eq 'ok') {
                   13789:         if (exists($currdirsrch{'available'})) {
                   13790:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   13791:                  $changes{'available'} = 1;
                   13792:              }
                   13793:         } else {
                   13794:             if ($env{'form.dirsrch_available'} eq '1') {
                   13795:                 $changes{'available'} = 1;
                   13796:             }
                   13797:         }
1.160.6.72  raeburn  13798:         if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78  raeburn  13799:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   13800:                 $changes{'lcavailable'} = 1;
                   13801:             }
1.24      raeburn  13802:         } else {
1.160.6.72  raeburn  13803:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   13804:                 $changes{'lcavailable'} = 1;
                   13805:             }
                   13806:         }
                   13807:         if (exists($currdirsrch{'localonly'})) {
                   13808:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  13809:                 $changes{'localonly'} = 1;
                   13810:             }
1.160.6.72  raeburn  13811:         } else {
                   13812:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
                   13813:                 $changes{'localonly'} = 1;
                   13814:             }
                   13815:         }
                   13816:         if (exists($currdirsrch{'lclocalonly'})) {
                   13817:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   13818:                 $changes{'lclocalonly'} = 1;
                   13819:             }
                   13820:         } else {
                   13821:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   13822:                 $changes{'lclocalonly'} = 1;
                   13823:             }
1.24      raeburn  13824:         }
1.23      raeburn  13825:         if (keys(%changes) > 0) {
                   13826:             $resulttext = &mt('Changes made:').'<ul>';
                   13827:             if ($changes{'available'}) {
                   13828:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   13829:             }
1.160.6.72  raeburn  13830:             if ($changes{'lcavailable'}) {
                   13831:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   13832:             }
1.24      raeburn  13833:             if ($changes{'localonly'}) {
1.160.6.72  raeburn  13834:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
                   13835:             }
                   13836:             if ($changes{'lclocalonly'}) {
                   13837:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24      raeburn  13838:             }
1.23      raeburn  13839:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   13840:                 my $chgtext;
1.26      raeburn  13841:                 if (ref($usertypes) eq 'HASH') {
                   13842:                     if (keys(%{$usertypes}) > 0) {
                   13843:                         foreach my $type (@{$types}) {
                   13844:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   13845:                                 $chgtext .= $usertypes->{$type}.'; ';
                   13846:                             }
                   13847:                         }
                   13848:                         if (grep(/^default$/,@cansearch)) {
                   13849:                             $chgtext .= $othertitle;
                   13850:                         } else {
                   13851:                             $chgtext =~ s/\; $//;
                   13852:                         }
1.160.6.13  raeburn  13853:                         $resulttext .=
                   13854:                             '<li>'.
                   13855:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   13856:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   13857:                             '</li>';
1.23      raeburn  13858:                     }
                   13859:                 }
                   13860:             }
                   13861:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   13862:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   13863:                 my $chgtext;
                   13864:                 foreach my $type (@{$titleorder}) {
                   13865:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   13866:                         if (defined($searchtitles->{$type})) {
                   13867:                             $chgtext .= $searchtitles->{$type}.'; ';
                   13868:                         }
                   13869:                     }
                   13870:                 }
                   13871:                 $chgtext =~ s/\; $//;
                   13872:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   13873:             }
1.25      raeburn  13874:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   13875:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   13876:                 my $chgtext;
                   13877:                 foreach my $type (@{$srchtypeorder}) {
                   13878:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   13879:                         if (defined($srchtypes_desc->{$type})) {
                   13880:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   13881:                         }
                   13882:                     }
                   13883:                 }
                   13884:                 $chgtext =~ s/\; $//;
1.160.6.13  raeburn  13885:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  13886:             }
                   13887:             $resulttext .= '</ul>';
1.160.6.81  raeburn  13888:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   13889:             if (ref($lastactref) eq 'HASH') {
                   13890:                 $lastactref->{'directorysrch'} = 1;
                   13891:             }
1.23      raeburn  13892:         } else {
1.160.6.72  raeburn  13893:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  13894:         }
                   13895:     } else {
                   13896:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  13897:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   13898:     }
                   13899:     return $resulttext;
                   13900: }
                   13901: 
1.28      raeburn  13902: sub modify_contacts {
1.160.6.24  raeburn  13903:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  13904:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   13905:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   13906:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   13907:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   13908:         }
                   13909:     }
1.160.6.78  raeburn  13910:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  13911:     my @contacts = ('supportemail','adminemail');
1.160.6.78  raeburn  13912:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95  raeburn  13913:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107  raeburn  13914:     my @toggles = ('reporterrors','reportupdates','reportstatus');
                   13915:     my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78  raeburn  13916:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  13917:     foreach my $type (@mailings) {
                   13918:         @{$newsetting{$type}} = 
                   13919:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   13920:         foreach my $item (@contacts) {
                   13921:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   13922:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   13923:             } else {
                   13924:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   13925:             }
1.160.6.78  raeburn  13926:         }
1.28      raeburn  13927:         $others{$type} = $env{'form.'.$type.'_others'};
                   13928:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78  raeburn  13929:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  13930:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   13931:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78  raeburn  13932:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   13933:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   13934:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   13935:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   13936:             }
1.134     raeburn  13937:         }
1.28      raeburn  13938:     }
                   13939:     foreach my $item (@contacts) {
                   13940:         $to{$item} = $env{'form.'.$item};
                   13941:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   13942:     }
1.160.6.23  raeburn  13943:     foreach my $item (@toggles) {
                   13944:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   13945:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   13946:         }
                   13947:     }
1.160.6.107  raeburn  13948:     my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
                   13949:     foreach my $item (@lonstatus) {
                   13950:         if ($item eq 'excluded') {
                   13951:             my (%serverhomes,@excluded);
                   13952:             map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
                   13953:             my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
                   13954:             if (@possexcluded) {
                   13955:                 foreach my $id (sort(@possexcluded)) {
                   13956:                     if ($serverhomes{$id}) {
                   13957:                         push(@excluded,$id);
                   13958:                     }
                   13959:                 }
                   13960:             }
                   13961:             if (@excluded) {
                   13962:                 $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
                   13963:             }
                   13964:         } elsif ($item eq 'weights') {
                   13965:             foreach my $type ('E','W','N','U') {
                   13966:                 $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   13967:                 if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                   13968:                     unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                   13969:                         $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                   13970:                             $env{'form.error'.$item.'_'.$type};
                   13971:                     }
                   13972:                 }
                   13973:             }
                   13974:         } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
                   13975:             $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
                   13976:             if ($env{'form.error'.$item} =~ /^\d+$/) {
                   13977:                 unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                   13978:                     $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   13979:                 }
                   13980:             }
                   13981:         }
                   13982:     }
1.160.6.78  raeburn  13983:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   13984:         foreach my $field (@{$fields}) {
                   13985:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   13986:                 my $value = $env{'form.helpform_'.$field};
                   13987:                 $value =~ s/^\s+|\s+$//g;
                   13988:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101  raeburn  13989:                     $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78  raeburn  13990:                     if ($field eq 'screenshot') {
                   13991:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   13992:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101  raeburn  13993:                             $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78  raeburn  13994:                         }
                   13995:                     }
                   13996:                 }
                   13997:             }
                   13998:         }
                   13999:     }
1.160.6.101  raeburn  14000:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   14001:     my (@statuses,%usertypeshash,@overrides);
                   14002:     if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
                   14003:         @statuses = @{$types};
                   14004:         if (ref($usertypes) eq 'HASH') {
                   14005:             %usertypeshash = %{$usertypes};
                   14006:         }
                   14007:     }
                   14008:     if (@statuses) {
                   14009:         my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
                   14010:         foreach my $type (@possoverrides) {
                   14011:             if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
                   14012:                 push(@overrides,$type);
                   14013:             }
                   14014:         }
                   14015:         if (@overrides) {
                   14016:             foreach my $type (@overrides) {
                   14017:                 my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
                   14018:                 foreach my $item (@contacts) {
                   14019:                     if (grep(/^\Q$item\E$/,@standard)) {
                   14020:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
                   14021:                         $newsetting{'override_'.$type}{$item} = 1;
                   14022:                     } else {
                   14023:                         $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
                   14024:                         $newsetting{'override_'.$type}{$item} = 0;
                   14025:                     }
                   14026:                 }
                   14027:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   14028:                 $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   14029:                 $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
                   14030:                 $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
                   14031:                 if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
                   14032:                     $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
                   14033:                     $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
                   14034:                     $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   14035:                     $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
                   14036:                 }
                   14037:             }    
                   14038:         }
                   14039:     }
1.28      raeburn  14040:     if (keys(%currsetting) > 0) {
                   14041:         foreach my $item (@contacts) {
                   14042:             if ($to{$item} ne $currsetting{$item}) {
                   14043:                 $changes{$item} = 1;
                   14044:             }
                   14045:         }
                   14046:         foreach my $type (@mailings) {
                   14047:             foreach my $item (@contacts) {
                   14048:                 if (ref($currsetting{$type}) eq 'HASH') {
                   14049:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   14050:                         push(@{$changes{$type}},$item);
                   14051:                     }
                   14052:                 } else {
                   14053:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   14054:                 }
                   14055:             }
                   14056:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   14057:                 push(@{$changes{$type}},'others');
                   14058:             }
1.160.6.78  raeburn  14059:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  14060:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   14061:                     push(@{$changes{$type}},'bcc'); 
                   14062:                 }
1.160.6.78  raeburn  14063:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   14064:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   14065:                     push(@{$changes{$type}},'include');
                   14066:                 }
                   14067:             }
                   14068:         }
                   14069:         if (ref($fields) eq 'ARRAY') {
                   14070:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   14071:                 foreach my $field (@{$fields}) {
                   14072:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   14073:                         push(@{$changes{'helpform'}},$field);
                   14074:                     }
                   14075:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   14076:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   14077:                             push(@{$changes{'helpform'}},'maxsize');
                   14078:                         }
                   14079:                     }
                   14080:                 }
                   14081:             } else {
                   14082:                 foreach my $field (@{$fields}) {
                   14083:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   14084:                         push(@{$changes{'helpform'}},$field);
                   14085:                     }
                   14086:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   14087:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   14088:                             push(@{$changes{'helpform'}},'maxsize');
                   14089:                         }
                   14090:                     }
                   14091:                 }
1.134     raeburn  14092:             }
1.28      raeburn  14093:         }
1.160.6.101  raeburn  14094:         if (@statuses) {
                   14095:             if (ref($currsetting{'overrides'}) eq 'HASH') {
                   14096:                 foreach my $key (keys(%{$currsetting{'overrides'}})) {
                   14097:                     if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
                   14098:                         if (ref($newsetting{'override_'.$key}) eq 'HASH') {
                   14099:                             foreach my $item (@contacts,'bcc','others','include') {
                   14100:                                 if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
                   14101:                                     push(@{$changes{'overrides'}},$key);
                   14102:                                     last;
                   14103:                                 }
                   14104:                             }
                   14105:                         } else {
                   14106:                             push(@{$changes{'overrides'}},$key);
                   14107:                         }
                   14108:                     }
                   14109:                 }
                   14110:                 foreach my $key (@overrides) {
                   14111:                     unless (exists($currsetting{'overrides'}{$key})) {
                   14112:                         push(@{$changes{'overrides'}},$key);
                   14113:                     }
                   14114:                 }
                   14115:             } else {
                   14116:                 foreach my $key (@overrides) {
                   14117:                     push(@{$changes{'overrides'}},$key);
                   14118:                 }
                   14119:             }
                   14120:         }
1.160.6.107  raeburn  14121:         if (ref($currsetting{'lonstatus'}) eq 'HASH') {
                   14122:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   14123:                 if ($key eq 'excluded') {
                   14124:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   14125:                         (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                   14126:                         if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   14127:                             (@{$currsetting{'lonstatus'}{$key}})) {
                   14128:                             my @diffs =
                   14129:                                 &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                   14130:                                                                    $currsetting{'lonstatus'}{$key});
                   14131:                             if (@diffs) {
                   14132:                                 push(@{$changes{'lonstatus'}},$key);
                   14133:                             }
                   14134:                         } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                   14135:                             push(@{$changes{'lonstatus'}},$key);
                   14136:                         }
                   14137:                     } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                   14138:                              (@{$currsetting{'lonstatus'}{$key}})) {
                   14139:                         push(@{$changes{'lonstatus'}},$key);
                   14140:                     }
                   14141:                 } elsif ($key eq 'weights') {
                   14142:                     if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                   14143:                         (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                   14144:                         if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                   14145:                             foreach my $type ('E','W','N','U') {
                   14146:                                 unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                   14147:                                         $currsetting{'lonstatus'}{$key}{$type}) {
                   14148:                                     push(@{$changes{'lonstatus'}},$key);
                   14149:                                     last;
                   14150:                                 }
                   14151:                             }
                   14152:                         } else {
                   14153:                             foreach my $type ('E','W','N','U') {
                   14154:                                 if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                   14155:                                     push(@{$changes{'lonstatus'}},$key);
                   14156:                                     last;
                   14157:                                 }
                   14158:                             }
                   14159:                         }
                   14160:                     } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                   14161:                         foreach my $type ('E','W','N','U') {
                   14162:                             if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                   14163:                                 push(@{$changes{'lonstatus'}},$key);
                   14164:                                 last;
                   14165:                             }
                   14166:                         }
                   14167:                     }
                   14168:                 } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                   14169:                     if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   14170:                         if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   14171:                             if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                   14172:                                 push(@{$changes{'lonstatus'}},$key);
                   14173:                             }
                   14174:                         } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                   14175:                             push(@{$changes{'lonstatus'}},$key);
                   14176:                         }
                   14177:                     } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                   14178:                         push(@{$changes{'lonstatus'}},$key);
                   14179:                     }
                   14180:                 }
                   14181:             }
                   14182:         } else {
                   14183:             if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   14184:                 foreach my $key ('excluded','weights','threshold','sysmail') {
                   14185:                     if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   14186:                         push(@{$changes{'lonstatus'}},$key);
                   14187:                     }
                   14188:                 }
                   14189:             }
                   14190:         }
1.28      raeburn  14191:     } else {
                   14192:         my %default;
                   14193:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   14194:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   14195:         $default{'errormail'} = 'adminemail';
                   14196:         $default{'packagesmail'} = 'adminemail';
                   14197:         $default{'helpdeskmail'} = 'supportemail';
1.160.6.78  raeburn  14198:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  14199:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  14200:         $default{'requestsmail'} = 'adminemail';
1.160.6.15  raeburn  14201:         $default{'updatesmail'} = 'adminemail';
1.160.6.91  raeburn  14202:         $default{'hostipmail'} = 'adminemail';
1.28      raeburn  14203:         foreach my $item (@contacts) {
                   14204:            if ($to{$item} ne $default{$item}) {
1.160.6.78  raeburn  14205:                $changes{$item} = 1;
1.160.6.23  raeburn  14206:            }
1.28      raeburn  14207:         }
                   14208:         foreach my $type (@mailings) {
                   14209:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   14210:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   14211:             }
                   14212:             if ($others{$type} ne '') {
                   14213:                 push(@{$changes{$type}},'others');
1.134     raeburn  14214:             }
1.160.6.78  raeburn  14215:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  14216:                 if ($bcc{$type} ne '') {
                   14217:                     push(@{$changes{$type}},'bcc');
                   14218:                 }
1.160.6.78  raeburn  14219:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   14220:                     push(@{$changes{$type}},'include');
                   14221:                 }
                   14222:             }
                   14223:         }
                   14224:         if (ref($fields) eq 'ARRAY') {
                   14225:             foreach my $field (@{$fields}) {
                   14226:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   14227:                     push(@{$changes{'helpform'}},$field);
                   14228:                 }
                   14229:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   14230:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   14231:                         push(@{$changes{'helpform'}},'maxsize');
                   14232:                     }
                   14233:                 }
1.134     raeburn  14234:             }
1.28      raeburn  14235:         }
1.160.6.107  raeburn  14236:         if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   14237:             foreach my $key ('excluded','weights','threshold','sysmail') {
                   14238:                 if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                   14239:                     push(@{$changes{'lonstatus'}},$key);
                   14240:                 }
                   14241:             }
                   14242:         }
1.28      raeburn  14243:     }
1.160.6.23  raeburn  14244:     foreach my $item (@toggles) {
                   14245:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   14246:             $changes{$item} = 1;
                   14247:         } elsif ((!$env{'form.'.$item}) &&
                   14248:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   14249:             $changes{$item} = 1;
                   14250:         }
                   14251:     }
1.28      raeburn  14252:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   14253:                                              $dom);
                   14254:     if ($putresult eq 'ok') {
                   14255:         if (keys(%changes) > 0) {
1.160.6.24  raeburn  14256:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  14257:             if (ref($lastactref) eq 'HASH') {
                   14258:                 $lastactref->{'domainconfig'} = 1;
                   14259:             }
1.28      raeburn  14260:             my ($titles,$short_titles)  = &contact_titles();
                   14261:             $resulttext = &mt('Changes made:').'<ul>';
                   14262:             foreach my $item (@contacts) {
                   14263:                 if ($changes{$item}) {
                   14264:                     $resulttext .= '<li>'.$titles->{$item}.
                   14265:                                     &mt(' set to: ').
                   14266:                                     '<span class="LC_cusr_emph">'.
                   14267:                                     $to{$item}.'</span></li>';
                   14268:                 }
                   14269:             }
                   14270:             foreach my $type (@mailings) {
                   14271:                 if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78  raeburn  14272:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   14273:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
                   14274:                     } else {
                   14275:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   14276:                     }
1.28      raeburn  14277:                     my @text;
                   14278:                     foreach my $item (@{$newsetting{$type}}) {
                   14279:                         push(@text,$short_titles->{$item});
                   14280:                     }
                   14281:                     if ($others{$type} ne '') {
                   14282:                         push(@text,$others{$type});
                   14283:                     }
1.160.6.78  raeburn  14284:                     if (@text) {
                   14285:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   14286:                                        join(', ',@text).'</span>';
                   14287:                     }
                   14288:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  14289:                         if ($bcc{$type} ne '') {
1.160.6.78  raeburn  14290:                             my $bcctext;
                   14291:                             if (@text) {
                   14292:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
                   14293:                             } else {
                   14294:                                 $bcctext = '(Bcc)';
                   14295:                             }
                   14296:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   14297:                         } elsif (!@text) {
                   14298:                             $resulttext .= &mt('No one');
1.134     raeburn  14299:                         }
1.160.6.78  raeburn  14300:                         if ($includestr{$type} ne '') {
                   14301:                             if ($includeloc{$type} eq 'b') {
                   14302:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   14303:                             } elsif ($includeloc{$type} eq 's') {
                   14304:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   14305:                             }
                   14306:                         }
                   14307:                     } elsif (!@text) {
                   14308:                         $resulttext .= &mt('No recipients');
1.134     raeburn  14309:                     }
                   14310:                     $resulttext .= '</li>';
1.28      raeburn  14311:                 }
                   14312:             }
1.160.6.101  raeburn  14313:             if (ref($changes{'overrides'}) eq 'ARRAY') {
                   14314:                 my @deletions;
                   14315:                 foreach my $type (@{$changes{'overrides'}}) {
                   14316:                     if ($usertypeshash{$type}) {
                   14317:                         if (grep(/^\Q$type\E/,@overrides)) {
                   14318:                             $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
                   14319:                                                       $usertypeshash{$type}).'<ul><li>';
                   14320:                             if (ref($newsetting{'override_'.$type}) eq 'HASH') {
                   14321:                                 my @text;
                   14322:                                 foreach my $item (@contacts) {
                   14323:                                     if ($newsetting{'override_'.$type}{$item}) {
                   14324:                                         push(@text,$short_titles->{$item});
                   14325:                                     }
                   14326:                                 }
                   14327:                                 if ($newsetting{'override_'.$type}{'others'} ne '') {
                   14328:                                     push(@text,$newsetting{'override_'.$type}{'others'});
                   14329:                                 }
                   14330: 
                   14331:                                 if (@text) {
                   14332:                                     $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
                   14333:                                                        '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
                   14334:                                 }
                   14335:                                 if ($newsetting{'override_'.$type}{'bcc'} ne '') {
                   14336:                                     my $bcctext;
                   14337:                                     if (@text) {
                   14338:                                         $bcctext = '&nbsp;'.&mt('with Bcc to');
                   14339:                                     } else {
                   14340:                                         $bcctext = '(Bcc)';
                   14341:                                     }
                   14342:                                     $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
                   14343:                                 } elsif (!@text) {
                   14344:                                      $resulttext .= &mt('Helpdesk e-mail sent to no one');
                   14345:                                 }
                   14346:                                 $resulttext .= '</li>';
                   14347:                                 if ($newsetting{'override_'.$type}{'include'} ne '') {
                   14348:                                     my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
                   14349:                                     if ($loc eq 'b') {
                   14350:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
                   14351:                                     } elsif ($loc eq 's') {
                   14352:                                         $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
                   14353:                                     }
                   14354:                                 }
                   14355:                             }
                   14356:                             $resulttext .= '</li></ul></li>';
                   14357:                         } else {
                   14358:                             push(@deletions,$usertypeshash{$type});
                   14359:                         }
                   14360:                     }
                   14361:                 }
                   14362:                 if (@deletions) {
                   14363:                     $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
                   14364:                                               join(', ',@deletions)).'</li>';
                   14365:                 }
                   14366:             }
1.160.6.23  raeburn  14367:             my @offon = ('off','on');
1.160.6.107  raeburn  14368:             my $corelink = &core_link_msu();
1.160.6.23  raeburn  14369:             if ($changes{'reporterrors'}) {
                   14370:                 $resulttext .= '<li>'.
                   14371:                                &mt('E-mail error reports to [_1] set to "'.
                   14372:                                    $offon[$env{'form.reporterrors'}].'".',
1.160.6.107  raeburn  14373:                                    $corelink).
1.160.6.23  raeburn  14374:                                '</li>';
                   14375:             }
                   14376:             if ($changes{'reportupdates'}) {
                   14377:                 $resulttext .= '<li>'.
                   14378:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   14379:                                     $offon[$env{'form.reportupdates'}].'".',
1.160.6.107  raeburn  14380:                                     $corelink).
1.160.6.23  raeburn  14381:                                 '</li>';
                   14382:             }
1.160.6.107  raeburn  14383:             if ($changes{'reportstatus'}) {
                   14384:                 $resulttext .= '<li>'.
                   14385:                                 &mt('E-mail status if errors above threshold to [_1] set to "'.
                   14386:                                     $offon[$env{'form.reportstatus'}].'".',
                   14387:                                     $corelink).
                   14388:                                 '</li>';
                   14389:             }
                   14390:             if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   14391:                 $resulttext .= '<li>'.
                   14392:                                &mt('Nightly status check e-mail settings').':<ul>';
                   14393:                 my (%defval,%use_def,%shown);
                   14394:                 $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   14395:                 $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   14396:                 $defval{'weights'} =
                   14397:                     join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
                   14398:                 $defval{'excluded'} = &mt('None');
                   14399:                 if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                   14400:                     foreach my $item ('threshold','sysmail','weights','excluded') {
                   14401:                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                   14402:                             if (($item eq 'threshold') || ($item eq 'sysmail')) {
                   14403:                                 $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                   14404:                             } elsif ($item eq 'weights') {
                   14405:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
                   14406:                                     foreach my $type ('E','W','N','U') {
                   14407:                                         $shown{$item} .= $lonstatus_names->{$type}.'=';
                   14408:                                         if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                   14409:                                             $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                   14410:                                         } else {
                   14411:                                             $shown{$item} .= $lonstatus_defs->{$type};
                   14412:                                         }
                   14413:                                         $shown{$item} .= ', ';
                   14414:                                     }
                   14415:                                     $shown{$item} =~ s/, $//;
                   14416:                                 } else {
                   14417:                                     $shown{$item} = $defval{$item};
                   14418:                                 }
                   14419:                             } elsif ($item eq 'excluded') {
                   14420:                                 if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                   14421:                                     $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                   14422:                                 } else {
                   14423:                                     $shown{$item} = $defval{$item};
                   14424:                                 }
                   14425:                             }
                   14426:                         } else {
                   14427:                             $shown{$item} = $defval{$item};
                   14428:                         }
                   14429:                     }
                   14430:                 } else {
                   14431:                     foreach my $item ('threshold','weights','excluded','sysmail') {
                   14432:                         $shown{$item} = $defval{$item};
                   14433:                     }
                   14434:                 }
                   14435:                 foreach my $item ('threshold','weights','excluded','sysmail') {
                   14436:                     $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                   14437:                                           $shown{$item}).'</li>';
                   14438:                 }
                   14439:                 $resulttext .= '</ul></li>';
                   14440:             }
1.160.6.78  raeburn  14441:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   14442:                 my (@optional,@required,@unused,$maxsizechg);
                   14443:                 foreach my $field (@{$changes{'helpform'}}) {
                   14444:                     if ($field eq 'maxsize') {
                   14445:                         $maxsizechg = 1;
                   14446:                         next;
                   14447:                     }
                   14448:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                   14449:                         push(@optional,$field);
                   14450:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   14451:                         push(@unused,$field);
                   14452:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                   14453:                         push(@required,$field);
                   14454:                     }
                   14455:                 }
                   14456:                 if (@optional) {
                   14457:                     $resulttext .= '<li>'.
                   14458:                                    &mt('Help form fields changed to "Optional": [_1].',
                   14459:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   14460:                                    '</li>';
                   14461:                 }
                   14462:                 if (@required) {
                   14463:                     $resulttext .= '<li>'.
                   14464:                                    &mt('Help form fields changed to "Required": [_1].',
                   14465:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   14466:                                    '</li>';
                   14467:                 }
                   14468:                 if (@unused) {
                   14469:                     $resulttext .= '<li>'.
                   14470:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   14471:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   14472:                                    '</li>';
                   14473:                 }
                   14474:                 if ($maxsizechg) {
                   14475:                     $resulttext .= '<li>'.
                   14476:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   14477:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   14478:                                    '</li>';
                   14479:                 }
                   14480:             }
1.28      raeburn  14481:             $resulttext .= '</ul>';
                   14482:         } else {
1.160.6.78  raeburn  14483:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  14484:         }
                   14485:     } else {
                   14486:         $resulttext = '<span class="LC_error">'.
                   14487:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   14488:     }
                   14489:     return $resulttext;
                   14490: }
                   14491: 
1.160.6.98  raeburn  14492: sub modify_passwords {
                   14493:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
                   14494:     my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
                   14495:         $updatedefaults,$updateconf);
                   14496:     my $customfn = 'resetpw.html';
                   14497:     if (ref($domconfig{'passwords'}) eq 'HASH') {
                   14498:         %current = %{$domconfig{'passwords'}};
                   14499:     }
                   14500:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   14501:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   14502:     if (ref($types) eq 'ARRAY') {
                   14503:         @oktypes = @{$types};
                   14504:     }
                   14505:     push(@oktypes,'default');
                   14506: 
                   14507:     my %titles = &Apache::lonlocal::texthash (
                   14508:         intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
                   14509:         intauth_check  => 'Check bcrypt cost if authenticated',
                   14510:         intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
                   14511:         permanent      => 'Permanent e-mail address',
                   14512:         critical       => 'Critical notification address',
                   14513:         notify         => 'Notification address',
                   14514:         min            => 'Minimum password length',
                   14515:         max            => 'Maximum password length',
                   14516:         chars          => 'Required characters',
                   14517:         numsaved       => 'Number of previous passwords to save',
                   14518:         reset          => 'Resetting Forgotten Password',
                   14519:         intauth        => 'Encryption of Stored Passwords (Internal Auth)',
                   14520:         rules          => 'Rules for LON-CAPA Passwords',
                   14521:         crsownerchg    => 'Course Owner Changing Student Passwords',
                   14522:         username       => 'Username',
                   14523:         email          => 'E-mail address',
                   14524:     );
                   14525: 
                   14526: #
                   14527: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
                   14528: #
                   14529:     my (%curr_defaults,%save_defaults);
                   14530:     if (ref($domconfig{'defaults'}) eq 'HASH') {
                   14531:         foreach my $key (keys(%{$domconfig{'defaults'}})) {
                   14532:             if ($key =~ /^intauth_(cost|check|switch)$/) {
                   14533:                 $curr_defaults{$key} = $domconfig{'defaults'}{$key};
                   14534:             } else {
                   14535:                 $save_defaults{$key} = $domconfig{'defaults'}{$key};
                   14536:             }
                   14537:         }
                   14538:     }
                   14539:     my %staticdefaults = (
                   14540:         'resetlink'      => 2,
                   14541:         'resetcase'      => \@oktypes,
                   14542:         'resetprelink'   => 'both',
                   14543:         'resetemail'     => ['critical','notify','permanent'],
                   14544:         'intauth_cost'   => 10,
                   14545:         'intauth_check'  => 0,
                   14546:         'intauth_switch' => 0,
                   14547:     );
1.160.6.99  raeburn  14548:     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98  raeburn  14549:     foreach my $type (@oktypes) {
                   14550:         $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
                   14551:     }
                   14552:     my $linklife = $env{'form.passwords_link'};
                   14553:     $linklife =~ s/^\s+|\s+$//g;
                   14554:     if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
                   14555:         $newvalues{'resetlink'} = $linklife;
                   14556:         if ($current{'resetlink'}) {
                   14557:             if ($current{'resetlink'} ne $linklife) {
                   14558:                 $changes{'reset'} = 1;
                   14559:             }
1.160.6.102  raeburn  14560:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  14561:             if ($staticdefaults{'resetlink'} ne $linklife) {
                   14562:                 $changes{'reset'} = 1;
                   14563:             }
                   14564:         }
                   14565:     } elsif ($current{'resetlink'}) {
                   14566:         $changes{'reset'} = 1;
                   14567:     }
                   14568:     my @casesens;
                   14569:     my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
                   14570:     foreach my $case (sort(@posscase)) {
                   14571:         if (grep(/^\Q$case\E$/,@oktypes)) {
                   14572:             push(@casesens,$case);
                   14573:         }
                   14574:     }
                   14575:     $newvalues{'resetcase'} = \@casesens;
                   14576:     if (ref($current{'resetcase'}) eq 'ARRAY') {
                   14577:         my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
                   14578:         if (@diffs > 0) {
                   14579:             $changes{'reset'} = 1;
                   14580:         }
1.160.6.102  raeburn  14581:     } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  14582:         my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
                   14583:         if (@diffs > 0) {
                   14584:             $changes{'reset'} = 1;
                   14585:         }
                   14586:     }
                   14587:     if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
                   14588:         $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
                   14589:         if (exists($current{'resetprelink'})) {
                   14590:             if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14591:                 $changes{'reset'} = 1;
                   14592:             }
1.160.6.102  raeburn  14593:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  14594:             if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   14595:                 $changes{'reset'} = 1;
                   14596:             }
                   14597:         }
                   14598:     } elsif ($current{'resetprelink'}) {
                   14599:         $changes{'reset'} = 1;
                   14600:     }
                   14601:     foreach my $type (@oktypes) {
                   14602:         my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
                   14603:         my @postlink;
                   14604:         foreach my $item (sort(@possplink)) {
                   14605:             if ($item =~ /^(email|username)$/) {
                   14606:                 push(@postlink,$item);
                   14607:             }
                   14608:         }
                   14609:         $newvalues{'resetpostlink'}{$type} = \@postlink;
                   14610:         unless ($changes{'reset'}) {
                   14611:             if (ref($current{'resetpostlink'}) eq 'HASH') {
                   14612:                 if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14613:                     my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                   14614:                     if (@diffs > 0) {
                   14615:                         $changes{'reset'} = 1;
                   14616:                     }
                   14617:                 } else {
                   14618:                     $changes{'reset'} = 1;
                   14619:                 }
1.160.6.102  raeburn  14620:             } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  14621:                 my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   14622:                 if (@diffs > 0) {
                   14623:                     $changes{'reset'} = 1;
                   14624:                 }
                   14625:             }
                   14626:         }
                   14627:     }
                   14628:     my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
                   14629:     my @resetemail;
                   14630:     foreach my $item (sort(@possemailsrc)) {
                   14631:         if ($item =~ /^(permanent|critical|notify)$/) {
                   14632:             push(@resetemail,$item);
                   14633:         }
                   14634:     }
                   14635:     $newvalues{'resetemail'} = \@resetemail;
                   14636:     unless ($changes{'reset'}) {
                   14637:         if (ref($current{'resetemail'}) eq 'ARRAY') {
                   14638:             my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
                   14639:             if (@diffs > 0) {
                   14640:                 $changes{'reset'} = 1;
                   14641:             }
1.160.6.102  raeburn  14642:         } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98  raeburn  14643:             my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
                   14644:             if (@diffs > 0) {
                   14645:                 $changes{'reset'} = 1;
                   14646:             }
                   14647:         }
                   14648:     }
                   14649:     if ($env{'form.passwords_stdtext'} == 0) {
                   14650:         $newvalues{'resetremove'} = 1;
                   14651:         unless ($current{'resetremove'}) {
                   14652:             $changes{'reset'} = 1;
                   14653:         }
                   14654:     } elsif ($current{'resetremove'}) {
                   14655:         $changes{'reset'} = 1;
                   14656:     }
                   14657:     if ($env{'form.passwords_customfile.filename'} ne '') {
                   14658:         my $servadm = $r->dir_config('lonAdmEMail');
                   14659:         my $servadm = $r->dir_config('lonAdmEMail');
                   14660:         my ($configuserok,$author_ok,$switchserver) =
                   14661:             &config_check($dom,$confname,$servadm);
                   14662:         my $error;
                   14663:         if ($configuserok eq 'ok') {
                   14664:             if ($switchserver) {
                   14665:                 $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
                   14666:             } else {
                   14667:                 if ($author_ok eq 'ok') {
                   14668:                     my ($result,$customurl) =
                   14669:                         &publishlogo($r,'upload','passwords_customfile',$dom,
                   14670:                                      $confname,'customtext/resetpw','','',$customfn);
                   14671:                     if ($result eq 'ok') {
                   14672:                         $newvalues{'resetcustom'} = $customurl;
                   14673:                         $changes{'reset'} = 1;
                   14674:                     } else {
                   14675:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                   14676:                     }
                   14677:                 } else {
                   14678:                     $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);
                   14679:                 }
                   14680:             }
                   14681:         } else {
                   14682:             $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);
                   14683:         }
                   14684:         if ($error) {
                   14685:             &Apache::lonnet::logthis($error);
                   14686:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   14687:         }
                   14688:     } elsif ($current{'resetcustom'}) {
                   14689:         if ($env{'form.passwords_custom_del'}) {
                   14690:             $changes{'reset'} = 1;
                   14691:         } else {
                   14692:             $newvalues{'resetcustom'} = $current{'resetcustom'};
                   14693:         }
                   14694:     }
                   14695:     $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
                   14696:     if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
                   14697:         $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
                   14698:         if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
                   14699:             $changes{'intauth'} = 1;
                   14700:         }
                   14701:     } else {
                   14702:         $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
                   14703:     }
                   14704:     if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
                   14705:         $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
                   14706:         if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
                   14707:             $changes{'intauth'} = 1;
                   14708:         }
                   14709:     } else {
                   14710:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14711:     }
                   14712:     if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
                   14713:         $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
                   14714:         if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
                   14715:             $changes{'intauth'} = 1;
                   14716:         }
                   14717:     } else {
                   14718:         $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
                   14719:     }
                   14720:     foreach my $item ('cost','check','switch') {
                   14721:         if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
                   14722:             $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
                   14723:             $updatedefaults = 1;
                   14724:         }
                   14725:     }
1.160.6.118.2  5(raebur 14726:2):     &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98  raeburn  14727:     my %crsownerchg = (
                   14728:                         by => [],
                   14729:                         for => [],
                   14730:                       );
                   14731:     foreach my $item ('by','for') {
                   14732:         my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
                   14733:         foreach my $type (sort(@posstypes)) {
                   14734:             if (grep(/^\Q$type\E$/,@oktypes)) {
                   14735:                 push(@{$crsownerchg{$item}},$type);
                   14736:             }
                   14737:         }
                   14738:     }
                   14739:     $newvalues{'crsownerchg'} = \%crsownerchg;
                   14740:     if (ref($current{'crsownerchg'}) eq 'HASH') {
                   14741:         foreach my $item ('by','for') {
                   14742:             if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   14743:                 my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   14744:                 if (@diffs > 0) {
                   14745:                     $changes{'crsownerchg'} = 1;
                   14746:                     last;
                   14747:                 }
                   14748:             }
                   14749:         }
1.160.6.102  raeburn  14750:     } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98  raeburn  14751:         foreach my $item ('by','for') {
                   14752:             if (@{$crsownerchg{$item}} > 0) {
                   14753:                 $changes{'crsownerchg'} = 1;
                   14754:                 last;
                   14755:             }
                   14756:         }
                   14757:     }
                   14758: 
                   14759:     my %confighash = (
                   14760:                         defaults  => \%save_defaults,
                   14761:                         passwords => \%newvalues,
                   14762:                      );
                   14763:     &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
                   14764: 
                   14765:     my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
                   14766:     if ($putresult eq 'ok') {
                   14767:         if (keys(%changes) > 0) {
                   14768:             $resulttext = &mt('Changes made: ').'<ul>';
                   14769:             foreach my $key ('reset','intauth','rules','crsownerchg') {
                   14770:                 if ($changes{$key}) {
                   14771:                     unless ($key eq 'intauth') {
                   14772:                         $updateconf = 1;
                   14773:                     }
                   14774:                     $resulttext .= '<li>'.$titles{$key}.':<ul>';
                   14775:                     if ($key eq 'reset') {
                   14776:                         if ($confighash{'passwords'}{'captcha'} eq 'original') {
                   14777:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                   14778:                         } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                   14779:                             $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104  raeburn  14780:                                            &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                   14781:                             if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                   14782:                                 $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                   14783:                                                &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                   14784:                             }
1.160.6.98  raeburn  14785:                         } else {
                   14786:                             $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                   14787:                         }
                   14788:                         if ($confighash{'passwords'}{'resetlink'}) {
                   14789:                             $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                   14790:                         } else {
                   14791:                             $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                   14792:                                                   &mt('Will default to 2 hours').'</li>';
                   14793:                         }
                   14794:                         if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                   14795:                             if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                   14796:                                 $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                   14797:                             } else {
                   14798:                                 my $casesens;
                   14799:                                 foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                   14800:                                     if ($type eq 'default') {
                   14801:                                         $casesens .= $othertitle.', ';
                   14802:                                     } elsif ($usertypes->{$type} ne '') {
                   14803:                                         $casesens .= $usertypes->{$type}.', ';
                   14804:                                     }
                   14805:                                 }
                   14806:                                 $casesens =~ s/\Q, \E$//;
                   14807:                                 $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                   14808:                             }
                   14809:                         } else {
                   14810:                             $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>';
                   14811:                         }
                   14812:                         if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                   14813:                             $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                   14814:                         } else {
                   14815:                             $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                   14816:                         }
                   14817:                         if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                   14818:                             my $output;
                   14819:                             if (ref($types) eq 'ARRAY') {
                   14820:                                 foreach my $type (@{$types}) {
                   14821:                                     if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                   14822:                                         if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                   14823:                                             $output .= $usertypes->{$type}.' -- '.&mt('none');
                   14824:                                         } else {
                   14825:                                             $output .= $usertypes->{$type}.' -- '.
                   14826:                                                        join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                   14827:                                         }
                   14828:                                     }
                   14829:                                 }
                   14830:                             }
                   14831:                             if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                   14832:                                 if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                   14833:                                     $output .= $othertitle.' -- '.&mt('none');
                   14834:                                 } else {
                   14835:                                     $output .= $othertitle.' -- '.
                   14836:                                                join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                   14837:                                 }
                   14838:                             }
                   14839:                             if ($output) {
                   14840:                                 $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                   14841:                             } else {
                   14842:                                 $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>';
                   14843:                             }
                   14844:                         } else {
                   14845:                             $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>';
                   14846:                         }
                   14847:                         if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                   14848:                             if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                   14849:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                   14850:                             } else {
                   14851:                                 $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                   14852:                             }
                   14853:                         } else {
1.160.6.110  raeburn  14854:                             $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.160.6.98  raeburn  14855:                         }
                   14856:                         if ($confighash{'passwords'}{'resetremove'}) {
                   14857:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                   14858:                         } else {
                   14859:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                   14860:                         }
                   14861:                         if ($confighash{'passwords'}{'resetcustom'}) {
                   14862:                             my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104  raeburn  14863:                                                                             &mt('custom text'),600,500,undef,undef,
                   14864:                                                                             undef,undef,'background-color:#ffffff');
                   14865:                             $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98  raeburn  14866:                         } else {
                   14867:                             $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                   14868:                         }
                   14869:                     } elsif ($key eq 'intauth') {
                   14870:                         foreach my $item ('cost','switch','check') {
                   14871:                             my $value = $save_defaults{$key.'_'.$item};
                   14872:                             if ($item eq 'switch') {
                   14873:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14874:                                                      0 => 'No',
                   14875:                                                      1 => 'Yes',
                   14876:                                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   14877:                                                  );
                   14878:                                 if ($value =~ /^(0|1|2)$/) {
                   14879:                                     $value = $optiondesc{$value};
                   14880:                                 } else {
                   14881:                                     $value = &mt('none -- defaults to No');
                   14882:                                 }
                   14883:                             } elsif ($item eq 'check') {
                   14884:                                 my %optiondesc = &Apache::lonlocal::texthash (
                   14885:                                                      0 => 'No',
                   14886:                                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   14887:                                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                   14888:                                                  );
                   14889:                                 if ($value =~ /^(0|1|2)$/) {
                   14890:                                     $value = $optiondesc{$value};
                   14891:                                 } else {
                   14892:                                     $value = &mt('none -- defaults to No');
                   14893:                                 }
                   14894:                             }
                   14895:                             $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                   14896:                         }
                   14897:                     } elsif ($key eq 'rules') {
                   14898:                         foreach my $rule ('min','max','numsaved') {
                   14899:                             if ($confighash{'passwords'}{$rule} eq '') {
                   14900:                                 if ($rule eq 'min') {
                   14901:                                     $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99  raeburn  14902:                                                    ' '.&mt('Default of [_1] will be used',
                   14903:                                                            $Apache::lonnet::passwdmin).'</li>';
1.160.6.98  raeburn  14904:                                 } else {
                   14905:                                     $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                   14906:                                 }
                   14907:                             } else {
                   14908:                                 $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                   14909:                             }
                   14910:                         }
1.160.6.104  raeburn  14911:                         if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
                   14912:                             if (@{$confighash{'passwords'}{'chars'}} > 0) {
                   14913:                                 my %rulenames = &Apache::lonlocal::texthash(
                   14914:                                                      uc => 'At least one upper case letter',
                   14915:                                                      lc => 'At least one lower case letter',
                   14916:                                                      num => 'At least one number',
                   14917:                                                      spec => 'At least one non-alphanumeric',
                   14918:                                                    );
                   14919:                                 my $needed = '<ul><li>'.
                   14920:                                              join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
                   14921:                                              '</li></ul>';
                   14922:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
                   14923:                             } else {
                   14924:                                 $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   14925:                             }
                   14926:                         } else {
                   14927:                             $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
                   14928:                         }
1.160.6.98  raeburn  14929:                     } elsif ($key eq 'crsownerchg') {
                   14930:                         if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                   14931:                             if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                   14932:                                 (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                   14933:                                 $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   14934:                             } else {
                   14935:                                 my %crsownerstr;
                   14936:                                 foreach my $item ('by','for') {
                   14937:                                     if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                   14938:                                         foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                   14939:                                             if ($type eq 'default') {
                   14940:                                                 $crsownerstr{$item} .= $othertitle.', ';
                   14941:                                             } elsif ($usertypes->{$type} ne '') {
                   14942:                                                 $crsownerstr{$item} .= $usertypes->{$type}.', ';
                   14943:                                             }
                   14944:                                         }
                   14945:                                         $crsownerstr{$item} =~ s/\Q, \E$//;
                   14946:                                     }
                   14947:                                 }
                   14948:                                 $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                   14949:                                            $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                   14950:                             }
                   14951:                         } else {
                   14952:                             $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                   14953:                         }
                   14954:                     }
                   14955:                     $resulttext .= '</ul></li>';
                   14956:                 }
                   14957:             }
                   14958:             $resulttext .= '</ul>';
                   14959:         } else {
                   14960:             $resulttext = &mt('No changes made to password settings');
                   14961:         }
                   14962:         my $cachetime = 24*60*60;
                   14963:         if ($updatedefaults) {
                   14964:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   14965:             if (ref($lastactref) eq 'HASH') {
                   14966:                 $lastactref->{'domdefaults'} = 1;
                   14967:             }
                   14968:         }
                   14969:         if ($updateconf) {
                   14970:             &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
                   14971:             if (ref($lastactref) eq 'HASH') {
                   14972:                 $lastactref->{'passwdconf'} = 1;
                   14973:             }
                   14974:         }
                   14975:     } else {
                   14976:         $resulttext = '<span class="LC_error">'.
                   14977:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   14978:     }
                   14979:     if ($errors) {
                   14980:         $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                   14981:                        $errors.'</ul></p>';
                   14982:     }
                   14983:     return $resulttext;
                   14984: }
                   14985: 
1.160.6.118.2  5(raebur 14986:2): sub password_rule_changes {
                   14987:2):     my ($prefix,$newvalues,$current,$changes) = @_;
                   14988:2):     return unless ((ref($newvalues) eq 'HASH') &&
                   14989:2):                    (ref($current) eq 'HASH') &&
                   14990:2):                    (ref($changes) eq 'HASH'));
                   14991:2):     my (@rules,%staticdefaults);
                   14992:2):     if ($prefix eq 'passwords') {
                   14993:2):         @rules = ('min','max','numsaved');
                   14994:2):     } elsif ($prefix eq 'secrets') {
                   14995:2):         @rules = ('min','max');
                   14996:2):     }
                   14997:2):     $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
                   14998:2):     foreach my $rule (@rules) {
                   14999:2):         $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
                   15000:2):         my $ruleok;
                   15001:2):         if ($rule eq 'min') {
                   15002:2):             if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
                   15003:2):                 if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
                   15004:2):                     $ruleok = 1;
                   15005:2):                 }
                   15006:2):             }
                   15007:2):         } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
                   15008:2):                  ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
                   15009:2):             $ruleok = 1;
                   15010:2):         }
                   15011:2):         if ($ruleok) {
                   15012:2):             $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
                   15013:2):             if (exists($current->{$rule})) {
                   15014:2):                 if ($newvalues->{$rule} ne $current->{$rule}) {
                   15015:2):                     $changes->{'rules'} = 1;
                   15016:2):                 }
                   15017:2):             } elsif ($rule eq 'min') {
                   15018:2):                 if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
                   15019:2):                     $changes->{'rules'} = 1;
                   15020:2):                 }
                   15021:2):             } else {
                   15022:2):                 $changes->{'rules'} = 1;
                   15023:2):             }
                   15024:2):         } elsif (exists($current->{$rule})) {
                   15025:2):             $changes->{'rules'} = 1;
                   15026:2):         }
                   15027:2):     }
                   15028:2):     my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
                   15029:2):     my @chars;
                   15030:2):     foreach my $item (sort(@posschars)) {
                   15031:2):         if ($item =~ /^(uc|lc|num|spec)$/) {
                   15032:2):             push(@chars,$item);
                   15033:2):         }
                   15034:2):     }
                   15035:2):     $newvalues->{'chars'} = \@chars;
                   15036:2):     unless ($changes->{'rules'}) {
                   15037:2):         if (ref($current->{'chars'}) eq 'ARRAY') {
                   15038:2):             my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
                   15039:2):             if (@diffs > 0) {
                   15040:2):                 $changes->{'rules'} = 1;
                   15041:2):             }
                   15042:2):         } else {
                   15043:2):             if (@chars > 0) {
                   15044:2):                 $changes->{'rules'} = 1;
                   15045:2):             }
                   15046:2):         }
                   15047:2):     }
                   15048:2):     return;
                   15049:2): }
                   15050:2): 
1.28      raeburn  15051: sub modify_usercreation {
1.27      raeburn  15052:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  15053:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  15054:     my $warningmsg;
1.27      raeburn  15055:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   15056:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34  raeburn  15057:             if ($key eq 'cancreate') {
                   15058:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   15059:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93  raeburn  15060:                         if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34  raeburn  15061:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93  raeburn  15062:                         } else {
                   15063:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34  raeburn  15064:                         }
1.50      raeburn  15065:                     }
1.43      raeburn  15066:                 }
1.160.6.34  raeburn  15067:             } elsif ($key eq 'email_rule') {
                   15068:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   15069:             } else {
                   15070:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43      raeburn  15071:             }
                   15072:         }
1.34      raeburn  15073:     }
1.160.6.34  raeburn  15074:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
                   15075:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
                   15076:     my @contexts = ('author','course','requestcrs');
                   15077:     foreach my $item(@contexts) {
                   15078:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  15079:     }
1.34      raeburn  15080:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15081:         foreach my $item (@contexts) {
1.160.6.34  raeburn  15082:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   15083:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  15084:             }
1.27      raeburn  15085:         }
1.34      raeburn  15086:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   15087:         foreach my $item (@contexts) {
1.43      raeburn  15088:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  15089:                 if ($cancreate{$item} ne 'any') {
                   15090:                     push(@{$changes{'cancreate'}},$item);
                   15091:                 }
                   15092:             } else {
                   15093:                 if ($cancreate{$item} ne 'none') {
                   15094:                     push(@{$changes{'cancreate'}},$item);
                   15095:                 }
1.27      raeburn  15096:             }
                   15097:         }
                   15098:     } else {
1.43      raeburn  15099:         foreach my $item (@contexts)  {
1.34      raeburn  15100:             push(@{$changes{'cancreate'}},$item);
                   15101:         }
1.27      raeburn  15102:     }
1.34      raeburn  15103: 
1.27      raeburn  15104:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   15105:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   15106:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   15107:                 push(@{$changes{'username_rule'}},$type);
                   15108:             }
                   15109:         }
                   15110:         foreach my $type (@username_rule) {
                   15111:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   15112:                 push(@{$changes{'username_rule'}},$type);
                   15113:             }
                   15114:         }
                   15115:     } else {
                   15116:         push(@{$changes{'username_rule'}},@username_rule);
                   15117:     }
                   15118: 
1.32      raeburn  15119:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   15120:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   15121:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   15122:                 push(@{$changes{'id_rule'}},$type);
                   15123:             }
                   15124:         }
                   15125:         foreach my $type (@id_rule) {
                   15126:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   15127:                 push(@{$changes{'id_rule'}},$type);
                   15128:             }
                   15129:         }
                   15130:     } else {
                   15131:         push(@{$changes{'id_rule'}},@id_rule);
                   15132:     }
                   15133: 
1.43      raeburn  15134:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  15135:     my @authtypes = ('int','krb4','krb5','loc');
                   15136:     my %authhash;
1.43      raeburn  15137:     foreach my $item (@authen_contexts) {
1.28      raeburn  15138:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   15139:         foreach my $auth (@authtypes) {
                   15140:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   15141:                 $authhash{$item}{$auth} = 1;
                   15142:             } else {
                   15143:                 $authhash{$item}{$auth} = 0;
                   15144:             }
                   15145:         }
                   15146:     }
                   15147:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  15148:         foreach my $item (@authen_contexts) {
1.28      raeburn  15149:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   15150:                 foreach my $auth (@authtypes) {
                   15151:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   15152:                         push(@{$changes{'authtypes'}},$item);
                   15153:                         last;
                   15154:                     }
                   15155:                 }
                   15156:             }
                   15157:         }
                   15158:     } else {
1.43      raeburn  15159:         foreach my $item (@authen_contexts) {
1.28      raeburn  15160:             push(@{$changes{'authtypes'}},$item);
                   15161:         }
                   15162:     }
                   15163: 
1.160.6.34  raeburn  15164:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   15165:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   15166:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   15167:     $save_usercreate{'id_rule'} = \@id_rule;
                   15168:     $save_usercreate{'username_rule'} = \@username_rule,
                   15169:     $save_usercreate{'authtypes'} = \%authhash;
                   15170: 
1.27      raeburn  15171:     my %usercreation_hash =  (
1.160.6.34  raeburn  15172:         usercreation     => \%save_usercreate,
                   15173:     );
1.27      raeburn  15174: 
                   15175:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   15176:                                              $dom);
1.50      raeburn  15177: 
1.160.6.34  raeburn  15178:     if ($putresult eq 'ok') {
                   15179:         if (keys(%changes) > 0) {
                   15180:             $resulttext = &mt('Changes made:').'<ul>';
                   15181:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   15182:                 my %lt = &usercreation_types();
                   15183:                 foreach my $type (@{$changes{'cancreate'}}) {
                   15184:                     my $chgtext = $lt{$type}.', ';
                   15185:                     if ($cancreate{$type} eq 'none') {
                   15186:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   15187:                     } elsif ($cancreate{$type} eq 'any') {
                   15188:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   15189:                     } elsif ($cancreate{$type} eq 'official') {
                   15190:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   15191:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   15192:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   15193:                     }
                   15194:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   15195:                 }
                   15196:             }
                   15197:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   15198:                 my ($rules,$ruleorder) = 
                   15199:                     &Apache::lonnet::inst_userrules($dom,'username');
                   15200:                 my $chgtext = '<ul>';
                   15201:                 foreach my $type (@username_rule) {
                   15202:                     if (ref($rules->{$type}) eq 'HASH') {
                   15203:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   15204:                     }
                   15205:                 }
                   15206:                 $chgtext .= '</ul>';
                   15207:                 if (@username_rule > 0) {
                   15208:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   15209:                 } else {
                   15210:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   15211:                 }
                   15212:             }
                   15213:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   15214:                 my ($idrules,$idruleorder) = 
                   15215:                     &Apache::lonnet::inst_userrules($dom,'id');
                   15216:                 my $chgtext = '<ul>';
                   15217:                 foreach my $type (@id_rule) {
                   15218:                     if (ref($idrules->{$type}) eq 'HASH') {
                   15219:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   15220:                     }
                   15221:                 }
                   15222:                 $chgtext .= '</ul>';
                   15223:                 if (@id_rule > 0) {
                   15224:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   15225:                 } else {
                   15226:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   15227:                 }
                   15228:             }
                   15229:             my %authname = &authtype_names();
                   15230:             my %context_title = &context_names();
                   15231:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   15232:                 my $chgtext = '<ul>';
                   15233:                 foreach my $type (@{$changes{'authtypes'}}) {
                   15234:                     my @allowed;
                   15235:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   15236:                     foreach my $auth (@authtypes) {
                   15237:                         if ($authhash{$type}{$auth}) {
                   15238:                             push(@allowed,$authname{$auth});
                   15239:                         }
                   15240:                     }
                   15241:                     if (@allowed > 0) {
                   15242:                         $chgtext .= join(', ',@allowed).'</li>';
                   15243:                     } else {
                   15244:                         $chgtext .= &mt('none').'</li>';
                   15245:                     }
                   15246:                 }
                   15247:                 $chgtext .= '</ul>';
                   15248:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   15249:                 $resulttext .= '</li>';
                   15250:             }
                   15251:             $resulttext .= '</ul>';
                   15252:         } else {
                   15253:             $resulttext = &mt('No changes made to user creation settings');
                   15254:         }
                   15255:     } else {
                   15256:         $resulttext = '<span class="LC_error">'.
                   15257:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   15258:     }
                   15259:     if ($warningmsg ne '') {
                   15260:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   15261:     }
                   15262:     return $resulttext;
                   15263: }
                   15264: 
                   15265: sub modify_selfcreation {
1.160.6.93  raeburn  15266:     my ($dom,$lastactref,%domconfig) = @_;
                   15267:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
                   15268:     my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
                   15269:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   15270:     my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
                   15271:     if (ref($typesref) eq 'ARRAY') {
                   15272:         @types = @{$typesref};
                   15273:     }
                   15274:     if (ref($usertypesref) eq 'HASH') {
                   15275:         %usertypes = %{$usertypesref};
1.160.6.35  raeburn  15276:     }
1.160.6.93  raeburn  15277:     $usertypes{'default'} = $othertitle;
1.160.6.34  raeburn  15278: #
                   15279: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   15280: #
                   15281:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   15282:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   15283:             if ($key eq 'cancreate') {
                   15284:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   15285:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   15286:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93  raeburn  15287:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   15288:                             ($item eq 'recaptchaversion') || ($item eq 'notify') ||
                   15289:                             ($item eq 'emailusername') || ($item eq 'shibenv') ||
                   15290:                             ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
                   15291:                             ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34  raeburn  15292:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15293:                         } else {
                   15294:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   15295:                         }
                   15296:                     }
                   15297:                 }
                   15298:             } elsif ($key eq 'email_rule') {
                   15299:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   15300:             } else {
                   15301:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   15302:             }
                   15303:         }
                   15304:     }
                   15305: #
                   15306: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   15307: #
                   15308:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   15309:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   15310:             if ($key eq 'selfcreate') {
                   15311:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15312:             } else {
                   15313:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   15314:             }
                   15315:         }
                   15316:     }
1.160.6.93  raeburn  15317: #
                   15318: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
                   15319: #
                   15320:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   15321:         foreach my $key (keys(%{$domconfig{'inststatus'}})) {
                   15322:             if ($key eq 'inststatusguest') {
                   15323:                 $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15324:             } else {
                   15325:                 $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
                   15326:             }
                   15327:         }
                   15328:     }
1.160.6.34  raeburn  15329: 
                   15330:     my @contexts = ('selfcreate');
                   15331:     @{$cancreate{'selfcreate'}} = ();
                   15332:     %{$cancreate{'emailusername'}} = ();
1.160.6.93  raeburn  15333:     if (@types) {
                   15334:         @{$cancreate{'statustocreate'}} = ();
                   15335:     }
1.160.6.40  raeburn  15336:     %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44  raeburn  15337:     %{$cancreate{'shibenv'}} = ();
1.160.6.93  raeburn  15338:     %{$cancreate{'emailverified'}} = ();
                   15339:     %{$cancreate{'emailoptions'}} = ();
                   15340:     %{$cancreate{'emaildomain'}} = ();
1.50      raeburn  15341:     my %selfcreatetypes = (
                   15342:                              sso   => 'users authenticated by institutional single sign on',
                   15343:                              login => 'users authenticated by institutional log-in',
1.160.6.93  raeburn  15344:                              email => 'users verified by e-mail',
1.50      raeburn  15345:                           );
1.160.6.34  raeburn  15346: #
                   15347: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   15348: # is permitted.
                   15349: #
1.160.6.40  raeburn  15350: 
1.160.6.93  raeburn  15351:     my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40  raeburn  15352: 
1.160.6.93  raeburn  15353:     my (@statuses,%email_rule);
1.160.6.35  raeburn  15354:     foreach my $item ('login','sso','email') {
1.160.6.34  raeburn  15355:         if ($item eq 'email') {
1.160.6.40  raeburn  15356:             if ($env{'form.cancreate_email'}) {
1.160.6.93  raeburn  15357:                 if (@types) {
                   15358:                     my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
                   15359:                     foreach my $status (@poss_statuses) {
                   15360:                         if (grep(/^\Q$status\E$/,(@types,'default'))) {
                   15361:                             push(@statuses,$status);
                   15362:                         }
                   15363:                     }
                   15364:                     $save_inststatus{'inststatusguest'} = \@statuses;
                   15365:                 } else {
                   15366:                     push(@statuses,'default');
                   15367:                 }
                   15368:                 if (@statuses) {
                   15369:                     my %curr_rule;
                   15370:                     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   15371:                         foreach my $type (@statuses) {
                   15372:                             $curr_rule{$type} = $curr_usercreation{'email_rule'};
                   15373:                         }
                   15374:                     } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
                   15375:                         foreach my $type (@statuses) {
                   15376:                             $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
                   15377:                         }
                   15378:                     }
                   15379:                     push(@{$cancreate{'selfcreate'}},'email');
                   15380:                     push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
                   15381:                     my %curremaildom;
                   15382:                     if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
                   15383:                         %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
                   15384:                     }
                   15385:                     foreach my $type (@statuses) {
                   15386:                         if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
                   15387:                             $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   15388:                         }
                   15389:                         if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
                   15390:                             $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
                   15391:                         }
                   15392:                         if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
                   15393: #
                   15394: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
                   15395: #
                   15396:                             my $chosen = $1;
                   15397:                             if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
                   15398:                                 my $emaildom;
                   15399:                                 if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
                   15400:                                     $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
                   15401:                                     $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
                   15402:                                     if (ref($curremaildom{$type}) eq 'HASH') {
                   15403:                                         if (exists($curremaildom{$type}{$chosen})) {
                   15404:                                             if ($curremaildom{$type}{$chosen} ne $emaildom) {
                   15405:                                                 push(@{$changes{'cancreate'}},'emaildomain');
                   15406:                                             }
                   15407:                                         } elsif ($emaildom ne '') {
                   15408:                                             push(@{$changes{'cancreate'}},'emaildomain');
                   15409:                                         }
                   15410:                                     } elsif ($emaildom ne '') {
                   15411:                                         push(@{$changes{'cancreate'}},'emaildomain');
                   15412:                                     }
                   15413:                                 }
                   15414:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15415:                             } elsif ($chosen eq 'custom') {
                   15416:                                 my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
                   15417:                                 $email_rule{$type} = [];
                   15418:                                 if (ref($emailrules) eq 'HASH') {
                   15419:                                     foreach my $rule (@possemail_rules) {
                   15420:                                         if (exists($emailrules->{$rule})) {
                   15421:                                             push(@{$email_rule{$type}},$rule);
                   15422:                                         }
                   15423:                                     }
                   15424:                                 }
                   15425:                                 if (@{$email_rule{$type}}) {
                   15426:                                     $cancreate{'emailoptions'}{$type} = 'custom';
                   15427:                                     if (ref($curr_rule{$type}) eq 'ARRAY') {
                   15428:                                         if (@{$curr_rule{$type}} > 0) {
                   15429:                                             foreach my $rule (@{$curr_rule{$type}}) {
                   15430:                                                 if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
                   15431:                                                     push(@{$changes{'email_rule'}},$type);
                   15432:                                                 }
                   15433:                                             }
                   15434:                                         }
                   15435:                                         foreach my $type (@{$email_rule{$type}}) {
                   15436:                                             if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
                   15437:                                                 push(@{$changes{'email_rule'}},$type);
                   15438:                                             }
                   15439:                                         }
                   15440:                                     } else {
                   15441:                                         push(@{$changes{'email_rule'}},$type);
                   15442:                                     }
                   15443:                                 }
                   15444:                             } else {
                   15445:                                 $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
                   15446:                             }
                   15447:                         }
                   15448:                     }
                   15449:                     if (@types) {
                   15450:                         if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15451:                             my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
                   15452:                             if (@changed) {
                   15453:                                 push(@{$changes{'inststatus'}},'inststatusguest');
                   15454:                             }
                   15455:                         } else {
                   15456:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15457:                         }
                   15458:                     }
                   15459:                 } else {
                   15460:                     delete($env{'form.cancreate_email'});
                   15461:                     if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15462:                         if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15463:                             push(@{$changes{'inststatus'}},'inststatusguest');
                   15464:                         }
                   15465:                     }
                   15466:                 }
                   15467:             } else {
                   15468:                 $save_inststatus{'inststatusguest'} = [];
                   15469:                 if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   15470:                     if (@{$curr_inststatus{'inststatusguest'}} > 0) {
                   15471:                         push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40  raeburn  15472:                     }
                   15473:                 }
1.160.6.34  raeburn  15474:             }
                   15475:         } else {
                   15476:             if ($env{'form.cancreate_'.$item}) {
                   15477:                 push(@{$cancreate{'selfcreate'}},$item);
                   15478:             }
                   15479:         }
                   15480:     }
1.160.6.93  raeburn  15481:     my (%userinfo,%savecaptcha);
1.160.6.34  raeburn  15482:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   15483: #
1.160.6.35  raeburn  15484: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   15485: # 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  15486: #
1.160.6.40  raeburn  15487: 
1.160.6.48  raeburn  15488:     if ($env{'form.cancreate_email'}) {
1.160.6.37  raeburn  15489:         push(@contexts,'emailusername');
1.160.6.93  raeburn  15490:         if (@statuses) {
                   15491:             foreach my $type (@statuses) {
1.160.6.35  raeburn  15492:                 if (ref($infofields) eq 'ARRAY') {
                   15493:                     foreach my $field (@{$infofields}) {
                   15494:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   15495:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   15496:                         }
                   15497:                     }
1.160.6.34  raeburn  15498:                 }
                   15499:             }
                   15500:         }
                   15501: #
                   15502: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93  raeburn  15503: # queued requests for self-creation of account verified by e-mail.
1.160.6.34  raeburn  15504: #
                   15505: 
                   15506:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   15507:         @approvalnotify = sort(@approvalnotify);
                   15508:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   15509:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15510:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   15511:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   15512:                     push(@{$changes{'cancreate'}},'notify');
                   15513:                 }
                   15514:             } else {
                   15515:                 if ($cancreate{'notify'}{'approval'}) {
                   15516:                     push(@{$changes{'cancreate'}},'notify');
                   15517:                 }
                   15518:             }
                   15519:         } elsif ($cancreate{'notify'}{'approval'}) {
                   15520:             push(@{$changes{'cancreate'}},'notify');
                   15521:         }
                   15522: 
                   15523:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   15524:     }
                   15525: #  
1.160.6.40  raeburn  15526: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34  raeburn  15527: # institutional log-in.
                   15528: #
                   15529:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   15530:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   15531:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   15532:             $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.').' '.
                   15533:                           &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.');
                   15534:         }
                   15535:     }
                   15536:     my @fields = ('lastname','firstname','middlename','generation',
                   15537:                   'permanentemail','id');
1.160.6.44  raeburn  15538:     my @shibfields = (@fields,'inststatus');
1.160.6.34  raeburn  15539:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   15540: #
                   15541: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   15542: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   15543: # may self-create accounts 
                   15544: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   15545: # which the user may supply, if institutional data is unavailable.
                   15546: #
                   15547:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93  raeburn  15548:         if (@types) {
                   15549:             @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   15550:             push(@contexts,'statustocreate');
                   15551:             foreach my $type (@types) {
1.160.6.34  raeburn  15552:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   15553:                 foreach my $field (@fields) {
                   15554:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   15555:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   15556:                     } else {
                   15557:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   15558:                     }
                   15559:                 }
                   15560:             }
                   15561:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93  raeburn  15562:                 foreach my $type (@types) {
1.160.6.34  raeburn  15563:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   15564:                         foreach my $field (@fields) {
                   15565:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   15566:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   15567:                                 push(@{$changes{'selfcreate'}},$type);
                   15568:                                 last;
                   15569:                             }
                   15570:                         }
                   15571:                     }
                   15572:                 }
                   15573:             } else {
1.160.6.93  raeburn  15574:                 foreach my $type (@types) {
1.160.6.34  raeburn  15575:                     push(@{$changes{'selfcreate'}},$type);
                   15576:                 }
                   15577:             }
                   15578:         }
1.160.6.44  raeburn  15579:         foreach my $field (@shibfields) {
                   15580:             if ($env{'form.shibenv_'.$field} ne '') {
                   15581:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   15582:             }
                   15583:         }
                   15584:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   15585:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   15586:                 foreach my $field (@shibfields) {
                   15587:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   15588:                         push(@{$changes{'cancreate'}},'shibenv');
                   15589:                     }
                   15590:                 }
                   15591:             } else {
                   15592:                 foreach my $field (@shibfields) {
                   15593:                     if ($env{'form.shibenv_'.$field}) {
                   15594:                         push(@{$changes{'cancreate'}},'shibenv');
                   15595:                         last;
                   15596:                     }
                   15597:                 }
                   15598:             }
                   15599:         }
1.160.6.34  raeburn  15600:     }
                   15601:     foreach my $item (@contexts) {
                   15602:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   15603:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   15604:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   15605:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   15606:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15607:                             push(@{$changes{'cancreate'}},$item);
                   15608:                         }
                   15609:                     }
                   15610:                 }
                   15611:             }
                   15612:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15613:                 foreach my $type (@{$cancreate{$item}}) {
                   15614:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   15615:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15616:                             push(@{$changes{'cancreate'}},$item);
                   15617:                         }
                   15618:                     }
                   15619:                 }
                   15620:             }
                   15621:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   15622:             if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93  raeburn  15623:                 foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
                   15624:                     if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15625:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
                   15626:                             unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  15627:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15628:                                     push(@{$changes{'cancreate'}},$item);
                   15629:                                 }
                   15630:                             }
                   15631:                         }
1.160.6.93  raeburn  15632:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15633:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  15634:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15635:                                 push(@{$changes{'cancreate'}},$item);
                   15636:                             }
1.160.6.34  raeburn  15637:                         }
                   15638:                     }
                   15639:                 }
1.160.6.93  raeburn  15640:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15641:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15642:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15643:                             if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
                   15644:                                 unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35  raeburn  15645:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15646:                                         push(@{$changes{'cancreate'}},$item);
                   15647:                                     }
                   15648:                                 }
                   15649:                             } else {
                   15650:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15651:                                     push(@{$changes{'cancreate'}},$item);
                   15652:                                 }
                   15653:                             }
                   15654:                         }
1.160.6.93  raeburn  15655:                     } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15656:                         if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35  raeburn  15657:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15658:                                 push(@{$changes{'cancreate'}},$item);
                   15659:                             }
1.160.6.34  raeburn  15660:                         }
                   15661:                     }
                   15662:                 }
                   15663:             }
                   15664:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   15665:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   15666:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   15667:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15668:                         push(@{$changes{'cancreate'}},$item);
                   15669:                     }
                   15670:                 }
1.160.6.93  raeburn  15671:             }
                   15672:         } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
                   15673:             if (ref($cancreate{$item}) eq 'HASH') {
                   15674:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15675:                     push(@{$changes{'cancreate'}},$item);
1.160.6.34  raeburn  15676:                 }
                   15677:             }
                   15678:         } elsif ($item eq 'emailusername') {
1.160.6.35  raeburn  15679:             if (ref($cancreate{$item}) eq 'HASH') {
                   15680:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   15681:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   15682:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   15683:                             if ($cancreate{$item}{$type}{$field}) {
                   15684:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   15685:                                     push(@{$changes{'cancreate'}},$item);
                   15686:                                 }
                   15687:                                 last;
                   15688:                             }
                   15689:                         }
                   15690:                     }
                   15691:                 }
1.160.6.34  raeburn  15692:             }
                   15693:         }
                   15694:     }
                   15695: #
                   15696: # Populate %save_usercreate hash with updates to self-creation configuration.
                   15697: #
                   15698:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   15699:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69  raeburn  15700:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34  raeburn  15701:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   15702:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   15703:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   15704:     }
1.160.6.40  raeburn  15705:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   15706:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   15707:     }
1.160.6.93  raeburn  15708:     if (ref($cancreate{'emailverified'}) eq 'HASH') {
                   15709:         $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
                   15710:     }
                   15711:     if (ref($cancreate{'emailoptions'}) eq 'HASH') {
                   15712:         $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
                   15713:     }
                   15714:     if (ref($cancreate{'emaildomain'}) eq 'HASH') {
                   15715:         $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
                   15716:     }
1.160.6.34  raeburn  15717:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15718:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   15719:     }
1.160.6.44  raeburn  15720:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   15721:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   15722:     }
1.160.6.34  raeburn  15723:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93  raeburn  15724:     $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34  raeburn  15725: 
                   15726:     my %userconfig_hash = (
                   15727:             usercreation     => \%save_usercreate,
                   15728:             usermodification => \%save_usermodify,
1.160.6.93  raeburn  15729:             inststatus       => \%save_inststatus,
1.160.6.34  raeburn  15730:     );
1.160.6.93  raeburn  15731: 
1.160.6.34  raeburn  15732:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   15733:                                              $dom);
                   15734: #
1.160.6.93  raeburn  15735: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34  raeburn  15736: #
1.27      raeburn  15737:     if ($putresult eq 'ok') {
                   15738:         if (keys(%changes) > 0) {
                   15739:             $resulttext = &mt('Changes made:').'<ul>';
                   15740:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34  raeburn  15741:                 my %lt = &selfcreation_types();
1.34      raeburn  15742:                 foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93  raeburn  15743:                     my $chgtext = '';
1.45      raeburn  15744:                     if ($type eq 'selfcreate') {
1.50      raeburn  15745:                         if (@{$cancreate{$type}} == 0) {
1.160.6.34  raeburn  15746:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  15747:                         } else {
1.160.6.34  raeburn  15748:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   15749:                                         '<ul>';
1.50      raeburn  15750:                             foreach my $case (@{$cancreate{$type}}) {
                   15751:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   15752:                             }
                   15753:                             $chgtext .= '</ul>';
1.100     raeburn  15754:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   15755:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   15756:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   15757:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93  raeburn  15758:                                             $chgtext .= '<span class="LC_warning">'.
                   15759:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
                   15760:                                                         '</span><br />';
1.100     raeburn  15761:                                         }
                   15762:                                     }
                   15763:                                 }
1.160.6.93  raeburn  15764:                                 if (grep(/^email$/,@{$cancreate{$type}})) {
                   15765:                                     if (!@statuses) {
                   15766:                                         $chgtext .= '<span class="LC_warning">'.
                   15767:                                                     &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.").
                   15768:                                                     '</span><br />';
                   15769: 
                   15770:                                     }
                   15771:                                 }
1.100     raeburn  15772:                             }
1.43      raeburn  15773:                         }
1.160.6.44  raeburn  15774:                     } elsif ($type eq 'shibenv') {
                   15775:                         if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93  raeburn  15776:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />'; 
1.160.6.44  raeburn  15777:                         } else {
                   15778:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   15779:                                         '<ul>';
                   15780:                             foreach my $field (@shibfields) {
                   15781:                                 next if ($cancreate{$type}{$field} eq '');
                   15782:                                 if ($field eq 'inststatus') {
                   15783:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   15784:                                 } else {
                   15785:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   15786:                                 }
                   15787:                             }
                   15788:                             $chgtext .= '</ul>';
1.160.6.93  raeburn  15789:                         }
1.93      raeburn  15790:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  15791:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   15792:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   15793:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   15794:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  15795:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  15796:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  15797:                                         $chgtext .= '<br />'.
                   15798:                                                     '<span class="LC_warning">'.
                   15799:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   15800:                                                     '</span>';
                   15801:                                     }
1.160.6.93  raeburn  15802:                                 } elsif (keys(%usertypes) > 0) {
1.96      raeburn  15803:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  15804:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   15805:                                     } else {
                   15806:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   15807:                                     }
                   15808:                                     $chgtext .= '<ul>';
                   15809:                                     foreach my $case (@{$cancreate{$type}}) {
                   15810:                                         if ($case eq 'default') {
                   15811:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   15812:                                         } else {
1.160.6.93  raeburn  15813:                                             $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93      raeburn  15814:                                         }
                   15815:                                     }
1.100     raeburn  15816:                                     $chgtext .= '</ul>';
                   15817:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93  raeburn  15818:                                         $chgtext .= '<span class="LC_warning">'.
1.160.6.34  raeburn  15819:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   15820:                                                     '</span>';
1.100     raeburn  15821:                                     }
                   15822:                                 }
                   15823:                             } else {
                   15824:                                 if (@{$cancreate{$type}} == 0) {
                   15825:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   15826:                                 } else {
                   15827:                                     $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  15828:                                 }
                   15829:                             }
1.160.6.93  raeburn  15830:                             $chgtext .= '<br />';
1.93      raeburn  15831:                         }
1.160.6.40  raeburn  15832:                     } elsif ($type eq 'selfcreateprocessing') {
                   15833:                         my %choices = &Apache::lonlocal::texthash (
                   15834:                                                                     automatic => 'Automatic approval',
                   15835:                                                                     approval  => 'Queued for approval',
                   15836:                                                                   );
1.160.6.93  raeburn  15837:                         if (@types) {
                   15838:                             if (@statuses) {
                   15839:                                 $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
                   15840:                                             '<ul>';
                   15841:                                 foreach my $status (@statuses) {
                   15842:                                     if ($status eq 'default') {
                   15843:                                         $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   15844:                                     } else {
                   15845:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
                   15846:                                     }
                   15847:                                 }
                   15848:                                 $chgtext .= '</ul>';
                   15849:                             }
                   15850:                         } else {
                   15851:                             $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
                   15852:                                             $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   15853:                         }
                   15854:                     } elsif ($type eq 'emailverified') {
                   15855:                         my %options = &Apache::lonlocal::texthash (
                   15856:                                                                     all   => 'Same as e-mail',
                   15857:                                                                     first => 'Omit @domain',
                   15858:                                                                     free  => 'Free to choose',
                   15859:                                                                   );
                   15860:                         if (@types) {
                   15861:                             if (@statuses) {
                   15862:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                   15863:                                             '<ul>';
                   15864:                                 foreach my $status (@statuses) {
                   15865:                                     if ($status eq 'default') {
                   15866:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   15867:                                     } else {
                   15868:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                   15869:                                     }
                   15870:                                 }
                   15871:                                 $chgtext .= '</ul>';
                   15872:                             }
1.160.6.40  raeburn  15873:                         } else {
1.160.6.93  raeburn  15874:                             $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
                   15875:                                             $options{$cancreate{'emailverified'}{'default'}});
                   15876:                         }
                   15877:                     } elsif ($type eq 'emailoptions') {
                   15878:                         my %options = &Apache::lonlocal::texthash (
                   15879:                                                                     any     => 'Any e-mail',
                   15880:                                                                     inst    => 'Institutional only',
                   15881:                                                                     noninst => 'Non-institutional only',
                   15882:                                                                     custom  => 'Custom restrictions',
                   15883:                                                                   );
                   15884:                         if (@types) {
                   15885:                             if (@statuses) {
                   15886:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
                   15887:                                             '<ul>';
                   15888:                                 foreach my $status (@statuses) {
                   15889:                                     if ($type eq 'default') {
                   15890:                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   15891:                                     } else {
                   15892:                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
                   15893:                                     }
                   15894:                                 }
                   15895:                                 $chgtext .= '</ul>';
                   15896:                             }
                   15897:                         } else {
                   15898:                             if ($cancreate{'emailoptions'}{'default'} eq 'any') {
                   15899:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
                   15900:                             } else {
                   15901:                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
                   15902:                                                 $options{$cancreate{'emailoptions'}{'default'}});
                   15903:                             }
                   15904:                         }
                   15905:                     } elsif ($type eq 'emaildomain') {
                   15906:                         my $output;
                   15907:                         if (@statuses) {
                   15908:                             foreach my $type (@statuses) {
                   15909:                                 if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
                   15910:                                     if ($cancreate{'emailoptions'}{$type} eq 'inst') {
                   15911:                                         if ($type eq 'default') {
                   15912:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15913:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15914:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15915:                                             } else {
                   15916:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15917:                                                                                         $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   15918:                                             }
                   15919:                                         } else {
                   15920:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15921:                                                 ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
                   15922:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15923:                                             } else {
                   15924:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
                   15925:                                                                                               $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
                   15926:                                             }
                   15927:                                         }
                   15928:                                     } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
                   15929:                                         if ($type eq 'default') {
                   15930:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15931:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15932:                                                 $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15933:                                             } else {
                   15934:                                                 $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15935:                                                                                         $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   15936:                                             }
                   15937:                                         } else {
                   15938:                                             if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
                   15939:                                                 ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
                   15940:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
                   15941:                                             } else {
                   15942:                                                 $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
                   15943:                                                                                                 $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
                   15944:                                             }
                   15945:                                         }
                   15946:                                     }
                   15947:                                 }
                   15948:                             }
                   15949:                         }
                   15950:                         if ($output ne '') {
                   15951:                             $chgtext .= &mt('For self-created accounts verified by e-mail address:').
                   15952:                                         '<ul>'.$output.'</ul>';
1.160.6.40  raeburn  15953:                         }
1.160.6.5  raeburn  15954:                     } elsif ($type eq 'captcha') {
1.160.6.34  raeburn  15955:                         if ($savecaptcha{$type} eq 'notused') {
1.160.6.5  raeburn  15956:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   15957:                         } else {
                   15958:                             my %captchas = &captcha_phrases();
1.160.6.34  raeburn  15959:                             if ($captchas{$savecaptcha{$type}}) {
                   15960:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5  raeburn  15961:                             } else {
                   15962:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                   15963:                             }
                   15964:                         }
                   15965:                     } elsif ($type eq 'recaptchakeys') {
                   15966:                         my ($privkey,$pubkey);
1.160.6.34  raeburn  15967:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   15968:                             $pubkey = $savecaptcha{$type}{'public'};
                   15969:                             $privkey = $savecaptcha{$type}{'private'};
1.160.6.5  raeburn  15970:                         }
                   15971:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   15972:                         if (!$pubkey) {
                   15973:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   15974:                         } else {
                   15975:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   15976:                         }
                   15977:                         if (!$privkey) {
                   15978:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   15979:                         } else {
                   15980:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   15981:                         }
                   15982:                         $chgtext .= '</ul>';
1.160.6.69  raeburn  15983:                     } elsif ($type eq 'recaptchaversion') {
                   15984:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
                   15985:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                   15986:                         }
1.160.6.34  raeburn  15987:                     } elsif ($type eq 'emailusername') {
                   15988:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93  raeburn  15989:                             if (@statuses) {
                   15990:                                 foreach my $type (@statuses) {
1.160.6.35  raeburn  15991:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   15992:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93  raeburn  15993:                                             $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  15994:                                                     '<ul>';
                   15995:                                             foreach my $field (@{$infofields}) {
                   15996:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   15997:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   15998:                                                 }
                   15999:                                             }
1.160.6.50  raeburn  16000:                                             $chgtext .= '</ul>';
                   16001:                                         } else {
1.160.6.93  raeburn  16002:                                             $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  16003:                                         }
                   16004:                                     } else {
1.160.6.93  raeburn  16005:                                         $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  16006:                                     }
                   16007:                                 }
                   16008:                             }
                   16009:                         }
                   16010:                     } elsif ($type eq 'notify') {
1.160.6.93  raeburn  16011:                         my $numapprove = 0;
1.160.6.34  raeburn  16012:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   16013:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   16014:                                 if ($cancreate{'notify'}{'approval'}) {
1.160.6.93  raeburn  16015:                                     $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   16016:                                     $numapprove ++;
1.160.6.34  raeburn  16017:                                 }
                   16018:                             }
1.43      raeburn  16019:                         }
1.160.6.93  raeburn  16020:                         unless ($numapprove) {
                   16021:                             $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   16022:                         }
1.34      raeburn  16023:                     }
1.160.6.34  raeburn  16024:                     if ($chgtext) {
                   16025:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  16026:                     }
                   16027:                 }
                   16028:             }
1.160.6.93  raeburn  16029:             if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43      raeburn  16030:                 my ($emailrules,$emailruleorder) =
                   16031:                     &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93  raeburn  16032:                 foreach my $type (@{$changes{'email_rule'}}) {
                   16033:                     if (ref($email_rule{$type}) eq 'ARRAY') {
                   16034:                         my $chgtext = '<ul>';
                   16035:                         foreach my $rule (@{$email_rule{$type}}) {
                   16036:                             if (ref($emailrules->{$rule}) eq 'HASH') {
                   16037:                                 $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
                   16038:                             }
                   16039:                         }
                   16040:                         $chgtext .= '</ul>';
                   16041:                         my $typename;
                   16042:                         if (@types) {
                   16043:                             if ($type eq 'default') {
                   16044:                                 $typename = $othertitle;
                   16045:                             } else {
                   16046:                                 $typename = $usertypes{$type};
                   16047:                             }
                   16048:                             $chgtext .= &mt('(Affiliation: [_1])',$typename);
                   16049:                         }
                   16050:                         if (@{$email_rule{$type}} > 0) {
                   16051:                             $resulttext .= '<li>'.
                   16052:                                            &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
                   16053:                                                $usertypes{$type}).
                   16054:                                            $chgtext.
                   16055:                                            '</li>';
                   16056:                         } else {
                   16057:                             $resulttext .= '<li>'.
                   16058:                                            &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
                   16059:                                            '</li>'.
                   16060:                                            &mt('(Affiliation: [_1])',$typename);
                   16061:                         }
1.43      raeburn  16062:                     }
                   16063:                 }
1.160.6.93  raeburn  16064:             }
                   16065:             if (ref($changes{'inststatus'}) eq 'ARRAY') {
                   16066:                 if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
                   16067:                     if (@{$save_inststatus{'inststatusguest'}} > 0) {
                   16068:                         my $chgtext = '<ul>';
                   16069:                         foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
                   16070:                             $chgtext .= '<li>'.$usertypes{$type}.'</li>';
                   16071:                         }
                   16072:                         $chgtext .= '</ul>';
                   16073:                         $resulttext .= '<li>'.
                   16074:                                        &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
                   16075:                                           $chgtext.
                   16076:                                        '</li>';
                   16077:                     } else {
                   16078:                         $resulttext .= '<li>'.
                   16079:                                        &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
                   16080:                                        '</li>';
                   16081:                     }
1.43      raeburn  16082:                 }
                   16083:             }
1.160.6.34  raeburn  16084:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   16085:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   16086:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   16087:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   16088:                     my $typename = $type;
1.160.6.93  raeburn  16089:                     if (keys(%usertypes) > 0) {
                   16090:                         if ($usertypes{$type} ne '') {
                   16091:                             $typename = $usertypes{$type};
1.28      raeburn  16092:                         }
                   16093:                     }
1.160.6.34  raeburn  16094:                     my @modifiable;
                   16095:                     $resulttext .= '<li>'.
                   16096:                                     &mt('Self-creation of account by users with status: [_1]',
                   16097:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   16098:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   16099:                     foreach my $field (@fields) {
                   16100:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   16101:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
                   16102:                         }
                   16103:                     }
                   16104:                     if (@modifiable > 0) {
                   16105:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  16106:                     } else {
1.160.6.34  raeburn  16107:                         $resulttext .= &mt('none');
1.43      raeburn  16108:                     }
1.160.6.34  raeburn  16109:                     $resulttext .= '</li>';
1.28      raeburn  16110:                 }
1.160.6.34  raeburn  16111:                 $resulttext .= '</ul></li>';
1.28      raeburn  16112:             }
1.27      raeburn  16113:             $resulttext .= '</ul>';
1.160.6.93  raeburn  16114:             my $cachetime = 24*60*60;
                   16115:             $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
                   16116:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   16117:             if (ref($lastactref) eq 'HASH') {
                   16118:                 $lastactref->{'domdefaults'} = 1;
                   16119:             }
1.27      raeburn  16120:         } else {
1.160.6.34  raeburn  16121:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  16122:         }
                   16123:     } else {
                   16124:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  16125:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16126:     }
1.43      raeburn  16127:     if ($warningmsg ne '') {
                   16128:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   16129:     }
1.23      raeburn  16130:     return $resulttext;
                   16131: }
                   16132: 
1.160.6.5  raeburn  16133: sub process_captcha {
1.160.6.104  raeburn  16134:     my ($container,$changes,$newsettings,$currsettings) = @_;
                   16135:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5  raeburn  16136:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   16137:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   16138:         $newsettings->{'captcha'} = 'original';
                   16139:     }
1.160.6.104  raeburn  16140:     my %current;
                   16141:     if (ref($currsettings) eq 'HASH') {
                   16142:         %current = %{$currsettings};
                   16143:     }
                   16144:     if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5  raeburn  16145:         if ($container eq 'cancreate') {
                   16146:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16147:                 push(@{$changes->{'cancreate'}},'captcha');
                   16148:             } elsif (!defined($changes->{'cancreate'})) {
                   16149:                 $changes->{'cancreate'} = ['captcha'];
                   16150:             }
1.160.6.102  raeburn  16151:         } elsif ($container eq 'passwords') {
                   16152:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  16153:         } else {
                   16154:             $changes->{'captcha'} = 1;
                   16155:         }
                   16156:     }
1.160.6.69  raeburn  16157:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5  raeburn  16158:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   16159:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   16160:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52  raeburn  16161:         $newpub =~ s/[^\w\-]//g;
                   16162:         $newpriv =~ s/[^\w\-]//g;
1.160.6.5  raeburn  16163:         $newsettings->{'recaptchakeys'} = {
                   16164:                                              public  => $newpub,
                   16165:                                              private => $newpriv,
                   16166:                                           };
1.160.6.69  raeburn  16167:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   16168:         $newversion =~ s/\D//g;
                   16169:         if ($newversion ne '2') {
                   16170:             $newversion = 1;
                   16171:         }
                   16172:         $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5  raeburn  16173:     }
1.160.6.104  raeburn  16174:     if (ref($current{'recaptchakeys'}) eq 'HASH') {
                   16175:         $currpub = $current{'recaptchakeys'}{'public'};
                   16176:         $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10  raeburn  16177:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   16178:             $newsettings->{'recaptchakeys'} = {
                   16179:                                                  public  => '',
                   16180:                                                  private => '',
                   16181:                                               }
                   16182:         }
1.160.6.5  raeburn  16183:     }
1.160.6.104  raeburn  16184:     if ($current{'captcha'} eq 'recaptcha') {
                   16185:         $currversion = $current{'recaptchaversion'};
1.160.6.69  raeburn  16186:         if ($currversion ne '2') {
                   16187:             $currversion = 1;
                   16188:         }
                   16189:     }
                   16190:     if ($currversion ne $newversion) {
                   16191:         if ($container eq 'cancreate') {
                   16192:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16193:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   16194:             } elsif (!defined($changes->{'cancreate'})) {
                   16195:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   16196:             }
1.160.6.102  raeburn  16197:         } elsif ($container eq 'passwords') {
                   16198:             $changes->{'reset'} = 1;
1.160.6.69  raeburn  16199:         } else {
                   16200:             $changes->{'recaptchaversion'} = 1;
                   16201:         }
                   16202:     }
1.160.6.5  raeburn  16203:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
                   16204:         if ($container eq 'cancreate') {
                   16205:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   16206:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   16207:             } elsif (!defined($changes->{'cancreate'})) {
                   16208:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   16209:             }
1.160.6.102  raeburn  16210:         } elsif ($container eq 'passwords') {
                   16211:             $changes->{'reset'} = 1;
1.160.6.5  raeburn  16212:         } else {
                   16213:             $changes->{'recaptchakeys'} = 1;
                   16214:         }
                   16215:     }
                   16216:     return;
                   16217: }
                   16218: 
1.33      raeburn  16219: sub modify_usermodification {
                   16220:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  16221:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  16222:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   16223:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34  raeburn  16224:             if ($key eq 'selfcreate') {
                   16225:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   16226:             } else {  
                   16227:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   16228:             }
1.33      raeburn  16229:         }
                   16230:     }
1.160.6.34  raeburn  16231:     my @contexts = ('author','course');
1.33      raeburn  16232:     my %context_title = (
                   16233:                            author => 'In author context',
                   16234:                            course => 'In course context',
                   16235:                         );
                   16236:     my @fields = ('lastname','firstname','middlename','generation',
                   16237:                   'permanentemail','id');
                   16238:     my %roles = (
                   16239:                   author => ['ca','aa'],
                   16240:                   course => ['st','ep','ta','in','cr'],
                   16241:                 );
                   16242:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   16243:     foreach my $context (@contexts) {
                   16244:         foreach my $role (@{$roles{$context}}) {
                   16245:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   16246:             foreach my $item (@fields) {
                   16247:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   16248:                     $modifyhash{$context}{$role}{$item} = 1;
                   16249:                 } else {
                   16250:                     $modifyhash{$context}{$role}{$item} = 0;
                   16251:                 }
                   16252:             }
                   16253:         }
                   16254:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   16255:             foreach my $role (@{$roles{$context}}) {
                   16256:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   16257:                     foreach my $field (@fields) {
                   16258:                         if ($modifyhash{$context}{$role}{$field} ne 
                   16259:                                 $curr_usermodification{$context}{$role}{$field}) {
                   16260:                             push(@{$changes{$context}},$role);
                   16261:                             last;
                   16262:                         }
                   16263:                     }
                   16264:                 }
                   16265:             }
                   16266:         } else {
                   16267:             foreach my $context (@contexts) {
                   16268:                 foreach my $role (@{$roles{$context}}) {
                   16269:                     push(@{$changes{$context}},$role);
                   16270:                 }
                   16271:             }
                   16272:         }
                   16273:     }
                   16274:     my %usermodification_hash =  (
                   16275:                                    usermodification => \%modifyhash,
                   16276:                                  );
                   16277:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   16278:                                              \%usermodification_hash,$dom);
                   16279:     if ($putresult eq 'ok') {
                   16280:         if (keys(%changes) > 0) {
                   16281:             $resulttext = &mt('Changes made: ').'<ul>';
                   16282:             foreach my $context (@contexts) {
                   16283:                 if (ref($changes{$context}) eq 'ARRAY') {
                   16284:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   16285:                     if (ref($changes{$context}) eq 'ARRAY') {
                   16286:                         foreach my $role (@{$changes{$context}}) {
                   16287:                             my $rolename;
1.160.6.34  raeburn  16288:                             if ($role eq 'cr') {
                   16289:                                 $rolename = &mt('Custom');
1.33      raeburn  16290:                             } else {
1.160.6.34  raeburn  16291:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  16292:                             }
                   16293:                             my @modifiable;
1.160.6.34  raeburn  16294:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  16295:                             foreach my $field (@fields) {
                   16296:                                 if ($modifyhash{$context}{$role}{$field}) {
                   16297:                                     push(@modifiable,$fieldtitles{$field});
                   16298:                                 }
                   16299:                             }
                   16300:                             if (@modifiable > 0) {
                   16301:                                 $resulttext .= join(', ',@modifiable);
                   16302:                             } else {
                   16303:                                 $resulttext .= &mt('none'); 
                   16304:                             }
                   16305:                             $resulttext .= '</li>';
                   16306:                         }
                   16307:                         $resulttext .= '</ul></li>';
                   16308:                     }
                   16309:                 }
                   16310:             }
                   16311:             $resulttext .= '</ul>';
                   16312:         } else {
                   16313:             $resulttext = &mt('No changes made to user modification settings');
                   16314:         }
                   16315:     } else {
                   16316:         $resulttext = '<span class="LC_error">'.
                   16317:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16318:     }
                   16319:     return $resulttext;
                   16320: }
                   16321: 
1.43      raeburn  16322: sub modify_defaults {
1.160.6.27  raeburn  16323:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  16324:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27  raeburn  16325:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80  raeburn  16326:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98  raeburn  16327:                  'portal_def');
1.43      raeburn  16328:     my @authtypes = ('internal','krb4','krb5','localauth');
                   16329:     foreach my $item (@items) {
                   16330:         $newvalues{$item} = $env{'form.'.$item};
                   16331:         if ($item eq 'auth_def') {
                   16332:             if ($newvalues{$item} ne '') {
                   16333:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   16334:                     push(@errors,$item);
                   16335:                 }
                   16336:             }
                   16337:         } elsif ($item eq 'lang_def') {
                   16338:             if ($newvalues{$item} ne '') {
                   16339:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   16340:                     my $langcode = $1;
1.103     raeburn  16341:                     if ($langcode ne 'x_chef') {
                   16342:                         if (code2language($langcode) eq '') {
                   16343:                             push(@errors,$item);
                   16344:                         }
1.43      raeburn  16345:                     }
                   16346:                 } else {
                   16347:                     push(@errors,$item);
                   16348:                 }
                   16349:             }
1.54      raeburn  16350:         } elsif ($item eq 'timezone_def') {
                   16351:             if ($newvalues{$item} ne '') {
1.62      raeburn  16352:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  16353:                     push(@errors,$item);   
                   16354:                 }
                   16355:             }
1.68      raeburn  16356:         } elsif ($item eq 'datelocale_def') {
                   16357:             if ($newvalues{$item} ne '') {
                   16358:                 my @datelocale_ids = DateTime::Locale->ids();
                   16359:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   16360:                     push(@errors,$item);
                   16361:                 }
                   16362:             }
1.141     raeburn  16363:         } elsif ($item eq 'portal_def') {
                   16364:             if ($newvalues{$item} ne '') {
                   16365:                 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])\/?$/) {
                   16366:                     push(@errors,$item);
                   16367:                 }
                   16368:             }
1.43      raeburn  16369:         }
                   16370:         if (grep(/^\Q$item\E$/,@errors)) {
                   16371:             $newvalues{$item} = $domdefaults{$item};
                   16372:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   16373:             $changes{$item} = 1;
                   16374:         }
1.72      raeburn  16375:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  16376:     }
1.160.6.98  raeburn  16377:     my %staticdefaults = (
                   16378:                            'intauth_cost'   => 10,
                   16379:                            'intauth_check'  => 0,
                   16380:                            'intauth_switch' => 0,
                   16381:                          );
                   16382:     foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
                   16383:         if (exists($domdefaults{$item})) {
                   16384:             $newvalues{$item} = $domdefaults{$item};
                   16385:         } else {
                   16386:             $newvalues{$item} = $staticdefaults{$item};
                   16387:         }
                   16388:     }
1.160.6.118.2  8(raebur 16389:2):     my ($unamemaprules,$ruleorder);
                   16390:2):     my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
                   16391:2):     if (@possunamemaprules) {
                   16392:2):         ($unamemaprules,$ruleorder) =
                   16393:2):             &Apache::lonnet::inst_userrules($dom,'unamemap');
                   16394:2):         if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   16395:2):             if (@{$ruleorder} > 0) {
                   16396:2):                 my %possrules;
                   16397:2):                 map { $possrules{$_} = 1; } @possunamemaprules;
                   16398:2):                 foreach my $rule (@{$ruleorder}) {
                   16399:2):                     if ($possrules{$rule}) {
                   16400:2):                         push(@{$newvalues{'unamemap_rule'}},$rule);
                   16401:2):                     }
                   16402:2):                 }
                   16403:2):             }
                   16404:2):         }
                   16405:2):     }
                   16406:2):     if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
                   16407:2):         if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   16408:2):             my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
                   16409:2):                                                                $newvalues{'unamemap_rule'});
                   16410:2):             if (@rulediffs) {
                   16411:2):                 $changes{'unamemap_rule'} = 1;
                   16412:2):                 $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   16413:2):             }
                   16414:2):         } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
                   16415:2):             $changes{'unamemap_rule'} = 1;
                   16416:2):             delete($domdefaults{'unamemap_rule'});
                   16417:2):         }
                   16418:2):     } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   16419:2):         if (@{$newvalues{'unamemap_rule'}} > 0) {
                   16420:2):             $changes{'unamemap_rule'} = 1;
                   16421:2):             $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
                   16422:2):         }
                   16423:2):     }
1.43      raeburn  16424:     my %defaults_hash = (
1.72      raeburn  16425:                          defaults => \%newvalues,
                   16426:                         );
1.43      raeburn  16427:     my $title = &defaults_titles();
1.160.6.40  raeburn  16428: 
                   16429:     my $currinststatus;
                   16430:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   16431:         $currinststatus = $domconfig{'inststatus'};
                   16432:     } else {
                   16433:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   16434:         $currinststatus = {
                   16435:                              inststatustypes => $usertypes,
                   16436:                              inststatusorder => $types,
                   16437:                              inststatusguest => [],
                   16438:                           };
                   16439:     }
                   16440:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   16441:     my @allpos;
                   16442:     my %alltypes;
1.160.6.93  raeburn  16443:     my @inststatusguest;
                   16444:     if (ref($currinststatus) eq 'HASH') {
                   16445:         if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   16446:             foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
                   16447:                 unless (grep(/^\Q$type\E$/,@todelete)) {
                   16448:                     push(@inststatusguest,$type);
                   16449:                 }
                   16450:             }
                   16451:         }
                   16452:     }
                   16453:     my ($currtitles,$currorder);
1.160.6.40  raeburn  16454:     if (ref($currinststatus) eq 'HASH') {
                   16455:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   16456:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   16457:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   16458:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   16459:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   16460:                     }
                   16461:                 }
                   16462:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   16463:                     my $position = $env{'form.inststatus_pos_'.$type};
                   16464:                     $position =~ s/\D+//g;
                   16465:                     $allpos[$position] = $type;
                   16466:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   16467:                     $alltypes{$type} =~ s/`//g;
                   16468:                 }
                   16469:             }
                   16470:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   16471:             $currtitles =~ s/,$//;
                   16472:         }
                   16473:     }
                   16474:     if ($env{'form.addinststatus'}) {
                   16475:         my $newtype = $env{'form.addinststatus'};
                   16476:         $newtype =~ s/\W//g;
                   16477:         unless (exists($alltypes{$newtype})) {
                   16478:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   16479:             $alltypes{$newtype} =~ s/`//g; 
                   16480:             my $position = $env{'form.addinststatus_pos'};
                   16481:             $position =~ s/\D+//g;
                   16482:             if ($position ne '') {
                   16483:                 $allpos[$position] = $newtype;
                   16484:             }
                   16485:         }
                   16486:     }
1.160.6.93  raeburn  16487:     my @orderedstatus;
1.160.6.40  raeburn  16488:     foreach my $type (@allpos) {
                   16489:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   16490:             push(@orderedstatus,$type);
                   16491:         }
                   16492:     }
                   16493:     foreach my $type (keys(%alltypes)) {
                   16494:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   16495:             delete($alltypes{$type});
                   16496:         }
                   16497:     }
                   16498:     $defaults_hash{'inststatus'} = {
                   16499:                                      inststatustypes => \%alltypes,
                   16500:                                      inststatusorder => \@orderedstatus,
1.160.6.93  raeburn  16501:                                      inststatusguest => \@inststatusguest,
1.160.6.40  raeburn  16502:                                    };
                   16503:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   16504:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   16505:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   16506:         }
                   16507:     }
                   16508:     if ($currorder ne join(',',@orderedstatus)) {
                   16509:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   16510:     }
                   16511:     my $newtitles;
                   16512:     foreach my $item (@orderedstatus) {
                   16513:         $newtitles .= $alltypes{$item}.',';
                   16514:     }
                   16515:     $newtitles =~ s/,$//;
                   16516:     if ($currtitles ne $newtitles) {
                   16517:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   16518:     }
1.43      raeburn  16519:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   16520:                                              $dom);
                   16521:     if ($putresult eq 'ok') {
                   16522:         if (keys(%changes) > 0) {
                   16523:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27  raeburn  16524:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  16525:             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";
                   16526:             foreach my $item (sort(keys(%changes))) {
1.160.6.40  raeburn  16527:                 if ($item eq 'inststatus') {
                   16528:                     if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93  raeburn  16529:                         if (@orderedstatus) {
1.160.6.40  raeburn  16530:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   16531:                             foreach my $type (@orderedstatus) { 
                   16532:                                 $resulttext .= $alltypes{$type}.', ';
                   16533:                             }
                   16534:                             $resulttext =~ s/, $//;
                   16535:                             $resulttext .= '</li>';
1.160.6.93  raeburn  16536:                         } else {
                   16537:                             $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40  raeburn  16538:                         }
                   16539:                     }
1.160.6.118.2  8(raebur 16540:2):                 } elsif ($item eq 'unamemap_rule') {
                   16541:2):                     if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
                   16542:2):                         my @rulenames;
                   16543:2):                         if (ref($unamemaprules) eq 'HASH') {
                   16544:2):                             foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
                   16545:2):                                 if (ref($unamemaprules->{$rule}) eq 'HASH') {
                   16546:2):                                     push(@rulenames,$unamemaprules->{$rule}->{'name'});
                   16547:2):                                 }
                   16548:2):                             }
                   16549:2):                         }
                   16550:2):                         if (@rulenames) {
                   16551:2):                             $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
                   16552:2):                                                      '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
                   16553:2):                                            '</li>';
                   16554:2):                         } else {
                   16555:2):                             $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>'; 
                   16556:2):                         } 
                   16557:2):                     } else {
                   16558:2):                         $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
                   16559:2):                     }
1.160.6.40  raeburn  16560:                 } else {
                   16561:                     my $value = $env{'form.'.$item};
                   16562:                     if ($value eq '') {
                   16563:                         $value = &mt('none');
                   16564:                     } elsif ($item eq 'auth_def') {
                   16565:                         my %authnames = &authtype_names();
                   16566:                         my %shortauth = (
                   16567:                                           internal   => 'int',
                   16568:                                           krb4       => 'krb4',
                   16569:                                           krb5       => 'krb5',
                   16570:                                           localauth  => 'loc',
                   16571:                         );
                   16572:                         $value = $authnames{$shortauth{$value}};
                   16573:                     }
                   16574:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   16575:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  16576:                 }
                   16577:             }
                   16578:             $resulttext .= '</ul>';
                   16579:             $mailmsgtext .= "\n";
                   16580:             my $cachetime = 24*60*60;
1.72      raeburn  16581:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  16582:             if (ref($lastactref) eq 'HASH') {
                   16583:                 $lastactref->{'domdefaults'} = 1;
                   16584:             }
1.68      raeburn  16585:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23  raeburn  16586:                 my $notify = 1;
                   16587:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   16588:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   16589:                         $notify = 0;
                   16590:                     }
                   16591:                 }
                   16592:                 if ($notify) {
                   16593:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   16594:                                                "LON-CAPA Domain Settings Change - $dom",
                   16595:                                                $mailmsgtext);
                   16596:                 }
1.54      raeburn  16597:             }
1.43      raeburn  16598:         } else {
1.54      raeburn  16599:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  16600:         }
                   16601:     } else {
                   16602:         $resulttext = '<span class="LC_error">'.
                   16603:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   16604:     }
                   16605:     if (@errors > 0) {
                   16606:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   16607:         foreach my $item (@errors) {
                   16608:             $resulttext .= ' "'.$title->{$item}.'",';
                   16609:         }
                   16610:         $resulttext =~ s/,$//;
                   16611:     }
                   16612:     return $resulttext;
                   16613: }
                   16614: 
1.46      raeburn  16615: sub modify_scantron {
1.160.6.24  raeburn  16616:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  16617:     my ($resulttext,%confhash,%changes,$errors);
                   16618:     my $custom = 'custom.tab';
                   16619:     my $default = 'default.tab';
                   16620:     my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97  raeburn  16621:     my ($configuserok,$author_ok,$switchserver) =
1.46      raeburn  16622:         &config_check($dom,$confname,$servadm);
                   16623:     if ($env{'form.scantronformat.filename'} ne '') {
                   16624:         my $error;
                   16625:         if ($configuserok eq 'ok') {
                   16626:             if ($switchserver) {
1.130     raeburn  16627:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  16628:             } else {
                   16629:                 if ($author_ok eq 'ok') {
                   16630:                     my ($result,$scantronurl) =
                   16631:                         &publishlogo($r,'upload','scantronformat',$dom,
                   16632:                                      $confname,'scantron','','',$custom);
                   16633:                     if ($result eq 'ok') {
                   16634:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  16635:                         $changes{'scantronformat'} = 1;
1.46      raeburn  16636:                     } else {
                   16637:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   16638:                     }
                   16639:                 } else {
                   16640:                     $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);
                   16641:                 }
                   16642:             }
                   16643:         } else {
                   16644:             $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);
                   16645:         }
                   16646:         if ($error) {
                   16647:             &Apache::lonnet::logthis($error);
                   16648:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   16649:         }
                   16650:     }
1.48      raeburn  16651:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16652:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   16653:             if ($env{'form.scantronformat_del'}) {
                   16654:                 $confhash{'scantron'}{'scantronformat'} = '';
                   16655:                 $changes{'scantronformat'} = 1;
1.160.6.97  raeburn  16656:             } else {
                   16657:                 $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
                   16658:             }
                   16659:         }
                   16660:     }
                   16661:     my @options = ('hdr','pad','rem');
                   16662:     my @fields = &scantroncsv_fields();
                   16663:     my %titles = &scantronconfig_titles();
                   16664:     my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
                   16665:     my ($newdat,$currdat,%newcol,%currcol);
                   16666:     if (grep(/^dat$/,@formats)) {
                   16667:         $confhash{'scantron'}{config}{dat} = 1;
                   16668:         $newdat = 1;
                   16669:     } else {
                   16670:         $newdat = 0;
                   16671:     }
                   16672:     if (grep(/^csv$/,@formats)) {
                   16673:         my %bynum;
                   16674:         foreach my $field (@fields) {
                   16675:             if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   16676:                 my $posscol = $1;
                   16677:                 if (($posscol < 20) && (!$bynum{$posscol})) {
                   16678:                     $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
                   16679:                     $bynum{$posscol} = $field;
                   16680:                     $newcol{$field} = $posscol;
                   16681:                 }
                   16682:             }
                   16683:         }
                   16684:         if (keys(%newcol)) {
                   16685:             foreach my $option (@options) {
                   16686:                 if ($env{'form.scantroncsv_'.$option}) {
                   16687:                     $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   16688:                 }
                   16689:             }
                   16690:         }
                   16691:     }
                   16692:     $currdat = 1;
                   16693:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   16694:         if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
                   16695:             unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
                   16696:                 $currdat = 0;
                   16697:             }
                   16698:             if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   16699:                 if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16700:                     %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   16701:                 }
                   16702:             }
                   16703:         }
                   16704:     }
                   16705:     if ($currdat != $newdat) {
                   16706:         $changes{'config'} = 1;
                   16707:     } else {
                   16708:         foreach my $field (@fields) {
                   16709:             if ($currcol{$field} ne '') {
                   16710:                 if ($currcol{$field} ne $newcol{$field}) {
                   16711:                     $changes{'config'} = 1;
                   16712:                     last;
                   16713:                 }
                   16714:             } elsif ($newcol{$field} ne '') {
                   16715:                 $changes{'config'} = 1;
                   16716:                 last;
1.46      raeburn  16717:             }
                   16718:         }
                   16719:     }
                   16720:     if (keys(%confhash) > 0) {
                   16721:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   16722:                                                  $dom);
                   16723:         if ($putresult eq 'ok') {
                   16724:             if (keys(%changes) > 0) {
1.48      raeburn  16725:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   16726:                     $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97  raeburn  16727:                     if ($changes{'scantronformat'}) {
                   16728:                         if ($confhash{'scantron'}{'scantronformat'} eq '') {
                   16729:                             $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                   16730:                         } else {
                   16731:                             $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                   16732:                         }
                   16733:                     }
                   16734:                     if ($changes{'config'}) {
                   16735:                         if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                   16736:                             if ($confhash{'scantron'}{'config'}{'dat'}) {
                   16737:                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                   16738:                             }
                   16739:                             if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   16740:                                 if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                   16741:                                     if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                   16742:                                         $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                   16743:                                         foreach my $field (@fields) {
                   16744:                                             if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                   16745:                                                 my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                   16746:                                                 $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                   16747:                                             }
                   16748:                                         }
                   16749:                                         $resulttext .= '</ul></li>';
                   16750:                                         if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                   16751:                                             if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                   16752:                                                 $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                   16753:                                                 foreach my $option (@options) {
                   16754:                                                     if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                   16755:                                                         $resulttext .= '<li>'.$titles{$option}.'</li>';
                   16756:                                                     }
                   16757:                                                 }
                   16758:                                                 $resulttext .= '</ul></li>';
                   16759:                                             }
                   16760:                                         }
                   16761:                                     }
                   16762:                                 }
                   16763:                             }
                   16764:                         } else {
                   16765:                             $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                   16766:                         }
1.46      raeburn  16767:                     }
1.48      raeburn  16768:                     $resulttext .= '</ul>';
                   16769:                 } else {
1.130     raeburn  16770:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  16771:                 }
                   16772:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  16773:                 if (ref($lastactref) eq 'HASH') {
                   16774:                     $lastactref->{'domainconfig'} = 1;
                   16775:                 }
1.46      raeburn  16776:             } else {
1.160.6.97  raeburn  16777:                 $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  16778:             }
                   16779:         } else {
                   16780:             $resulttext = '<span class="LC_error">'.
                   16781:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   16782:         }
                   16783:     } else {
1.160.6.97  raeburn  16784:         $resulttext = &mt('No changes made to bubblesheet format settings');
1.46      raeburn  16785:     }
                   16786:     if ($errors) {
                   16787:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   16788:                        $errors.'</ul>';
                   16789:     }
                   16790:     return $resulttext;
                   16791: }
                   16792: 
1.48      raeburn  16793: sub modify_coursecategories {
1.160.6.43  raeburn  16794:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  16795:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   16796:         $cathash);
1.48      raeburn  16797:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42  raeburn  16798:     my @catitems = ('unauth','auth');
                   16799:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  16800:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  16801:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   16802:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   16803:             $changes{'togglecats'} = 1;
                   16804:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   16805:         }
                   16806:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   16807:             $changes{'categorize'} = 1;
                   16808:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   16809:         }
1.120     raeburn  16810:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   16811:             $changes{'togglecatscomm'} = 1;
                   16812:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   16813:         }
                   16814:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   16815:             $changes{'categorizecomm'} = 1;
                   16816:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   16817:         }
1.160.6.42  raeburn  16818:         foreach my $item (@catitems) {
                   16819:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16820:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   16821:                     $changes{$item} = 1;
                   16822:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16823:                 }
                   16824:             }
                   16825:         }
1.57      raeburn  16826:     } else {
                   16827:         $changes{'togglecats'} = 1;
                   16828:         $changes{'categorize'} = 1;
1.124     raeburn  16829:         $changes{'togglecatscomm'} = 1;
                   16830:         $changes{'categorizecomm'} = 1;
1.87      raeburn  16831:         $domconfig{'coursecategories'} = {
                   16832:                                              togglecats => $env{'form.togglecats'},
                   16833:                                              categorize => $env{'form.categorize'},
1.124     raeburn  16834:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   16835:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  16836:                                          };
1.160.6.42  raeburn  16837:         foreach my $item (@catitems) {
                   16838:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   16839:                 $changes{$item} = 1;
                   16840:             }
                   16841:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   16842:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   16843:             }
                   16844:         }
1.57      raeburn  16845:     }
                   16846:     if (ref($cathash) eq 'HASH') {
                   16847:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  16848:             push (@deletecategory,'instcode::0');
                   16849:         }
1.120     raeburn  16850:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   16851:             push(@deletecategory,'communities::0');
                   16852:         }
1.48      raeburn  16853:     }
1.57      raeburn  16854:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   16855:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  16856:         if (@deletecategory > 0) {
                   16857:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  16858:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  16859:             foreach my $item (@deletecategory) {
1.57      raeburn  16860:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   16861:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  16862:                     $deletions{$item} = 1;
1.57      raeburn  16863:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  16864:                 }
                   16865:             }
                   16866:         }
1.57      raeburn  16867:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  16868:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  16869:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  16870:                 $reorderings{$item} = 1;
1.57      raeburn  16871:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  16872:             }
                   16873:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   16874:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   16875:                 my $newdepth = $depth+1;
                   16876:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16877:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  16878:                 $adds{$newitem} = 1; 
                   16879:             }
                   16880:             if ($env{'form.subcat_'.$item} ne '') {
                   16881:                 my $newcat = $env{'form.subcat_'.$item};
                   16882:                 my $newdepth = $depth+1;
                   16883:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  16884:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  16885:                 $adds{$newitem} = 1;
                   16886:             }
                   16887:         }
                   16888:     }
                   16889:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  16890:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  16891:             my $newitem = 'instcode::0';
1.57      raeburn  16892:             if ($cathash->{$newitem} eq '') {  
                   16893:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16894:                 $adds{$newitem} = 1;
                   16895:             }
                   16896:         } else {
                   16897:             my $newitem = 'instcode::0';
1.57      raeburn  16898:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  16899:             $adds{$newitem} = 1;
                   16900:         }
                   16901:     }
1.120     raeburn  16902:     if ($env{'form.communities'} eq '1') {
                   16903:         if (ref($cathash) eq 'HASH') {
                   16904:             my $newitem = 'communities::0';
                   16905:             if ($cathash->{$newitem} eq '') {
                   16906:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16907:                 $adds{$newitem} = 1;
                   16908:             }
                   16909:         } else {
                   16910:             my $newitem = 'communities::0';
                   16911:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   16912:             $adds{$newitem} = 1;
                   16913:         }
                   16914:     }
1.48      raeburn  16915:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  16916:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   16917:             ($env{'form.addcategory_name'} ne 'communities')) {
                   16918:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   16919:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   16920:             $adds{$newitem} = 1;
                   16921:         }
1.48      raeburn  16922:     }
1.57      raeburn  16923:     my $putresult;
1.48      raeburn  16924:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16925:         if (keys(%deletions) > 0) {
                   16926:             foreach my $key (keys(%deletions)) {
                   16927:                 if ($predelallitems{$key} ne '') {
                   16928:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   16929:                 }
                   16930:             }
                   16931:         }
                   16932:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  16933:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  16934:         if (ref($chkcats[0]) eq 'ARRAY') {
                   16935:             my $depth = 0;
                   16936:             my $chg = 0;
                   16937:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   16938:                 my $name = $chkcats[0][$i];
                   16939:                 my $item;
                   16940:                 if ($name eq '') {
                   16941:                     $chg ++;
                   16942:                 } else {
                   16943:                     $item = &escape($name).'::0';
                   16944:                     if ($chg) {
1.57      raeburn  16945:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  16946:                     }
                   16947:                     $depth ++; 
1.57      raeburn  16948:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  16949:                     $depth --;
                   16950:                 }
                   16951:             }
                   16952:         }
1.57      raeburn  16953:     }
                   16954:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16955:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  16956:         if ($putresult eq 'ok') {
1.57      raeburn  16957:             my %title = (
1.120     raeburn  16958:                          togglecats     => 'Show/Hide a course in catalog',
                   16959:                          categorize     => 'Assign a category to a course',
                   16960:                          togglecatscomm => 'Show/Hide a community in catalog',
                   16961:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  16962:                         );
                   16963:             my %level = (
1.120     raeburn  16964:                          dom  => 'set in Domain ("Modify Course/Community")',
                   16965:                          crs  => 'set in Course ("Course Configuration")',
                   16966:                          comm => 'set in Community ("Community Configuration")',
1.160.6.42  raeburn  16967:                          none     => 'No catalog',
                   16968:                          std      => 'Standard catalog',
                   16969:                          domonly  => 'Domain-only catalog',
                   16970:                          codesrch => 'Code search form',
1.57      raeburn  16971:                         );
1.48      raeburn  16972:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  16973:             if ($changes{'togglecats'}) {
                   16974:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   16975:             }
                   16976:             if ($changes{'categorize'}) {
                   16977:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  16978:             }
1.120     raeburn  16979:             if ($changes{'togglecatscomm'}) {
                   16980:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   16981:             }
                   16982:             if ($changes{'categorizecomm'}) {
                   16983:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   16984:             }
1.160.6.42  raeburn  16985:             if ($changes{'unauth'}) {
                   16986:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   16987:             }
                   16988:             if ($changes{'auth'}) {
                   16989:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   16990:             }
1.57      raeburn  16991:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   16992:                 my $cathash;
                   16993:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   16994:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   16995:                 } else {
                   16996:                     $cathash = {};
                   16997:                 } 
                   16998:                 my (@cats,@trails,%allitems);
                   16999:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   17000:                 if (keys(%deletions) > 0) {
                   17001:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   17002:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   17003:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   17004:                     }
                   17005:                     $resulttext .= '</ul></li>';
                   17006:                 }
                   17007:                 if (keys(%reorderings) > 0) {
                   17008:                     my %sort_by_trail;
                   17009:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   17010:                     foreach my $key (keys(%reorderings)) {
                   17011:                         if ($allitems{$key} ne '') {
                   17012:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   17013:                         }
1.48      raeburn  17014:                     }
1.57      raeburn  17015:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   17016:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   17017:                     }
                   17018:                     $resulttext .= '</ul></li>';
1.48      raeburn  17019:                 }
1.57      raeburn  17020:                 if (keys(%adds) > 0) {
                   17021:                     my %sort_by_trail;
                   17022:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   17023:                     foreach my $key (keys(%adds)) {
                   17024:                         if ($allitems{$key} ne '') {
                   17025:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   17026:                         }
                   17027:                     }
                   17028:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   17029:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  17030:                     }
1.57      raeburn  17031:                     $resulttext .= '</ul></li>';
1.48      raeburn  17032:                 }
1.160.6.92  raeburn  17033:                 &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   17034:                 if (ref($lastactref) eq 'HASH') {
                   17035:                     $lastactref->{'cats'} = 1;
                   17036:                 }
1.48      raeburn  17037:             }
                   17038:             $resulttext .= '</ul>';
1.160.6.43  raeburn  17039:             if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50  raeburn  17040:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   17041:                 if ($changes{'auth'}) {
                   17042:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   17043:                 }
                   17044:                 if ($changes{'unauth'}) {
                   17045:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   17046:                 }
                   17047:                 my $cachetime = 24*60*60;
                   17048:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43  raeburn  17049:                 if (ref($lastactref) eq 'HASH') {
1.160.6.50  raeburn  17050:                     $lastactref->{'domdefaults'} = 1;
1.160.6.43  raeburn  17051:                 }
                   17052:             }
1.48      raeburn  17053:         } else {
                   17054:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  17055:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  17056:         }
                   17057:     } else {
1.120     raeburn  17058:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  17059:     }
                   17060:     return $resulttext;
                   17061: }
                   17062: 
1.69      raeburn  17063: sub modify_serverstatuses {
                   17064:     my ($dom,%domconfig) = @_;
                   17065:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   17066:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   17067:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   17068:     }
                   17069:     my @pages = &serverstatus_pages();
                   17070:     foreach my $type (@pages) {
                   17071:         $newserverstatus{$type}{'namedusers'} = '';
                   17072:         $newserverstatus{$type}{'machines'} = '';
                   17073:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   17074:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   17075:             my @okusers;
                   17076:             foreach my $user (@users) {
                   17077:                 my ($uname,$udom) = split(/:/,$user);
                   17078:                 if (($udom =~ /^$match_domain$/) &&   
                   17079:                     (&Apache::lonnet::domain($udom)) &&
                   17080:                     ($uname =~ /^$match_username$/)) {
                   17081:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   17082:                         push(@okusers,$user);
                   17083:                     }
                   17084:                 }
                   17085:             }
                   17086:             if (@okusers > 0) {
                   17087:                  @okusers = sort(@okusers);
                   17088:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   17089:             }
                   17090:         }
                   17091:         if (defined($env{'form.'.$type.'_machines'})) {
                   17092:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   17093:             my @okmachines;
                   17094:             foreach my $ip (@machines) {
                   17095:                 my @parts = split(/\./,$ip);
                   17096:                 next if (@parts < 4);
                   17097:                 my $badip = 0;
                   17098:                 for (my $i=0; $i<4; $i++) {
                   17099:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   17100:                         $badip = 1;
                   17101:                         last;
                   17102:                     }
                   17103:                 }
                   17104:                 if (!$badip) {
                   17105:                     push(@okmachines,$ip);     
                   17106:                 }
                   17107:             }
                   17108:             @okmachines = sort(@okmachines);
                   17109:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   17110:         }
                   17111:     }
                   17112:     my %serverstatushash =  (
                   17113:                                 serverstatuses => \%newserverstatus,
                   17114:                             );
                   17115:     foreach my $type (@pages) {
1.83      raeburn  17116:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  17117:             my (@current,@new);
1.83      raeburn  17118:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  17119:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   17120:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   17121:                 }
                   17122:             }
                   17123:             if ($newserverstatus{$type}{$setting} ne '') {
                   17124:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  17125:             }
                   17126:             if (@current > 0) {
                   17127:                 if (@new > 0) {
                   17128:                     foreach my $item (@current) {
                   17129:                         if (!grep(/^\Q$item\E$/,@new)) {
                   17130:                             $changes{$type}{$setting} = 1;
1.82      raeburn  17131:                             last;
                   17132:                         }
                   17133:                     }
1.84      raeburn  17134:                     foreach my $item (@new) {
                   17135:                         if (!grep(/^\Q$item\E$/,@current)) {
                   17136:                             $changes{$type}{$setting} = 1;
                   17137:                             last;
1.82      raeburn  17138:                         }
                   17139:                     }
                   17140:                 } else {
1.83      raeburn  17141:                     $changes{$type}{$setting} = 1;
1.69      raeburn  17142:                 }
1.83      raeburn  17143:             } elsif (@new > 0) {
                   17144:                 $changes{$type}{$setting} = 1;
1.69      raeburn  17145:             }
                   17146:         }
                   17147:     }
                   17148:     if (keys(%changes) > 0) {
1.81      raeburn  17149:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  17150:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   17151:                                                  \%serverstatushash,$dom);
                   17152:         if ($putresult eq 'ok') {
                   17153:             $resulttext .= &mt('Changes made:').'<ul>';
                   17154:             foreach my $type (@pages) {
1.84      raeburn  17155:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  17156:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  17157:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  17158:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   17159:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   17160:                         } else {
                   17161:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   17162:                         }
1.84      raeburn  17163:                     }
                   17164:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  17165:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   17166:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   17167:                         } else {
                   17168:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   17169:                         }
                   17170: 
                   17171:                     }
                   17172:                     $resulttext .= '</ul></li>';
                   17173:                 }
                   17174:             }
                   17175:             $resulttext .= '</ul>';
                   17176:         } else {
                   17177:             $resulttext = '<span class="LC_error">'.
                   17178:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   17179: 
                   17180:         }
                   17181:     } else {
                   17182:         $resulttext = &mt('No changes made to access to server status pages');
                   17183:     }
                   17184:     return $resulttext;
                   17185: }
                   17186: 
1.118     jms      17187: sub modify_helpsettings {
1.160.6.77  raeburn  17188:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  17189:     my ($resulttext,$errors,%changes,%helphash);
                   17190:     my %defaultchecked = ('submitbugs' => 'on');
                   17191:     my @offon = ('off','on');
1.118     jms      17192:     my @toggles = ('submitbugs');
1.160.6.77  raeburn  17193:     my %current = ('submitbugs' => '',
                   17194:                    'adhoc'      => {},
                   17195:                   );
1.118     jms      17196:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73  raeburn  17197:         %current = %{$domconfig{'helpsettings'}};
                   17198:     }
1.160.6.77  raeburn  17199:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73  raeburn  17200:     foreach my $item (@toggles) {
                   17201:         if ($defaultchecked{$item} eq 'on') { 
                   17202:             if ($current{$item} eq '') {
                   17203:                 if ($env{'form.'.$item} eq '0') {
1.160.6.5  raeburn  17204:                     $changes{$item} = 1;
                   17205:                 }
1.160.6.73  raeburn  17206:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   17207:                 $changes{$item} = 1;
                   17208:             }
                   17209:         } elsif ($defaultchecked{$item} eq 'off') {
                   17210:             if ($current{$item} eq '') {
                   17211:                 if ($env{'form.'.$item} eq '1') {
1.160.6.5  raeburn  17212:                     $changes{$item} = 1;
                   17213:                 }
1.160.6.73  raeburn  17214:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   17215:                 $changes{$item} = 1;
                   17216:             }
                   17217:         }
                   17218:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   17219:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   17220:         }
                   17221:     }
1.160.6.77  raeburn  17222:     my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73  raeburn  17223:     my $confname = $dom.'-domainconfig';
                   17224:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  17225:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   17226:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  17227:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
                   17228:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  17229:     my %lt = &Apache::lonlocal::texthash(
                   17230:                     s      => 'system',
                   17231:                     d      => 'domain',
                   17232:                     order  => 'Display order',
                   17233:                     access => 'Role usage',
1.160.6.79  raeburn  17234:                     all    => 'All with domain helpdesk or helpdesk assistant role',
                   17235:                     dh     => 'All with domain helpdesk role',
                   17236:                     da     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  17237:                     none   => 'None',
                   17238:                     status => 'Determined based on institutional status',
                   17239:                     inc    => 'Include all, but exclude specific personnel',
                   17240:                     exc    => 'Exclude all, but include specific personnel',
                   17241:     );
                   17242:     for (my $num=0; $num<=$maxnum; $num++) {
                   17243:         my ($prefix,$identifier,$rolename,%curr);
                   17244:         if ($num == $maxnum) {
                   17245:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   17246:             $identifier = 'custhelp'.$num;
                   17247:             $prefix = 'helproles_'.$num;
                   17248:             $rolename = $env{'form.custhelpname'.$num};
                   17249:             $rolename=~s/[^A-Za-z0-9]//gs;
                   17250:             next if ($rolename eq '');
                   17251:             next if (exists($existing{'rolesdef_'.$rolename}));
                   17252:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   17253:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   17254:                                                      $newprivs{'c'},$confname,$dom);
                   17255:             if ($result ne 'ok') {
                   17256:                 $errors .= '<li><span class="LC_error">'.
                   17257:                            &mt('An error occurred storing the new custom role: [_1]',
                   17258:                            $result).'</span></li>';
                   17259:                 next;
                   17260:             } else {
                   17261:                 $changedprivs{$rolename} = \%newprivs;
                   17262:                 $newrole = $rolename;
                   17263:             }
                   17264:         } else {
                   17265:             $prefix = 'helproles_'.$num;
                   17266:             $rolename = $env{'form.'.$prefix};
                   17267:             next if ($rolename eq '');
                   17268:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   17269:             $identifier = 'custhelp'.$num;
                   17270:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   17271:             my %currprivs;
                   17272:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
                   17273:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   17274:             foreach my $level ('c','d','s') {
                   17275:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   17276:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   17277:                                                              $newprivs{'c'},$confname,$dom);
                   17278:                     if ($result ne 'ok') {
                   17279:                         $errors .= '<li><span class="LC_error">'.
                   17280:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   17281:                                        $rolename,$result).'</span></li>';
                   17282:                     } else {
                   17283:                         $changedprivs{$rolename} = \%newprivs;
                   17284:                     }
                   17285:                     last;
                   17286:                 }
                   17287:             }
                   17288:             if (ref($current{'adhoc'}) eq 'HASH') {
                   17289:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17290:                     %curr = %{$current{'adhoc'}{$rolename}};
                   17291:                 }
                   17292:             }
                   17293:         }
                   17294:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   17295:         $newpos =~ s/\D+//g;
                   17296:         $allpos[$newpos] = $rolename;
                   17297:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   17298:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   17299:         if ($curr{'desc'}) {
                   17300:             if ($curr{'desc'} ne $newdesc) {
                   17301:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17302:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   17303:             }
                   17304:         } elsif ($newdesc ne '') {
                   17305:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   17306:             $newsettings{$rolename}{'desc'} = $newdesc;
                   17307:         }
                   17308:         my $access = $env{'form.'.$prefix.'_access'};
                   17309:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   17310:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   17311:             if ($access eq 'status') {
                   17312:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   17313:                 if (scalar(@statuses) == 0) {
                   17314:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
                   17315:                 } else {
                   17316:                     my (@shownstatus,$numtypes);
                   17317:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17318:                     if (ref($types) eq 'ARRAY') {
                   17319:                         $numtypes = scalar(@{$types});
                   17320:                         foreach my $type (sort(@statuses)) {
                   17321:                             if ($type eq 'default') {
                   17322:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17323:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   17324:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   17325:                                 push(@shownstatus,$usertypes->{$type});
                   17326:                             }
1.160.6.73  raeburn  17327:                         }
                   17328:                     }
1.160.6.77  raeburn  17329:                     if (grep(/^default$/,@statuses)) {
                   17330:                         push(@shownstatus,$othertitle);
                   17331:                     }
                   17332:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   17333:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   17334:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   17335:                     } else {
                   17336:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   17337:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   17338:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17339:                             if (@diffs) {
                   17340:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   17341:                             }
                   17342:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17343:                             $changes{'customrole'}{$rolename}{$access} = 1;
                   17344:                         }
                   17345:                     }
                   17346:                 }
                   17347:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   17348:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   17349:                 my @newspecstaff;
                   17350:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   17351:                 foreach my $person (sort(@personnel)) {
                   17352:                     if ($domhelpdesk{$person}) {
                   17353:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   17354:                     }
                   17355:                 }
                   17356:                 if (ref($curr{$access}) eq 'ARRAY') {
                   17357:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   17358:                     if (@diffs) {
                   17359:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   17360:                     }
                   17361:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17362:                     $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73  raeburn  17363:                 }
1.160.6.77  raeburn  17364:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   17365:                     my ($uname,$udom) = split(/:/,$person);
                   17366:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   17367:                 }
                   17368:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26  raeburn  17369:             }
1.160.6.77  raeburn  17370:         } else {
                   17371:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   17372:         }
                   17373:         unless ($curr{'access'} eq $access) {
                   17374:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   17375:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73  raeburn  17376:         }
                   17377:     }
1.160.6.77  raeburn  17378:     if (@allpos > 0) {
                   17379:         my $idx = 0;
                   17380:         foreach my $rolename (@allpos) {
                   17381:             if ($rolename ne '') {
                   17382:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   17383:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   17384:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   17385:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   17386:                             $changes{'customrole'}{$rolename}{'order'} = 1;
                   17387:                             $newsettings{$rolename}{'order'} = $idx+1;
                   17388:                         }
                   17389:                     }
1.160.6.73  raeburn  17390:                 }
1.160.6.77  raeburn  17391:                 $idx ++;
1.122     jms      17392:             }
                   17393:         }
1.118     jms      17394:     }
1.123     jms      17395:     my $putresult;
                   17396:     if (keys(%changes) > 0) {
1.160.6.5  raeburn  17397:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   17398:         if ($putresult eq 'ok') {
1.160.6.77  raeburn  17399:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   17400:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   17401:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   17402:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   17403:                 }
                   17404:             }
                   17405:             my $cachetime = 24*60*60;
                   17406:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   17407:             if (ref($lastactref) eq 'HASH') {
                   17408:                 $lastactref->{'domdefaults'} = 1;
                   17409:             }
                   17410:         } else {
                   17411:             $errors .= '<li><span class="LC_error">'.
                   17412:                        &mt('An error occurred storing the settings: [_1]',
                   17413:                            $putresult).'</span></li>';
                   17414:         }
                   17415:     }
                   17416:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   17417:         $resulttext = &mt('Changes made:').'<ul>';
                   17418:         my (%shownprivs,@levelorder);
                   17419:         @levelorder = ('c','d','s');
                   17420:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5  raeburn  17421:             foreach my $item (sort(keys(%changes))) {
                   17422:                 if ($item eq 'submitbugs') {
                   17423:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   17424:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   17425:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73  raeburn  17426:                 } elsif ($item eq 'customrole') {
                   17427:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77  raeburn  17428:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   17429:                         my %keytext = &Apache::lonlocal::texthash(
                   17430:                                                                    order  => 'Order',
                   17431:                                                                    desc   => 'Role description',
                   17432:                                                                    access => 'Role usage',
1.160.6.83  raeburn  17433:                                                                    status => 'Allowed institutional types',
1.160.6.77  raeburn  17434:                                                                    exc    => 'Allowed personnel',
                   17435:                                                                    inc    => 'Disallowed personnel',
                   17436:                         );
1.160.6.73  raeburn  17437:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77  raeburn  17438:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   17439:                                 if ($role eq $newrole) {
                   17440:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   17441:                                                               $role).'<ul>';
                   17442:                                 } else {
                   17443:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17444:                                                               $role).'<ul>';
                   17445:                                 }
                   17446:                                 foreach my $key (@keyorder) {
                   17447:                                     if ($changes{'customrole'}{$role}{$key}) {
                   17448:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   17449:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   17450:                                                        '</li>';
                   17451:                                     }
                   17452:                                 }
                   17453:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   17454:                                     $shownprivs{$role} = 1;
                   17455:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   17456:                                     foreach my $level (@levelorder) {
                   17457:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17458:                                             next if ($item eq '');
                   17459:                                             my ($priv) = split(/\&/,$item,2);
                   17460:                                             if (&Apache::lonnet::plaintext($priv)) {
                   17461:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17462:                                                 unless ($level eq 'c') {
                   17463:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   17464:                                                 }
                   17465:                                                 $resulttext .= '</li>';
                   17466:                                             }
                   17467:                                         }
                   17468:                                     }
                   17469:                                     $resulttext .= '</ul>';
                   17470:                                 }
                   17471:                                 $resulttext .= '</ul></li>';
                   17472:                             }
1.160.6.73  raeburn  17473:                         }
                   17474:                     }
1.160.6.5  raeburn  17475:                 }
                   17476:             }
                   17477:         }
1.160.6.77  raeburn  17478:         if (keys(%changedprivs)) {
                   17479:             foreach my $role (sort(keys(%changedprivs))) {
                   17480:                 unless ($shownprivs{$role}) {
                   17481:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   17482:                                               $role).'<ul>'.
                   17483:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   17484:                     foreach my $level (@levelorder) {
                   17485:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   17486:                             next if ($item eq '');
                   17487:                             my ($priv) = split(/\&/,$item,2);
                   17488:                             if (&Apache::lonnet::plaintext($priv)) {
                   17489:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   17490:                                 unless ($level eq 'c') {
                   17491:                                     $resulttext .= ' ('.$lt{$level}.')';
                   17492:                                 }
                   17493:                                 $resulttext .= '</li>';
                   17494:                             }
                   17495:                         }
                   17496:                     }
                   17497:                     $resulttext .= '</ul></li></ul></li>';
                   17498:                 }
                   17499:             }
                   17500:         }
                   17501:         $resulttext .= '</ul>';
                   17502:     } else {
                   17503:         $resulttext = &mt('No changes made to help settings');
1.118     jms      17504:     }
                   17505:     if ($errors) {
1.160.6.5  raeburn  17506:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77  raeburn  17507:                                     $errors.'</ul>';
1.118     jms      17508:     }
                   17509:     return $resulttext;
                   17510: }
                   17511: 
1.121     raeburn  17512: sub modify_coursedefaults {
1.160.6.27  raeburn  17513:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  17514:     my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57  raeburn  17515:     my %defaultchecked = (
                   17516:                            'uselcmath'       => 'on',
1.160.6.115  raeburn  17517:                            'usejsme'         => 'on',
                   17518:                            'inline_chem'     => 'on',
1.160.6.118.2  4(raebur 17519:2):                            'ltiauth'         => 'off',
1.160.6.57  raeburn  17520:                          );
1.160.6.118.2  4(raebur 17521:2):     my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21  raeburn  17522:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70  raeburn  17523:                    'uploadquota_community','uploadquota_textbook','mysqltables_official',
                   17524:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30  raeburn  17525:     my @types = ('official','unofficial','community','textbook');
1.160.6.21  raeburn  17526:     my %staticdefaults = (
                   17527:                            anonsurvey_threshold => 10,
                   17528:                            uploadquota          => 500,
1.160.6.57  raeburn  17529:                            postsubmit           => 60,
1.160.6.70  raeburn  17530:                            mysqltables          => 172800,
1.160.6.21  raeburn  17531:                          );
1.160.6.90  raeburn  17532:     my %texoptions = (
                   17533:                         MathJax  => 'MathJax',
                   17534:                         mimetex  => &mt('Convert to Images'),
                   17535:                         tth      => &mt('TeX to HTML'),
                   17536:                      );
1.121     raeburn  17537:     $defaultshash{'coursedefaults'} = {};
                   17538: 
                   17539:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   17540:         if ($domconfig{'coursedefaults'} eq '') {
                   17541:             $domconfig{'coursedefaults'} = {};
                   17542:         }
                   17543:     }
                   17544: 
                   17545:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   17546:         foreach my $item (@toggles) {
                   17547:             if ($defaultchecked{$item} eq 'on') {
                   17548:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17549:                     ($env{'form.'.$item} eq '0')) {
                   17550:                     $changes{$item} = 1;
1.160.6.16  raeburn  17551:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  17552:                     $changes{$item} = 1;
                   17553:                 }
                   17554:             } elsif ($defaultchecked{$item} eq 'off') {
                   17555:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   17556:                     ($env{'form.'.$item} eq '1')) {
                   17557:                     $changes{$item} = 1;
                   17558:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   17559:                     $changes{$item} = 1;
                   17560:                 }
                   17561:             }
                   17562:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   17563:         }
1.160.6.21  raeburn  17564:         foreach my $item (@numbers) {
                   17565:             my ($currdef,$newdef);
1.160.6.26  raeburn  17566:             $newdef = $env{'form.'.$item};
1.160.6.21  raeburn  17567:             if ($item eq 'anonsurvey_threshold') {
                   17568:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   17569:                 $newdef =~ s/\D//g;
                   17570:                 if ($newdef eq '' || $newdef < 1) {
                   17571:                     $newdef = 1;
                   17572:                 }
                   17573:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   17574:             } else {
1.160.6.70  raeburn  17575:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   17576:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   17577:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21  raeburn  17578:                 }
                   17579:                 $newdef =~ s/[^\w.\-]//g;
1.160.6.70  raeburn  17580:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21  raeburn  17581:             }
                   17582:             if ($currdef ne $newdef) {
                   17583:                 if ($item eq 'anonsurvey_threshold') {
                   17584:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   17585:                         $changes{$item} = 1;
                   17586:                     }
1.160.6.70  raeburn  17587:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   17588:                     my $setting = $1;
                   17589:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   17590:                         $changes{$setting} = 1;
1.160.6.21  raeburn  17591:                     }
                   17592:                 }
1.139     raeburn  17593:             }
                   17594:         }
1.160.6.90  raeburn  17595:         my $texengine;
                   17596:         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
                   17597:             $texengine = $env{'form.texengine'};
                   17598:             my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                   17599:             if ($currdef eq '') {
                   17600:                 unless ($texengine eq $Apache::lonnet::deftex) {
                   17601:                     $changes{'texengine'} = 1;
                   17602:                 }
                   17603:             } elsif ($currdef ne $texengine) {
                   17604:                 $changes{'texengine'} = 1;
                   17605:             }
                   17606:         }
                   17607:         if ($texengine ne '') {
                   17608:             $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
                   17609:         }
1.160.6.64  raeburn  17610:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   17611:         my @currclonecode;
                   17612:         if (ref($currclone) eq 'HASH') {
                   17613:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   17614:                 @currclonecode = @{$currclone->{'instcode'}};
                   17615:             }
                   17616:         }
                   17617:         my $newclone;
                   17618:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
                   17619:             $newclone = $env{'form.canclone'};
                   17620:         }
                   17621:         if ($newclone eq 'instcode') {
                   17622:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   17623:             my (%codedefaults,@code_order,@clonecode);
                   17624:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   17625:                                                     \@code_order);
                   17626:             foreach my $item (@code_order) {
                   17627:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   17628:                     push(@clonecode,$item);
                   17629:                 }
                   17630:             }
                   17631:             if (@clonecode) {
                   17632:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   17633:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   17634:                 if (@diffs) {
                   17635:                     $changes{'canclone'} = 1;
                   17636:                 }
                   17637:             } else {
                   17638:                 $newclone eq '';
                   17639:             }
                   17640:         } elsif ($newclone ne '') {
                   17641:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   17642:         }
                   17643:         if ($newclone ne $currclone) {
                   17644:             $changes{'canclone'} = 1;
                   17645:         }
1.160.6.57  raeburn  17646:         my %credits;
                   17647:         foreach my $type (@types) {
                   17648:             unless ($type eq 'community') {
                   17649:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   17650:                 $credits{$type} =~ s/[^\d.]+//g;
                   17651:             }
                   17652:         }
                   17653:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   17654:             ($env{'form.coursecredits'} eq '1')) {
                   17655:             $changes{'coursecredits'} = 1;
                   17656:             foreach my $type (keys(%credits)) {
                   17657:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17658:             }
                   17659:         } else {
                   17660:             if ($env{'form.coursecredits'} eq '1') {
                   17661:                 foreach my $type (@types) {
                   17662:                     unless ($type eq 'community') {
                   17663:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
                   17664:                             $changes{'coursecredits'} = 1;
                   17665:                         }
                   17666:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   17667:                     }
                   17668:                 }
                   17669:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17670:                 foreach my $type (@types) {
                   17671:                     unless ($type eq 'community') {
                   17672:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   17673:                             $changes{'coursecredits'} = 1;
                   17674:                             last;
                   17675:                         }
                   17676:                     }
                   17677:                 }
                   17678:             }
                   17679:         }
                   17680:         if ($env{'form.postsubmit'} eq '1') {
                   17681:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   17682:             my %currtimeout;
                   17683:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17684:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   17685:                     $changes{'postsubmit'} = 1;
                   17686:                 }
                   17687:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17688:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   17689:                 }
                   17690:             } else {
                   17691:                 $changes{'postsubmit'} = 1;
                   17692:             }
                   17693:             foreach my $type (@types) {
                   17694:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   17695:                 $timeout =~ s/\D//g;
                   17696:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   17697:                     $timeout = '';
                   17698:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   17699:                     $timeout = '0';
                   17700:                 }
                   17701:                 unless ($timeout eq '') {
                   17702:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   17703:                 }
                   17704:                 if (exists($currtimeout{$type})) {
                   17705:                     if ($timeout ne $currtimeout{$type}) {
                   17706:                         $changes{'postsubmit'} = 1;
                   17707:                     }
                   17708:                 } elsif ($timeout ne '') {
                   17709:                     $changes{'postsubmit'} = 1;
                   17710:                 }
                   17711:             }
                   17712:         } else {
                   17713:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   17714:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17715:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   17716:                     $changes{'postsubmit'} = 1;
                   17717:                 }
                   17718:             } else {
                   17719:                 $changes{'postsubmit'} = 1;
                   17720:             }
1.160.6.16  raeburn  17721:         }
1.121     raeburn  17722:     }
                   17723:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   17724:                                              $dom);
                   17725:     if ($putresult eq 'ok') {
                   17726:         if (keys(%changes) > 0) {
1.160.6.27  raeburn  17727:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57  raeburn  17728:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64  raeburn  17729:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115  raeburn  17730:                 ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2  4(raebur 17731:2):                 ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
                   17732:2):                 foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57  raeburn  17733:                     if ($changes{$item}) {
                   17734:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   17735:                     }
1.160.6.16  raeburn  17736:                 }
                   17737:                 if ($changes{'coursecredits'}) {
                   17738:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  17739:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   17740:                             $domdefaults{$type.'credits'} =
                   17741:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   17742:                         }
                   17743:                     }
                   17744:                 }
                   17745:                 if ($changes{'postsubmit'}) {
                   17746:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17747:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   17748:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17749:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   17750:                                 $domdefaults{$type.'postsubtimeout'} =
                   17751:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17752:                             }
                   17753:                         }
1.160.6.16  raeburn  17754:                     }
                   17755:                 }
1.160.6.21  raeburn  17756:                 if ($changes{'uploadquota'}) {
                   17757:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17758:                         foreach my $type (@types) {
                   17759:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   17760:                         }
                   17761:                     }
                   17762:                 }
1.160.6.64  raeburn  17763:                 if ($changes{'canclone'}) {
                   17764:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17765:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17766:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   17767:                             if (@clonecodes) {
                   17768:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   17769:                             }
                   17770:                         }
                   17771:                     } else {
                   17772:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   17773:                     }
                   17774:                 }
1.121     raeburn  17775:                 my $cachetime = 24*60*60;
                   17776:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  17777:                 if (ref($lastactref) eq 'HASH') {
                   17778:                     $lastactref->{'domdefaults'} = 1;
                   17779:                 }
1.121     raeburn  17780:             }
                   17781:             $resulttext = &mt('Changes made:').'<ul>';
                   17782:             foreach my $item (sort(keys(%changes))) {
1.160.6.57  raeburn  17783:                 if ($item eq 'uselcmath') {
1.121     raeburn  17784:                     if ($env{'form.'.$item} eq '1') {
1.160.6.57  raeburn  17785:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121     raeburn  17786:                     } else {
1.160.6.57  raeburn  17787:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   17788:                     }
                   17789:                 } elsif ($item eq 'usejsme') {
                   17790:                     if ($env{'form.'.$item} eq '1') {
                   17791:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   17792:                     } else {
                   17793:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121     raeburn  17794:                     }
1.160.6.115  raeburn  17795:                 } elsif ($item eq 'inline_chem') {
                   17796:                     if ($env{'form.'.$item} eq '1') {
                   17797:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
                   17798:                     } else {
                   17799:                         $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
                   17800:                     }
1.160.6.90  raeburn  17801:                 } elsif ($item eq 'texengine') {
                   17802:                     if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
                   17803:                         $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
                   17804:                                                   $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
                   17805:                     }
1.139     raeburn  17806:                 } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26  raeburn  17807:                     $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  17808:                 } elsif ($item eq 'uploadquota') {
                   17809:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   17810:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   17811:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   17812:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30  raeburn  17813:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   17814: 
1.160.6.21  raeburn  17815:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   17816:                                        '</ul>'.
                   17817:                                        '</li>';
                   17818:                     } else {
                   17819:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   17820:                     }
1.160.6.70  raeburn  17821:                 } elsif ($item eq 'mysqltables') {
                   17822:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   17823:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   17824:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   17825:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   17826:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   17827:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   17828:                                        '</ul>'.
                   17829:                                        '</li>';
                   17830:                     } else {
                   17831:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   17832:                     }
1.160.6.57  raeburn  17833:                 } elsif ($item eq 'postsubmit') {
                   17834:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   17835:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   17836:                     } else {
                   17837:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   17838:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   17839:                             $resulttext .= &mt('durations:').'<ul>';
                   17840:                             foreach my $type (@types) {
                   17841:                                 $resulttext .= '<li>';
                   17842:                                 my $timeout;
                   17843:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   17844:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   17845:                                 }
                   17846:                                 my $display;
                   17847:                                 if ($timeout eq '0') {
                   17848:                                     $display = &mt('unlimited');
                   17849:                                 } elsif ($timeout eq '') {
                   17850:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   17851:                                 } else {
                   17852:                                     $display = &mt('[quant,_1,second]',$timeout);
                   17853:                                 }
                   17854:                                 if ($type eq 'community') {
                   17855:                                     $resulttext .= &mt('Communities');
                   17856:                                 } elsif ($type eq 'official') {
                   17857:                                     $resulttext .= &mt('Official courses');
                   17858:                                 } elsif ($type eq 'unofficial') {
                   17859:                                     $resulttext .= &mt('Unofficial courses');
                   17860:                                 } elsif ($type eq 'textbook') {
                   17861:                                     $resulttext .= &mt('Textbook courses');
                   17862:                                 }
                   17863:                                 $resulttext .= ' -- '.$display.'</li>';
                   17864:                             }
                   17865:                             $resulttext .= '</ul>';
                   17866:                         }
                   17867:                         $resulttext .= '</li>';
                   17868:                     }
1.160.6.16  raeburn  17869:                 } elsif ($item eq 'coursecredits') {
                   17870:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   17871:                         if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30  raeburn  17872:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   17873:                             ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16  raeburn  17874:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17875:                         } else {
                   17876:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   17877:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   17878:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30  raeburn  17879:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16  raeburn  17880:                                            '</ul>'.
                   17881:                                            '</li>';
                   17882:                         }
                   17883:                     } else {
                   17884:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   17885:                     }
1.160.6.64  raeburn  17886:                 } elsif ($item eq 'canclone') {
                   17887:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   17888:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   17889:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   17890:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   17891:                         }
                   17892:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   17893:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   17894:                     } else {
                   17895:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
                   17896:                     }
1.160.6.118.2  4(raebur 17897:2):                 } elsif ($item eq 'ltiauth') {
                   17898:2):                     if ($env{'form.'.$item} eq '1') {
                   17899:2):                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
                   17900:2):                     } else {
                   17901:2):                         $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
                   17902:2):                     }
1.140     raeburn  17903:                 }
1.121     raeburn  17904:             }
                   17905:             $resulttext .= '</ul>';
                   17906:         } else {
                   17907:             $resulttext = &mt('No changes made to course defaults');
                   17908:         }
                   17909:     } else {
                   17910:         $resulttext = '<span class="LC_error">'.
                   17911:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   17912:     }
                   17913:     return $resulttext;
                   17914: }
                   17915: 
1.160.6.37  raeburn  17916: sub modify_selfenrollment {
                   17917:     my ($dom,$lastactref,%domconfig) = @_;
                   17918:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   17919:     my @types = ('official','unofficial','community','textbook');
                   17920:     my %titles = &tool_titles();
                   17921:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   17922:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   17923:     $ordered{'default'} = ['types','registered','approval','limit'];
                   17924: 
                   17925:     my (%roles,%shown,%toplevel);
                   17926:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   17927: 
                   17928:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   17929:         if ($domconfig{'selfenrollment'} eq '') {
                   17930:             $domconfig{'selfenrollment'} = {};
                   17931:         }
                   17932:     }
                   17933:     %toplevel = (
                   17934:                   admin      => 'Configuration Rights',
                   17935:                   default    => 'Default settings',
                   17936:                   validation => 'Validation of self-enrollment requests',
                   17937:                 );
                   17938:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   17939: 
                   17940:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   17941:         foreach my $item (@{$ordered{'admin'}}) {
                   17942:             foreach my $type (@types) {
                   17943:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   17944:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   17945:                 } else {
                   17946:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   17947:                 }
                   17948:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   17949:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   17950:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   17951:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   17952:                             push(@{$changes{'admin'}{$type}},$item);
                   17953:                         }
                   17954:                     } else {
                   17955:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17956:                             push(@{$changes{'admin'}{$type}},$item);
                   17957:                         }
                   17958:                     }
                   17959:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   17960:                     push(@{$changes{'admin'}{$type}},$item);
                   17961:                 }
                   17962:             }
                   17963:         }
                   17964:     }
                   17965: 
                   17966:     foreach my $item (@{$ordered{'default'}}) {
                   17967:         foreach my $type (@types) {
                   17968:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   17969:             if ($item eq 'types') {
                   17970:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   17971:                     $value = '';
                   17972:                 }
                   17973:             } elsif ($item eq 'registered') {
                   17974:                 unless ($value eq '1') {
                   17975:                     $value = 0;
                   17976:                 }
                   17977:             } elsif ($item eq 'approval') {
                   17978:                 unless ($value =~ /^[012]$/) {
                   17979:                     $value = 0;
                   17980:                 }
                   17981:             } else {
                   17982:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   17983:                     $value = 'none';
                   17984:                 }
                   17985:             }
                   17986:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   17987:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   17988:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   17989:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   17990:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   17991:                          push(@{$changes{'default'}{$type}},$item);
                   17992:                     }
                   17993:                 } else {
                   17994:                     push(@{$changes{'default'}{$type}},$item);
                   17995:                 }
                   17996:             } else {
                   17997:                 push(@{$changes{'default'}{$type}},$item);
                   17998:             }
                   17999:             if ($item eq 'limit') {
                   18000:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   18001:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   18002:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   18003:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   18004:                     }
                   18005:                 } else {
                   18006:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   18007:                 }
                   18008:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   18009:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   18010:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   18011:                          push(@{$changes{'default'}{$type}},'cap');
                   18012:                     }
                   18013:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   18014:                     push(@{$changes{'default'}{$type}},'cap');
                   18015:                 }
                   18016:             }
                   18017:         }
                   18018:     }
                   18019: 
                   18020:     foreach my $item (@{$itemsref}) {
                   18021:         if ($item eq 'fields') {
                   18022:             my @changed;
                   18023:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   18024:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   18025:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   18026:             }
                   18027:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   18028:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   18029:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   18030:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   18031:                 } else {
                   18032:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   18033:                 }
                   18034:             } else {
                   18035:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   18036:             }
                   18037:             if (@changed) {
                   18038:                 if ($selfenrollhash{'validation'}{$item}) { 
                   18039:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   18040:                 } else {
                   18041:                     $changes{'validation'}{$item} = &mt('None');
                   18042:                 }
                   18043:             }
                   18044:         } else {
                   18045:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   18046:             if ($item eq 'markup') {
                   18047:                if ($env{'form.selfenroll_validation_'.$item}) {
                   18048:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   18049:                }
                   18050:             }
                   18051:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   18052:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   18053:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   18054:                 }
                   18055:             }
                   18056:         }
                   18057:     }
                   18058: 
                   18059:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   18060:                                              $dom);
                   18061:     if ($putresult eq 'ok') {
                   18062:         if (keys(%changes) > 0) {
                   18063:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   18064:             $resulttext = &mt('Changes made:').'<ul>';
                   18065:             foreach my $key ('admin','default','validation') {
                   18066:                 if (ref($changes{$key}) eq 'HASH') {
                   18067:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   18068:                     if ($key eq 'validation') {
                   18069:                         foreach my $item (@{$itemsref}) {
                   18070:                             if (exists($changes{$key}{$item})) {
                   18071:                                 if ($item eq 'markup') {
                   18072:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   18073:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   18074:                                 } else {  
                   18075:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   18076:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   18077:                                 }
                   18078:                             }
                   18079:                         }
                   18080:                     } else {
                   18081:                         foreach my $type (@types) {
                   18082:                             if ($type eq 'community') {
                   18083:                                 $roles{'1'} = &mt('Community personnel');
                   18084:                             } else {
                   18085:                                 $roles{'1'} = &mt('Course personnel');
                   18086:                             }
                   18087:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
                   18088:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   18089:                                     if ($key eq 'admin') {
                   18090:                                         my @mgrdc = ();
                   18091:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   18092:                                             foreach my $item (@{$ordered{'admin'}}) {
                   18093:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   18094:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   18095:                                                         push(@mgrdc,$item);
                   18096:                                                     }
                   18097:                                                 }
                   18098:                                             }
                   18099:                                             if (@mgrdc) {
                   18100:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   18101:                                             } else {
                   18102:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   18103:                                             }
                   18104:                                         }
                   18105:                                     } else {
                   18106:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   18107:                                             foreach my $item (@{$ordered{$key}}) {
                   18108:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   18109:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   18110:                                                         $selfenrollhash{$key}{$type}{$item};
                   18111:                                                 }
                   18112:                                             }
                   18113:                                         }
                   18114:                                     }
                   18115:                                 }
                   18116:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   18117:                                 foreach my $item (@{$ordered{$key}}) {
                   18118:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   18119:                                         $resulttext .= '<li>';
                   18120:                                         if ($key eq 'admin') {
                   18121:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   18122:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   18123:                                         } else {
                   18124:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   18125:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   18126:                                         }
                   18127:                                         $resulttext .= '</li>';
                   18128:                                     }
                   18129:                                 }
                   18130:                                 $resulttext .= '</ul></li>';
                   18131:                             }
                   18132:                         }
                   18133:                         $resulttext .= '</ul></li>'; 
                   18134:                     }
                   18135:                 }
1.160.6.93  raeburn  18136:             }
                   18137:             if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   18138:                 my $cachetime = 24*60*60;
                   18139:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18140:                 if (ref($lastactref) eq 'HASH') {
                   18141:                     $lastactref->{'domdefaults'} = 1;
1.160.6.37  raeburn  18142:                 }
                   18143:             }
                   18144:             $resulttext .= '</ul>';
                   18145:         } else {
                   18146:             $resulttext = &mt('No changes made to self-enrollment settings');
                   18147:         }
                   18148:     } else {
                   18149:         $resulttext = '<span class="LC_error">'.
                   18150:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   18151:     }
                   18152:     return $resulttext;
                   18153: }
                   18154: 
1.160.6.113  raeburn  18155: sub modify_wafproxy {
                   18156:     my ($dom,$action,$lastactref,%domconfig) = @_;
                   18157:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   18158:     my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
                   18159:         %wafproxy,%changes,%expirecache,%expiresaml);
                   18160:     foreach my $server (sort(keys(%servers))) {
                   18161:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   18162:         if ($serverhome eq $server) {
                   18163:             my $serverdom = &Apache::lonnet::host_domain($server);
                   18164:             if ($serverdom eq $dom) {
                   18165:                 $canset{$server} = 1;
                   18166:             }
                   18167:         }
                   18168:     }
                   18169:     if (ref($domconfig{'wafproxy'}) eq 'HASH') {
                   18170:         %{$values{$dom}} = ();
                   18171:         if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
                   18172:             %curralias = %{$domconfig{'wafproxy'}{'alias'}};
                   18173:         }
                   18174:         if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
                   18175:             %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
                   18176:         }
                   18177:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
                   18178:             $currvalue{$item} = $domconfig{'wafproxy'}{$item};
                   18179:         }
                   18180:     }
                   18181:     my $output;
                   18182:     if (keys(%canset)) {
                   18183:         %{$wafproxy{'alias'}} = ();
                   18184:         %{$wafproxy{'saml'}} = ();
                   18185:         foreach my $key (sort(keys(%canset))) {
                   18186:             if ($env{'form.wafproxy_'.$dom}) {
                   18187:                 $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
                   18188:                 $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
                   18189:                 if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
                   18190:                     $changes{'alias'} = 1;
                   18191:                 }
                   18192:                 if ($env{'form.wafproxy_alias_saml_'.$key}) {
                   18193:                     $wafproxy{'saml'}{$key} = 1;
                   18194:                 }
                   18195:                 if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
                   18196:                     $changes{'saml'} = 1;
                   18197:                 }
                   18198:             } else {
                   18199:                 $wafproxy{'alias'}{$key} = '';
                   18200:                 $wafproxy{'saml'}{$key} = '';
                   18201:                 if ($curralias{$key}) {
                   18202:                     $changes{'alias'} = 1;
                   18203:                 }
                   18204:                 if ($currsaml{$key}) {
                   18205:                     $changes{'saml'} = 1;
                   18206:                 }
                   18207:             }
                   18208:             if ($wafproxy{'alias'}{$key} eq '') {
                   18209:                 if ($curralias{$key}) {
                   18210:                     $expirecache{$key} = 1;
                   18211:                 }
                   18212:                 delete($wafproxy{'alias'}{$key});
                   18213:             }
                   18214:             if ($wafproxy{'saml'}{$key} eq '') {
                   18215:                 if ($currsaml{$key}) {
                   18216:                     $expiresaml{$key} = 1;
                   18217:                 }
                   18218:                 delete($wafproxy{'saml'}{$key});
                   18219:             }
                   18220:         }
                   18221:         unless (keys(%{$wafproxy{'alias'}})) {
                   18222:             delete($wafproxy{'alias'});
                   18223:         }
                   18224:         unless (keys(%{$wafproxy{'saml'}})) {
                   18225:             delete($wafproxy{'saml'});
                   18226:         }
                   18227:         # Localization for values in %warn occurs in &mt() calls separately.
                   18228:         my %warn = (
                   18229:                      trusted => 'trusted IP range(s)',
                   18230:                      vpnint => 'internal IP range(s) for VPN sessions(s)',
                   18231:                      vpnext => 'IP range(s) for backend WAF connections',
                   18232:                    );
                   18233:         foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
                   18234:             my $possible = $env{'form.wafproxy_'.$item};
                   18235:             $possible =~ s/^\s+|\s+$//g;
                   18236:             if ($possible ne '') {
                   18237:                 if ($item eq 'remoteip') {
                   18238:                     if ($possible =~ /^[mhn]$/) {
                   18239:                         $wafproxy{$item} = $possible;
                   18240:                     }
                   18241:                 } elsif ($item eq 'ipheader') {
                   18242:                     if ($wafproxy{'remoteip'} eq 'h') {
                   18243:                         $wafproxy{$item} = $possible;
                   18244:                     }
                   18245:                 } elsif ($item eq 'sslopt') {
                   18246:                     if ($possible =~ /^0|1$/) {
                   18247:                         $wafproxy{$item} = $possible;
                   18248:                     }
                   18249:                 } else {
                   18250:                     my (@ok,$count);
                   18251:                     if (($item eq 'vpnint') || ($item eq 'vpnext')) {
                   18252:                         unless ($env{'form.wafproxy_vpnaccess'}) {
                   18253:                             $possible = '';
                   18254:                         }
                   18255:                     } elsif ($item eq 'trusted') {
                   18256:                         unless ($wafproxy{'remoteip'} eq 'h') {
                   18257:                             $possible = '';
                   18258:                         }
                   18259:                     }
                   18260:                     unless ($possible eq '') {
                   18261:                         $possible =~ s/[\r\n]+/\s/g;
                   18262:                         $possible =~ s/\s*-\s*/-/g;
                   18263:                         $possible =~ s/\s+/,/g;
                   18264:                         $possible =~ s/,+/,/g;
                   18265:                     }
                   18266:                     $count = 0;
                   18267:                     if ($possible ne '') {
                   18268:                         foreach my $poss (split(/\,/,$possible)) {
                   18269:                             $count ++;
                   18270:                             $poss = &validate_ip_pattern($poss);
                   18271:                             if ($poss ne '') {
                   18272:                                 push(@ok,$poss);
                   18273:                             }
                   18274:                         }
                   18275:                         my $diff = $count - scalar(@ok);
                   18276:                         if ($diff) {
                   18277:                             push(@warnings,'<li>'.
                   18278:                                  &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
                   18279:                                      $diff,$warn{$item}).
                   18280:                                  '</li>');
                   18281:                         }
                   18282:                         if (@ok) {
                   18283:                             my @cidr_list;
                   18284:                             foreach my $item (@ok) {
                   18285:                                 @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
                   18286:                             }
                   18287:                             $wafproxy{$item} = join(',',@cidr_list);
                   18288:                         }
                   18289:                     }
                   18290:                 }
                   18291:                 if ($wafproxy{$item} ne $currvalue{$item}) {
                   18292:                     $changes{$item} = 1;
                   18293:                 }
                   18294:             } elsif ($currvalue{$item}) {
                   18295:                 $changes{$item} = 1;
                   18296:             }
                   18297:         }
                   18298:     } else {
                   18299:         if (keys(%curralias)) {
                   18300:             $changes{'alias'} = 1;
                   18301:         }
                   18302:         if (keys(%currsaml)) {
                   18303:             $changes{'saml'} = 1;
                   18304:         }
                   18305:         if (keys(%currvalue)) {
                   18306:             foreach my $key (keys(%currvalue)) {
                   18307:                 $changes{$key} = 1;
                   18308:             }
                   18309:         }
                   18310:     }
                   18311:     if (keys(%changes)) {
                   18312:         my %defaultshash = (
                   18313:                               wafproxy => \%wafproxy,
                   18314:                            );
                   18315:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18316:                                                  $dom);
                   18317:         if ($putresult eq 'ok') {
                   18318:             my $cachetime = 24*60*60;
                   18319:             my (%domdefaults,$updatedomdefs);
                   18320:             foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
                   18321:                 if ($changes{$item}) {
                   18322:                     unless ($updatedomdefs) {
                   18323:                         %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   18324:                         $updatedomdefs = 1;
                   18325:                     }
                   18326:                     if ($wafproxy{$item}) {
                   18327:                         $domdefaults{'waf_'.$item} = $wafproxy{$item};
                   18328:                     } elsif (exists($domdefaults{'waf_'.$item})) {
                   18329:                         delete($domdefaults{'waf_'.$item});
                   18330:                     }
                   18331:                 }
                   18332:             }
                   18333:             if ($updatedomdefs) {
                   18334:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   18335:                 if (ref($lastactref) eq 'HASH') {
                   18336:                     $lastactref->{'domdefaults'} = 1;
                   18337:                 }
                   18338:             }
                   18339:             if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
                   18340:                 my %updates = %expirecache;
                   18341:                 foreach my $key (keys(%expirecache)) {
                   18342:                     &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
                   18343:                 }
                   18344:                 if (ref($wafproxy{'alias'}) eq 'HASH') {
                   18345:                     my $cachetime = 24*60*60;
                   18346:                     foreach my $key (keys(%{$wafproxy{'alias'}})) {
                   18347:                         $updates{$key} = 1;
                   18348:                         &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
                   18349:                                                       $cachetime);
                   18350:                     }
                   18351:                 }
                   18352:                 if (ref($lastactref) eq 'HASH') {
                   18353:                     $lastactref->{'proxyalias'} = \%updates;
                   18354:                 }
                   18355:             }
                   18356:             if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
                   18357:                 my %samlupdates = %expiresaml;
                   18358:                 foreach my $key (keys(%expiresaml)) {
                   18359:                     &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
                   18360:                 }
                   18361:                 if (ref($wafproxy{'saml'}) eq 'HASH') {
                   18362:                     my $cachetime = 24*60*60;
                   18363:                     foreach my $key (keys(%{$wafproxy{'saml'}})) {
                   18364:                         $samlupdates{$key} = 1;
                   18365:                         &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
                   18366:                                                       $cachetime);
                   18367:                     }
                   18368:                 }
                   18369:                 if (ref($lastactref) eq 'HASH') {
                   18370:                     $lastactref->{'proxysaml'} = \%samlupdates;
                   18371:                 }
                   18372:             }
                   18373:             $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118  raeburn  18374:             foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113  raeburn  18375:                 if ($changes{$item}) {
                   18376:                     if ($item eq 'alias') {
                   18377:                         my $numaliased = 0;
                   18378:                         if (ref($wafproxy{'alias'}) eq 'HASH') {
                   18379:                             my $shown;
                   18380:                             if (keys(%{$wafproxy{'alias'}})) {
                   18381:                                 foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
                   18382:                                     $shown .= '<li>'.&mt('[_1] aliased by [_2]',
                   18383:                                                          &Apache::lonnet::hostname($server),
                   18384:                                                          $wafproxy{'alias'}{$server}).'</li>';
                   18385:                                     $numaliased ++;
                   18386:                                 }
                   18387:                                 if ($numaliased) {
                   18388:                                     $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
                   18389:                                                           '<ul>'.$shown.'</ul>').'</li>';
                   18390:                                 }
                   18391:                             }
                   18392:                         }
                   18393:                         unless ($numaliased) {
                   18394:                             $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
                   18395:                         }
                   18396:                     } elsif ($item eq 'saml') {
                   18397:                         my $shown;
                   18398:                         if (ref($wafproxy{'saml'}) eq 'HASH') {
                   18399:                             if (keys(%{$wafproxy{'saml'}})) {
                   18400:                                 $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
                   18401:                             }
                   18402:                         }
                   18403:                         if ($shown) {
                   18404:                             $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
                   18405:                                                   $shown).'</li>';
                   18406:                         } else {
                   18407:                             $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
                   18408:                         }
                   18409:                     } else {
                   18410:                         if ($item eq 'remoteip') {
                   18411:                             my %ip_methods = &remoteip_methods();
                   18412:                             if ($wafproxy{$item} =~ /^[mh]$/) {
                   18413:                                 $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
                   18414:                                                       $ip_methods{$wafproxy{$item}}).'</li>';
                   18415:                             } else {
                   18416:                                 if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
                   18417:                                     $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
                   18418:                                                '</li>';
                   18419:                                 } else {
                   18420:                                     $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
                   18421:                                 }
                   18422:                             }
                   18423:                         } elsif ($item eq 'ipheader') {
                   18424:                             if ($wafproxy{$item}) {
                   18425:                                 $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
                   18426:                                                       $wafproxy{$item}).'</li>';
                   18427:                             } else {
                   18428:                                 $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
                   18429:                             }
                   18430:                         } elsif ($item eq 'trusted') {
                   18431:                             if ($wafproxy{$item}) {
                   18432:                                 $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
                   18433:                                                       $wafproxy{$item}).'</li>';
                   18434:                             } else {
                   18435:                                 $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
                   18436:                             }
                   18437:                         } elsif ($item eq 'vpnint') {
                   18438:                             if ($wafproxy{$item}) {
                   18439:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
                   18440:                                                        $wafproxy{$item}).'</li>';
                   18441:                             } else {
                   18442:                                 $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
                   18443:                             }
                   18444:                         } elsif ($item eq 'vpnext') {
                   18445:                             if ($wafproxy{$item}) {
                   18446:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
                   18447:                                                        $wafproxy{$item}).'</li>';
                   18448:                             } else {
                   18449:                                 $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
                   18450:                             }
                   18451:                         } elsif ($item eq 'sslopt') {
                   18452:                             if ($wafproxy{$item}) {
                   18453:                                 $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
                   18454:                             } else {
                   18455:                                 $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
                   18456:                             }
                   18457:                         }
                   18458:                     }
                   18459:                 }
                   18460:             }
                   18461:         } else {
                   18462:             $output = '<span class="LC_error">'.
                   18463:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   18464:         }
                   18465:     } elsif (keys(%canset)) {
                   18466:         $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
                   18467:     }
                   18468:     if (@warnings) {
                   18469:         $output .= '<br />'.&mt('Warnings:').'<ul>'.
                   18470:                        join("\n",@warnings).'</ul>';
                   18471:     }
                   18472:     return $output;
                   18473: }
                   18474: 
                   18475: sub validate_ip_pattern {
                   18476:     my ($pattern) = @_;
                   18477:     if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
                   18478:         my ($start,$end) = ($1,$2);
                   18479:         if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
                   18480:             if (($start !~ m{/}) && ($end !~ m{/})) {
                   18481:                 return $start.'-'.$end;
                   18482:             }
                   18483:         }
                   18484:     } elsif ($pattern ne '') {
                   18485:         $pattern = &Net::CIDR::cidrvalidate($pattern);
                   18486:         if ($pattern ne '') {
                   18487:             return $pattern;
                   18488:         }
                   18489:     }
                   18490:     return;
                   18491: }
                   18492: 
1.137     raeburn  18493: sub modify_usersessions {
1.160.6.27  raeburn  18494:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  18495:     my @hostingtypes = ('version','excludedomain','includedomain');
                   18496:     my @offloadtypes = ('primary','default');
                   18497:     my %types = (
                   18498:                   remote => \@hostingtypes,
                   18499:                   hosted => \@hostingtypes,
                   18500:                   spares => \@offloadtypes,
                   18501:                 );
                   18502:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  18503:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  18504:     my (%by_ip,%by_location,@intdoms);
                   18505:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   18506:     my @locations = sort(keys(%by_location));
1.137     raeburn  18507:     my (%defaultshash,%changes);
                   18508:     foreach my $prefix (@prefixes) {
                   18509:         $defaultshash{'usersessions'}{$prefix} = {};
                   18510:     }
1.160.6.27  raeburn  18511:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  18512:     my $resulttext;
1.138     raeburn  18513:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  18514:     foreach my $prefix (@prefixes) {
1.145     raeburn  18515:         next if ($prefix eq 'spares');
                   18516:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  18517:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   18518:             if ($type eq 'version') {
                   18519:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   18520:                 my $okvalue;
                   18521:                 if ($value ne '') {
                   18522:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   18523:                         $okvalue = $value;
                   18524:                     }
                   18525:                 }
                   18526:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18527:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   18528:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   18529:                             if ($inuse == 0) {
                   18530:                                 $changes{$prefix}{$type} = 1;
                   18531:                             } else {
                   18532:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   18533:                                     $changes{$prefix}{$type} = 1;
                   18534:                                 }
                   18535:                                 if ($okvalue ne '') {
                   18536:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18537:                                 } 
                   18538:                             }
                   18539:                         } else {
                   18540:                             if (($inuse == 1) && ($okvalue ne '')) {
                   18541:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18542:                                 $changes{$prefix}{$type} = 1;
                   18543:                             }
                   18544:                         }
                   18545:                     } else {
                   18546:                         if (($inuse == 1) && ($okvalue ne '')) {
                   18547:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18548:                             $changes{$prefix}{$type} = 1;
                   18549:                         }
                   18550:                     }
                   18551:                 } else {
                   18552:                     if (($inuse == 1) && ($okvalue ne '')) {
                   18553:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   18554:                         $changes{$prefix}{$type} = 1;
                   18555:                     }
                   18556:                 }
                   18557:             } else {
                   18558:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   18559:                 my @okvals;
                   18560:                 foreach my $val (@vals) {
1.138     raeburn  18561:                     if ($val =~ /:/) {
                   18562:                         my @items = split(/:/,$val);
                   18563:                         foreach my $item (@items) {
                   18564:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   18565:                                 push(@okvals,$item);
                   18566:                             }
                   18567:                         }
                   18568:                     } else {
                   18569:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   18570:                             push(@okvals,$val);
                   18571:                         }
1.137     raeburn  18572:                     }
                   18573:                 }
                   18574:                 @okvals = sort(@okvals);
                   18575:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18576:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   18577:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   18578:                             if ($inuse == 0) {
                   18579:                                 $changes{$prefix}{$type} = 1; 
                   18580:                             } else {
                   18581:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18582:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   18583:                                 if (@changed > 0) {
                   18584:                                     $changes{$prefix}{$type} = 1;
                   18585:                                 }
                   18586:                             }
                   18587:                         } else {
                   18588:                             if ($inuse == 1) {
                   18589:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18590:                                 $changes{$prefix}{$type} = 1;
                   18591:                             }
                   18592:                         } 
                   18593:                     } else {
                   18594:                         if ($inuse == 1) {
                   18595:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18596:                             $changes{$prefix}{$type} = 1;
                   18597:                         }
                   18598:                     }
                   18599:                 } else {
                   18600:                     if ($inuse == 1) {
                   18601:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   18602:                         $changes{$prefix}{$type} = 1;
                   18603:                     }
                   18604:                 }
                   18605:             }
                   18606:         }
                   18607:     }
1.145     raeburn  18608: 
                   18609:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  18610:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  18611:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   18612:     my $savespares;
                   18613: 
                   18614:     foreach my $lonhost (sort(keys(%servers))) {
                   18615:         my $serverhomeID =
                   18616:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  18617:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  18618:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   18619:         my %spareschg;
                   18620:         foreach my $type (@{$types{'spares'}}) {
                   18621:             my @okspares;
                   18622:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   18623:             foreach my $server (@checked) {
1.152     raeburn  18624:                 if (&Apache::lonnet::hostname($server) ne '') {
                   18625:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   18626:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   18627:                             push(@okspares,$server);
                   18628:                         }
1.145     raeburn  18629:                     }
                   18630:                 }
                   18631:             }
                   18632:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   18633:             my $newspare;
1.152     raeburn  18634:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   18635:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  18636:                     $newspare = $new;
                   18637:                 }
                   18638:             }
1.152     raeburn  18639:             my @spares;
                   18640:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   18641:                 @spares = sort(@okspares,$newspare);
                   18642:             } else {
                   18643:                 @spares = sort(@okspares);
                   18644:             }
                   18645:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  18646:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   18647:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  18648:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  18649:                     if (@diffs > 0) {
                   18650:                         $spareschg{$type} = 1;
                   18651:                     }
                   18652:                 }
                   18653:             }
                   18654:         }
                   18655:         if (keys(%spareschg) > 0) {
                   18656:             $changes{'spares'}{$lonhost} = \%spareschg;
                   18657:         }
                   18658:     }
1.160.6.61  raeburn  18659:     $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105  raeburn  18660:     $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61  raeburn  18661:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   18662:     my @okoffload;
                   18663:     if (@offloadnow) {
                   18664:         foreach my $server (@offloadnow) {
                   18665:             if (&Apache::lonnet::hostname($server) ne '') {
                   18666:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   18667:                     push(@okoffload,$server);
                   18668:                 }
                   18669:             }
                   18670:         }
                   18671:         if (@okoffload) {
                   18672:             foreach my $lonhost (@okoffload) {
                   18673:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   18674:             }
                   18675:         }
                   18676:     }
1.160.6.105  raeburn  18677:     my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
                   18678:     my @okoffloadoth;
                   18679:     if (@offloadoth) {
                   18680:         foreach my $server (@offloadoth) {
                   18681:             if (&Apache::lonnet::hostname($server) ne '') {
                   18682:                 unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
                   18683:                     push(@okoffloadoth,$server);
                   18684:                 }
                   18685:             }
                   18686:         }
                   18687:         if (@okoffloadoth) {
                   18688:             foreach my $lonhost (@okoffloadoth) {
                   18689:                 $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
                   18690:             }
                   18691:         }
                   18692:     }
1.145     raeburn  18693:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   18694:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   18695:             if (ref($changes{'spares'}) eq 'HASH') {
                   18696:                 if (keys(%{$changes{'spares'}}) > 0) {
                   18697:                     $savespares = 1;
                   18698:                 }
                   18699:             }
                   18700:         } else {
                   18701:             $savespares = 1;
                   18702:         }
1.160.6.105  raeburn  18703:         foreach my $offload ('offloadnow','offloadoth') {
                   18704:             if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
                   18705:                 foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
                   18706:                     unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
                   18707:                         $changes{$offload} = 1;
1.160.6.61  raeburn  18708:                         last;
                   18709:                     }
                   18710:                 }
1.160.6.105  raeburn  18711:                 unless ($changes{$offload}) {
                   18712:                     foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
                   18713:                         unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
                   18714:                             $changes{$offload} = 1;
                   18715:                             last;
                   18716:                         }
                   18717:                     }
                   18718:                 }
                   18719:             } else {
                   18720:                 if (($offload eq 'offloadnow') && (@okoffload)) {
                   18721:                      $changes{'offloadnow'} = 1;
                   18722:                 }
                   18723:                 if (($offload eq 'offloadoth') && (@okoffloadoth)) {
                   18724:                     $changes{'offloadoth'} = 1;
                   18725:                 }
1.160.6.61  raeburn  18726:             }
1.160.6.105  raeburn  18727:         }
                   18728:     } else {
                   18729:         if (@okoffload) {
1.160.6.61  raeburn  18730:             $changes{'offloadnow'} = 1;
                   18731:         }
1.160.6.105  raeburn  18732:         if (@okoffloadoth) {
                   18733:             $changes{'offloadoth'} = 1;
                   18734:         }
1.145     raeburn  18735:     }
1.147     raeburn  18736:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   18737:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  18738:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   18739:                                                  $dom);
                   18740:         if ($putresult eq 'ok') {
                   18741:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18742:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   18743:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   18744:                 }
                   18745:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   18746:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   18747:                 }
1.160.6.61  raeburn  18748:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18749:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   18750:                 }
1.160.6.105  raeburn  18751:                 if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   18752:                     $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
                   18753:                 }
1.137     raeburn  18754:             }
                   18755:             my $cachetime = 24*60*60;
                   18756:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81  raeburn  18757:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27  raeburn  18758:             if (ref($lastactref) eq 'HASH') {
                   18759:                 $lastactref->{'domdefaults'} = 1;
1.160.6.81  raeburn  18760:                 $lastactref->{'usersessions'} = 1;
1.160.6.27  raeburn  18761:             }
1.147     raeburn  18762:             if (keys(%changes) > 0) {
                   18763:                 my %lt = &usersession_titles();
                   18764:                 $resulttext = &mt('Changes made:').'<ul>';
                   18765:                 foreach my $prefix (@prefixes) {
                   18766:                     if (ref($changes{$prefix}) eq 'HASH') {
                   18767:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   18768:                         if ($prefix eq 'spares') {
                   18769:                             if (ref($changes{$prefix}) eq 'HASH') {
                   18770:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   18771:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  18772:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27  raeburn  18773:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   18774:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  18775:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   18776:                                         foreach my $type (@{$types{$prefix}}) {
                   18777:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   18778:                                                 my $offloadto = &mt('None');
                   18779:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   18780:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   18781:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   18782:                                                     }
1.145     raeburn  18783:                                                 }
1.147     raeburn  18784:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  18785:                                             }
1.137     raeburn  18786:                                         }
                   18787:                                     }
1.147     raeburn  18788:                                     $resulttext .= '</li>';
1.137     raeburn  18789:                                 }
                   18790:                             }
1.147     raeburn  18791:                         } else {
                   18792:                             foreach my $type (@{$types{$prefix}}) {
                   18793:                                 if (defined($changes{$prefix}{$type})) {
                   18794:                                     my $newvalue;
                   18795:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   18796:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   18797:                                             if ($type eq 'version') {
                   18798:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   18799:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   18800:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   18801:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   18802:                                                 }
1.145     raeburn  18803:                                             }
                   18804:                                         }
                   18805:                                     }
1.147     raeburn  18806:                                     if ($newvalue eq '') {
                   18807:                                         if ($type eq 'version') {
                   18808:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   18809:                                         } else {
                   18810:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   18811:                                         }
1.145     raeburn  18812:                                     } else {
1.147     raeburn  18813:                                         if ($type eq 'version') {
                   18814:                                             $newvalue .= ' '.&mt('(or later)'); 
                   18815:                                         }
                   18816:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  18817:                                     }
1.137     raeburn  18818:                                 }
                   18819:                             }
                   18820:                         }
1.147     raeburn  18821:                         $resulttext .= '</ul>';
1.137     raeburn  18822:                     }
                   18823:                 }
1.160.6.61  raeburn  18824:                 if ($changes{'offloadnow'}) {
                   18825:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   18826:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105  raeburn  18827:                             $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61  raeburn  18828:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   18829:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   18830:                             }
                   18831:                             $resulttext .= '</ul>';
                   18832:                         } else {
1.160.6.105  raeburn  18833:                             $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
                   18834:                         }
                   18835:                     } else {
                   18836:                         $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
                   18837:                     }
                   18838:                 }
                   18839:                 if ($changes{'offloadoth'}) {
                   18840:                     if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
                   18841:                         if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
                   18842:                             $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
                   18843:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
                   18844:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   18845:                             }
                   18846:                             $resulttext .= '</ul>';
                   18847:                         } else {
                   18848:                             $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61  raeburn  18849:                         }
                   18850:                     } else {
1.160.6.105  raeburn  18851:                         $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61  raeburn  18852:                     }
                   18853:                 }
1.147     raeburn  18854:                 $resulttext .= '</ul>';
                   18855:             } else {
                   18856:                 $resulttext = $nochgmsg;
1.137     raeburn  18857:             }
                   18858:         } else {
                   18859:             $resulttext = '<span class="LC_error">'.
                   18860:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   18861:         }
                   18862:     } else {
1.147     raeburn  18863:         $resulttext = $nochgmsg;
1.137     raeburn  18864:     }
                   18865:     return $resulttext;
                   18866: }
                   18867: 
1.150     raeburn  18868: sub modify_loadbalancing {
                   18869:     my ($dom,%domconfig) = @_;
                   18870:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   18871:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   18872:     my ($othertitle,$usertypes,$types) =
                   18873:         &Apache::loncommon::sorted_inst_types($dom);
                   18874:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55  raeburn  18875:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  18876:     my @sparestypes = ('primary','default');
                   18877:     my %typetitles = &sparestype_titles();
                   18878:     my $resulttext;
1.160.6.94  raeburn  18879:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  18880:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18881:         %existing = %{$domconfig{'loadbalancing'}};
                   18882:     }
                   18883:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  18884:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  18885:     my ($saveloadbalancing,%defaultshash,%changes);
                   18886:     my ($alltypes,$othertypes,$titles) =
                   18887:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   18888:     my %ruletitles = &offloadtype_text();
                   18889:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   18890:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   18891:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   18892:         if ($balancer eq '') {
                   18893:             next;
                   18894:         }
                   18895:         if (!exists($servers{$balancer})) {
                   18896:             if (exists($currbalancer{$balancer})) {
                   18897:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  18898:             }
1.160.6.7  raeburn  18899:             next;
                   18900:         }
                   18901:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   18902:             push(@{$changes{'delete'}},$balancer);
                   18903:             next;
                   18904:         }
                   18905:         if (!exists($currbalancer{$balancer})) {
                   18906:             push(@{$changes{'add'}},$balancer);
                   18907:         }
                   18908:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   18909:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   18910:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   18911:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   18912:             $saveloadbalancing = 1;
                   18913:         }
                   18914:         foreach my $sparetype (@sparestypes) {
                   18915:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   18916:             my @offloadto;
                   18917:             foreach my $target (@targets) {
                   18918:                 if (($servers{$target}) && ($target ne $balancer)) {
                   18919:                     if ($sparetype eq 'default') {
                   18920:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   18921:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  18922:                         }
                   18923:                     }
1.160.6.7  raeburn  18924:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   18925:                         push(@offloadto,$target);
                   18926:                     }
1.150     raeburn  18927:                 }
                   18928:             }
1.160.6.76  raeburn  18929:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   18930:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   18931:                     push(@offloadto,$balancer);
                   18932:                 }
                   18933:             }
                   18934:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  18935:         }
1.160.6.94  raeburn  18936:         if ($env{'form.loadbalancing_cookie_'.$i}) {
                   18937:             $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
                   18938:             if (exists($currbalancer{$balancer})) {
                   18939:                 unless ($currcookies{$balancer}) {
                   18940:                     $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18941:                 }
                   18942:             }
                   18943:         } elsif (exists($currbalancer{$balancer})) {
                   18944:             if ($currcookies{$balancer}) {
                   18945:                 $changes{'curr'}{$balancer}{'cookie'} = 1;
                   18946:             }
                   18947:         }
1.160.6.7  raeburn  18948:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  18949:             foreach my $sparetype (@sparestypes) {
1.160.6.7  raeburn  18950:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   18951:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  18952:                     if (@targetdiffs > 0) {
1.160.6.7  raeburn  18953:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18954:                     }
1.160.6.7  raeburn  18955:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18956:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18957:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  18958:                     }
                   18959:                 }
                   18960:             }
                   18961:         } else {
1.160.6.7  raeburn  18962:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   18963:                 foreach my $sparetype (@sparestypes) {
                   18964:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   18965:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   18966:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   18967:                         }
1.150     raeburn  18968:                     }
                   18969:                 }
1.160.6.7  raeburn  18970:             }
1.150     raeburn  18971:         }
                   18972:         my $ishomedom;
1.160.6.7  raeburn  18973:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   18974:             $ishomedom = 1;
1.150     raeburn  18975:         }
                   18976:         if (ref($alltypes) eq 'ARRAY') {
                   18977:             foreach my $type (@{$alltypes}) {
                   18978:                 my $rule;
1.160.6.7  raeburn  18979:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  18980:                          (!$ishomedom)) {
1.160.6.7  raeburn  18981:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   18982:                 }
                   18983:                 if ($rule eq 'specific') {
1.160.6.55  raeburn  18984:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   18985:                     if (exists($servers{$specifiedhost})) {
                   18986:                         $rule = $specifiedhost;
                   18987:                     }
1.150     raeburn  18988:                 }
1.160.6.7  raeburn  18989:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   18990:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   18991:                     if ($rule ne $currrules{$balancer}{$type}) {
                   18992:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18993:                     }
                   18994:                 } elsif ($rule ne '') {
1.160.6.7  raeburn  18995:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  18996:                 }
                   18997:             }
                   18998:         }
1.160.6.7  raeburn  18999:     }
                   19000:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   19001:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   19002:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   19003:             $defaultshash{'loadbalancing'} = {};
                   19004:         }
                   19005:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   19006:                                                  \%defaultshash,$dom);
                   19007:         if ($putresult eq 'ok') {
                   19008:             if (keys(%changes) > 0) {
1.160.6.54  raeburn  19009:                 my %toupdate;
1.160.6.7  raeburn  19010:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   19011:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   19012:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54  raeburn  19013:                         $toupdate{$balancer} = 1;
1.150     raeburn  19014:                     }
1.160.6.7  raeburn  19015:                 }
                   19016:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   19017:                     foreach my $balancer (sort(@{$changes{'add'}})) {
                   19018:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54  raeburn  19019:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  19020:                     }
                   19021:                 }
                   19022:                 if (ref($changes{'curr'}) eq 'HASH') {
                   19023:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55  raeburn  19024:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  19025:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   19026:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   19027:                                 my %offloadstr;
                   19028:                                 foreach my $sparetype (@sparestypes) {
                   19029:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   19030:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   19031:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   19032:                                         }
                   19033:                                     }
1.150     raeburn  19034:                                 }
1.160.6.7  raeburn  19035:                                 if (keys(%offloadstr) == 0) {
                   19036:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  19037:                                 } else {
1.160.6.7  raeburn  19038:                                     my $showoffload;
                   19039:                                     foreach my $sparetype (@sparestypes) {
                   19040:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   19041:                                         if (defined($offloadstr{$sparetype})) {
                   19042:                                             $showoffload .= $offloadstr{$sparetype};
                   19043:                                         } else {
                   19044:                                             $showoffload .= &mt('None');
                   19045:                                         }
                   19046:                                         $showoffload .= ('&nbsp;'x3);
                   19047:                                     }
                   19048:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  19049:                                 }
                   19050:                             }
                   19051:                         }
1.160.6.7  raeburn  19052:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   19053:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   19054:                                 foreach my $type (@{$alltypes}) {
                   19055:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   19056:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   19057:                                         my $balancetext;
                   19058:                                         if ($rule eq '') {
                   19059:                                             $balancetext =  $ruletitles{'default'};
1.160.6.26  raeburn  19060:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55  raeburn  19061:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                   19062:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54  raeburn  19063:                                                 foreach my $sparetype (@sparestypes) {
                   19064:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   19065:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   19066:                                                     }
                   19067:                                                 }
1.160.6.55  raeburn  19068:                                                 foreach my $item (@{$alltypes}) {
                   19069:                                                     next if ($item =~  /^_LC_ipchange/);
                   19070:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   19071:                                                     if ($hasrule eq 'homeserver') {
                   19072:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   19073:                                                     } else {
                   19074:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   19075:                                                             if ($servers{$hasrule}) {
                   19076:                                                                 $toupdate{$hasrule} = 1;
                   19077:                                                             }
                   19078:                                                         }
                   19079:                                                     }
                   19080:                                                 }
                   19081:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   19082:                                                     $balancetext =  $ruletitles{$rule};
                   19083:                                                 } else {
                   19084:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   19085:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   19086:                                                     if ($receiver) {
                   19087:                                                         $toupdate{$receiver};
                   19088:                                                     }
                   19089:                                                 }
                   19090:                                             } else {
                   19091:                                                 $balancetext =  $ruletitles{$rule};
1.160.6.54  raeburn  19092:                                             }
1.160.6.7  raeburn  19093:                                         } else {
                   19094:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   19095:                                         }
1.160.6.26  raeburn  19096:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  19097:                                     }
                   19098:                                 }
                   19099:                             }
                   19100:                         }
1.160.6.94  raeburn  19101:                         if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117  raeburn  19102:                             if ($currcookies{$balancer}) {
                   19103:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
                   19104:                                                           $balancer).'</li>';
                   19105:                             } else {
                   19106:                                 $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                   19107:                                                           $balancer).'</li>';
                   19108:                             }
1.160.6.94  raeburn  19109:                         }
1.160.6.106  raeburn  19110:                     }
                   19111:                 }
                   19112:                 if (keys(%toupdate)) {
                   19113:                     my %thismachine;
                   19114:                     my $updatedhere;
                   19115:                     my $cachetime = 60*60*24;
                   19116:                     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   19117:                     foreach my $lonhost (keys(%toupdate)) {
                   19118:                         if ($thismachine{$lonhost}) {
                   19119:                             unless ($updatedhere) {
                   19120:                                 &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   19121:                                                               $defaultshash{'loadbalancing'},
                   19122:                                                               $cachetime);
                   19123:                                 $updatedhere = 1;
1.160.6.54  raeburn  19124:                             }
1.160.6.106  raeburn  19125:                         } else {
                   19126:                             my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   19127:                             &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54  raeburn  19128:                         }
1.150     raeburn  19129:                     }
1.160.6.7  raeburn  19130:                 }
                   19131:                 if ($resulttext ne '') {
                   19132:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  19133:                 } else {
                   19134:                     $resulttext = $nochgmsg;
                   19135:                 }
                   19136:             } else {
1.160.6.7  raeburn  19137:                 $resulttext = $nochgmsg;
1.150     raeburn  19138:             }
                   19139:         } else {
1.160.6.7  raeburn  19140:             $resulttext = '<span class="LC_error">'.
                   19141:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  19142:         }
                   19143:     } else {
1.160.6.7  raeburn  19144:         $resulttext = $nochgmsg;
1.150     raeburn  19145:     }
                   19146:     return $resulttext;
                   19147: }
                   19148: 
1.48      raeburn  19149: sub recurse_check {
                   19150:     my ($chkcats,$categories,$depth,$name) = @_;
                   19151:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   19152:         my $chg = 0;
                   19153:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   19154:             my $category = $chkcats->[$depth]{$name}[$j];
                   19155:             my $item;
                   19156:             if ($category eq '') {
                   19157:                 $chg ++;
                   19158:             } else {
                   19159:                 my $deeper = $depth + 1;
                   19160:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   19161:                 if ($chg) {
                   19162:                     $categories->{$item} -= $chg;
                   19163:                 }
                   19164:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   19165:                 $deeper --;
                   19166:             }
                   19167:         }
                   19168:     }
                   19169:     return;
                   19170: }
                   19171: 
                   19172: sub recurse_cat_deletes {
                   19173:     my ($item,$coursecategories,$deletions) = @_;
                   19174:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   19175:     my $subdepth = $depth + 1;
                   19176:     if (ref($coursecategories) eq 'HASH') {
                   19177:         foreach my $subitem (keys(%{$coursecategories})) {
                   19178:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   19179:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   19180:                 delete($coursecategories->{$subitem});
                   19181:                 $deletions->{$subitem} = 1;
                   19182:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26  raeburn  19183:             }
1.48      raeburn  19184:         }
                   19185:     }
                   19186:     return;
                   19187: }
                   19188: 
1.125     raeburn  19189: sub active_dc_picker {
1.160.6.16  raeburn  19190:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77  raeburn  19191:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16  raeburn  19192:     my @domcoord = keys(%domcoords);
                   19193:     if (keys(%currhash)) {
                   19194:         foreach my $dc (keys(%currhash)) {
                   19195:             unless (exists($domcoords{$dc})) {
                   19196:                 push(@domcoord,$dc);
                   19197:             }
                   19198:         }
                   19199:     }
                   19200:     @domcoord = sort(@domcoord);
                   19201:     my $numdcs = scalar(@domcoord);
                   19202:     my $rows = 0;
                   19203:     my $table;
1.125     raeburn  19204:     if ($numdcs > 1) {
1.160.6.16  raeburn  19205:         $table = '<table>';
                   19206:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  19207:             my $rem = $i%($numinrow);
                   19208:             if ($rem == 0) {
                   19209:                 if ($i > 0) {
1.160.6.16  raeburn  19210:                     $table .= '</tr>';
1.125     raeburn  19211:                 }
1.160.6.16  raeburn  19212:                 $table .= '<tr>';
                   19213:                 $rows ++;
1.125     raeburn  19214:             }
1.160.6.16  raeburn  19215:             my $check = '';
                   19216:             if ($inputtype eq 'radio') {
                   19217:                 if (keys(%currhash) == 0) {
                   19218:                     if (!$i) {
                   19219:                         $check = ' checked="checked"';
                   19220:                     }
                   19221:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   19222:                     $check = ' checked="checked"';
                   19223:                 }
                   19224:             } else {
                   19225:                 if (exists($currhash{$domcoord[$i]})) {
                   19226:                     $check = ' checked="checked"';
1.125     raeburn  19227:                 }
                   19228:             }
1.160.6.16  raeburn  19229:             if ($i == @domcoord - 1) {
1.125     raeburn  19230:                 my $colsleft = $numinrow - $rem;
                   19231:                 if ($colsleft > 1) {
1.160.6.16  raeburn  19232:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  19233:                 } else {
1.160.6.16  raeburn  19234:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  19235:                 }
                   19236:             } else {
1.160.6.16  raeburn  19237:                 $table .= '<td class="LC_left_item">';
                   19238:             }
                   19239:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   19240:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   19241:             $table .= '<span class="LC_nobreak"><label>'.
                   19242:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   19243:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   19244:             if ($user ne $dcname.':'.$dcdom) {
1.160.6.32  raeburn  19245:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.125     raeburn  19246:             }
1.160.6.33  raeburn  19247:             $table .= '</label></span></td>';
1.125     raeburn  19248:         }
1.160.6.16  raeburn  19249:         $table .= '</tr></table>';
                   19250:     } elsif ($numdcs == 1) {
1.160.6.32  raeburn  19251:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   19252:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16  raeburn  19253:         if ($inputtype eq 'radio') {
1.160.6.50  raeburn  19254:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31  raeburn  19255:             if ($user ne $dcname.':'.$dcdom) {
                   19256:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   19257:             }
1.160.6.16  raeburn  19258:         } else {
                   19259:             my $check;
                   19260:             if (exists($currhash{$domcoord[0]})) {
                   19261:                 $check = ' checked="checked"';
                   19262:             }
1.160.6.50  raeburn  19263:             $table = '<span class="LC_nobreak"><label>'.
                   19264:                      '<input type="checkbox" name="'.$name.'" '.
                   19265:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31  raeburn  19266:             if ($user ne $dcname.':'.$dcdom) {
                   19267:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   19268:             }
                   19269:             $table .= '</label></span>';
1.160.6.16  raeburn  19270:             $rows ++;
                   19271:         }
1.125     raeburn  19272:     }
1.160.6.16  raeburn  19273:     return ($numdcs,$table,$rows);
1.125     raeburn  19274: }
                   19275: 
1.137     raeburn  19276: sub usersession_titles {
                   19277:     return &Apache::lonlocal::texthash(
                   19278:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   19279:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  19280:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  19281:                version => 'LON-CAPA version requirement',
1.138     raeburn  19282:                excludedomain => 'Allow all, but exclude specific domains',
                   19283:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  19284:                primary => 'Primary (checked first)',
1.154     raeburn  19285:                default => 'Default',
1.137     raeburn  19286:            );
                   19287: }
                   19288: 
1.152     raeburn  19289: sub id_for_thisdom {
                   19290:     my (%servers) = @_;
                   19291:     my %altids;
                   19292:     foreach my $server (keys(%servers)) {
                   19293:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   19294:         if ($serverhome ne $server) {
                   19295:             $altids{$serverhome} = $server;
                   19296:         }
                   19297:     }
                   19298:     return %altids;
                   19299: }
                   19300: 
1.150     raeburn  19301: sub count_servers {
                   19302:     my ($currbalancer,%servers) = @_;
                   19303:     my (@spares,$numspares);
                   19304:     foreach my $lonhost (sort(keys(%servers))) {
                   19305:         next if ($currbalancer eq $lonhost);
                   19306:         push(@spares,$lonhost);
                   19307:     }
                   19308:     if ($currbalancer) {
                   19309:         $numspares = scalar(@spares);
                   19310:     } else {
                   19311:         $numspares = scalar(@spares) - 1;
                   19312:     }
                   19313:     return ($numspares,@spares);
                   19314: }
                   19315: 
                   19316: sub lonbalance_targets_js {
1.160.6.7  raeburn  19317:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  19318:     my $select = &mt('Select');
                   19319:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   19320:     if (ref($servers) eq 'HASH') {
                   19321:         $alltargets = join("','",sort(keys(%{$servers})));
                   19322:         my @homedoms;
                   19323:         foreach my $server (sort(keys(%{$servers}))) {
                   19324:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   19325:                 push(@homedoms,'1');
                   19326:             } else {
                   19327:                 push(@homedoms,'0');
                   19328:             }
                   19329:         }
                   19330:         $allishome = join("','",@homedoms);
                   19331:     }
                   19332:     if (ref($types) eq 'ARRAY') {
                   19333:         if (@{$types} > 0) {
                   19334:             @alltypes = @{$types};
                   19335:         }
                   19336:     }
                   19337:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   19338:     $allinsttypes = join("','",@alltypes);
1.160.6.94  raeburn  19339:     my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7  raeburn  19340:     if (ref($settings) eq 'HASH') {
                   19341:         %existing = %{$settings};
                   19342:     }
                   19343:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94  raeburn  19344:                               \%currtargets,\%currrules,\%currcookies);
1.160.6.7  raeburn  19345:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  19346:     return <<"END";
                   19347: 
                   19348: <script type="text/javascript">
                   19349: // <![CDATA[
                   19350: 
1.160.6.7  raeburn  19351: currBalancers = new Array('$balancers');
                   19352: 
                   19353: function toggleTargets(balnum) {
                   19354:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19355:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   19356:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   19357:     var prevbalancer = prevhostitem.value;
                   19358:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19359:     prevhostitem.value = balancer;
                   19360:     if (prevbalancer != '') {
                   19361:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   19362:         if (prevIdx != -1) {
                   19363:             currBalancers.splice(prevIdx,1);
                   19364:         }
                   19365:     }
1.150     raeburn  19366:     if (balancer == '') {
1.160.6.7  raeburn  19367:         hideSpares(balnum);
1.150     raeburn  19368:     } else {
1.160.6.7  raeburn  19369:         var currIdx = currBalancers.indexOf(balancer);
                   19370:         if (currIdx == -1) {
                   19371:             currBalancers.push(balancer);
                   19372:         }
1.150     raeburn  19373:         var homedoms = new Array('$allishome');
1.160.6.7  raeburn  19374:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   19375:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  19376:     }
1.160.6.7  raeburn  19377:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  19378:     return;
                   19379: }
                   19380: 
1.160.6.7  raeburn  19381: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  19382:     var alltargets = new Array('$alltargets');
                   19383:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  19384:     var offloadtypes = new Array('primary','default');
                   19385: 
1.160.6.7  raeburn  19386:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   19387:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  19388:  
1.151     raeburn  19389:     for (var i=0; i<offloadtypes.length; i++) {
                   19390:         var count = 0;
                   19391:         for (var j=0; j<alltargets.length; j++) {
                   19392:             if (alltargets[j] != balancer) {
1.160.6.7  raeburn  19393:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   19394:                 item.value = alltargets[j];
                   19395:                 item.style.textAlign='left';
                   19396:                 item.style.textFace='normal';
                   19397:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   19398:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   19399:                     item.disabled = '';
                   19400:                 } else {
                   19401:                     item.disabled = 'disabled';
                   19402:                     item.checked = false;
                   19403:                 }
1.151     raeburn  19404:                 count ++;
                   19405:             }
1.150     raeburn  19406:         }
                   19407:     }
1.151     raeburn  19408:     for (var k=0; k<insttypes.length; k++) {
                   19409:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  19410:             if (ishomedom == 1) {
1.160.6.7  raeburn  19411:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19412:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19413:             } else {
1.160.6.7  raeburn  19414:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19415:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  19416:             }
                   19417:         } else {
1.160.6.7  raeburn  19418:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   19419:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  19420:         }
1.151     raeburn  19421:         if ((insttypes[k] != '_LC_external') && 
                   19422:             ((insttypes[k] != '_LC_internetdom') ||
                   19423:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7  raeburn  19424:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   19425:             item.options.length = 0;
                   19426:             item.options[0] = new Option("","",true,true);
                   19427:             var idx = 0;
1.151     raeburn  19428:             for (var m=0; m<alltargets.length; m++) {
1.160.6.7  raeburn  19429:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   19430:                     idx ++;
                   19431:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  19432:                 }
                   19433:             }
                   19434:         }
                   19435:     }
                   19436:     return;
                   19437: }
                   19438: 
1.160.6.7  raeburn  19439: function hideSpares(balnum) {
1.150     raeburn  19440:     var alltargets = new Array('$alltargets');
                   19441:     var insttypes = new Array('$allinsttypes');
                   19442:     var offloadtypes = new Array('primary','default');
                   19443: 
1.160.6.7  raeburn  19444:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   19445:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  19446: 
                   19447:     var total = alltargets.length - 1;
                   19448:     for (var i=0; i<offloadtypes; i++) {
                   19449:         for (var j=0; j<total; j++) {
1.160.6.7  raeburn  19450:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   19451:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   19452:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  19453:         }
1.150     raeburn  19454:     }
                   19455:     for (var k=0; k<insttypes.length; k++) {
1.160.6.7  raeburn  19456:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   19457:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  19458:         if (insttypes[k] != '_LC_external') {
1.160.6.7  raeburn  19459:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   19460:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  19461:         }
                   19462:     }
                   19463:     return;
                   19464: }
                   19465: 
1.160.6.7  raeburn  19466: function checkOffloads(item,balnum,type) {
1.150     raeburn  19467:     var alltargets = new Array('$alltargets');
                   19468:     var offloadtypes = new Array('primary','default');
                   19469:     if (item.checked) {
                   19470:         var total = alltargets.length - 1;
                   19471:         var other;
                   19472:         if (type == offloadtypes[0]) {
1.151     raeburn  19473:             other = offloadtypes[1];
1.150     raeburn  19474:         } else {
1.151     raeburn  19475:             other = offloadtypes[0];
1.150     raeburn  19476:         }
                   19477:         for (var i=0; i<total; i++) {
1.160.6.7  raeburn  19478:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  19479:             if (server == item.value) {
1.160.6.7  raeburn  19480:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   19481:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  19482:                 }
                   19483:             }
                   19484:         }
                   19485:     }
                   19486:     return;
                   19487: }
                   19488: 
1.160.6.7  raeburn  19489: function singleServerToggle(balnum,type) {
                   19490:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  19491:     if (offloadtoSelIdx == 0) {
1.160.6.7  raeburn  19492:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   19493:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19494: 
                   19495:     } else {
1.160.6.7  raeburn  19496:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   19497:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  19498:     }
                   19499:     return;
                   19500: }
                   19501: 
1.160.6.7  raeburn  19502: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  19503:     if (type == '_LC_external') {
1.160.6.26  raeburn  19504:         return;
1.150     raeburn  19505:     }
1.160.6.7  raeburn  19506:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  19507:     for (var i=0; i<typesRules.length; i++) {
                   19508:         if (formname.elements[typesRules[i]].checked) {
                   19509:             if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7  raeburn  19510:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   19511:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  19512:             } else {
1.160.6.7  raeburn  19513:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   19514:             }
                   19515:         }
                   19516:     }
                   19517:     return;
                   19518: }
                   19519: 
                   19520: function balancerDeleteChange(balnum) {
                   19521:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   19522:     var baltotal = document.getElementById('loadbalancing_total').value;
                   19523:     var addtarget;
                   19524:     var removetarget;
                   19525:     var action = 'delete';
                   19526:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   19527:         var lonhost = hostitem.value;
                   19528:         var currIdx = currBalancers.indexOf(lonhost);
                   19529:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   19530:             if (currIdx != -1) {
                   19531:                 currBalancers.splice(currIdx,1);
                   19532:             }
                   19533:             addtarget = lonhost;
                   19534:         } else {
                   19535:             if (currIdx == -1) {
                   19536:                 currBalancers.push(lonhost);
                   19537:             }
                   19538:             removetarget = lonhost;
                   19539:             action = 'undelete';
                   19540:         }
                   19541:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   19542:     }
                   19543:     return;
                   19544: }
                   19545: 
                   19546: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   19547:     if (baltotal > 1) {
                   19548:         var offloadtypes = new Array('primary','default');
                   19549:         var alltargets = new Array('$alltargets');
                   19550:         var insttypes = new Array('$allinsttypes');
                   19551:         for (var i=0; i<baltotal; i++) {
                   19552:             if (i != balnum) {
                   19553:                 for (var j=0; j<offloadtypes.length; j++) {
                   19554:                     var total = alltargets.length - 1;
                   19555:                     for (var k=0; k<total; k++) {
                   19556:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   19557:                         var server = serveritem.value;
                   19558:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   19559:                             if (server == addtarget) {
                   19560:                                 serveritem.disabled = '';
                   19561:                             }
                   19562:                         }
                   19563:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19564:                             if (server == removetarget) {
                   19565:                                 serveritem.disabled = 'disabled';
                   19566:                                 serveritem.checked = false;
                   19567:                             }
                   19568:                         }
                   19569:                     }
                   19570:                 }
                   19571:                 for (var j=0; j<insttypes.length; j++) {
                   19572:                     if (insttypes[j] != '_LC_external') {
                   19573:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   19574:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   19575:                             var currSel = singleserver.selectedIndex;
                   19576:                             var currVal = singleserver.options[currSel].value;
                   19577:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   19578:                                 var numoptions = singleserver.options.length;
                   19579:                                 var needsnew = 1;
                   19580:                                 for (var k=0; k<numoptions; k++) {
                   19581:                                     if (singleserver.options[k] == addtarget) {
                   19582:                                         needsnew = 0;
                   19583:                                         break;
                   19584:                                     }
                   19585:                                 }
                   19586:                                 if (needsnew == 1) {
                   19587:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   19588:                                 }
                   19589:                             }
                   19590:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   19591:                                 singleserver.options.length = 0;
                   19592:                                 if ((currVal) && (currVal != removetarget)) {
                   19593:                                     singleserver.options[0] = new Option("","",false,false);
                   19594:                                 } else {
                   19595:                                     singleserver.options[0] = new Option("","",true,true);
                   19596:                                 }
                   19597:                                 var idx = 0;
                   19598:                                 for (var m=0; m<alltargets.length; m++) {
                   19599:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   19600:                                         idx ++;
                   19601:                                         if (currVal == alltargets[m]) {
                   19602:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   19603:                                         } else {
                   19604:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   19605:                                         }
                   19606:                                     }
                   19607:                                 }
                   19608:                             }
                   19609:                         }
                   19610:                     }
                   19611:                 }
1.150     raeburn  19612:             }
                   19613:         }
                   19614:     }
                   19615:     return;
                   19616: }
                   19617: 
1.152     raeburn  19618: // ]]>
                   19619: </script>
                   19620: 
                   19621: END
                   19622: }
                   19623: 
                   19624: sub new_spares_js {
                   19625:     my @sparestypes = ('primary','default');
                   19626:     my $types = join("','",@sparestypes);
                   19627:     my $select = &mt('Select');
                   19628:     return <<"END";
                   19629: 
                   19630: <script type="text/javascript">
                   19631: // <![CDATA[
                   19632: 
                   19633: function updateNewSpares(formname,lonhost) {
                   19634:     var types = new Array('$types');
                   19635:     var include = new Array();
                   19636:     var exclude = new Array();
                   19637:     for (var i=0; i<types.length; i++) {
                   19638:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   19639:         for (var j=0; j<spareboxes.length; j++) {
                   19640:             if (formname.elements[spareboxes[j]].checked) {
                   19641:                 exclude.push(formname.elements[spareboxes[j]].value);
                   19642:             } else {
                   19643:                 include.push(formname.elements[spareboxes[j]].value);
                   19644:             }
                   19645:         }
                   19646:     }
                   19647:     for (var i=0; i<types.length; i++) {
                   19648:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   19649:         var selIdx = newSpare.selectedIndex;
                   19650:         var currnew = newSpare.options[selIdx].value;
                   19651:         var okSpares = new Array();
                   19652:         for (var j=0; j<newSpare.options.length; j++) {
                   19653:             var possible = newSpare.options[j].value;
                   19654:             if (possible != '') {
                   19655:                 if (exclude.indexOf(possible) == -1) {
                   19656:                     okSpares.push(possible);
                   19657:                 } else {
                   19658:                     if (currnew == possible) {
                   19659:                         selIdx = 0;
                   19660:                     }
                   19661:                 }
                   19662:             }
                   19663:         }
                   19664:         for (var k=0; k<include.length; k++) {
                   19665:             if (okSpares.indexOf(include[k]) == -1) {
                   19666:                 okSpares.push(include[k]);
                   19667:             }
                   19668:         }
                   19669:         okSpares.sort();
                   19670:         newSpare.options.length = 0;
                   19671:         if (selIdx == 0) {
                   19672:             newSpare.options[0] = new Option("$select","",true,true);
                   19673:         } else {
                   19674:             newSpare.options[0] = new Option("$select","",false,false);
                   19675:         }
                   19676:         for (var m=0; m<okSpares.length; m++) {
                   19677:             var idx = m+1;
                   19678:             var selThis = 0;
                   19679:             if (selIdx != 0) {
                   19680:                 if (okSpares[m] == currnew) {
                   19681:                     selThis = 1;
                   19682:                 }
                   19683:             }
                   19684:             if (selThis == 1) {
                   19685:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   19686:             } else {
                   19687:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   19688:             }
                   19689:         }
                   19690:     }
                   19691:     return;
                   19692: }
                   19693: 
                   19694: function checkNewSpares(lonhost,type) {
                   19695:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   19696:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   19697:     if (chosen != '') { 
                   19698:         var othertype;
                   19699:         var othernewSpare;
                   19700:         if (type == 'primary') {
                   19701:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   19702:         }
                   19703:         if (type == 'default') {
                   19704:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   19705:         }
                   19706:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   19707:             othernewSpare.selectedIndex = 0;
                   19708:         }
                   19709:     }
                   19710:     return;
                   19711: }
                   19712: 
                   19713: // ]]>
                   19714: </script>
                   19715: 
                   19716: END
                   19717: 
                   19718: }
                   19719: 
                   19720: sub common_domprefs_js {
                   19721:     return <<"END";
                   19722: 
                   19723: <script type="text/javascript">
                   19724: // <![CDATA[
                   19725: 
1.150     raeburn  19726: function getIndicesByName(formname,item) {
1.152     raeburn  19727:     var group = new Array();
1.150     raeburn  19728:     for (var i=0;i<formname.elements.length;i++) {
                   19729:         if (formname.elements[i].name == item) {
1.152     raeburn  19730:             group.push(formname.elements[i].id);
1.150     raeburn  19731:         }
                   19732:     }
1.152     raeburn  19733:     return group;
1.150     raeburn  19734: }
                   19735: 
                   19736: // ]]>
                   19737: </script>
                   19738: 
                   19739: END
1.152     raeburn  19740: 
1.150     raeburn  19741: }
                   19742: 
1.160.6.5  raeburn  19743: sub recaptcha_js {
                   19744:     my %lt = &captcha_phrases();
                   19745:     return <<"END";
                   19746: 
                   19747: <script type="text/javascript">
                   19748: // <![CDATA[
                   19749: 
                   19750: function updateCaptcha(caller,context) {
                   19751:     var privitem;
                   19752:     var pubitem;
                   19753:     var privtext;
                   19754:     var pubtext;
1.160.6.69  raeburn  19755:     var versionitem;
                   19756:     var versiontext;
1.160.6.5  raeburn  19757:     if (document.getElementById(context+'_recaptchapub')) {
                   19758:         pubitem = document.getElementById(context+'_recaptchapub');
                   19759:     } else {
                   19760:         return;
                   19761:     }
                   19762:     if (document.getElementById(context+'_recaptchapriv')) {
                   19763:         privitem = document.getElementById(context+'_recaptchapriv');
                   19764:     } else {
                   19765:         return;
                   19766:     }
                   19767:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   19768:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   19769:     } else {
                   19770:         return;
                   19771:     }
                   19772:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   19773:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   19774:     } else {
                   19775:         return;
                   19776:     }
1.160.6.69  raeburn  19777:     if (document.getElementById(context+'_recaptchaversion')) {
                   19778:         versionitem = document.getElementById(context+'_recaptchaversion');
                   19779:     } else {
                   19780:         return;
                   19781:     }
                   19782:     if (document.getElementById(context+'_recaptchavertxt')) {
                   19783:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   19784:     } else {
                   19785:         return;
                   19786:     }
1.160.6.5  raeburn  19787:     if (caller.checked) {
                   19788:         if (caller.value == 'recaptcha') {
                   19789:             pubitem.type = 'text';
                   19790:             privitem.type = 'text';
                   19791:             pubitem.size = '40';
                   19792:             privitem.size = '40';
                   19793:             pubtext.innerHTML = "$lt{'pub'}";
                   19794:             privtext.innerHTML = "$lt{'priv'}";
1.160.6.69  raeburn  19795:             versionitem.type = 'text';
                   19796:             versionitem.size = '3';
                   19797:             versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5  raeburn  19798:         } else {
                   19799:             pubitem.type = 'hidden';
                   19800:             privitem.type = 'hidden';
1.160.6.69  raeburn  19801:             versionitem.type = 'hidden';
1.160.6.5  raeburn  19802:             pubtext.innerHTML = '';
                   19803:             privtext.innerHTML = '';
1.160.6.69  raeburn  19804:             versiontext.innerHTML = '';
1.160.6.5  raeburn  19805:         }
                   19806:     }
                   19807:     return;
                   19808: }
                   19809: 
                   19810: // ]]>
                   19811: </script>
                   19812: 
                   19813: END
                   19814: 
                   19815: }
                   19816: 
1.160.6.40  raeburn  19817: sub toggle_display_js {
1.160.6.16  raeburn  19818:     return <<"END";
                   19819: 
                   19820: <script type="text/javascript">
                   19821: // <![CDATA[
                   19822: 
1.160.6.40  raeburn  19823: function toggleDisplay(domForm,caller) {
                   19824:     if (document.getElementById(caller)) {
                   19825:         var divitem = document.getElementById(caller);
                   19826:         var optionsElement = domForm.coursecredits;
1.160.6.64  raeburn  19827:         var checkval = 1;
                   19828:         var dispval = 'block';
1.160.6.93  raeburn  19829:         var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40  raeburn  19830:         if (caller == 'emailoptions') {
                   19831:             optionsElement = domForm.cancreate_email; 
                   19832:         }
1.160.6.57  raeburn  19833:         if (caller == 'studentsubmission') {
                   19834:             optionsElement = domForm.postsubmit;
                   19835:         }
1.160.6.64  raeburn  19836:         if (caller == 'cloneinstcode') {
                   19837:             optionsElement = domForm.canclone;
                   19838:             checkval = 'instcode';
                   19839:         }
1.160.6.93  raeburn  19840:         if (selfcreateRegExp.test(caller)) {
                   19841:             optionsElement = domForm.elements[caller];
                   19842:             checkval = 'other';
                   19843:             dispval = 'inline'
                   19844:         }
1.160.6.40  raeburn  19845:         if (optionsElement.length) {
1.160.6.16  raeburn  19846:             var currval;
1.160.6.40  raeburn  19847:             for (var i=0; i<optionsElement.length; i++) {
                   19848:                 if (optionsElement[i].checked) {
                   19849:                    currval = optionsElement[i].value;
1.160.6.16  raeburn  19850:                 }
                   19851:             }
1.160.6.64  raeburn  19852:             if (currval == checkval) {
                   19853:                 divitem.style.display = dispval;
1.160.6.16  raeburn  19854:             } else {
1.160.6.40  raeburn  19855:                 divitem.style.display = 'none';
1.160.6.16  raeburn  19856:             }
                   19857:         }
                   19858:     }
                   19859:     return;
                   19860: }
                   19861: 
                   19862: // ]]>
                   19863: </script>
                   19864: 
                   19865: END
                   19866: 
                   19867: }
                   19868: 
1.160.6.5  raeburn  19869: sub captcha_phrases {
                   19870:     return &Apache::lonlocal::texthash (
                   19871:                  priv => 'Private key',
                   19872:                  pub  => 'Public key',
                   19873:                  original  => 'original (CAPTCHA)',
                   19874:                  recaptcha => 'successor (ReCAPTCHA)',
                   19875:                  notused   => 'unused',
1.160.6.69  raeburn  19876:                  ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5  raeburn  19877:     );
                   19878: }
                   19879: 
1.160.6.24  raeburn  19880: sub devalidate_remote_domconfs {
1.160.6.27  raeburn  19881:     my ($dom,$cachekeys) = @_;
                   19882:     return unless (ref($cachekeys) eq 'HASH');
1.160.6.24  raeburn  19883:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   19884:     my %thismachine;
                   19885:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2  1(raebur 19886:1):     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113  raeburn  19887:                       'directorysrch','passwdconf','cats','proxyalias','proxysaml',
                   19888:                       'ipaccess');
                   19889:     my %cache_by_lonhost;
                   19890:     if (exists($cachekeys->{'samllanding'})) {
                   19891:         if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
                   19892:             my %landing = %{$cachekeys->{'samllanding'}};
                   19893:             my %domservers = &Apache::lonnet::get_servers($dom);
                   19894:             if (keys(%domservers)) {
                   19895:                 foreach my $server (keys(%domservers)) {
                   19896:                     my @cached;
                   19897:                     next if ($thismachine{$server});
                   19898:                     if ($landing{$server}) {
                   19899:                         push(@cached,&escape('samllanding').':'.&escape($server));
                   19900:                     }
                   19901:                     if (@cached) {
                   19902:                         $cache_by_lonhost{$server} = \@cached;
                   19903:                     }
                   19904:                 }
                   19905:             }
                   19906:         }
                   19907:     }
1.160.6.61  raeburn  19908:     if (keys(%servers)) {
1.160.6.24  raeburn  19909:         foreach my $server (keys(%servers)) {
                   19910:             next if ($thismachine{$server});
1.160.6.27  raeburn  19911:             my @cached;
                   19912:             foreach my $name (@posscached) {
                   19913:                 if ($cachekeys->{$name}) {
1.160.6.113  raeburn  19914:                     if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
                   19915:                         if (ref($cachekeys->{$name}) eq 'HASH') {
                   19916:                             foreach my $key (keys(%{$cachekeys->{$name}})) {
                   19917:                                 push(@cached,&escape($name).':'.&escape($key));
                   19918:                             }
                   19919:                         }
                   19920:                     } else {
                   19921:                         push(@cached,&escape($name).':'.&escape($dom));
                   19922:                     }
1.160.6.27  raeburn  19923:                 }
                   19924:             }
1.160.6.113  raeburn  19925:             if ((exists($cache_by_lonhost{$server})) &&
                   19926:                 (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
                   19927:                 push(@cached,@{$cache_by_lonhost{$server}});
                   19928:             }
1.160.6.27  raeburn  19929:             if (@cached) {
                   19930:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   19931:             }
1.160.6.24  raeburn  19932:         }
                   19933:     }
                   19934:     return;
                   19935: }
                   19936: 
1.3       raeburn  19937: 1;

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