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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.160.6.84.2.  (raeburn    4:): # $Id: domainprefs.pm,v 1.160.6.84.2.2 2017/06/23 14:59:27 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: ###############################################################
1.160.6.84.2.  (raeburn   30:): ###############################################################
1.1       raeburn    31: 
1.101     raeburn    32: =pod
                     33: 
                     34: =head1 NAME
                     35: 
                     36: Apache::domainprefs.pm
                     37: 
                     38: =head1 SYNOPSIS
                     39: 
                     40: Handles configuration of a LON-CAPA domain.  
                     41: 
                     42: This is part of the LearningOnline Network with CAPA project
                     43: described at http://www.lon-capa.org.
                     44: 
                     45: 
                     46: =head1 OVERVIEW
                     47: 
                     48: Each institution using LON-CAPA will typically have a single domain designated 
1.160.6.13  raeburn    49: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    50: may define a default set of logos and a color scheme which can be used to "brand"
                     51: the LON-CAPA instance. In addition, an institution will typically have a language
                     52: and timezone which are used for the majority of courses.
                     53: 
                     54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     55: host of other domain-wide settings which determine the types of functionality
                     56: available to users and courses in the domain.
                     57: 
                     58: There is also a mechanism to configure cataloging of courses in the domain, and
                     59: controls on the operation of automated processes which govern such things as
                     60: roster updates, user directory updates and processing of course requests.
                     61: 
                     62: The domain coordination manual which is built dynamically on install/update of 
                     63: LON-CAPA from the relevant help items provides more information about domain 
                     64: configuration.
                     65: 
                     66: Most of the domain settings are stored in the configuration.db GDBM file which is
                     67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     68: where $dom is the domain.  The configuration.db stores settings in a number of 
                     69: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     70: the domain as files (e.g., image files for logos etc., or plain text files for
                     71: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     72: session hosted on the primary library server in the domain, as these files are 
                     73: stored in author space belonging to a special $dom-domainconfig user.   
                     74: 
                     75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     76: the current settings, and provides an interface to make modifications.
                     77: 
                     78: =head1 SUBROUTINES
                     79: 
                     80: =over
                     81: 
                     82: =item print_quotas()
                     83: 
                     84: Inputs: 4 
                     85: 
                     86: $dom,$settings,$rowtotal,$action.
                     87: 
                     88: $dom is the domain, $settings is a reference to a hash of current settings for
                     89: the current context, $rowtotal is a reference to the scalar used to record the 
1.160.6.27  raeburn    90: number of rows displayed on the page, and $action is the context (quotas, 
1.160.6.5  raeburn    91: requestcourses or requestauthor).
1.101     raeburn    92: 
                     93: The print_quotas routine was orginally created to display/store information
                     94: about default quota sizes for portfolio spaces for the different types of 
                     95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     96: but is now also used to manage availability of user tools: 
                     97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20  raeburn    98: used by course owners to request creation of a course, and to display/store
1.160.6.34  raeburn    99: default quota sizes for Authoring Spaces.
1.160.6.20  raeburn   100: 
1.101     raeburn   101: Outputs: 1
                    102: 
                    103: $datatable  - HTML containing form elements which allow settings to be changed. 
                    104: 
                    105: In the case of course requests, radio buttons are displayed for each institutional
                    106: affiliate type (and also default, and _LC_adv) for each of the course types 
1.160.6.30  raeburn   107: (official, unofficial, community, and textbook).  In each case the radio buttons 
                    108: allow the selection of one of four values:
1.101     raeburn   109: 
1.104     raeburn   110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   111: which have the following effects:
                    112: 
                    113: 0
                    114: 
                    115: =over
                    116: 
                    117: - course requests are not allowed for this course types/affiliation
                    118: 
                    119: =back
                    120: 
1.104     raeburn   121: approval 
1.101     raeburn   122: 
                    123: =over 
                    124: 
                    125: - course requests must be approved by a Doman Coordinator in the 
                    126: course's domain
                    127: 
                    128: =back
                    129: 
                    130: validate 
                    131: 
                    132: =over
                    133: 
                    134: - an institutional validation (e.g., check requestor is instructor
                    135: of record) needs to be passed before the course will be created.  The required
                    136: validation is in localenroll.pm on the primary library server for the course 
                    137: domain.
                    138: 
                    139: =back
                    140: 
                    141: autolimit 
                    142: 
                    143: =over
                    144:  
1.143     raeburn   145: - course requests will be processed automatically up to a limit of
1.101     raeburn   146: N requests for the course type for the particular requestor.
                    147: If N is undefined, there is no limit to the number of course requests
                    148: which a course owner may submit and have processed automatically. 
                    149: 
                    150: =back
                    151: 
                    152: =item modify_quotas() 
                    153: 
                    154: =back
                    155: 
                    156: =cut
                    157: 
1.1       raeburn   158: package Apache::domainprefs;
                    159: 
                    160: use strict;
                    161: use Apache::Constants qw(:common :http);
                    162: use Apache::lonnet;
                    163: use Apache::loncommon();
                    164: use Apache::lonhtmlcommon();
                    165: use Apache::lonlocal;
1.43      raeburn   166: use Apache::lonmsg();
1.91      raeburn   167: use Apache::lonconfigsettings;
1.160.6.37  raeburn   168: use Apache::lonuserutils();
1.160.6.39  raeburn   169: use Apache::loncoursequeueadmin();
1.69      raeburn   170: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   171: use LONCAPA::Enrollment;
1.81      raeburn   172: use LONCAPA::lonauthcgi();
1.9       raeburn   173: use File::Copy;
1.43      raeburn   174: use Locale::Language;
1.62      raeburn   175: use DateTime::TimeZone;
1.68      raeburn   176: use DateTime::Locale;
1.1       raeburn   177: 
1.155     raeburn   178: my $registered_cleanup;
                    179: my $modified_urls;
                    180: 
1.1       raeburn   181: sub handler {
                    182:     my $r=shift;
                    183:     if ($r->header_only) {
                    184:         &Apache::loncommon::content_type($r,'text/html');
                    185:         $r->send_http_header;
                    186:         return OK;
                    187:     }
                    188: 
1.91      raeburn   189:     my $context = 'domain';
1.1       raeburn   190:     my $dom = $env{'request.role.domain'};
1.5       albertel  191:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn   192:     if (&Apache::lonnet::allowed('mau',$dom)) {
                    193:         &Apache::loncommon::content_type($r,'text/html');
                    194:         $r->send_http_header;
                    195:     } else {
                    196:         $env{'user.error.msg'}=
                    197:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                    198:         return HTTP_NOT_ACCEPTABLE;
                    199:     }
1.155     raeburn   200: 
                    201:     $registered_cleanup=0;
                    202:     @{$modified_urls}=();
                    203: 
1.1       raeburn   204:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    205:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58      raeburn   206:                                             ['phase','actions']);
1.30      raeburn   207:     my $phase = 'pickactions';
1.3       raeburn   208:     if ( exists($env{'form.phase'}) ) {
                    209:         $phase = $env{'form.phase'};
                    210:     }
1.150     raeburn   211:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3       raeburn   212:     my %domconfig =
1.6       raeburn   213:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125     raeburn   214:                 'quotas','autoenroll','autoupdate','autocreate',
                    215:                 'directorysrch','usercreation','usermodification',
                    216:                 'contacts','defaults','scantron','coursecategories',
1.160.6.73  raeburn   217:                 'serverstatuses','requestcourses','helpsettings',
                    218:                 'coursedefaults','usersessions','loadbalancing',
1.160.6.84.2.  (raeburn  219:):                 'requestauthor','selfenrollment','inststatus',
                    220:):                 'ltitools'],$dom);
                    221:):     if (ref($domconfig{'ltitools'}) eq 'HASH') {
                    222:):         my %encconfig =
                    223:):             &Apache::lonnet::get_dom('encconfig',['ltitools'],$dom);
                    224:):         if (ref($encconfig{'ltitools'}) eq 'HASH') {
                    225:):             foreach my $id (keys(%{$domconfig{'ltitools'}})) {
                    226:):                 if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
                    227:):                     foreach my $item ('key','secret') {
                    228:):                         $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
                    229:):                     }
                    230:):                 }
                    231:):             }
                    232:):         }
                    233:):     }
1.43      raeburn   234:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   235:                        'autoupdate','autocreate','directorysrch','contacts',
1.160.6.34  raeburn   236:                        'usercreation','selfcreation','usermodification','scantron',
1.160.6.5  raeburn   237:                        'requestcourses','requestauthor','coursecategories',
1.160.6.73  raeburn   238:                        'serverstatuses','helpsettings','coursedefaults',
1.160.6.84.2.  (raeburn  239:):                        'ltitools','selfenrollment','usersessions');
1.160.6.7  raeburn   240:     my %existing;
                    241:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    242:         %existing = %{$domconfig{'loadbalancing'}};
                    243:     }
                    244:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   245:         push(@prefs_order,'loadbalancing');
                    246:     }
1.30      raeburn   247:     my %prefs = (
                    248:         'rolecolors' =>
                    249:                    { text => 'Default color schemes',
1.67      raeburn   250:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   251:                      header => [{col1 => 'Student Settings',
                    252:                                  col2 => '',},
                    253:                                 {col1 => 'Coordinator Settings',
                    254:                                  col2 => '',},
                    255:                                 {col1 => 'Author Settings',
                    256:                                  col2 => '',},
                    257:                                 {col1 => 'Administrator Settings',
                    258:                                  col2 => '',}],
1.160.6.37  raeburn   259:                       print => \&print_rolecolors,
                    260:                       modify => \&modify_rolecolors,
1.30      raeburn   261:                     },
1.110     raeburn   262:         'login' =>
1.30      raeburn   263:                     { text => 'Log-in page options',
1.67      raeburn   264:                       help => 'Domain_Configuration_Login_Page',
1.160.6.5  raeburn   265:                       header => [{col1 => 'Log-in Page Items',
                    266:                                   col2 => '',},
                    267:                                  {col1 => 'Log-in Help',
1.160.6.56  raeburn   268:                                   col2 => 'Value'},
                    269:                                  {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   270:                                   col2 => 'Value'}],
1.160.6.37  raeburn   271:                       print => \&print_login,
                    272:                       modify => \&modify_login,
1.30      raeburn   273:                     },
1.43      raeburn   274:         'defaults' => 
1.160.6.40  raeburn   275:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   276:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   277:                       header => [{col1 => 'Setting',
1.160.6.40  raeburn   278:                                   col2 => 'Value'},
1.160.6.80  raeburn   279:                                  {col1 => 'Internal Authentication',
                    280:                                   col2 => 'Value'},
1.160.6.40  raeburn   281:                                  {col1 => 'Institutional user types',
                    282:                                   col2 => 'Assignable to e-mail usernames'}],
1.160.6.37  raeburn   283:                       print => \&print_defaults,
                    284:                       modify => \&modify_defaults,
1.43      raeburn   285:                     },
1.30      raeburn   286:         'quotas' => 
1.160.6.20  raeburn   287:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   288:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   289:                       header => [{col1 => 'User affiliation',
1.72      raeburn   290:                                   col2 => 'Available tools',
1.160.6.28  raeburn   291:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37  raeburn   292:                       print => \&print_quotas,
                    293:                       modify => \&modify_quotas,
1.30      raeburn   294:                     },
                    295:         'autoenroll' =>
                    296:                    { text => 'Auto-enrollment settings',
1.67      raeburn   297:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   298:                      header => [{col1 => 'Configuration setting',
                    299:                                  col2 => 'Value(s)'}],
1.160.6.37  raeburn   300:                      print => \&print_autoenroll,
                    301:                      modify => \&modify_autoenroll,
1.30      raeburn   302:                    },
                    303:         'autoupdate' => 
                    304:                    { text => 'Auto-update settings',
1.67      raeburn   305:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   306:                      header => [{col1 => 'Setting',
                    307:                                  col2 => 'Value',},
1.131     raeburn   308:                                 {col1 => 'Setting',
                    309:                                  col2 => 'Affiliation'},
1.43      raeburn   310:                                 {col1 => 'User population',
1.160.6.35  raeburn   311:                                  col2 => 'Updatable user data'}],
1.160.6.37  raeburn   312:                      print => \&print_autoupdate,
                    313:                      modify => \&modify_autoupdate,
1.30      raeburn   314:                   },
1.125     raeburn   315:         'autocreate' => 
                    316:                   { text => 'Auto-course creation settings',
                    317:                      help => 'Domain_Configuration_Auto_Creation',
                    318:                      header => [{col1 => 'Configuration Setting',
                    319:                                  col2 => 'Value',}],
1.160.6.37  raeburn   320:                      print => \&print_autocreate,
                    321:                      modify => \&modify_autocreate,
1.125     raeburn   322:                   },
1.30      raeburn   323:         'directorysrch' => 
1.160.6.72  raeburn   324:                   { text => 'Directory searches',
1.67      raeburn   325:                     help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72  raeburn   326:                     header => [{col1 => 'Institutional Directory Setting',
                    327:                                 col2 => 'Value',},
                    328:                                {col1 => 'LON-CAPA Directory Setting',
1.30      raeburn   329:                                 col2 => 'Value',}],
1.160.6.37  raeburn   330:                     print => \&print_directorysrch,
                    331:                     modify => \&modify_directorysrch,
1.30      raeburn   332:                   },
                    333:         'contacts' =>
1.160.6.78  raeburn   334:                   { text => 'E-mail addresses and helpform',
1.67      raeburn   335:                     help => 'Domain_Configuration_Contact_Info',
1.160.6.78  raeburn   336:                     header => [{col1 => 'Default e-mail addresses',
                    337:                                 col2 => 'Value',},
                    338:                                {col1 => 'Recipient(s) for notifications',
                    339:                                 col2 => 'Value',},
                    340:                                {col1 => 'Ask helpdesk form settings',
                    341:                                 col2 => 'Value',},],
1.160.6.37  raeburn   342:                     print => \&print_contacts,
                    343:                     modify => \&modify_contacts,
1.30      raeburn   344:                   },
                    345:         'usercreation' => 
                    346:                   { text => 'User creation',
1.67      raeburn   347:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   348:                     header => [{col1 => 'Format rule type',
                    349:                                 col2 => 'Format rules in force'},
1.34      raeburn   350:                                {col1 => 'User account creation',
                    351:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   352:                                {col1 => 'Context',
1.43      raeburn   353:                                 col2 => 'Assignable authentication types'}],
1.160.6.37  raeburn   354:                     print => \&print_usercreation,
                    355:                     modify => \&modify_usercreation,
1.30      raeburn   356:                   },
1.160.6.34  raeburn   357:         'selfcreation' => 
                    358:                   { text => 'Users self-creating accounts',
                    359:                     help => 'Domain_Configuration_Self_Creation', 
                    360:                     header => [{col1 => 'Self-creation with institutional username',
                    361:                                 col2 => 'Enabled?'},
                    362:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    363:                                 col2 => 'Information user can enter'},
                    364:                                {col1 => 'Self-creation with e-mail as username',
                    365:                                 col2 => 'Settings'}],
1.160.6.37  raeburn   366:                     print => \&print_selfcreation,
                    367:                     modify => \&modify_selfcreation,
1.160.6.34  raeburn   368:                   },
1.69      raeburn   369:         'usermodification' =>
1.33      raeburn   370:                   { text => 'User modification',
1.67      raeburn   371:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   372:                     header => [{col1 => 'Target user has role',
1.160.6.35  raeburn   373:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   374:                                {col1 => 'Target user has role',
1.160.6.35  raeburn   375:                                 col2 => 'User information updatable in course context'}],
1.160.6.37  raeburn   376:                     print => \&print_usermodification,
                    377:                     modify => \&modify_usermodification,
1.33      raeburn   378:                   },
1.69      raeburn   379:         'scantron' =>
1.95      www       380:                   { text => 'Bubblesheet format file',
1.67      raeburn   381:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   382:                     header => [ {col1 => 'Item',
                    383:                                  col2 => '',
                    384:                               }],
1.160.6.37  raeburn   385:                     print => \&print_scantron,
                    386:                     modify => \&modify_scantron,
1.46      raeburn   387:                   },
1.86      raeburn   388:         'requestcourses' => 
                    389:                  {text => 'Request creation of courses',
                    390:                   help => 'Domain_Configuration_Request_Courses',
                    391:                   header => [{col1 => 'User affiliation',
1.102     raeburn   392:                               col2 => 'Availability/Processing of requests',},
                    393:                              {col1 => 'Setting',
1.160.6.30  raeburn   394:                               col2 => 'Value'},
                    395:                              {col1 => 'Available textbooks',
1.160.6.39  raeburn   396:                               col2 => ''},
1.160.6.46  raeburn   397:                              {col1 => 'Available templates',
                    398:                               col2 => ''},
1.160.6.39  raeburn   399:                              {col1 => 'Validation (not official courses)',
                    400:                               col2 => 'Value'},],
1.160.6.37  raeburn   401:                   print => \&print_quotas,
                    402:                   modify => \&modify_quotas,
1.86      raeburn   403:                  },
1.160.6.5  raeburn   404:         'requestauthor' =>
1.160.6.34  raeburn   405:                  {text => 'Request Authoring Space',
1.160.6.5  raeburn   406:                   help => 'Domain_Configuration_Request_Author',
                    407:                   header => [{col1 => 'User affiliation',
                    408:                               col2 => 'Availability/Processing of requests',},
                    409:                              {col1 => 'Setting',
                    410:                               col2 => 'Value'}],
1.160.6.37  raeburn   411:                   print => \&print_quotas,
                    412:                   modify => \&modify_quotas,
1.160.6.5  raeburn   413:                  },
1.69      raeburn   414:         'coursecategories' =>
1.120     raeburn   415:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   416:                     help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42  raeburn   417:                     header => [{col1 => 'Catalog type/availability',
                    418:                                 col2 => '',},
                    419:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   420:                                 col2 => '',},
                    421:                                {col1 => 'Categories',
                    422:                                 col2 => '',
                    423:                                }],
1.160.6.37  raeburn   424:                     print => \&print_coursecategories,
                    425:                     modify => \&modify_coursecategories,
1.69      raeburn   426:                   },
                    427:         'serverstatuses' =>
1.77      raeburn   428:                  {text   => 'Access to server status pages',
1.69      raeburn   429:                   help   => 'Domain_Configuration_Server_Status',
                    430:                   header => [{col1 => 'Status Page',
                    431:                               col2 => 'Other named users',
                    432:                               col3 => 'Specific IPs',
                    433:                             }],
1.160.6.37  raeburn   434:                   print => \&print_serverstatuses,
                    435:                   modify => \&modify_serverstatuses,
1.69      raeburn   436:                  },
1.160.6.73  raeburn   437:         'helpsettings' =>
                    438:                  {text   => 'Support settings',
                    439:                   help   => 'Domain_Configuration_Help_Settings',
                    440:                   header => [{col1 => 'Help Page Settings (logged-in users)',
                    441:                               col2 => 'Value'},
                    442:                              {col1 => 'Helpdesk Roles',
                    443:                               col2 => 'Settings'},],
                    444:                   print  => \&print_helpsettings,
                    445:                   modify => \&modify_helpsettings,
                    446:                  },
1.160.6.39  raeburn   447:         'coursedefaults' => 
1.160.6.16  raeburn   448:                  {text => 'Course/Community defaults',
                    449:                   help => 'Domain_Configuration_Course_Defaults',
1.160.6.57  raeburn   450:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    451:                               col2 => 'Value',},
                    452:                              {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16  raeburn   453:                               col2 => 'Value',},],
1.160.6.37  raeburn   454:                   print => \&print_coursedefaults,
                    455:                   modify => \&modify_coursedefaults,
                    456:                  },
1.160.6.39  raeburn   457:         'selfenrollment' => 
1.160.6.37  raeburn   458:                  {text   => 'Self-enrollment in Course/Community',
                    459:                   help   => 'Domain_Configuration_Selfenrollment',
                    460:                   header => [{col1 => 'Configuration Rights',
                    461:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    462:                              {col1 => 'Defaults',
                    463:                               col2 => 'Value'},
                    464:                              {col1 => 'Self-enrollment validation (optional)',
                    465:                               col2 => 'Value'},],
                    466:                   print => \&print_selfenrollment,
                    467:                   modify => \&modify_selfenrollment,
1.160.6.16  raeburn   468:                  },
1.141     raeburn   469:         'usersessions' =>
1.145     raeburn   470:                  {text  => 'User session hosting/offloading',
1.137     raeburn   471:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   472:                   header => [{col1 => 'Domain server',
                    473:                               col2 => 'Servers to offload sessions to when busy'},
                    474:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   475:                               col2 => 'Rules'},
                    476:                              {col1 => "Hosting domain's own users elsewhere",
                    477:                               col2 => 'Rules'}],
1.160.6.37  raeburn   478:                   print => \&print_usersessions,
                    479:                   modify => \&modify_usersessions,
1.137     raeburn   480:                  },
1.160.6.78  raeburn   481:         'loadbalancing' =>
1.160.6.7  raeburn   482:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   483:                   help  => 'Domain_Configuration_Load_Balancing',
1.160.6.7  raeburn   484:                   header => [{col1 => 'Balancers',
1.150     raeburn   485:                               col2 => 'Default destinations',
1.160.6.13  raeburn   486:                               col3 => 'User affiliation',
1.150     raeburn   487:                               col4 => 'Overrides'},
                    488:                             ],
1.160.6.37  raeburn   489:                   print => \&print_loadbalancing,
                    490:                   modify => \&modify_loadbalancing,
1.150     raeburn   491:                  },
1.160.6.84.2.  (raeburn  492:):         'ltitools' =>
                    493:):                  {text => 'External Tools (LTI)',
                    494:):                   help => 'Domain_Configuration_LTI_Tools',
                    495:):                   header => [{col1 => 'Setting',
                    496:):                               col2 => 'Value',}],
                    497:):                   print => \&print_ltitools,
                    498:):                   modify => \&modify_ltitools,
                    499:):                  },
1.3       raeburn   500:     );
1.110     raeburn   501:     if (keys(%servers) > 1) {
                    502:         $prefs{'login'}  = { text   => 'Log-in page options',
                    503:                              help   => 'Domain_Configuration_Login_Page',
                    504:                             header => [{col1 => 'Log-in Service',
                    505:                                         col2 => 'Server Setting',},
                    506:                                        {col1 => 'Log-in Page Items',
1.160.6.5  raeburn   507:                                         col2 => ''},
                    508:                                        {col1 => 'Log-in Help',
1.160.6.56  raeburn   509:                                         col2 => 'Value'},
                    510:                                        {col1 => 'Custom HTML in document head',
1.160.6.5  raeburn   511:                                         col2 => 'Value'}],
1.160.6.37  raeburn   512:                             print => \&print_login,
                    513:                             modify => \&modify_login,
1.110     raeburn   514:                            };
                    515:     }
1.160.6.13  raeburn   516: 
1.6       raeburn   517:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   518:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   519:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   520:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   521:       text=>"Settings to display/modify"});
1.9       raeburn   522:     my $confname = $dom.'-domainconfig';
1.160.6.13  raeburn   523: 
1.3       raeburn   524:     if ($phase eq 'process') {
1.160.6.27  raeburn   525:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    526:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33  raeburn   527:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24  raeburn   528:             $r->rflush();
1.160.6.27  raeburn   529:             &devalidate_remote_domconfs($dom,$result);
1.160.6.24  raeburn   530:         }
1.30      raeburn   531:     } elsif ($phase eq 'display') {
1.160.6.16  raeburn   532:         my $js = &recaptcha_js().
1.160.6.40  raeburn   533:                  &toggle_display_js();
1.160.6.7  raeburn   534:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   535:             my ($othertitle,$usertypes,$types) =
                    536:                 &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7  raeburn   537:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    538:                                           $domconfig{'loadbalancing'}).
1.160.6.6  raeburn   539:                    &new_spares_js().
                    540:                    &common_domprefs_js().
                    541:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   542:         }
1.160.6.30  raeburn   543:         if (grep(/^requestcourses$/,@actions)) {
                    544:             my $javascript_validations;
                    545:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    546:             $js .= <<END;
                    547: <script type="text/javascript">
                    548: $javascript_validations
                    549: </script>
                    550: $coursebrowserjs
                    551: END
                    552:         }
1.160.6.78  raeburn   553:         if (grep(/^contacts$/,@actions)) {
                    554:             $js .= &contacts_javascript();
                    555:         }
1.150     raeburn   556:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   557:     } else {
1.160.6.11  raeburn   558: # check if domconfig user exists for the domain.
                    559:         my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26  raeburn   560:         my ($configuserok,$author_ok,$switchserver) =
1.160.6.11  raeburn   561:             &config_check($dom,$confname,$servadm);
                    562:         unless ($configuserok eq 'ok') {
                    563:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    564:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
                    565:                           $confname).
                    566:                       '<br />'
                    567:             );
                    568:             if ($switchserver) {
                    569:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    570:                           '<br />'.
                    571:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    572:                           '<br />'.
                    573:                           &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).
                    574:                           '<br />'.
                    575:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    576:                 );
                    577:             } else {
                    578:                 $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.').
                    579:                           '<br />'.
                    580:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    581:                 );
                    582:             }
                    583:             $r->print(&Apache::loncommon::end_page());
                    584:             return OK;
                    585:         }
1.21      raeburn   586:         if (keys(%domconfig) == 0) {
                    587:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   588:             my @ids=&Apache::lonnet::current_machine_ids();
                    589:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   590:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   591:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   592:                 my $custom_img_count = 0;
                    593:                 foreach my $img (@loginimages) {
                    594:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    595:                         $custom_img_count ++;
                    596:                     }
                    597:                 }
                    598:                 foreach my $role (@roles) {
                    599:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    600:                         $custom_img_count ++;
                    601:                     }
                    602:                 }
                    603:                 if ($custom_img_count > 0) {
1.94      raeburn   604:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   605:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   606:                     $r->print(
                    607:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    608:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    609:     &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 />'.
                    610:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    611:                     if ($switch_server) {
1.30      raeburn   612:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   613:                     }
1.91      raeburn   614:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   615:                     return OK;
                    616:                 }
                    617:             }
                    618:         }
1.91      raeburn   619:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   620:     }
                    621:     return OK;
                    622: }
                    623: 
                    624: sub process_changes {
1.160.6.24  raeburn   625:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   626:     my %domconfig;
                    627:     if (ref($values) eq 'HASH') {
                    628:         %domconfig = %{$values};
                    629:     }
1.3       raeburn   630:     my $output;
                    631:     if ($action eq 'login') {
1.160.6.24  raeburn   632:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   633:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   634:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24  raeburn   635:                                      $lastactref,%domconfig);
1.3       raeburn   636:     } elsif ($action eq 'quotas') {
1.160.6.30  raeburn   637:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   638:     } elsif ($action eq 'autoenroll') {
1.160.6.24  raeburn   639:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   640:     } elsif ($action eq 'autoupdate') {
                    641:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   642:     } elsif ($action eq 'autocreate') {
                    643:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   644:     } elsif ($action eq 'directorysrch') {
1.160.6.81  raeburn   645:         $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27      raeburn   646:     } elsif ($action eq 'usercreation') {
1.28      raeburn   647:         $output = &modify_usercreation($dom,%domconfig);
1.160.6.34  raeburn   648:     } elsif ($action eq 'selfcreation') {
                    649:         $output = &modify_selfcreation($dom,%domconfig);
1.33      raeburn   650:     } elsif ($action eq 'usermodification') {
                    651:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   652:     } elsif ($action eq 'contacts') {
1.160.6.24  raeburn   653:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   654:     } elsif ($action eq 'defaults') {
1.160.6.27  raeburn   655:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   656:     } elsif ($action eq 'scantron') {
1.160.6.24  raeburn   657:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   658:     } elsif ($action eq 'coursecategories') {
1.160.6.43  raeburn   659:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   660:     } elsif ($action eq 'serverstatuses') {
                    661:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   662:     } elsif ($action eq 'requestcourses') {
1.160.6.30  raeburn   663:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5  raeburn   664:     } elsif ($action eq 'requestauthor') {
1.160.6.30  raeburn   665:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73  raeburn   666:     } elsif ($action eq 'helpsettings') {
1.160.6.77  raeburn   667:         $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16  raeburn   668:     } elsif ($action eq 'coursedefaults') {
1.160.6.27  raeburn   669:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37  raeburn   670:     } elsif ($action eq 'selfenrollment') {
                    671:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   672:     } elsif ($action eq 'usersessions') {
1.160.6.27  raeburn   673:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   674:     } elsif ($action eq 'loadbalancing') {
                    675:         $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.84.2.  (raeburn  676:):     } elsif ($action eq 'ltitools') {
                    677:):         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   678:     }
                    679:     return $output;
                    680: }
                    681: 
                    682: sub print_config_box {
1.9       raeburn   683:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   684:     my $rowtotal = 0;
1.49      raeburn   685:     my $output;
                    686:     if ($action eq 'coursecategories') {
                    687:         $output = &coursecategories_javascript($settings);
1.160.6.40  raeburn   688:     } elsif ($action eq 'defaults') {
                    689:         $output = &defaults_javascript($settings); 
1.160.6.73  raeburn   690:     } elsif ($action eq 'helpsettings') {
                    691:         my (%privs,%levelscurrent);
                    692:         my %full=();
                    693:         my %levels=(
                    694:                      course => {},
                    695:                      domain => {},
                    696:                      system => {},
                    697:                    );
                    698:         my $context = 'domain';
                    699:         my $crstype = 'Course';
                    700:         my $formname = 'display';
                    701:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                    702:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                    703:         $output =
                    704:             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
                    705:                                                       \@templateroles);
1.91      raeburn   706:     }
1.160.6.40  raeburn   707:     $output .=
1.30      raeburn   708:          '<table class="LC_nested_outer">
1.3       raeburn   709:           <tr>
1.66      raeburn   710:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    711:            &mt($item->{text}).'&nbsp;'.
                    712:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    713:           '</tr>';
1.30      raeburn   714:     $rowtotal ++;
1.110     raeburn   715:     my $numheaders = 1;
                    716:     if (ref($item->{'header'}) eq 'ARRAY') {
                    717:         $numheaders = scalar(@{$item->{'header'}});
                    718:     }
                    719:     if ($numheaders > 1) {
1.64      raeburn   720:         my $colspan = '';
1.145     raeburn   721:         my $rightcolspan = '';
1.160.6.42  raeburn   722:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72  raeburn   723:             ($action eq 'directorysrch') ||
1.160.6.56  raeburn   724:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   725:             $colspan = ' colspan="2"';
                    726:         }
1.145     raeburn   727:         if ($action eq 'usersessions') {
                    728:             $rightcolspan = ' colspan="3"'; 
                    729:         }
1.30      raeburn   730:         $output .= '
1.3       raeburn   731:           <tr>
                    732:            <td>
                    733:             <table class="LC_nested">
                    734:              <tr class="LC_info_row">
1.59      bisitz    735:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   736:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   737:              </tr>';
1.69      raeburn   738:         $rowtotal ++;
1.160.6.37  raeburn   739:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57  raeburn   740:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   741:             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.78  raeburn   742:             ($action eq 'helpsettings') || ($action eq 'contacts')) {
1.160.6.37  raeburn   743:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   744:         } elsif ($action eq 'coursecategories') {
1.160.6.37  raeburn   745:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   746:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   747:             if ($numheaders == 4) {
1.160.6.5  raeburn   748:                 $colspan = ' colspan="2"';
                    749:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    750:             } else {
                    751:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    752:             }
1.160.6.37  raeburn   753:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn   754:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       755:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   756:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2  raeburn   757:         }
1.30      raeburn   758:         $output .= '
1.6       raeburn   759:            </table>
                    760:           </td>
                    761:          </tr>
                    762:          <tr>
                    763:            <td>
                    764:             <table class="LC_nested">
                    765:              <tr class="LC_info_row">
1.160.6.37  raeburn   766:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    767:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   768:              </tr>';
                    769:             $rowtotal ++;
1.160.6.37  raeburn   770:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    771:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78  raeburn   772:             ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.80  raeburn   773:             ($action eq 'contacts') || ($action eq 'defaults')) {
1.160.6.42  raeburn   774:             if ($action eq 'coursecategories') {
                    775:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    776:                 $colspan = ' colspan="2"';
                    777:             } else {
                    778:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    779:             }
                    780:             $output .= '
1.63      raeburn   781:            </table>
                    782:           </td>
                    783:          </tr>
                    784:          <tr>
                    785:            <td>
                    786:             <table class="LC_nested">
                    787:              <tr class="LC_info_row">
                    788:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34  raeburn   789:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42  raeburn   790:              </tr>'."\n";
                    791:             if ($action eq 'coursecategories') {
                    792:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                    793:             } else {
                    794:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    795:             }
1.63      raeburn   796:             $rowtotal ++;
1.160.6.57  raeburn   797:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.73  raeburn   798:                  ($action eq 'defaults') || ($action eq 'directorysrch') ||
                    799:                  ($action eq 'helpsettings')) {
1.160.6.37  raeburn   800:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn   801:         } elsif ($action eq 'login') {
1.160.6.56  raeburn   802:             if ($numheaders == 4) {
1.160.6.5  raeburn   803:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    804:            </table>
                    805:           </td>
                    806:          </tr>
                    807:          <tr>
                    808:            <td>
                    809:             <table class="LC_nested">
                    810:              <tr class="LC_info_row">
                    811:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30  raeburn   812:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5  raeburn   813:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    814:                 $rowtotal ++;
                    815:             } else {
                    816:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    817:             }
1.160.6.56  raeburn   818:             $output .= '
                    819:            </table>
                    820:           </td>
                    821:          </tr>
                    822:          <tr>
                    823:            <td>
                    824:             <table class="LC_nested">
                    825:              <tr class="LC_info_row">';
                    826:             if ($numheaders == 4) {
                    827:                 $output .= '
                    828:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    829:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    830:              </tr>';
                    831:             } else {
                    832:                 $output .= '
                    833:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    834:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    835:              </tr>';
                    836:             }
                    837:             $rowtotal ++;
                    838:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   839:         } elsif ($action eq 'requestcourses') {
1.160.6.50  raeburn   840:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    841:             $rowtotal ++;
                    842:             $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30  raeburn   843:            </table>
                    844:           </td>
                    845:          </tr>
                    846:          <tr>
                    847:            <td>
                    848:             <table class="LC_nested">
                    849:              <tr class="LC_info_row">
                    850:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    851:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46  raeburn   852:                        &textbookcourses_javascript($settings).
                    853:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    854:             </table>
                    855:            </td>
                    856:           </tr>
                    857:          <tr>
                    858:            <td>
                    859:             <table class="LC_nested">
                    860:              <tr class="LC_info_row">
                    861:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    862:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    863:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39  raeburn   864:             </table>
                    865:            </td>
                    866:           </tr>
                    867:           <tr>
                    868:            <td>
                    869:             <table class="LC_nested">
                    870:              <tr class="LC_info_row">
1.160.6.46  raeburn   871:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    872:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39  raeburn   873:              </tr>'.
                    874:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5  raeburn   875:         } elsif ($action eq 'requestauthor') {
                    876:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50  raeburn   877:             $rowtotal ++;
1.122     jms       878:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   879:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   880:            </table>
                    881:           </td>
                    882:          </tr>
                    883:          <tr>
                    884:            <td>
                    885:             <table class="LC_nested">
                    886:              <tr class="LC_info_row">
1.69      raeburn   887:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    888:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    889:               <td class="LC_right_item" valign="top">'.
                    890:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   891:              </tr>'.
1.30      raeburn   892:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   893:            </table>
                    894:           </td>
                    895:          </tr>
                    896:          <tr>
                    897:            <td>
                    898:             <table class="LC_nested">
                    899:              <tr class="LC_info_row">
1.59      bisitz    900:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    901:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   902:              </tr>'.
1.30      raeburn   903:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    904:             $rowtotal += 2;
1.6       raeburn   905:         }
1.3       raeburn   906:     } else {
1.30      raeburn   907:         $output .= '
1.3       raeburn   908:           <tr>
                    909:            <td>
                    910:             <table class="LC_nested">
1.30      raeburn   911:              <tr class="LC_info_row">';
1.160.6.72  raeburn   912:         if ($action eq 'login') {
1.30      raeburn   913:             $output .= '  
1.59      bisitz    914:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   915:         } elsif ($action eq 'serverstatuses') {
                    916:             $output .= '
                    917:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    918:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    919: 
1.6       raeburn   920:         } else {
1.30      raeburn   921:             $output .= '
1.69      raeburn   922:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    923:         }
1.72      raeburn   924:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    925:             $output .= '<td class="LC_left_item" valign="top">'.
                    926:                        &mt($item->{'header'}->[0]->{'col2'});
                    927:             if ($action eq 'serverstatuses') {
                    928:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    929:             } 
1.69      raeburn   930:         } else {
                    931:             $output .= '<td class="LC_right_item" valign="top">'.
                    932:                        &mt($item->{'header'}->[0]->{'col2'});
                    933:         }
                    934:         $output .= '</td>';
                    935:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   936:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    937:                 $output .= '<td class="LC_left_item" valign="top">'.
                    938:                             &mt($item->{'header'}->[0]->{'col3'});
                    939:             } else {
                    940:                 $output .= '<td class="LC_right_item" valign="top">'.
                    941:                            &mt($item->{'header'}->[0]->{'col3'});
                    942:             }
1.69      raeburn   943:             if ($action eq 'serverstatuses') {
                    944:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    945:             }
                    946:             $output .= '</td>';
1.6       raeburn   947:         }
1.150     raeburn   948:         if ($item->{'header'}->[0]->{'col4'}) {
                    949:             $output .= '<td class="LC_right_item" valign="top">'.
                    950:                        &mt($item->{'header'}->[0]->{'col4'});
                    951:         }
1.69      raeburn   952:         $output .= '</tr>';
1.48      raeburn   953:         $rowtotal ++;
1.160.6.5  raeburn   954:         if ($action eq 'quotas') {
1.86      raeburn   955:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72  raeburn   956:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || 
1.160.6.84.2.  (raeburn  957:):                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
                    958:):                  ($action eq 'ltitools')) {
1.160.6.37  raeburn   959:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn   960:         } elsif ($action eq 'scantron') {
                    961:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.121     raeburn   962:         }
1.3       raeburn   963:     }
1.30      raeburn   964:     $output .= '
1.3       raeburn   965:    </table>
                    966:   </td>
                    967:  </tr>
1.30      raeburn   968: </table><br />';
                    969:     return ($output,$rowtotal);
1.1       raeburn   970: }
                    971: 
1.3       raeburn   972: sub print_login {
1.160.6.5  raeburn   973:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   974:     my ($css_class,$datatable);
1.6       raeburn   975:     my %choices = &login_choices();
1.110     raeburn   976: 
1.160.6.5  raeburn   977:     if ($caller eq 'service') {
1.149     raeburn   978:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   979:         my $choice = $choices{'disallowlogin'};
                    980:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   981:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   982:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   983:                       '<th>'.$choices{'server'}.'</th>'.
                    984:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    985:                       '<th>'.$choices{'custompath'}.'</th>'.
                    986:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   987:         my %disallowed;
                    988:         if (ref($settings) eq 'HASH') {
                    989:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    990:                %disallowed = %{$settings->{'loginvia'}};
                    991:             }
                    992:         }
                    993:         foreach my $lonhost (sort(keys(%servers))) {
                    994:             my $direct = 'selected="selected"';
1.128     raeburn   995:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    996:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    997:                     $direct = '';
                    998:                 }
1.110     raeburn   999:             }
1.115     raeburn  1000:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn  1001:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn  1002:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                   1003:                           '</option>';
1.160.6.13  raeburn  1004:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn  1005:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn  1006:                 my $selected = '';
1.128     raeburn  1007:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1008:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                   1009:                         $selected = 'selected="selected"';
                   1010:                     }
1.110     raeburn  1011:                 }
                   1012:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                   1013:                               $servers{$hostid}.'</option>';
                   1014:             }
1.128     raeburn  1015:             $datatable .= '</select></td>'.
                   1016:                           '<td><select name="'.$lonhost.'_serverpath">';
                   1017:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                   1018:                 my $pathname = $path;
                   1019:                 if ($path eq 'custom') {
                   1020:                     $pathname = &mt('Custom Path').' ->';
                   1021:                 }
                   1022:                 my $selected = '';
                   1023:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1024:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                   1025:                         $selected = 'selected="selected"';
                   1026:                     }
                   1027:                 } elsif ($path eq '') {
                   1028:                     $selected = 'selected="selected"';
                   1029:                 }
                   1030:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                   1031:             }
                   1032:             $datatable .= '</select></td>';
                   1033:             my ($custom,$exempt);
                   1034:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1035:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1036:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1037:             }
                   1038:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1039:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1040:                           '</tr>';
1.110     raeburn  1041:         }
                   1042:         $datatable .= '</table></td></tr>';
                   1043:         return $datatable;
1.160.6.5  raeburn  1044:     } elsif ($caller eq 'page') {
                   1045:         my %defaultchecked = ( 
                   1046:                                'coursecatalog' => 'on',
1.160.6.14  raeburn  1047:                                'helpdesk'      => 'on',
1.160.6.5  raeburn  1048:                                'adminmail'     => 'off',
                   1049:                                'newuser'       => 'off',
                   1050:                              );
1.160.6.14  raeburn  1051:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5  raeburn  1052:         my (%checkedon,%checkedoff);
1.42      raeburn  1053:         foreach my $item (@toggles) {
1.160.6.5  raeburn  1054:             if ($defaultchecked{$item} eq 'on') { 
                   1055:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1056:                 $checkedoff{$item} = ' ';
1.160.6.5  raeburn  1057:             } elsif ($defaultchecked{$item} eq 'off') {
                   1058:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1059:                 $checkedon{$item} = ' ';
                   1060:             }
1.1       raeburn  1061:         }
1.160.6.5  raeburn  1062:         my @images = ('img','logo','domlogo','login');
                   1063:         my @logintext = ('textcol','bgcol');
                   1064:         my @bgs = ('pgbg','mainbg','sidebg');
                   1065:         my @links = ('link','alink','vlink');
                   1066:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1067:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1068:         my (%is_custom,%designs);
                   1069:         my %defaults = (
                   1070:                        font => $defaultdesign{'login.font'},
                   1071:                        );
1.6       raeburn  1072:         foreach my $item (@images) {
1.160.6.5  raeburn  1073:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1074:             $defaults{'showlogo'}{$item} = 1;
                   1075:         }
                   1076:         foreach my $item (@bgs) {
                   1077:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1078:         }
1.41      raeburn  1079:         foreach my $item (@logintext) {
1.160.6.5  raeburn  1080:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1081:         }
1.160.6.5  raeburn  1082:         foreach my $item (@links) {
                   1083:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1084:         }
1.160.6.5  raeburn  1085:         if (ref($settings) eq 'HASH') {
                   1086:             foreach my $item (@toggles) {
                   1087:                 if ($settings->{$item} eq '1') {
                   1088:                     $checkedon{$item} =  ' checked="checked" ';
                   1089:                     $checkedoff{$item} = ' ';
                   1090:                 } elsif ($settings->{$item} eq '0') {
                   1091:                     $checkedoff{$item} =  ' checked="checked" ';
                   1092:                     $checkedon{$item} = ' ';
                   1093:                 }
1.6       raeburn  1094:             }
1.160.6.5  raeburn  1095:             foreach my $item (@images) {
                   1096:                 if (defined($settings->{$item})) {
                   1097:                     $designs{$item} = $settings->{$item};
                   1098:                     $is_custom{$item} = 1;
                   1099:                 }
                   1100:                 if (defined($settings->{'showlogo'}{$item})) {
                   1101:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1102:                 }
                   1103:             }
                   1104:             foreach my $item (@logintext) {
                   1105:                 if ($settings->{$item} ne '') {
                   1106:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1107:                     $is_custom{$item} = 1;
                   1108:                 }
                   1109:             }
                   1110:             if ($settings->{'font'} ne '') {
                   1111:                 $designs{'font'} = $settings->{'font'};
                   1112:                 $is_custom{'font'} = 1;
                   1113:             }
                   1114:             foreach my $item (@bgs) {
                   1115:                 if ($settings->{$item} ne '') {
                   1116:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1117:                     $is_custom{$item} = 1;
                   1118:                 }
                   1119:             }
                   1120:             foreach my $item (@links) {
                   1121:                 if ($settings->{$item} ne '') {
                   1122:                     $designs{'links'}{$item} = $settings->{$item};
                   1123:                     $is_custom{$item} = 1;
                   1124:                 }
                   1125:             }
                   1126:         } else {
                   1127:             if ($designhash{$dom.'.login.font'} ne '') {
                   1128:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1129:                 $is_custom{'font'} = 1;
                   1130:             }
                   1131:             foreach my $item (@images) {
                   1132:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1133:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1134:                     $is_custom{$item} = 1;
                   1135:                 }
                   1136:             }
                   1137:             foreach my $item (@bgs) {
                   1138:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1139:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1140:                     $is_custom{$item} = 1;
                   1141:                 }
                   1142:             }
                   1143:             foreach my $item (@links) {
                   1144:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1145:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1146:                     $is_custom{$item} = 1;
                   1147:                 }
1.6       raeburn  1148:             }
                   1149:         }
1.160.6.5  raeburn  1150:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1151:                                                       logo => 'Institution Logo',
                   1152:                                                       domlogo => 'Domain Logo',
                   1153:                                                       login => 'Login box');
                   1154:         my $itemcount = 1;
                   1155:         foreach my $item (@toggles) {
                   1156:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1157:             $datatable .=  
                   1158:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1159:                 '</td><td>'.
                   1160:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1161:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1162:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1163:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1164:                 '</tr>';
                   1165:             $itemcount ++;
1.6       raeburn  1166:         }
1.160.6.5  raeburn  1167:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1168:         $datatable .= '</tr></table></td></tr>';
                   1169:     } elsif ($caller eq 'help') {
                   1170:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1171:         my $switchserver = &check_switchserver($dom,$confname);
                   1172:         my $itemcount = 1;
                   1173:         $defaulturl = '/adm/loginproblems.html';
                   1174:         $defaulttype = 'default';
                   1175:         %lt = &Apache::lonlocal::texthash (
                   1176:                      del     => 'Delete?',
                   1177:                      rep     => 'Replace:',
                   1178:                      upl     => 'Upload:',
                   1179:                      default => 'Default',
                   1180:                      custom  => 'Custom',
                   1181:                                              );
                   1182:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1183:         my @currlangs;
                   1184:         if (ref($settings) eq 'HASH') {
                   1185:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1186:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1187:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1188:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1189:                     $type{$key} = 'custom';
                   1190:                     unless ($key eq 'nolang') {
                   1191:                         push(@currlangs,$key);
                   1192:                     }
                   1193:                 }
                   1194:             } elsif ($settings->{'helpurl'} ne '') {
                   1195:                 $type{'nolang'} = 'custom';
                   1196:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1197:             }
                   1198:         }
1.160.6.5  raeburn  1199:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1200:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1201:             $datatable .= '<tr'.$css_class.'>';
                   1202:             if ($url{$lang} eq '') {
                   1203:                 $url{$lang} = $defaulturl;
                   1204:             }
                   1205:             if ($type{$lang} eq '') {
                   1206:                 $type{$lang} = $defaulttype;
                   1207:             }
                   1208:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1209:             if ($lang eq 'nolang') {
                   1210:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1211:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1212:             } else {
                   1213:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1214:                                   $langchoices{$lang},
                   1215:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1216:             }
                   1217:             $datatable .= '</span></td>'."\n".
                   1218:                           '<td class="LC_left_item">';
                   1219:             if ($type{$lang} eq 'custom') {
                   1220:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1221:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1222:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1223:             } else {
                   1224:                 $datatable .= $lt{'upl'};
                   1225:             }
                   1226:             $datatable .='<br />';
                   1227:             if ($switchserver) {
                   1228:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1229:             } else {
                   1230:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1231:             }
1.160.6.5  raeburn  1232:             $datatable .= '</td></tr>';
                   1233:             $itemcount ++;
1.6       raeburn  1234:         }
1.160.6.5  raeburn  1235:         my @addlangs;
                   1236:         foreach my $lang (sort(keys(%langchoices))) {
                   1237:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1238:             push(@addlangs,$lang);
                   1239:         }
                   1240:         if (@addlangs > 0) {
                   1241:             my %toadd;
                   1242:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1243:             $toadd{''} = &mt('Select');
                   1244:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1245:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1246:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1247:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1248:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1249:             if ($switchserver) {
                   1250:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1251:             } else {
                   1252:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1253:             }
1.160.6.5  raeburn  1254:             $datatable .= '</td></tr>';
                   1255:             $itemcount ++;
1.6       raeburn  1256:         }
1.160.6.5  raeburn  1257:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56  raeburn  1258:     } elsif ($caller eq 'headtag') {
                   1259:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1260:         my $choice = $choices{'headtag'};
                   1261:         $css_class = ' class="LC_odd_row"';
                   1262:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1263:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1264:                       '<th>'.$choices{'current'}.'</th>'.
                   1265:                       '<th>'.$choices{'action'}.'</th>'.
                   1266:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1267:         my (%currurls,%currexempt);
                   1268:         if (ref($settings) eq 'HASH') {
                   1269:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1270:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1271:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1272:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1273:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1274:                     }
                   1275:                 }
                   1276:             }
                   1277:         }
                   1278:         my %lt = &Apache::lonlocal::texthash(
                   1279:                                                del  => 'Delete?',
                   1280:                                                rep  => 'Replace:',
                   1281:                                                upl  => 'Upload:',
                   1282:                                                curr => 'View contents',
                   1283:                                                none => 'None',
                   1284:         );
                   1285:         my $switchserver = &check_switchserver($dom,$confname);
                   1286:         foreach my $lonhost (sort(keys(%domservers))) {
                   1287:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1288:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1289:             if ($currurls{$lonhost}) {
                   1290:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1291:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1292:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1293:                               '">'.$lt{'curr'}.'</a></td>'.
                   1294:                               '<td><span class="LC_nobreak"><label>'.
                   1295:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1296:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1297:             } else {
                   1298:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1299:             }
                   1300:             $datatable .='<br />';
                   1301:             if ($switchserver) {
                   1302:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1303:             } else {
                   1304:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1305:             }
                   1306:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
                   1307:         }
                   1308:         $datatable .= '</table></td></tr>';
1.1       raeburn  1309:     }
1.6       raeburn  1310:     return $datatable;
                   1311: }
                   1312: 
                   1313: sub login_choices {
                   1314:     my %choices =
                   1315:         &Apache::lonlocal::texthash (
1.116     bisitz   1316:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1317:             adminmail     => "Display Administrator's E-mail Address?",
1.160.6.14  raeburn  1318:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1319:             disallowlogin => "Login page requests redirected",
                   1320:             hostid        => "Server",
1.128     raeburn  1321:             server        => "Redirect to:",
                   1322:             serverpath    => "Path",
                   1323:             custompath    => "Custom", 
                   1324:             exempt        => "Exempt IP(s)",
1.110     raeburn  1325:             directlogin   => "No redirect",
                   1326:             newuser       => "Link to create a user account",
                   1327:             img           => "Header",
                   1328:             logo          => "Main Logo",
                   1329:             domlogo       => "Domain Logo",
                   1330:             login         => "Log-in Header", 
                   1331:             textcol       => "Text color",
                   1332:             bgcol         => "Box color",
                   1333:             bgs           => "Background colors",
                   1334:             links         => "Link colors",
                   1335:             font          => "Font color",
                   1336:             pgbg          => "Header",
                   1337:             mainbg        => "Page",
                   1338:             sidebg        => "Login box",
                   1339:             link          => "Link",
                   1340:             alink         => "Active link",
                   1341:             vlink         => "Visited link",
1.160.6.56  raeburn  1342:             headtag       => "Custom markup",
                   1343:             action        => "Action",
                   1344:             current       => "Current",
1.6       raeburn  1345:         );
                   1346:     return %choices;
                   1347: }
                   1348: 
                   1349: sub print_rolecolors {
1.30      raeburn  1350:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1351:     my %choices = &color_font_choices();
                   1352:     my @bgs = ('pgbg','tabbg','sidebg');
                   1353:     my @links = ('link','alink','vlink');
                   1354:     my @images = ('img');
                   1355:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1356:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1357:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1358:     my (%is_custom,%designs);
1.160.6.22  raeburn  1359:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1360:     if (ref($settings) eq 'HASH') {
                   1361:         if (ref($settings->{$role}) eq 'HASH') {
                   1362:             if ($settings->{$role}->{'img'} ne '') {
                   1363:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1364:                 $is_custom{'img'} = 1;
                   1365:             }
                   1366:             if ($settings->{$role}->{'font'} ne '') {
                   1367:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1368:                 $is_custom{'font'} = 1;
                   1369:             }
1.97      tempelho 1370:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1371:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1372:                 $is_custom{'fontmenu'} = 1;
                   1373:             }
1.6       raeburn  1374:             foreach my $item (@bgs) {
                   1375:                 if ($settings->{$role}->{$item} ne '') {
                   1376:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1377:                     $is_custom{$item} = 1;
                   1378:                 }
                   1379:             }
                   1380:             foreach my $item (@links) {
                   1381:                 if ($settings->{$role}->{$item} ne '') {
                   1382:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1383:                     $is_custom{$item} = 1;
                   1384:                 }
                   1385:             }
                   1386:         }
                   1387:     } else {
                   1388:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1389:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1390:             $is_custom{'img'} = 1;
                   1391:         }
1.97      tempelho 1392:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1393:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1394:             $is_custom{'fontmenu'} = 1; 
                   1395:         }
1.6       raeburn  1396:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1397:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1398:             $is_custom{'font'} = 1;
                   1399:         }
                   1400:         foreach my $item (@bgs) {
                   1401:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1402:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1403:                 $is_custom{$item} = 1;
                   1404:             
                   1405:             }
                   1406:         }
                   1407:         foreach my $item (@links) {
                   1408:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1409:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1410:                 $is_custom{$item} = 1;
                   1411:             }
                   1412:         }
                   1413:     }
                   1414:     my $itemcount = 1;
1.30      raeburn  1415:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1416:     $datatable .= '</tr></table></td></tr>';
                   1417:     return $datatable;
                   1418: }
                   1419: 
1.160.6.22  raeburn  1420: sub role_defaults {
                   1421:     my ($role,$bgs,$links,$images,$logintext) = @_;
                   1422:     my %defaults;
                   1423:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
                   1424:         return %defaults;
                   1425:     }
                   1426:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1427:     if ($role eq 'login') {
                   1428:         %defaults = (
                   1429:                        font => $defaultdesign{$role.'.font'},
                   1430:                     );
                   1431:         if (ref($logintext) eq 'ARRAY') {
                   1432:             foreach my $item (@{$logintext}) {
                   1433:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1434:             }
                   1435:         }
                   1436:         foreach my $item (@{$images}) {
                   1437:             $defaults{'showlogo'}{$item} = 1;
                   1438:         }
                   1439:     } else {
                   1440:         %defaults = (
                   1441:                        img => $defaultdesign{$role.'.img'},
                   1442:                        font => $defaultdesign{$role.'.font'},
                   1443:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1444:                     );
                   1445:     }
                   1446:     foreach my $item (@{$bgs}) {
                   1447:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1448:     }
                   1449:     foreach my $item (@{$links}) {
                   1450:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1451:     }
                   1452:     foreach my $item (@{$images}) {
                   1453:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1454:     }
                   1455:     return %defaults;
                   1456: }
                   1457: 
1.6       raeburn  1458: sub display_color_options {
1.9       raeburn  1459:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1460:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1461:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1462:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134     raeburn  1463:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1464:         '<td>'.$choices->{'font'}.'</td>';
                   1465:     if (!$is_custom->{'font'}) {
1.30      raeburn  1466:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1467:     } else {
                   1468:         $datatable .= '<td>&nbsp;</td>';
                   1469:     }
1.160.6.9  raeburn  1470:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1471: 
1.8       raeburn  1472:     $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1473:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   1474:                   ' value="'.$current_color.'" />&nbsp;'.
                   1475:                   '&nbsp;</td></tr>';
1.107     raeburn  1476:     unless ($role eq 'login') { 
                   1477:         $datatable .= '<tr'.$css_class.'>'.
                   1478:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1479:         if (!$is_custom->{'fontmenu'}) {
                   1480:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1481:         } else {
                   1482:             $datatable .= '<td>&nbsp;</td>';
                   1483:         }
1.160.6.22  raeburn  1484: 	$current_color = $designs->{'fontmenu'} ?
                   1485: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1486:         $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9  raeburn  1487:                       '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22  raeburn  1488: 		      .$role.'_fontmenu"'.
1.160.6.9  raeburn  1489:                       ' value="'.$current_color.'" />&nbsp;'.
                   1490:                       '&nbsp;</td></tr>';
1.97      tempelho 1491:     }
1.9       raeburn  1492:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1493:     foreach my $img (@{$images}) {
1.18      albertel 1494: 	$itemcount ++;
1.6       raeburn  1495:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1496:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1497:                       '<td>'.$choices->{$img};
1.41      raeburn  1498:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1499:         if ($role eq 'login') {
                   1500:             if ($img eq 'login') {
                   1501:                 $login_hdr_pick =
1.135     bisitz   1502:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1503:                 $logincolors =
                   1504:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22  raeburn  1505:                                        $designs,$defaults);
1.70      raeburn  1506:             } elsif ($img ne 'domlogo') {
                   1507:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1508:             }
                   1509:         }
                   1510:         $datatable .= '</td>';
1.6       raeburn  1511:         if ($designs->{$img} ne '') {
                   1512:             $imgfile = $designs->{$img};
1.18      albertel 1513: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1514:         } else {
                   1515:             $imgfile = $defaults->{$img};
                   1516:         }
                   1517:         if ($imgfile) {
1.9       raeburn  1518:             my ($showfile,$fullsize);
                   1519:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1520:                 my $urldir = $1;
                   1521:                 my $filename = $2;
                   1522:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1523:                 if (@info) {
                   1524:                     my $thumbfile = 'tn-'.$filename;
                   1525:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1526:                     if (@thumb) {
                   1527:                         $showfile = $urldir.'/'.$thumbfile;
                   1528:                     } else {
                   1529:                         $showfile = $imgfile;
                   1530:                     }
                   1531:                 } else {
                   1532:                     $showfile = '';
                   1533:                 }
                   1534:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1535:                 $showfile = $imgfile;
1.6       raeburn  1536:                 my $imgdir = $1;
                   1537:                 my $filename = $2;
1.159     raeburn  1538:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1539:                     $showfile = "/$imgdir/tn-".$filename;
                   1540:                 } else {
1.159     raeburn  1541:                     my $input = $londocroot.$imgfile;
                   1542:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1543:                     if (!-e $output) {
1.9       raeburn  1544:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1545:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1546:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1547:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1548:                                 my $size = $width.'x'.$height;
                   1549:                                 system("convert -sample $size $input $output");
1.159     raeburn  1550:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1551:                             }
                   1552:                         }
1.6       raeburn  1553:                     }
                   1554:                 }
1.16      raeburn  1555:             }
1.6       raeburn  1556:             if ($showfile) {
1.40      raeburn  1557:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1558:                     if ($showfile =~ m{^/res/}) {
                   1559:                         my $local_showfile =
                   1560:                             &Apache::lonnet::filelocation('',$showfile);
                   1561:                         &Apache::lonnet::repcopy($local_showfile);
                   1562:                     }
                   1563:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1564:                 }
                   1565:                 if ($imgfile) {
                   1566:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1567:                         if ($imgfile =~ m{^/res/}) {
                   1568:                             my $local_imgfile =
                   1569:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1570:                             &Apache::lonnet::repcopy($local_imgfile);
                   1571:                         }
                   1572:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1573:                     } else {
                   1574:                         $fullsize = $imgfile;
                   1575:                     }
                   1576:                 }
1.41      raeburn  1577:                 $datatable .= '<td>';
                   1578:                 if ($img eq 'login') {
1.135     bisitz   1579:                     $datatable .= $login_hdr_pick;
                   1580:                 } 
1.41      raeburn  1581:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1582:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1583:             } else {
1.160.6.22  raeburn  1584:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1585:                               &mt('Upload:').'<br />';
1.6       raeburn  1586:             }
                   1587:         } else {
1.160.6.22  raeburn  1588:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1589:                           &mt('Upload:').'<br />';
1.6       raeburn  1590:         }
1.9       raeburn  1591:         if ($switchserver) {
                   1592:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1593:         } else {
1.135     bisitz   1594:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1595:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1596:             }
1.9       raeburn  1597:         }
                   1598:         $datatable .= '</td></tr>';
1.6       raeburn  1599:     }
                   1600:     $itemcount ++;
                   1601:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1602:     $datatable .= '<tr'.$css_class.'>'.
                   1603:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1604:     my $bgs_def;
                   1605:     foreach my $item (@{$bgs}) {
                   1606:         if (!$is_custom->{$item}) {
1.70      raeburn  1607:             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6       raeburn  1608:         }
                   1609:     }
                   1610:     if ($bgs_def) {
1.8       raeburn  1611:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1612:     } else {
                   1613:         $datatable .= '<td>&nbsp;</td>';
                   1614:     }
                   1615:     $datatable .= '<td class="LC_right_item">'.
                   1616:                   '<table border="0"><tr>';
1.160.6.13  raeburn  1617: 
1.6       raeburn  1618:     foreach my $item (@{$bgs}) {
1.160.6.22  raeburn  1619:         $datatable .= '<td align="center">'.$choices->{$item};
                   1620: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1621:         if ($designs->{'bgs'}{$item}) {
1.160.6.9  raeburn  1622:             $datatable .= '&nbsp;';
1.6       raeburn  1623:         }
1.160.6.9  raeburn  1624:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1625:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1626:     }
                   1627:     $datatable .= '</tr></table></td></tr>';
                   1628:     $itemcount ++;
                   1629:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1630:     $datatable .= '<tr'.$css_class.'>'.
                   1631:                   '<td>'.$choices->{'links'}.'</td>';
                   1632:     my $links_def;
                   1633:     foreach my $item (@{$links}) {
                   1634:         if (!$is_custom->{$item}) {
1.30      raeburn  1635:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6       raeburn  1636:         }
                   1637:     }
                   1638:     if ($links_def) {
1.8       raeburn  1639:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1640:     } else {
                   1641:         $datatable .= '<td>&nbsp;</td>';
                   1642:     }
                   1643:     $datatable .= '<td class="LC_right_item">'.
                   1644:                   '<table border="0"><tr>';
                   1645:     foreach my $item (@{$links}) {
1.160.6.39  raeburn  1646: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22  raeburn  1647:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1648:         if ($designs->{'links'}{$item}) {
1.160.6.9  raeburn  1649:             $datatable.='&nbsp;';
1.6       raeburn  1650:         }
1.160.6.9  raeburn  1651:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1652:                       '" /></td>';
                   1653:     }
1.30      raeburn  1654:     $$rowtotal += $itemcount;
1.3       raeburn  1655:     return $datatable;
                   1656: }
                   1657: 
1.70      raeburn  1658: sub logo_display_options {
                   1659:     my ($img,$defaults,$designs) = @_;
                   1660:     my $checkedon;
                   1661:     if (ref($defaults) eq 'HASH') {
                   1662:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1663:             if ($defaults->{'showlogo'}{$img}) {
                   1664:                 $checkedon = 'checked="checked" ';     
                   1665:             }
                   1666:         } 
                   1667:     }
                   1668:     if (ref($designs) eq 'HASH') {
                   1669:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1670:             if (defined($designs->{'showlogo'}{$img})) {
                   1671:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1672:                     $checkedon = '';
                   1673:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1674:                     $checkedon = 'checked="checked" ';
                   1675:                 }
                   1676:             }
                   1677:         }
                   1678:     }
                   1679:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1680:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1681:            &mt('show').'</label>'."\n";
                   1682: }
                   1683: 
1.41      raeburn  1684: sub login_header_options  {
1.135     bisitz   1685:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1686:     my $output = '';
1.41      raeburn  1687:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1688:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1689:         if (!$is_custom->{'textcol'}) {
                   1690:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1691:                        '&nbsp;&nbsp;&nbsp;';
                   1692:         }
                   1693:         if (!$is_custom->{'bgcol'}) {
                   1694:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1695:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1696:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1697:         }
                   1698:         $output .= '<br />';
                   1699:     }
                   1700:     $output .='<br />';
                   1701:     return $output;
                   1702: }
                   1703: 
                   1704: sub login_text_colors {
1.160.6.22  raeburn  1705:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1706:     my $color_menu = '<table border="0"><tr>';
                   1707:     foreach my $item (@{$logintext}) {
1.160.6.22  raeburn  1708:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1709:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1710:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1711:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1712:     }
                   1713:     $color_menu .= '</tr></table><br />';
                   1714:     return $color_menu;
                   1715: }
                   1716: 
                   1717: sub image_changes {
                   1718:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1719:     my $output;
1.135     bisitz   1720:     if ($img eq 'login') {
                   1721:             # suppress image for Log-in header
                   1722:     } elsif (!$is_custom) {
1.70      raeburn  1723:         if ($img ne 'domlogo') {
1.41      raeburn  1724:             $output .= &mt('Default image:').'<br />';
                   1725:         } else {
                   1726:             $output .= &mt('Default in use:').'<br />';
                   1727:         }
                   1728:     }
1.135     bisitz   1729:     if ($img eq 'login') { # suppress image for Log-in header
                   1730:         $output .= '<td>'.$logincolors;
1.41      raeburn  1731:     } else {
1.135     bisitz   1732:         if ($img_import) {
                   1733:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1734:         }
                   1735:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1736:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1737:         if ($is_custom) {
                   1738:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1739:                        '<input type="checkbox" name="'.
                   1740:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1741:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1742:         } else {
1.160.6.22  raeburn  1743:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1744:         }
1.41      raeburn  1745:     }
                   1746:     return $output;
                   1747: }
                   1748: 
1.3       raeburn  1749: sub print_quotas {
1.86      raeburn  1750:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1751:     my $context;
                   1752:     if ($action eq 'quotas') {
                   1753:         $context = 'tools';
                   1754:     } else {
                   1755:         $context = $action;
                   1756:     }
1.160.6.20  raeburn  1757:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1758:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1759:     my $typecount = 0;
1.101     raeburn  1760:     my ($css_class,%titles);
1.86      raeburn  1761:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  1762:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  1763:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1764:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1765:         %titles = &courserequest_titles();
1.160.6.5  raeburn  1766:     } elsif ($context eq 'requestauthor') {
                   1767:         @usertools = ('author');
                   1768:         @options = ('norequest','approval','automatic');
                   1769:         %titles = &authorrequest_titles();
1.86      raeburn  1770:     } else {
1.160.6.4  raeburn  1771:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1772:         %titles = &tool_titles();
1.86      raeburn  1773:     }
1.26      raeburn  1774:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1775:         foreach my $type (@{$types}) {
1.160.6.20  raeburn  1776:             my ($currdefquota,$currauthorquota);
1.160.6.5  raeburn  1777:             unless (($context eq 'requestcourses') ||
                   1778:                     ($context eq 'requestauthor')) {
1.86      raeburn  1779:                 if (ref($settings) eq 'HASH') {
                   1780:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20  raeburn  1781:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1782:                     } else {
                   1783:                         $currdefquota = $settings->{$type};
                   1784:                     }
1.160.6.20  raeburn  1785:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1786:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1787:                     }
1.78      raeburn  1788:                 }
1.72      raeburn  1789:             }
1.3       raeburn  1790:             if (defined($usertypes->{$type})) {
                   1791:                 $typecount ++;
                   1792:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1793:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1794:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1795:                               '<td class="LC_left_item">';
1.101     raeburn  1796:                 if ($context eq 'requestcourses') {
                   1797:                     $datatable .= '<table><tr>';
                   1798:                 }
                   1799:                 my %cell;  
1.72      raeburn  1800:                 foreach my $item (@usertools) {
1.101     raeburn  1801:                     if ($context eq 'requestcourses') {
                   1802:                         my ($curroption,$currlimit);
                   1803:                         if (ref($settings) eq 'HASH') {
                   1804:                             if (ref($settings->{$item}) eq 'HASH') {
                   1805:                                 $curroption = $settings->{$item}->{$type};
                   1806:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1807:                                     $currlimit = $1; 
                   1808:                                 }
                   1809:                             }
                   1810:                         }
                   1811:                         if (!$curroption) {
                   1812:                             $curroption = 'norequest';
                   1813:                         }
                   1814:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1815:                         foreach my $option (@options) {
                   1816:                             my $val = $option;
                   1817:                             if ($option eq 'norequest') {
                   1818:                                 $val = 0;  
                   1819:                             }
                   1820:                             if ($option eq 'validate') {
                   1821:                                 my $canvalidate = 0;
                   1822:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1823:                                     if ($validations{$item}{$type}) {
                   1824:                                         $canvalidate = 1;
                   1825:                                     }
                   1826:                                 }
                   1827:                                 next if (!$canvalidate);
                   1828:                             }
                   1829:                             my $checked = '';
                   1830:                             if ($option eq $curroption) {
                   1831:                                 $checked = ' checked="checked"';
                   1832:                             } elsif ($option eq 'autolimit') {
                   1833:                                 if ($curroption =~ /^autolimit/) {
                   1834:                                     $checked = ' checked="checked"';
                   1835:                                 }                       
                   1836:                             } 
                   1837:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1838:                                   '<input type="radio" name="crsreq_'.$item.
                   1839:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1840:                                   $titles{$option}.'</label>';
1.101     raeburn  1841:                             if ($option eq 'autolimit') {
1.127     raeburn  1842:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1843:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1844:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1845:                             }
1.127     raeburn  1846:                             $cell{$item} .= '</span> ';
1.103     raeburn  1847:                             if ($option eq 'autolimit') {
1.127     raeburn  1848:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1849:                             }
1.101     raeburn  1850:                         }
1.160.6.5  raeburn  1851:                     } elsif ($context eq 'requestauthor') {
                   1852:                         my $curroption;
                   1853:                         if (ref($settings) eq 'HASH') {
                   1854:                             $curroption = $settings->{$type};
                   1855:                         }
                   1856:                         if (!$curroption) {
                   1857:                             $curroption = 'norequest';
                   1858:                         }
                   1859:                         foreach my $option (@options) {
                   1860:                             my $val = $option;
                   1861:                             if ($option eq 'norequest') {
                   1862:                                 $val = 0;
                   1863:                             }
                   1864:                             my $checked = '';
                   1865:                             if ($option eq $curroption) {
                   1866:                                 $checked = ' checked="checked"';
                   1867:                             }
                   1868:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1869:                                   '<input type="radio" name="authorreq_'.$type.
                   1870:                                   '" value="'.$val.'"'.$checked.' />'.
                   1871:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1872:                         }
1.101     raeburn  1873:                     } else {
                   1874:                         my $checked = 'checked="checked" ';
                   1875:                         if (ref($settings) eq 'HASH') {
                   1876:                             if (ref($settings->{$item}) eq 'HASH') {
                   1877:                                 if ($settings->{$item}->{$type} == 0) {
                   1878:                                     $checked = '';
                   1879:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1880:                                     $checked =  'checked="checked" ';
                   1881:                                 }
1.78      raeburn  1882:                             }
1.72      raeburn  1883:                         }
1.101     raeburn  1884:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1885:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1886:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1887:                                       '</label></span>&nbsp; ';
1.72      raeburn  1888:                     }
1.101     raeburn  1889:                 }
                   1890:                 if ($context eq 'requestcourses') {
                   1891:                     $datatable .= '</tr><tr>';
                   1892:                     foreach my $item (@usertools) {
1.106     raeburn  1893:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1894:                     }
                   1895:                     $datatable .= '</tr></table>';
1.72      raeburn  1896:                 }
1.86      raeburn  1897:                 $datatable .= '</td>';
1.160.6.5  raeburn  1898:                 unless (($context eq 'requestcourses') ||
                   1899:                         ($context eq 'requestauthor')) {
1.86      raeburn  1900:                     $datatable .= 
1.160.6.20  raeburn  1901:                               '<td class="LC_right_item">'.
                   1902:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1903:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1904:                               '" value="'.$currdefquota.
1.160.6.20  raeburn  1905:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1906:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1907:                               '<input type="text" name="authorquota_'.$type.
                   1908:                               '" value="'.$currauthorquota.
                   1909:                               '" size="5" /></span></td>';
1.86      raeburn  1910:                 }
                   1911:                 $datatable .= '</tr>';
1.3       raeburn  1912:             }
                   1913:         }
                   1914:     }
1.160.6.5  raeburn  1915:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1916:         $defaultquota = '20';
1.160.6.20  raeburn  1917:         $authorquota = '500';
1.86      raeburn  1918:         if (ref($settings) eq 'HASH') {
                   1919:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1920:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1921:             } elsif (defined($settings->{'default'})) {
                   1922:                 $defaultquota = $settings->{'default'};
                   1923:             }
1.160.6.20  raeburn  1924:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1925:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1926:             }
1.3       raeburn  1927:         }
                   1928:     }
                   1929:     $typecount ++;
                   1930:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1931:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1932:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1933:                   '<td class="LC_left_item">';
1.101     raeburn  1934:     if ($context eq 'requestcourses') {
                   1935:         $datatable .= '<table><tr>';
                   1936:     }
                   1937:     my %defcell;
1.72      raeburn  1938:     foreach my $item (@usertools) {
1.101     raeburn  1939:         if ($context eq 'requestcourses') {
                   1940:             my ($curroption,$currlimit);
                   1941:             if (ref($settings) eq 'HASH') {
                   1942:                 if (ref($settings->{$item}) eq 'HASH') {
                   1943:                     $curroption = $settings->{$item}->{'default'};
                   1944:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1945:                         $currlimit = $1;
                   1946:                     }
                   1947:                 }
                   1948:             }
                   1949:             if (!$curroption) {
                   1950:                 $curroption = 'norequest';
                   1951:             }
                   1952:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1953:             foreach my $option (@options) {
                   1954:                 my $val = $option;
                   1955:                 if ($option eq 'norequest') {
                   1956:                     $val = 0;
                   1957:                 }
                   1958:                 if ($option eq 'validate') {
                   1959:                     my $canvalidate = 0;
                   1960:                     if (ref($validations{$item}) eq 'HASH') {
                   1961:                         if ($validations{$item}{'default'}) {
                   1962:                             $canvalidate = 1;
                   1963:                         }
                   1964:                     }
                   1965:                     next if (!$canvalidate);
                   1966:                 }
                   1967:                 my $checked = '';
                   1968:                 if ($option eq $curroption) {
                   1969:                     $checked = ' checked="checked"';
                   1970:                 } elsif ($option eq 'autolimit') {
                   1971:                     if ($curroption =~ /^autolimit/) {
                   1972:                         $checked = ' checked="checked"';
                   1973:                     }
                   1974:                 }
                   1975:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1976:                                   '<input type="radio" name="crsreq_'.$item.
                   1977:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1978:                                   $titles{$option}.'</label>';
                   1979:                 if ($option eq 'autolimit') {
1.127     raeburn  1980:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1981:                                        $item.'_limit_default" size="1" '.
                   1982:                                        'value="'.$currlimit.'" />';
                   1983:                 }
1.127     raeburn  1984:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1985:                 if ($option eq 'autolimit') {
1.127     raeburn  1986:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1987:                 }
1.101     raeburn  1988:             }
1.160.6.5  raeburn  1989:         } elsif ($context eq 'requestauthor') {
                   1990:             my $curroption;
                   1991:             if (ref($settings) eq 'HASH') {
1.160.6.8  raeburn  1992:                 $curroption = $settings->{'default'};
1.160.6.5  raeburn  1993:             }
                   1994:             if (!$curroption) {
                   1995:                 $curroption = 'norequest';
                   1996:             }
                   1997:             foreach my $option (@options) {
                   1998:                 my $val = $option;
                   1999:                 if ($option eq 'norequest') {
                   2000:                     $val = 0;
                   2001:                 }
                   2002:                 my $checked = '';
                   2003:                 if ($option eq $curroption) {
                   2004:                     $checked = ' checked="checked"';
                   2005:                 }
                   2006:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   2007:                               '<input type="radio" name="authorreq_default"'.
                   2008:                               ' value="'.$val.'"'.$checked.' />'.
                   2009:                               $titles{$option}.'</label></span>&nbsp; ';
                   2010:             }
1.101     raeburn  2011:         } else {
                   2012:             my $checked = 'checked="checked" ';
                   2013:             if (ref($settings) eq 'HASH') {
                   2014:                 if (ref($settings->{$item}) eq 'HASH') {
                   2015:                     if ($settings->{$item}->{'default'} == 0) {
                   2016:                         $checked = '';
                   2017:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   2018:                         $checked = 'checked="checked" ';
                   2019:                     }
1.78      raeburn  2020:                 }
1.72      raeburn  2021:             }
1.101     raeburn  2022:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2023:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2024:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   2025:                           '</label></span>&nbsp; ';
                   2026:         }
                   2027:     }
                   2028:     if ($context eq 'requestcourses') {
                   2029:         $datatable .= '</tr><tr>';
                   2030:         foreach my $item (@usertools) {
1.106     raeburn  2031:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  2032:         }
1.101     raeburn  2033:         $datatable .= '</tr></table>';
1.72      raeburn  2034:     }
1.86      raeburn  2035:     $datatable .= '</td>';
1.160.6.5  raeburn  2036:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20  raeburn  2037:         $datatable .= '<td class="LC_right_item">'.
                   2038:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2039:                       '<input type="text" name="defaultquota" value="'.
1.160.6.20  raeburn  2040:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2041:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2042:                       '<input type="text" name="authorquota" value="'.
                   2043:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2044:     }
                   2045:     $datatable .= '</tr>';
1.72      raeburn  2046:     $typecount ++;
                   2047:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2048:     $datatable .= '<tr'.$css_class.'>'.
1.160.6.20  raeburn  2049:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2050:     if ($context eq 'requestcourses') {
1.109     raeburn  2051:         $datatable .= &mt('(overrides affiliation, if set)').
                   2052:                       '</td>'.
                   2053:                       '<td class="LC_left_item">'.
                   2054:                       '<table><tr>';
1.101     raeburn  2055:     } else {
1.109     raeburn  2056:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2057:                       '</td>'.
                   2058:                       '<td class="LC_left_item" colspan="2">'.
                   2059:                       '<br />';
1.101     raeburn  2060:     }
                   2061:     my %advcell;
1.72      raeburn  2062:     foreach my $item (@usertools) {
1.101     raeburn  2063:         if ($context eq 'requestcourses') {
                   2064:             my ($curroption,$currlimit);
                   2065:             if (ref($settings) eq 'HASH') {
                   2066:                 if (ref($settings->{$item}) eq 'HASH') {
                   2067:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2068:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2069:                         $currlimit = $1;
                   2070:                     }
                   2071:                 }
                   2072:             }
                   2073:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2074:             my $checked = '';
                   2075:             if ($curroption eq '') {
                   2076:                 $checked = ' checked="checked"';
                   2077:             }
                   2078:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2079:                                '<input type="radio" name="crsreq_'.$item.
                   2080:                                '__LC_adv" value=""'.$checked.' />'.
                   2081:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2082:             foreach my $option (@options) {
                   2083:                 my $val = $option;
                   2084:                 if ($option eq 'norequest') {
                   2085:                     $val = 0;
                   2086:                 }
                   2087:                 if ($option eq 'validate') {
                   2088:                     my $canvalidate = 0;
                   2089:                     if (ref($validations{$item}) eq 'HASH') {
                   2090:                         if ($validations{$item}{'_LC_adv'}) {
                   2091:                             $canvalidate = 1;
                   2092:                         }
                   2093:                     }
                   2094:                     next if (!$canvalidate);
                   2095:                 }
                   2096:                 my $checked = '';
1.104     raeburn  2097:                 if ($val eq $curroption) {
1.101     raeburn  2098:                     $checked = ' checked="checked"';
                   2099:                 } elsif ($option eq 'autolimit') {
                   2100:                     if ($curroption =~ /^autolimit/) {
                   2101:                         $checked = ' checked="checked"';
                   2102:                     }
                   2103:                 }
                   2104:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2105:                                   '<input type="radio" name="crsreq_'.$item.
                   2106:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2107:                                   $titles{$option}.'</label>';
                   2108:                 if ($option eq 'autolimit') {
1.127     raeburn  2109:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2110:                                        $item.'_limit__LC_adv" size="1" '.
                   2111:                                        'value="'.$currlimit.'" />';
                   2112:                 }
1.127     raeburn  2113:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2114:                 if ($option eq 'autolimit') {
1.127     raeburn  2115:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2116:                 }
1.101     raeburn  2117:             }
1.160.6.5  raeburn  2118:         } elsif ($context eq 'requestauthor') {
                   2119:             my $curroption;
                   2120:             if (ref($settings) eq 'HASH') {
                   2121:                 $curroption = $settings->{'_LC_adv'};
                   2122:             }
                   2123:             my $checked = '';
                   2124:             if ($curroption eq '') {
                   2125:                 $checked = ' checked="checked"';
                   2126:             }
                   2127:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2128:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2129:                           ' value=""'.$checked.' />'.
                   2130:                           &mt('No override set').'</label></span>&nbsp; ';
                   2131:             foreach my $option (@options) {
                   2132:                 my $val = $option;
                   2133:                 if ($option eq 'norequest') {
                   2134:                     $val = 0;
                   2135:                 }
                   2136:                 my $checked = '';
                   2137:                 if ($val eq $curroption) {
                   2138:                     $checked = ' checked="checked"';
                   2139:                 }
                   2140:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8  raeburn  2141:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2142:                               ' value="'.$val.'"'.$checked.' />'.
1.160.6.5  raeburn  2143:                               $titles{$option}.'</label></span>&nbsp; ';
                   2144:             }
1.101     raeburn  2145:         } else {
                   2146:             my $checked = 'checked="checked" ';
                   2147:             if (ref($settings) eq 'HASH') {
                   2148:                 if (ref($settings->{$item}) eq 'HASH') {
                   2149:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2150:                         $checked = '';
                   2151:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2152:                         $checked = 'checked="checked" ';
                   2153:                     }
1.79      raeburn  2154:                 }
1.72      raeburn  2155:             }
1.101     raeburn  2156:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2157:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2158:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2159:                           '</label></span>&nbsp; ';
                   2160:         }
                   2161:     }
                   2162:     if ($context eq 'requestcourses') {
                   2163:         $datatable .= '</tr><tr>';
                   2164:         foreach my $item (@usertools) {
1.106     raeburn  2165:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2166:         }
1.101     raeburn  2167:         $datatable .= '</tr></table>';
1.72      raeburn  2168:     }
1.98      raeburn  2169:     $datatable .= '</td></tr>';
1.30      raeburn  2170:     $$rowtotal += $typecount;
1.3       raeburn  2171:     return $datatable;
                   2172: }
                   2173: 
1.160.6.5  raeburn  2174: sub print_requestmail {
                   2175:     my ($dom,$action,$settings,$rowtotal) = @_;
1.160.6.25  raeburn  2176:     my ($now,$datatable,%currapp);
1.102     raeburn  2177:     $now = time;
                   2178:     if (ref($settings) eq 'HASH') {
                   2179:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2180:             if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34  raeburn  2181:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2182:             }
                   2183:         }
                   2184:     }
1.160.6.16  raeburn  2185:     my $numinrow = 2;
1.160.6.34  raeburn  2186:     my $css_class;
                   2187:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.160.6.5  raeburn  2188:     my $text;
                   2189:     if ($action eq 'requestcourses') {
                   2190:         $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34  raeburn  2191:     } elsif ($action eq 'requestauthor') {
                   2192:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5  raeburn  2193:     } else {
1.160.6.34  raeburn  2194:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5  raeburn  2195:     }
1.160.6.34  raeburn  2196:     $datatable = '<tr'.$css_class.'>'.
1.160.6.5  raeburn  2197:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2198:                  ' <td class="LC_left_item">';
1.160.6.16  raeburn  2199:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34  raeburn  2200:                                                  $action.'notifyapproval',%currapp);
1.160.6.16  raeburn  2201:     if ($numdc > 0) {
                   2202:         $datatable .= $table;
1.102     raeburn  2203:     } else {
                   2204:         $datatable .= &mt('There are no active Domain Coordinators');
                   2205:     }
                   2206:     $datatable .='</td></tr>';
                   2207:     return $datatable;
                   2208: }
                   2209: 
1.160.6.30  raeburn  2210: sub print_studentcode {
                   2211:     my ($settings,$rowtotal) = @_;
                   2212:     my $rownum = 0; 
                   2213:     my ($output,%current);
                   2214:     my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51  raeburn  2215:     if (ref($settings) eq 'HASH') {
                   2216:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2217:             foreach my $type (@crstypes) {
                   2218:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2219:             }
1.160.6.30  raeburn  2220:         }
                   2221:     }
                   2222:     $output .= '<tr>'.
                   2223:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2224:                '<td class="LC_left_item">';
                   2225:     foreach my $type (@crstypes) {
                   2226:         my $check = ' ';
                   2227:         if ($current{$type}) {
                   2228:             $check = ' checked="checked" ';
                   2229:         }
                   2230:         $output .= '<span class="LC_nobreak"><label>'.
                   2231:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2232:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2233:     }
                   2234:     $output .= '</td></tr>';
                   2235:     $$rowtotal ++;
                   2236:     return $output;
                   2237: }
                   2238: 
                   2239: sub print_textbookcourses {
1.160.6.46  raeburn  2240:     my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30  raeburn  2241:     my $rownum = 0;
                   2242:     my $css_class;
                   2243:     my $itemcount = 1;
                   2244:     my $maxnum = 0;
                   2245:     my $bookshash;
                   2246:     if (ref($settings) eq 'HASH') {
1.160.6.46  raeburn  2247:         $bookshash = $settings->{$type};
1.160.6.30  raeburn  2248:     }
                   2249:     my %ordered;
                   2250:     if (ref($bookshash) eq 'HASH') {
                   2251:         foreach my $item (keys(%{$bookshash})) {
                   2252:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2253:                 my $num = $bookshash->{$item}{'order'};
                   2254:                 $ordered{$num} = $item;
                   2255:             }
                   2256:         }
                   2257:     }
                   2258:     my $confname = $dom.'-domainconfig';
                   2259:     my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46  raeburn  2260:     my $maxnum = scalar(keys(%ordered));
                   2261:     my $datatable;
1.160.6.30  raeburn  2262:     if (keys(%ordered)) {
                   2263:         my @items = sort { $a <=> $b } keys(%ordered);
                   2264:         for (my $i=0; $i<@items; $i++) {
                   2265:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2266:             my $key = $ordered{$items[$i]};
                   2267:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2268:             my $coursetitle = $coursehash{'description'};
1.160.6.47  raeburn  2269:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30  raeburn  2270:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2271:                 $subject = $bookshash->{$key}->{'subject'};
                   2272:                 $title = $bookshash->{$key}->{'title'};
1.160.6.46  raeburn  2273:                 if ($type eq 'textbooks') {
1.160.6.47  raeburn  2274:                     $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46  raeburn  2275:                     $author = $bookshash->{$key}->{'author'};
                   2276:                     $image = $bookshash->{$key}->{'image'};
                   2277:                     if ($image ne '') {
                   2278:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2279:                         my $imagethumb = "$path/tn-".$imagefile;
                   2280:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2281:                     }
1.160.6.30  raeburn  2282:                 }
                   2283:             }
1.160.6.46  raeburn  2284:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30  raeburn  2285:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46  raeburn  2286:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30  raeburn  2287:             for (my $k=0; $k<=$maxnum; $k++) {
                   2288:                 my $vpos = $k+1;
                   2289:                 my $selstr;
                   2290:                 if ($k == $i) {
                   2291:                     $selstr = ' selected="selected" ';
                   2292:                 }
                   2293:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2294:             }
                   2295:             $datatable .= '</select>'.('&nbsp;'x2).
1.160.6.46  raeburn  2296:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30  raeburn  2297:                 &mt('Delete?').'</label></span></td>'.
                   2298:                 '<td colspan="2">'.
1.160.6.46  raeburn  2299:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30  raeburn  2300:                 ('&nbsp;'x2).
1.160.6.46  raeburn  2301:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2302:             if ($type eq 'textbooks') {
                   2303:                 $datatable .= ('&nbsp;'x2).
1.160.6.47  raeburn  2304:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2305:                               ('&nbsp;'x2).
1.160.6.46  raeburn  2306:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2307:                               ('&nbsp;'x2).
                   2308:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2309:                 if ($image) {
                   2310:                     $datatable .= '<span class="LC_nobreak">'.
                   2311:                                   $imgsrc.
                   2312:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2313:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2314:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2315:                 }
                   2316:                 if ($switchserver) {
                   2317:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2318:                 } else {
                   2319:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2320:                 }
1.160.6.30  raeburn  2321:             }
1.160.6.46  raeburn  2322:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30  raeburn  2323:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2324:                           $coursetitle.'</span></td></tr>'."\n";
                   2325:             $itemcount ++;
                   2326:         }
                   2327:     }
                   2328:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46  raeburn  2329:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30  raeburn  2330:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46  raeburn  2331:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2332:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30  raeburn  2333:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2334:         my $vpos = $k+1;
                   2335:         my $selstr;
                   2336:         if ($k == $maxnum) {
                   2337:             $selstr = ' selected="selected" ';
                   2338:         }
                   2339:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2340:     }
                   2341:     $datatable .= '</select>&nbsp;'."\n".
1.160.6.46  raeburn  2342:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.160.6.30  raeburn  2343:                   '<td colspan="2">'.
1.160.6.46  raeburn  2344:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30  raeburn  2345:                   ('&nbsp;'x2).
1.160.6.46  raeburn  2346:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2347:                   ('&nbsp;'x2);
                   2348:     if ($type eq 'textbooks') {
1.160.6.47  raeburn  2349:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2350:                       ('&nbsp;'x2).
                   2351:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46  raeburn  2352:                       ('&nbsp;'x2).
                   2353:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2354:         if ($switchserver) {
                   2355:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2356:         } else {
                   2357:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2358:         }
1.160.6.30  raeburn  2359:     }
                   2360:     $datatable .= '</span>'."\n".
                   2361:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.160.6.46  raeburn  2362:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2363:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30  raeburn  2364:                   &Apache::loncommon::selectcourse_link
1.160.6.46  raeburn  2365:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.160.6.30  raeburn  2366:                   '</span></td>'."\n".
                   2367:                   '</tr>'."\n";
                   2368:     $itemcount ++;
                   2369:     return $datatable;
                   2370: }
                   2371: 
                   2372: sub textbookcourses_javascript {
1.160.6.46  raeburn  2373:     my ($settings) = @_;
                   2374:     return unless(ref($settings) eq 'HASH');
                   2375:     my (%ordered,%total,%jstext);
                   2376:     foreach my $type ('textbooks','templates') {
                   2377:         $total{$type} = 0;
                   2378:         if (ref($settings->{$type}) eq 'HASH') {
                   2379:             foreach my $item (keys(%{$settings->{$type}})) {
                   2380:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2381:                     my $num = $settings->{$type}->{$item}{'order'};
                   2382:                     $ordered{$type}{$num} = $item;
                   2383:                 }
                   2384:             }
                   2385:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2386:         }
                   2387:         my @jsarray = ();
                   2388:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2389:             push(@jsarray,$ordered{$type}{$item});
                   2390:         }
                   2391:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30  raeburn  2392:     }
                   2393:     return <<"ENDSCRIPT";
                   2394: <script type="text/javascript">
                   2395: // <![CDATA[
1.160.6.46  raeburn  2396: function reorderBooks(form,item,caller) {
1.160.6.30  raeburn  2397:     var changedVal;
1.160.6.46  raeburn  2398: $jstext{'textbooks'};
                   2399: $jstext{'templates'};
                   2400:     var newpos;
                   2401:     var maxh;
                   2402:     if (caller == 'textbooks') {  
                   2403:         newpos = 'textbooks_addbook_pos';
                   2404:         maxh = 1 + $total{'textbooks'};
                   2405:     } else {
                   2406:         newpos = 'templates_addbook_pos';
                   2407:         maxh = 1 + $total{'templates'};
                   2408:     }
1.160.6.30  raeburn  2409:     var current = new Array;
                   2410:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2411:     if (item == newpos) {
                   2412:         changedVal = newitemVal;
                   2413:     } else {
                   2414:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2415:         current[newitemVal] = newpos;
                   2416:     }
1.160.6.46  raeburn  2417:     if (caller == 'textbooks') {
                   2418:         for (var i=0; i<textbooks.length; i++) {
                   2419:             var elementName = 'textbooks_'+textbooks[i];
                   2420:             if (elementName != item) {
                   2421:                 if (form.elements[elementName]) {
                   2422:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2423:                     current[currVal] = elementName;
                   2424:                 }
                   2425:             }
                   2426:         }
                   2427:     }
                   2428:     if (caller == 'templates') {
                   2429:         for (var i=0; i<templates.length; i++) {
                   2430:             var elementName = 'templates_'+templates[i];
                   2431:             if (elementName != item) {
                   2432:                 if (form.elements[elementName]) {
                   2433:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2434:                     current[currVal] = elementName;
                   2435:                 }
1.160.6.30  raeburn  2436:             }
                   2437:         }
                   2438:     }
                   2439:     var oldVal;
                   2440:     for (var j=0; j<maxh; j++) {
                   2441:         if (current[j] == undefined) {
                   2442:             oldVal = j;
                   2443:         }
                   2444:     }
                   2445:     if (oldVal < changedVal) {
                   2446:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2447:            var elementName = current[k];
                   2448:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2449:         }
                   2450:     } else {
                   2451:         for (var k=changedVal; k<oldVal; k++) {
                   2452:             var elementName = current[k];
                   2453:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2454:         }
                   2455:     }
                   2456:     return;
                   2457: }
                   2458: 
                   2459: // ]]>
                   2460: </script>
                   2461: 
                   2462: ENDSCRIPT
                   2463: }
                   2464: 
1.160.6.84.2.  (raeburn 2465:): sub ltitools_javascript {
                   2466:):     my ($settings) = @_;
                   2467:):     return unless(ref($settings) eq 'HASH');
                   2468:):     my (%ordered,$total,%jstext);
                   2469:):     $total = 0;
                   2470:):     foreach my $item (keys(%{$settings})) {
                   2471:):         if (ref($settings->{$item}) eq 'HASH') {
                   2472:):             my $num = $settings->{$item}{'order'};
                   2473:):             $ordered{$num} = $item;
                   2474:):         }
                   2475:):     }
                   2476:):     $total = scalar(keys(%{$settings}));
                   2477:):     my @jsarray = ();
                   2478:):     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2479:):         push(@jsarray,$ordered{$item});
                   2480:):     }
                   2481:):     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2482:):     return <<"ENDSCRIPT";
                   2483:): <script type="text/javascript">
                   2484:): // <![CDATA[
                   2485:): function reorderLTI(form,item) {
                   2486:):     var changedVal;
                   2487:): $jstext
                   2488:):     var newpos = 'ltitools_add_pos';
                   2489:):     var maxh = 1 + $total;
                   2490:):     var current = new Array;
                   2491:):     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2492:):     if (item == newpos) {
                   2493:):         changedVal = newitemVal;
                   2494:):     } else {
                   2495:):         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2496:):         current[newitemVal] = newpos;
                   2497:):     }
                   2498:):     for (var i=0; i<ltitools.length; i++) {
                   2499:):         var elementName = 'ltitools_'+ltitools[i];
                   2500:):         if (elementName != item) {
                   2501:):             if (form.elements[elementName]) {
                   2502:):                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2503:):                 current[currVal] = elementName;
                   2504:):             }
                   2505:):         }
                   2506:):     }
                   2507:):     var oldVal;
                   2508:):     for (var j=0; j<maxh; j++) {
                   2509:):         if (current[j] == undefined) {
                   2510:):             oldVal = j;
                   2511:):         }
                   2512:):     }
                   2513:):     if (oldVal < changedVal) {
                   2514:):         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2515:):            var elementName = current[k];
                   2516:):            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2517:):         }
                   2518:):     } else {
                   2519:):         for (var k=changedVal; k<oldVal; k++) {
                   2520:):             var elementName = current[k];
                   2521:):             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2522:):         }
                   2523:):     }
                   2524:):     return;
                   2525:): }
                   2526:): 
                   2527:): // ]]>
                   2528:): </script>
                   2529:): 
                   2530:): ENDSCRIPT
                   2531:): }
                   2532:): 
1.3       raeburn  2533: sub print_autoenroll {
1.30      raeburn  2534:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2535:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.68  raeburn  2536:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff,$failsafe);
1.3       raeburn  2537:     if (ref($settings) eq 'HASH') {
                   2538:         if (exists($settings->{'run'})) {
                   2539:             if ($settings->{'run'} eq '0') {
                   2540:                 $runoff = ' checked="checked" ';
                   2541:                 $runon = ' ';
                   2542:             } else {
                   2543:                 $runon = ' checked="checked" ';
                   2544:                 $runoff = ' ';
                   2545:             }
                   2546:         } else {
                   2547:             if ($autorun) {
                   2548:                 $runon = ' checked="checked" ';
                   2549:                 $runoff = ' ';
                   2550:             } else {
                   2551:                 $runoff = ' checked="checked" ';
                   2552:                 $runon = ' ';
                   2553:             }
                   2554:         }
1.129     raeburn  2555:         if (exists($settings->{'co-owners'})) {
                   2556:             if ($settings->{'co-owners'} eq '0') {
                   2557:                 $coownersoff = ' checked="checked" ';
                   2558:                 $coownerson = ' ';
                   2559:             } else {
                   2560:                 $coownerson = ' checked="checked" ';
                   2561:                 $coownersoff = ' ';
                   2562:             }
                   2563:         } else {
                   2564:             $coownersoff = ' checked="checked" ';
                   2565:             $coownerson = ' ';
                   2566:         }
1.3       raeburn  2567:         if (exists($settings->{'sender_domain'})) {
                   2568:             $defdom = $settings->{'sender_domain'};
                   2569:         }
1.160.6.68  raeburn  2570:         if (exists($settings->{'autofailsafe'})) {
                   2571:             $failsafe = $settings->{'autofailsafe'};
                   2572:         }
1.14      raeburn  2573:     } else {
                   2574:         if ($autorun) {
                   2575:             $runon = ' checked="checked" ';
                   2576:             $runoff = ' ';
                   2577:         } else {
                   2578:             $runoff = ' checked="checked" ';
                   2579:             $runon = ' ';
                   2580:         }
1.3       raeburn  2581:     }
                   2582:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2583:     my $notif_sender;
                   2584:     if (ref($settings) eq 'HASH') {
                   2585:         $notif_sender = $settings->{'sender_uname'};
                   2586:     }
1.3       raeburn  2587:     my $datatable='<tr class="LC_odd_row">'.
                   2588:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2589:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2590:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2591:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2592:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2593:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2594:                   '</tr><tr>'.
                   2595:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2596:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2597:                   &mt('username').':&nbsp;'.
                   2598:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2599:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2600:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2601:                   '<tr class="LC_odd_row">'.
                   2602:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2603:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2604:                   '<input type="radio" name="autoassign_coowners"'.
                   2605:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2606:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2607:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68  raeburn  2608:                   '</tr><tr>'.
                   2609:                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   2610:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2611:                   '<input type="text" name="autoenroll_failsafe"'.
                   2612:                   ' value="'.$failsafe.'" size="4" /></td></tr>';
                   2613:     $$rowtotal += 4;
1.3       raeburn  2614:     return $datatable;
                   2615: }
                   2616: 
                   2617: sub print_autoupdate {
1.30      raeburn  2618:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2619:     my $datatable;
                   2620:     if ($position eq 'top') {
                   2621:         my $updateon = ' ';
                   2622:         my $updateoff = ' checked="checked" ';
                   2623:         my $classlistson = ' ';
                   2624:         my $classlistsoff = ' checked="checked" ';
                   2625:         if (ref($settings) eq 'HASH') {
                   2626:             if ($settings->{'run'} eq '1') {
                   2627:                 $updateon = $updateoff;
                   2628:                 $updateoff = ' ';
                   2629:             }
                   2630:             if ($settings->{'classlists'} eq '1') {
                   2631:                 $classlistson = $classlistsoff;
                   2632:                 $classlistsoff = ' ';
                   2633:             }
                   2634:         }
                   2635:         my %title = (
                   2636:                    run => 'Auto-update active?',
                   2637:                    classlists => 'Update information in classlists?',
                   2638:                     );
                   2639:         $datatable = '<tr class="LC_odd_row">'. 
                   2640:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2641:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2642:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2643:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2644:                   '<label><input type="radio" name="autoupdate_run"'.
                   2645:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2646:                   '</tr><tr>'.
                   2647:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2648:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2649:                   '<label><input type="radio" name="classlists"'.
                   2650:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2651:                   '<label><input type="radio" name="classlists"'.
                   2652:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2653:                   '</tr>';
1.30      raeburn  2654:         $$rowtotal += 2;
1.131     raeburn  2655:     } elsif ($position eq 'middle') {
                   2656:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2657:         my $numinrow = 3;
                   2658:         my $locknamesettings;
                   2659:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2660:                                      $dom,$numinrow,$othertitle,
                   2661:                                     'lockablenames');
                   2662:         $$rowtotal ++;
1.3       raeburn  2663:     } else {
1.44      raeburn  2664:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2665:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2666:                       'permanentemail','id');
1.33      raeburn  2667:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2668:         my $numrows = 0;
1.26      raeburn  2669:         if (ref($types) eq 'ARRAY') {
                   2670:             if (@{$types} > 0) {
                   2671:                 $datatable = 
                   2672:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2673:                                          \@fields,$types,\$numrows);
1.30      raeburn  2674:                     $$rowtotal += @{$types}; 
1.26      raeburn  2675:             }
1.3       raeburn  2676:         }
                   2677:         $datatable .= 
                   2678:             &usertype_update_row($settings,{'default' => $othertitle},
                   2679:                                  \%fieldtitles,\@fields,['default'],
                   2680:                                  \$numrows);
1.30      raeburn  2681:         $$rowtotal ++;     
1.3       raeburn  2682:     }
                   2683:     return $datatable;
                   2684: }
                   2685: 
1.125     raeburn  2686: sub print_autocreate {
                   2687:     my ($dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  2688:     my (%createon,%createoff,%currhash);
1.125     raeburn  2689:     my @types = ('xml','req');
                   2690:     if (ref($settings) eq 'HASH') {
                   2691:         foreach my $item (@types) {
                   2692:             $createoff{$item} = ' checked="checked" ';
                   2693:             $createon{$item} = ' ';
                   2694:             if (exists($settings->{$item})) {
                   2695:                 if ($settings->{$item}) {
                   2696:                     $createon{$item} = ' checked="checked" ';
                   2697:                     $createoff{$item} = ' ';
                   2698:                 }
                   2699:             }
                   2700:         }
1.160.6.16  raeburn  2701:         if ($settings->{'xmldc'} ne '') {
                   2702:             $currhash{$settings->{'xmldc'}} = 1;
                   2703:         }
1.125     raeburn  2704:     } else {
                   2705:         foreach my $item (@types) {
                   2706:             $createoff{$item} = ' checked="checked" ';
                   2707:             $createon{$item} = ' ';
                   2708:         }
                   2709:     }
                   2710:     $$rowtotal += 2;
1.160.6.16  raeburn  2711:     my $numinrow = 2;
1.125     raeburn  2712:     my $datatable='<tr class="LC_odd_row">'.
                   2713:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2714:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2715:                   '<input type="radio" name="autocreate_xml"'.
                   2716:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2717:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2718:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2719:                   '</td></tr><tr>'.
                   2720:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2721:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2722:                   '<input type="radio" name="autocreate_req"'.
                   2723:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2724:                   '<label><input type="radio" name="autocreate_req"'.
                   2725:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16  raeburn  2726:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2727:                                                    'autocreate_xmldc',%currhash);
1.160.6.50  raeburn  2728:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2729:     if ($numdc > 1) {
1.160.6.50  raeburn  2730:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2731:                       '</td><td class="LC_left_item">';
1.125     raeburn  2732:     } else {
1.160.6.50  raeburn  2733:         $datatable .= &mt('Course creation processed as:').
                   2734:                       '</td><td class="LC_right_item">';
1.125     raeburn  2735:     }
1.160.6.50  raeburn  2736:     $datatable .= $dctable.'</td></tr>';
1.160.6.16  raeburn  2737:     $$rowtotal += $rows;
1.125     raeburn  2738:     return $datatable;
                   2739: }
                   2740: 
1.23      raeburn  2741: sub print_directorysrch {
1.160.6.72  raeburn  2742:     my ($position,$dom,$settings,$rowtotal) = @_;
                   2743:     my $datatable;
                   2744:     if ($position eq 'top') {
                   2745:         my $instsrchon = ' ';
                   2746:         my $instsrchoff = ' checked="checked" ';
                   2747:         my ($exacton,$containson,$beginson);
                   2748:         my $instlocalon = ' ';
                   2749:         my $instlocaloff = ' checked="checked" ';
                   2750:         if (ref($settings) eq 'HASH') {
                   2751:             if ($settings->{'available'} eq '1') {
                   2752:                 $instsrchon = $instsrchoff;
                   2753:                 $instsrchoff = ' ';
                   2754:             }
                   2755:             if ($settings->{'localonly'} eq '1') {
                   2756:                 $instlocalon = $instlocaloff;
                   2757:                 $instlocaloff = ' ';
                   2758:             }
                   2759:             if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2760:                 foreach my $type (@{$settings->{'searchtypes'}}) {
                   2761:                     if ($type eq 'exact') {
                   2762:                         $exacton = ' checked="checked" ';
                   2763:                     } elsif ($type eq 'contains') {
                   2764:                         $containson = ' checked="checked" ';
                   2765:                     } elsif ($type eq 'begins') {
                   2766:                         $beginson = ' checked="checked" ';
                   2767:                     }
                   2768:                 }
                   2769:             } else {
                   2770:                 if ($settings->{'searchtypes'} eq 'exact') {
                   2771:                     $exacton = ' checked="checked" ';
                   2772:                 } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2773:                     $containson = ' checked="checked" ';
                   2774:                 } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25      raeburn  2775:                     $exacton = ' checked="checked" ';
                   2776:                     $containson = ' checked="checked" ';
                   2777:                 }
                   2778:             }
1.23      raeburn  2779:         }
1.160.6.72  raeburn  2780:         my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2781:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2782: 
1.160.6.72  raeburn  2783:         my $numinrow = 4;
                   2784:         my $cansrchrow = 0;
                   2785:         $datatable='<tr class="LC_odd_row">'.
                   2786:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
                   2787:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2788:                    '<input type="radio" name="dirsrch_available"'.
                   2789:                    $instsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2790:                    '<label><input type="radio" name="dirsrch_available"'.
                   2791:                    $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2792:                    '</tr><tr>'.
                   2793:                    '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
                   2794:                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2795:                    '<input type="radio" name="dirsrch_instlocalonly"'.
                   2796:                    $instlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2797:                    '<label><input type="radio" name="dirsrch_instlocalonly"'.
                   2798:                    $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2799:                    '</tr>';
                   2800:         $$rowtotal += 2;
                   2801:         if (ref($usertypes) eq 'HASH') {
                   2802:             if (keys(%{$usertypes}) > 0) {
                   2803:                 $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2804:                                              $numinrow,$othertitle,'cansearch');
                   2805:                 $cansrchrow = 1;
                   2806:             }
1.26      raeburn  2807:         }
1.160.6.72  raeburn  2808:         if ($cansrchrow) {
                   2809:             $$rowtotal ++;
                   2810:             $datatable .= '<tr>';
                   2811:         } else {
                   2812:             $datatable .= '<tr class="LC_odd_row">';
                   2813:         }
                   2814:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2815:                       '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
                   2816:         foreach my $title (@{$titleorder}) {
                   2817:             if (defined($searchtitles->{$title})) {
                   2818:                 my $check = ' ';
                   2819:                 if (ref($settings) eq 'HASH') {
                   2820:                     if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2821:                         if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2822:                             $check = ' checked="checked" ';
                   2823:                         }
1.39      raeburn  2824:                     }
1.25      raeburn  2825:                 }
1.160.6.72  raeburn  2826:                 $datatable .= '<td class="LC_left_item">'.
                   2827:                               '<span class="LC_nobreak"><label>'.
                   2828:                               '<input type="checkbox" name="searchby" '.
                   2829:                               'value="'.$title.'"'.$check.'/>'.
                   2830:                               $searchtitles->{$title}.'</label></span></td>';
1.25      raeburn  2831:             }
                   2832:         }
1.160.6.72  raeburn  2833:         $datatable .= '</tr></table></td></tr>';
                   2834:         $$rowtotal ++;
                   2835:         if ($cansrchrow) {
                   2836:             $datatable .= '<tr class="LC_odd_row">';
                   2837:         } else {
                   2838:             $datatable .= '<tr>';
                   2839:         }
                   2840:         $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
                   2841:                       '<td class="LC_left_item" colspan="2">'.
                   2842:                       '<span class="LC_nobreak"><label>'.
                   2843:                       '<input type="checkbox" name="searchtypes" '.
                   2844:                       $exacton.' value="exact" />'.&mt('Exact match').
                   2845:                       '</label>&nbsp;'.
                   2846:                       '<label><input type="checkbox" name="searchtypes" '.
                   2847:                       $beginson.' value="begins" />'.&mt('Begins with').
                   2848:                       '</label>&nbsp;'.
                   2849:                       '<label><input type="checkbox" name="searchtypes" '.
                   2850:                       $containson.' value="contains" />'.&mt('Contains').
                   2851:                       '</label></span></td></tr>';
                   2852:         $$rowtotal ++;
1.26      raeburn  2853:     } else {
1.160.6.72  raeburn  2854:         my $domsrchon = ' checked="checked" ';
                   2855:         my $domsrchoff = ' ';
                   2856:         my $domlocalon = ' ';
                   2857:         my $domlocaloff = ' checked="checked" ';
                   2858:         if (ref($settings) eq 'HASH') {
                   2859:             if ($settings->{'lclocalonly'} eq '1') {
                   2860:                 $domlocalon = $domlocaloff;
                   2861:                 $domlocaloff = ' ';
                   2862:             }
                   2863:             if ($settings->{'lcavailable'} eq '0') {
                   2864:                 $domsrchoff = $domsrchon;
                   2865:                 $domsrchon = ' ';
                   2866:             }
                   2867:         }
                   2868:         $datatable='<tr class="LC_odd_row">'.
                   2869:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
                   2870:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2871:                       '<input type="radio" name="dirsrch_domavailable"'.
                   2872:                       $domsrchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2873:                       '<label><input type="radio" name="dirsrch_domavailable"'.
                   2874:                       $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2875:                       '</tr><tr>'.
                   2876:                       '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
                   2877:                       '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2878:                       '<input type="radio" name="dirsrch_domlocalonly"'.
                   2879:                       $domlocaloff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2880:                       '<label><input type="radio" name="dirsrch_domlocalonly"'.
                   2881:                       $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
                   2882:                       '</tr>';
                   2883:         $$rowtotal += 2;
1.26      raeburn  2884:     }
1.25      raeburn  2885:     return $datatable;
                   2886: }
                   2887: 
1.28      raeburn  2888: sub print_contacts {
1.160.6.78  raeburn  2889:     my ($position,$dom,$settings,$rowtotal) = @_;
1.28      raeburn  2890:     my $datatable;
                   2891:     my @contacts = ('adminemail','supportemail');
1.160.6.78  raeburn  2892:     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
                   2893:         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);
                   2894:     if ($position eq 'top') {
                   2895:         if (ref($settings) eq 'HASH') {
                   2896:             foreach my $item (@contacts) {
                   2897:                 if (exists($settings->{$item})) {
                   2898:                     $to{$item} = $settings->{$item};
                   2899:                 }
1.28      raeburn  2900:             }
                   2901:         }
1.160.6.78  raeburn  2902:     } elsif ($position eq 'middle') {
                   2903:         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
                   2904:                      'updatesmail','idconflictsmail');
1.28      raeburn  2905:         foreach my $type (@mailings) {
1.160.6.78  raeburn  2906:             $otheremails{$type} = '';
                   2907:         }
                   2908:     } else {
                   2909:         @mailings = ('helpdeskmail','otherdomsmail');
                   2910:         foreach my $type (@mailings) {
                   2911:             $otheremails{$type} = '';
                   2912:         }
                   2913:         $bccemails{'helpdeskmail'} = '';
                   2914:         $bccemails{'otherdomsmail'} = '';
                   2915:         $includestr{'helpdeskmail'} = '';
                   2916:         $includestr{'otherdomsmail'} = '';
                   2917:         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
                   2918:     }
                   2919:     if (ref($settings) eq 'HASH') {
                   2920:         unless ($position eq 'top') {
                   2921:             foreach my $type (@mailings) {
                   2922:                 if (exists($settings->{$type})) {
                   2923:                     if (ref($settings->{$type}) eq 'HASH') {
                   2924:                         foreach my $item (@contacts) {
                   2925:                             if ($settings->{$type}{$item}) {
                   2926:                                 $checked{$type}{$item} = ' checked="checked" ';
                   2927:                             }
1.28      raeburn  2928:                         }
1.160.6.78  raeburn  2929:                         $otheremails{$type} = $settings->{$type}{'others'};
                   2930:                         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   2931:                             $bccemails{$type} = $settings->{$type}{'bcc'};
                   2932:                             if ($settings->{$type}{'include'} ne '') {
                   2933:                                 ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2934:                                 $includestr{$type} = &unescape($includestr{$type});
                   2935:                             }
                   2936:                         }
                   2937:                     }
                   2938:                 } elsif ($type eq 'lonstatusmail') {
                   2939:                     $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2940:                 }
                   2941:             }
                   2942:         }
                   2943:         if ($position eq 'bottom') {
                   2944:             foreach my $type (@mailings) {
                   2945:                 $bccemails{$type} = $settings->{$type}{'bcc'};
                   2946:                 if ($settings->{$type}{'include'} ne '') {
                   2947:                     ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
                   2948:                     $includestr{$type} = &unescape($includestr{$type});
                   2949:                 }
                   2950:             }
                   2951:             if (ref($settings->{'helpform'}) eq 'HASH') {
                   2952:                 if (ref($fields) eq 'ARRAY') {
                   2953:                     foreach my $field (@{$fields}) {
                   2954:                         $currfield{$field} = $settings->{'helpform'}{$field};
1.28      raeburn  2955:                     }
1.160.6.78  raeburn  2956:                 }
                   2957:                 if (exists($settings->{'helpform'}{'maxsize'})) {
                   2958:                     $maxsize = $settings->{'helpform'}{'maxsize'};
                   2959:                 } else {
                   2960:                     $maxsize = '1.0';
                   2961:                 }
                   2962:             } else {
                   2963:                 if (ref($fields) eq 'ARRAY') {
                   2964:                     foreach my $field (@{$fields}) {
                   2965:                         $currfield{$field} = 'yes';
1.134     raeburn  2966:                     }
1.28      raeburn  2967:                 }
1.160.6.78  raeburn  2968:                 $maxsize = '1.0';
1.28      raeburn  2969:             }
                   2970:         }
                   2971:     } else {
1.160.6.78  raeburn  2972:         if ($position eq 'top') {
                   2973:             $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2974:             $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2975:             $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2976:             $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   2977:             $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
                   2978:             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
                   2979:             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
                   2980:             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
                   2981:         } elsif ($position eq 'bottom') {
                   2982:             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2983:             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
                   2984:             if (ref($fields) eq 'ARRAY') {
                   2985:                 foreach my $field (@{$fields}) {
                   2986:                     $currfield{$field} = 'yes';
                   2987:                 }
                   2988:             }
                   2989:             $maxsize = '1.0';
                   2990:         }
1.28      raeburn  2991:     }
                   2992:     my ($titles,$short_titles) = &contact_titles();
                   2993:     my $rownum = 0;
                   2994:     my $css_class;
1.160.6.78  raeburn  2995:     if ($position eq 'top') {
                   2996:         foreach my $item (@contacts) {
                   2997:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   2998:             $datatable .= '<tr'.$css_class.'>'. 
                   2999:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   3000:                           '</span></td><td class="LC_right_item">'.
                   3001:                           '<input type="text" name="'.$item.'" value="'.
                   3002:                           $to{$item}.'" /></td></tr>';
                   3003:             $rownum ++;
                   3004:         }
                   3005:     } else {
                   3006:         foreach my $type (@mailings) {
                   3007:             $css_class = $rownum%2?' class="LC_odd_row"':'';
                   3008:             $datatable .= '<tr'.$css_class.'>'.
                   3009:                           '<td><span class="LC_nobreak">'.
                   3010:                           $titles->{$type}.': </span></td>'.
                   3011:                           '<td class="LC_left_item">';
                   3012:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3013:                 $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
                   3014:             }
                   3015:             $datatable .= '<span class="LC_nobreak">';
                   3016:             foreach my $item (@contacts) {
                   3017:                 $datatable .= '<label>'.
                   3018:                               '<input type="checkbox" name="'.$type.'"'.
                   3019:                               $checked{$type}{$item}.
                   3020:                               ' value="'.$item.'" />'.$short_titles->{$item}.
                   3021:                               '</label>&nbsp;';
                   3022:             }
                   3023:             $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   3024:                           '<input type="text" name="'.$type.'_others" '.
                   3025:                           'value="'.$otheremails{$type}.'"  />';
                   3026:             my %locchecked;
                   3027:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   3028:                 foreach my $loc ('s','b') {
                   3029:                     if ($includeloc{$type} eq $loc) {
                   3030:                         $locchecked{$loc} = ' checked="checked"';
                   3031:                         last;
                   3032:                     }
                   3033:                 }
                   3034:                 $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
                   3035:                               '<input type="text" name="'.$type.'_bcc" '.
                   3036:                               'value="'.$bccemails{$type}.'"  /></fieldset>'.
                   3037:                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                   3038:                               &mt('Text automatically added to e-mail:').' '.
                   3039:                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.
                   3040:                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                   3041:                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                   3042:                               ('&nbsp;'x2).
                   3043:                               '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
                   3044:                               '</span></fieldset>';
                   3045:             }
                   3046:             $datatable .= '</td></tr>'."\n";
                   3047:             $rownum ++;
                   3048:         }
1.28      raeburn  3049:     }
1.160.6.78  raeburn  3050:     if ($position eq 'middle') {
                   3051:         my %choices;
                   3052:         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   3053:                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3054:                                        &mt('LON-CAPA core group - MSU'),600,500));
                   3055:         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   3056:                                         &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   3057:                                         &mt('LON-CAPA core group - MSU'),600,500));
                   3058:         my @toggles = ('reporterrors','reportupdates');
                   3059:         my %defaultchecked = ('reporterrors'  => 'on',
                   3060:                               'reportupdates' => 'on');
                   3061:         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3062:                                                    \%choices,$rownum);
                   3063:         $datatable .= $reports;
                   3064:     } elsif ($position eq 'bottom') {
1.69      raeburn  3065:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  3066:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.78  raeburn  3067:                       '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
                   3068:                       &mt('(e-mail, subject, and description always shown)').
                   3069:                       '</td><td class="LC_left_item">';
                   3070:         if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
                   3071:             (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
                   3072:             $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
                   3073:             foreach my $field (@{$fields}) {
                   3074:                 $datatable .= '<tr><td>'.$fieldtitles->{$field};
                   3075:                 if (($field eq 'screenshot') || ($field eq 'cc')) {
                   3076:                     $datatable .= ' '.&mt('(logged-in users)');
                   3077:                 }
                   3078:                 $datatable .='</td><td>';
                   3079:                 my $clickaction;
                   3080:                 if ($field eq 'screenshot') {
                   3081:                     $clickaction = ' onclick="screenshotSize(this);"';
                   3082:                 }
                   3083:                 if (ref($possoptions->{$field}) eq 'ARRAY') {
                   3084:                     foreach my $option (@{$possoptions->{$field}}) {
                   3085:                         my $checked;
                   3086:                         if ($currfield{$field} eq $option) {
                   3087:                             $checked = ' checked="checked"';
                   3088:                         }
                   3089:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   3090:                                       '<input type="radio" name="helpform_'.$field.'" '.
                   3091:                                       'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
                   3092:                                       '</label></span>'.('&nbsp;'x2);
                   3093:                     }
                   3094:                 }
                   3095:                 if ($field eq 'screenshot') {
                   3096:                     my $display;
                   3097:                     if ($currfield{$field} eq 'no') {
                   3098:                         $display = ' style="display:none"';
                   3099:                     }
                   3100:                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.
                   3101:                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                   3102:                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                   3103:                 }
                   3104:                 $datatable .= '</td></tr>';
                   3105:             }
                   3106:             $datatable .= '</table>';
1.134     raeburn  3107:         }
                   3108:         $datatable .= '</td></tr>'."\n";
1.160.6.23  raeburn  3109:         $rownum ++;
1.28      raeburn  3110:     }
1.30      raeburn  3111:     $$rowtotal += $rownum;
1.28      raeburn  3112:     return $datatable;
                   3113: }
                   3114: 
1.160.6.78  raeburn  3115: sub contacts_javascript {
                   3116:     return <<"ENDSCRIPT";
                   3117: 
                   3118: <script type="text/javascript">
                   3119: // <![CDATA[
                   3120: 
                   3121: function screenshotSize(field) {
                   3122:     if (document.getElementById('help_screenshotsize')) {
                   3123:         if (field.value == 'no') {
                   3124:             document.getElementById('help_screenshotsize').style.display="none";
                   3125:         } else {
                   3126:             document.getElementById('help_screenshotsize').style.display="";
                   3127:         }
                   3128:     }
                   3129:     return;
                   3130: }
                   3131: 
                   3132: // ]]>
                   3133: </script>
                   3134: 
                   3135: ENDSCRIPT
                   3136: }
                   3137: 
1.118     jms      3138: sub print_helpsettings {
1.160.6.73  raeburn  3139:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3140:     my $confname = $dom.'-domainconfig';
1.160.6.77  raeburn  3141:     my $formname = 'display';
1.160.6.5  raeburn  3142:     my ($datatable,$itemcount);
1.160.6.73  raeburn  3143:     if ($position eq 'top') {
                   3144:         $itemcount = 1;
                   3145:         my (%choices,%defaultchecked,@toggles);
                   3146:         $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   3147:                                      &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   3148:                                      &mt('LON-CAPA bug tracker'),600,500));
                   3149:         %defaultchecked = ('submitbugs' => 'on');
                   3150:         @toggles = ('submitbugs');
                   3151:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   3152:                                                      \%choices,$itemcount);
                   3153:         $$rowtotal ++;
                   3154:     } else {
                   3155:         my $css_class;
                   3156:         my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  3157:         my (%customroles,%ordered,%current);
1.160.6.84  raeburn  3158:         if (ref($settings) eq 'HASH') {
                   3159:             if (ref($settings->{'adhoc'}) eq 'HASH') {
                   3160:                 %current = %{$settings->{'adhoc'}};
                   3161:             }
1.160.6.77  raeburn  3162:         }
                   3163:         my $count = 0;
                   3164:         foreach my $key (sort(keys(%existing))) {
1.160.6.73  raeburn  3165:             if ($key=~/^rolesdef\_(\w+)$/) {
                   3166:                 my $rolename = $1;
1.160.6.77  raeburn  3167:                 my (%privs,$order);
1.160.6.73  raeburn  3168:                 ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
                   3169:                 $customroles{$rolename} = \%privs;
1.160.6.77  raeburn  3170:                 if (ref($current{$rolename}) eq 'HASH') {
                   3171:                     $order = $current{$rolename}{'order'};
                   3172:                 }
                   3173:                 if ($order eq '') {
                   3174:                     $order = $count;
                   3175:                 }
                   3176:                 $ordered{$order} = $rolename;
                   3177:                 $count++;
1.160.6.73  raeburn  3178:             }
                   3179:         }
1.160.6.77  raeburn  3180:         my $maxnum = scalar(keys(%ordered));
                   3181:         my @roles_by_num = ();
                   3182:         foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   3183:             push(@roles_by_num,$item);
                   3184:         }
                   3185:         my $context = 'domprefs';
                   3186:         my $crstype = 'Course';
                   3187:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  3188:         my @accesstypes = ('all','dh','da','none');
1.160.6.77  raeburn  3189:         my ($numstatustypes,@jsarray);
                   3190:         if (ref($types) eq 'ARRAY') {
                   3191:             if (@{$types} > 0) {
                   3192:                 $numstatustypes = scalar(@{$types});
                   3193:                 push(@accesstypes,'status');
                   3194:                 @jsarray = ('bystatus');
                   3195:             }
                   3196:         }
1.160.6.79  raeburn  3197:         my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh'.'da']);
1.160.6.77  raeburn  3198:         if (keys(%domhelpdesk)) {
                   3199:             push(@accesstypes,('inc','exc'));
                   3200:             push(@jsarray,('notinc','notexc'));
                   3201:         }
                   3202:         my $hiddenstr = join("','",@jsarray);
                   3203:         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73  raeburn  3204:         my $context = 'domprefs';
                   3205:         my $crstype = 'Course';
1.160.6.77  raeburn  3206:         my $prefix = 'helproles_';
                   3207:         my $add_class = 'LC_hidden';
                   3208:         foreach my $num (@roles_by_num) {
                   3209:             my $role = $ordered{$num};
                   3210:             my ($desc,$access,@statuses);
                   3211:             if (ref($current{$role}) eq 'HASH') {
                   3212:                 $desc = $current{$role}{'desc'};
                   3213:                 $access = $current{$role}{'access'};
                   3214:                 if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
                   3215:                     @statuses = @{$current{$role}{'insttypes'}};
                   3216:                 }
                   3217:             }
                   3218:             if ($desc eq '') {
                   3219:                 $desc = $role;
                   3220:             }
                   3221:             my $identifier = 'custhelp'.$num;
1.160.6.73  raeburn  3222:             my %full=();
                   3223:             my %levels= (
                   3224:                          course => {},
                   3225:                          domain => {},
                   3226:                          system => {},
                   3227:                         );
                   3228:             my %levelscurrent=(
                   3229:                                course => {},
                   3230:                                domain => {},
                   3231:                                system => {},
                   3232:                               );
                   3233:             &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
                   3234:             my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
                   3235:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77  raeburn  3236:             my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
                   3237:             $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
                   3238:                           '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
                   3239:             for (my $k=0; $k<=$maxnum; $k++) {
                   3240:                 my $vpos = $k+1;
                   3241:                 my $selstr;
                   3242:                 if ($k == $num) {
                   3243:                     $selstr = ' selected="selected" ';
                   3244:                 }
                   3245:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3246:             }
                   3247:             $datatable .= '</select>'.('&nbsp;'x2).
                   3248:                           '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
                   3249:                           '</td>'.
                   3250:                           '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3251:                           &mt('Name shown to users:').
                   3252:                           '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
                   3253:                           '</fieldset>'.
                   3254:                           &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
                   3255:                                                 $othertitle,$usertypes,$types,\%domhelpdesk).
                   3256:                           '<fieldset>'.
                   3257:                           '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73  raeburn  3258:                           &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77  raeburn  3259:                                                                    \%levelscurrent,$identifier,
                   3260:                                                                    'LC_hidden',$prefix.$num.'_privs').
                   3261:                           '</fieldset></td>';
1.160.6.73  raeburn  3262:             $itemcount ++;
                   3263:         }
                   3264:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3265:         my $newcust = 'custhelp'.$count;
                   3266:         my (%privs,%levelscurrent);
                   3267:         my %full=();
                   3268:         my %levels= (
                   3269:                      course => {},
                   3270:                      domain => {},
                   3271:                      system => {},
                   3272:                     );
                   3273:         &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
                   3274:         my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77  raeburn  3275:         my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
                   3276:         $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
                   3277:                       '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
                   3278:                       '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
                   3279:         for (my $k=0; $k<$maxnum+1; $k++) {
                   3280:             my $vpos = $k+1;
                   3281:             my $selstr;
                   3282:             if ($k == $maxnum) {
                   3283:                 $selstr = ' selected="selected" ';
                   3284:             }
                   3285:             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3286:         }
                   3287:         $datatable .= '</select>&nbsp;'."\n".
1.160.6.73  raeburn  3288:                       '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
                   3289:                       '</label></span></td>'.
1.160.6.77  raeburn  3290:                       '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
                   3291:                       '<span class="LC_nobreak">'.
                   3292:                       &mt('Internal name:').
                   3293:                       '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
                   3294:                       '</span>'.('&nbsp;'x4).
                   3295:                       '<span class="LC_nobreak">'.
                   3296:                       &mt('Name shown to users:').
                   3297:                       '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
                   3298:                       '</span></fieldset>'.
                   3299:                        &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
                   3300:                                              $usertypes,$types,\%domhelpdesk).
                   3301:                       '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73  raeburn  3302:                       &Apache::lonuserutils::custom_role_header($context,$crstype,
                   3303:                                                                 \@templateroles,$newcust).
                   3304:                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                   3305:                                                                \%levelscurrent,$newcust).
1.160.6.77  raeburn  3306:                       '</fieldset></td></tr>';
1.160.6.73  raeburn  3307:         $count ++;
                   3308:         $$rowtotal += $count;
                   3309:     }
1.160.6.5  raeburn  3310:     return $datatable;
1.121     raeburn  3311: }
                   3312: 
1.160.6.77  raeburn  3313: sub adhocbutton {
                   3314:     my ($prefix,$num,$field,$visibility) = @_;
                   3315:     my %lt = &Apache::lonlocal::texthash(
                   3316:                                           show => 'Show details',
                   3317:                                           hide => 'Hide details',
                   3318:                                         );
                   3319:     return '<span style="text-decoration:line-through; font-weight: normal;">'.('&nbsp;'x10).
                   3320:            '</span>'.('&nbsp;'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
                   3321:            ' value="'.$lt{$visibility}.'" style="height:20px;" '.
                   3322:            'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.('&nbsp;'x2);
                   3323: }
                   3324: 
                   3325: sub helpsettings_javascript {
                   3326:     my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
                   3327:     return unless(ref($roles_by_num) eq 'ARRAY');
                   3328:     my %html_js_lt = &Apache::lonlocal::texthash(
                   3329:                                           show => 'Show details',
                   3330:                                           hide => 'Hide details',
                   3331:                                         );
                   3332:     &html_escape(\%html_js_lt);
                   3333:     my $jstext = '    var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
                   3334:     return <<"ENDSCRIPT";
                   3335: <script type="text/javascript">
                   3336: // <![CDATA[
                   3337: 
                   3338: function reorderHelpRoles(form,item) {
                   3339:     var changedVal;
                   3340: $jstext
                   3341:     var newpos = 'helproles_${total}_pos';
                   3342:     var maxh = 1 + $total;
                   3343:     var current = new Array();
                   3344:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   3345:     if (item == newpos) {
                   3346:         changedVal = newitemVal;
                   3347:     } else {
                   3348:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   3349:         current[newitemVal] = newpos;
                   3350:     }
                   3351:     for (var i=0; i<helproles.length; i++) {
                   3352:         var elementName = 'helproles_'+helproles[i]+'_pos';
                   3353:         if (elementName != item) {
                   3354:             if (form.elements[elementName]) {
                   3355:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   3356:                 current[currVal] = elementName;
                   3357:             }
                   3358:         }
                   3359:     }
                   3360:     var oldVal;
                   3361:     for (var j=0; j<maxh; j++) {
                   3362:         if (current[j] == undefined) {
                   3363:             oldVal = j;
                   3364:         }
                   3365:     }
                   3366:     if (oldVal < changedVal) {
                   3367:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   3368:            var elementName = current[k];
                   3369:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   3370:         }
                   3371:     } else {
                   3372:         for (var k=changedVal; k<oldVal; k++) {
                   3373:             var elementName = current[k];
                   3374:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   3375:         }
                   3376:     }
                   3377:     return;
                   3378: }
                   3379: 
                   3380: function helpdeskAccess(num) {
                   3381:     var curraccess = null;
                   3382:     if (document.$formname.elements['helproles_'+num+'_access'].length) {
                   3383:         for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
                   3384:             if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
                   3385:                 curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
                   3386:             }
                   3387:         }
                   3388:     }
                   3389:     var shown = Array();
                   3390:     var hidden = Array();
                   3391:     if (curraccess == 'none') {
                   3392:         hidden = Array('$hiddenstr');
                   3393:     } else {
                   3394:         if (curraccess == 'status') {
                   3395:             shown = Array('bystatus');
                   3396:             hidden = Array('notinc','notexc');
                   3397:         } else {
                   3398:             if (curraccess == 'exc') {
                   3399:                 shown = Array('notexc');
                   3400:                 hidden = Array('notinc','bystatus');
                   3401:             }
                   3402:             if (curraccess == 'inc') {
                   3403:                 shown = Array('notinc');
                   3404:                 hidden = Array('notexc','bystatus');
                   3405:             }
1.160.6.79  raeburn  3406:             if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77  raeburn  3407:                 hidden = Array('notinc','notexc','bystatus');
                   3408:             }
                   3409:         }
                   3410:     }
                   3411:     if (hidden.length > 0) {
                   3412:         for (var i=0; i<hidden.length; i++) {
                   3413:             if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
                   3414:                 document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
                   3415:             }
                   3416:         }
                   3417:     }
                   3418:     if (shown.length > 0) {
                   3419:         for (var i=0; i<shown.length; i++) {
                   3420:             if (document.getElementById('helproles_'+num+'_'+shown[i])) {
                   3421:                 if (shown[i] == 'privs') {
                   3422:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
                   3423:                 } else {
                   3424:                     document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
                   3425:                 }
                   3426:             }
                   3427:         }
                   3428:     }
                   3429:     return;
                   3430: }
                   3431: 
                   3432: function toggleHelpdeskItem(num,field) {
                   3433:     if (document.getElementById('helproles_'+num+'_'+field)) {
                   3434:         if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
                   3435:             document.getElementById('helproles_'+num+'_'+field).className =
                   3436:                 document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
                   3437:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3438:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
                   3439:             }
                   3440:         } else {
                   3441:             document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
                   3442:             if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
                   3443:                 document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
                   3444:             }
                   3445:         }
                   3446:     }
                   3447:     return;
                   3448: }
                   3449: 
                   3450: // ]]>
                   3451: </script>
                   3452: 
                   3453: ENDSCRIPT
                   3454: }
                   3455: 
                   3456: sub helpdeskroles_access {
                   3457:     my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
                   3458:         $usertypes,$types,$domhelpdesk) = @_;
                   3459:     return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
                   3460:     my %lt = &Apache::lonlocal::texthash(
                   3461:                     'rou'    => 'Role usage',
                   3462:                     'whi'    => 'Which helpdesk personnel may use this role?',
1.160.6.79  raeburn  3463:                     'all'    => 'All with domain helpdesk or helpdesk assistant role',
                   3464:                     'dh'     => 'All with domain helpdesk role',
                   3465:                     'da'     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  3466:                     'none'   => 'None',
                   3467:                     'status' => 'Determined based on institutional status',
                   3468:                     'inc'    => 'Include all, but exclude specific personnel',
                   3469:                     'exc'    => 'Exclude all, but include specific personnel',
                   3470:                   );
                   3471:     my %usecheck = (
                   3472:                      all => ' checked="checked"',
                   3473:                    );
                   3474:     my %displaydiv = (
                   3475:                       status => 'none',
                   3476:                       inc    => 'none',
                   3477:                       exc    => 'none',
                   3478:                       priv   => 'block',
                   3479:                      );
                   3480:     my $output;
                   3481:     if (ref($current) eq 'HASH') {
                   3482:         if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
                   3483:             if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
                   3484:                 $usecheck{$current->{access}} = $usecheck{'all'};
                   3485:                 delete($usecheck{'all'});
                   3486:                 if ($current->{access} =~ /^(status|inc|exc)$/) {
                   3487:                     my $access = $1;
                   3488:                     $displaydiv{$access} = 'inline';
                   3489:                 } elsif ($current->{access} eq 'none') {
                   3490:                     $displaydiv{'priv'} = 'none';
                   3491:                 }
                   3492:             }
                   3493:         }
                   3494:     }
                   3495:     $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
                   3496:               '<p>'.$lt{'whi'}.'</p>';
                   3497:     foreach my $access (@{$accesstypes}) {
                   3498:         $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
                   3499:                    ' onclick="helpdeskAccess('."'$num'".');" />'.
                   3500:                    $lt{$access}.'</label>';
                   3501:         if ($access eq 'status') {
                   3502:             $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
                   3503:                        &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
                   3504:                                                                  $othertitle,$usertypes,$types).
                   3505:                        '</div>';
                   3506:         } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
                   3507:             $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
                   3508:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3509:                        '</div>';
                   3510:         } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
                   3511:             $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
                   3512:                        &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
                   3513:                        '</div>';
                   3514:         }
                   3515:         $output .= '</p>';
                   3516:     }
                   3517:     $output .= '</fieldset>';
                   3518:     return $output;
                   3519: }
                   3520: 
1.121     raeburn  3521: sub radiobutton_prefs {
1.160.6.16  raeburn  3522:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.57  raeburn  3523:         $additional,$align) = @_;
1.121     raeburn  3524:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   3525:                    (ref($choices) eq 'HASH'));
                   3526: 
                   3527:     my (%checkedon,%checkedoff,$datatable,$css_class);
                   3528: 
                   3529:     foreach my $item (@{$toggles}) {
                   3530:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      3531:             $checkedon{$item} = ' checked="checked" ';
                   3532:             $checkedoff{$item} = ' ';
1.121     raeburn  3533:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      3534:             $checkedoff{$item} = ' checked="checked" ';
                   3535:             $checkedon{$item} = ' ';
                   3536:         }
                   3537:     }
                   3538:     if (ref($settings) eq 'HASH') {
1.121     raeburn  3539:         foreach my $item (@{$toggles}) {
1.118     jms      3540:             if ($settings->{$item} eq '1') {
                   3541:                 $checkedon{$item} =  ' checked="checked" ';
                   3542:                 $checkedoff{$item} = ' ';
                   3543:             } elsif ($settings->{$item} eq '0') {
                   3544:                 $checkedoff{$item} =  ' checked="checked" ';
                   3545:                 $checkedon{$item} = ' ';
                   3546:             }
                   3547:         }
1.121     raeburn  3548:     }
1.160.6.16  raeburn  3549:     if ($onclick) {
                   3550:         $onclick = ' onclick="'.$onclick.'"';
                   3551:     }
1.121     raeburn  3552:     foreach my $item (@{$toggles}) {
1.118     jms      3553:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  3554:         $datatable .=
1.160.6.16  raeburn  3555:             '<tr'.$css_class.'><td valign="top">'.
                   3556:             '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57  raeburn  3557:             '</span></td>';
                   3558:         if ($align eq 'left') {
                   3559:             $datatable .= '<td class="LC_left_item">';
                   3560:         } else {
                   3561:             $datatable .= '<td class="LC_right_item">';
                   3562:         }
                   3563:         $datatable .=
                   3564:             '<span class="LC_nobreak">'.
1.118     jms      3565:             '<label><input type="radio" name="'.
1.160.6.16  raeburn  3566:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      3567:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.160.6.16  raeburn  3568:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   3569:             '</span>'.$additional.
                   3570:             '</td>'.
1.118     jms      3571:             '</tr>';
                   3572:         $itemcount ++;
1.121     raeburn  3573:     }
                   3574:     return ($datatable,$itemcount);
                   3575: }
                   3576: 
1.160.6.84.2.  (raeburn 3577:): sub print_ltitools {
                   3578:):     my ($dom,$settings,$rowtotal) = @_;
                   3579:):     my $rownum = 0;
                   3580:):     my $css_class;
                   3581:):     my $itemcount = 1;
                   3582:):     my $maxnum = 0;
                   3583:):     my %ordered;
                   3584:):     if (ref($settings) eq 'HASH') {
                   3585:):         foreach my $item (keys(%{$settings})) {
                   3586:):             if (ref($settings->{$item}) eq 'HASH') {
                   3587:):                 my $num = $settings->{$item}{'order'};
                   3588:):                 $ordered{$num} = $item;
                   3589:):             }
                   3590:):         }
                   3591:):     }
                   3592:):     my $confname = $dom.'-domainconfig';
                   3593:):     my $switchserver = &check_switchserver($dom,$confname);
                   3594:):     my $maxnum = scalar(keys(%ordered));
                   3595:):     my $datatable = &ltitools_javascript($settings);
                   3596:):     my %lt = &ltitools_names();
                   3597:):     my @courseroles = ('cc','in','ta','ep','st');
                   3598:):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   3599:):     my @fields = ('fullname','firstname','lastname','email','user','roles');
                   3600:):     if (keys(%ordered)) {
                   3601:):         my @items = sort { $a <=> $b } keys(%ordered);
                   3602:):         for (my $i=0; $i<@items; $i++) {
                   3603:):             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3604:):             my $item = $ordered{$items[$i]};
                   3605:):             my ($title,$key,$secret,$url,$imgsrc,$version);
                   3606:):             if (ref($settings->{$item}) eq 'HASH') {
                   3607:):                 $title = $settings->{$item}->{'title'};
                   3608:):                 $url = $settings->{$item}->{'url'};
                   3609:):                 $key = $settings->{$item}->{'key'};
                   3610:):                 $secret = $settings->{$item}->{'secret'};
                   3611:):                 my $image = $settings->{$item}->{'image'};
                   3612:):                 if ($image ne '') {
                   3613:):                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   3614:):                 }
                   3615:):             }
                   3616:):             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
                   3617:):             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3618:):                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   3619:):             for (my $k=0; $k<=$maxnum; $k++) {
                   3620:):                 my $vpos = $k+1;
                   3621:):                 my $selstr;
                   3622:):                 if ($k == $i) {
                   3623:):                     $selstr = ' selected="selected" ';
                   3624:):                 }
                   3625:):                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3626:):             }
                   3627:):             $datatable .= '</select>'.('&nbsp;'x2).
                   3628:):                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   3629:):                 &mt('Delete?').'</label></span></td>'.
                   3630:):                 '<td colspan="2">'.
                   3631:):                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3632:):                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
                   3633:):                 ('&nbsp;'x2).
                   3634:):                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   3635:):                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   3636:):                 ('&nbsp;'x2).
                   3637:):                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   3638:):                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3639:):                 '<br /><br />'.
                   3640:):                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
                   3641:):                 ' value="'.$url.'" /></span>'.
                   3642:):                 ('&nbsp;'x2).
                   3643:):                 '<span class="LC_nobreak">'.$lt{'key'}.
                   3644:):                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   3645:):                 ('&nbsp;'x2).
                   3646:):                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   3647:):                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   3648:):                 '<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>'.
                   3649:):                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   3650:):                 '</fieldset>'.
                   3651:):                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3652:):                 '<span class="LC_nobreak">'.&mt('Display target:');
                   3653:):             my %currdisp;
                   3654:):             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   3655:):                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   3656:):                     $currdisp{'window'} = ' checked="checked"';
                   3657:):                 } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
                   3658:):                     $currdisp{'tab'} = ' checked="checked"';
                   3659:):                 } else {
                   3660:):                     $currdisp{'iframe'} = ' checked="checked"';
                   3661:):                 }
                   3662:):                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   3663:):                     $currdisp{'width'} = $1;
                   3664:):                 }
                   3665:):                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   3666:):                      $currdisp{'height'} = $1;
                   3667:):                 }
                   3668:):                 $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
                   3669:):                 $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
                   3670:):             } else {
                   3671:):                 $currdisp{'iframe'} = ' checked="checked"';
                   3672:):             }
                   3673:):             foreach my $disp ('iframe','tab','window') {
                   3674:):                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   3675:):                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3676:):             }
                   3677:):             $datatable .= ('&nbsp;'x4);
                   3678:):             foreach my $dimen ('width','height') {
                   3679:):                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3680:):                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   3681:):                               ('&nbsp;'x2);
                   3682:):             }
                   3683:):             $datatable .= '<br />'.
                   3684:):                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   3685:):                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.
                   3686:):                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   3687:):                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                   3688:):                           '</textarea></div><div style=""></div><br />';
                   3689:):             $datatable .= '<br />';
                   3690:):             foreach my $extra ('passback','roster') {
                   3691:):                 my $checkedon = '';
                   3692:):                 my $checkedoff = ' checked="checked"';
                   3693:):                 if ($settings->{$item}->{$extra}) {
                   3694:):                     $checkedon = $checkedoff;
                   3695:):                     $checkedoff = '';
                   3696:):                 }
                   3697:):                 $datatable .= $lt{$extra}.'&nbsp;'.
                   3698:):                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
                   3699:):                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   3700:):                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
                   3701:):                               &mt('No').'</label>'.('&nbsp;'x4);
                   3702:):             }
                   3703:):             $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   3704:):             if ($imgsrc) {
                   3705:):                 $datatable .= $imgsrc.
                   3706:):                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   3707:):                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   3708:):                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   3709:):             } else {
                   3710:):                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3711:):             }
                   3712:):             if ($switchserver) {
                   3713:):                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3714:):             } else {
                   3715:):                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   3716:):             }
                   3717:):             $datatable .= '</span></fieldset>';
                   3718:):             my (%checkedfields,%rolemaps);
                   3719:):             if (ref($settings->{$item}) eq 'HASH') {
                   3720:):                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   3721:):                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   3722:):                 }
                   3723:):                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   3724:):                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   3725:):                     $checkedfields{'roles'} = 1;
                   3726:):                 }
                   3727:):             }
                   3728:):             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3729:):                           '<span class="LC_nobreak">';
                   3730:):             foreach my $field (@fields) {
                   3731:):                 my $checked;
                   3732:):                 if ($checkedfields{$field}) {
                   3733:):                     $checked = ' checked="checked"';
                   3734:):                 }
                   3735:):                 $datatable .= '<label>'.
                   3736:):                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
                   3737:):                               $lt{$field}.'</label>'.('&nbsp;' x2);
                   3738:):             }
                   3739:):             $datatable .= '</span></fieldset>'.
                   3740:):                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3741:):             foreach my $role (@courseroles) {
                   3742:):                 my ($selected,$selectnone);
                   3743:):                 if (!$rolemaps{$role}) {
                   3744:):                     $selectnone = ' selected="selected"';
                   3745:):                 }
                   3746:):                 $datatable .= '<td align="center">'.
                   3747:):                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3748:):                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   3749:):                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   3750:):                 foreach my $ltirole (@ltiroles) {
                   3751:):                     unless ($selectnone) {
                   3752:):                         if ($rolemaps{$role} eq $ltirole) {
                   3753:):                             $selected = ' selected="selected"';
                   3754:):                         } else {
                   3755:):                             $selected = '';
                   3756:):                         }
                   3757:):                     }
                   3758:):                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   3759:):                 }
                   3760:):                 $datatable .= '</select></td>';
                   3761:):             }
                   3762:):             $datatable .= '</tr></table></fieldset>';
                   3763:):             my %courseconfig;
                   3764:):             if (ref($settings->{$item}) eq 'HASH') {
                   3765:):                 if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
                   3766:):                     %courseconfig = %{$settings->{$item}->{'crsconf'}};
                   3767:):                 }
                   3768:):             }
                   3769:):             $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   3770:):             foreach my $item ('label','title','target','linktext','explanation') {
                   3771:):                 my $checked;
                   3772:):                 if ($courseconfig{$item}) {
                   3773:):                     $checked = ' checked="checked"';
                   3774:):                 }
                   3775:):                 $datatable .= '<label>'.
                   3776:):                        '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
                   3777:):                        $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   3778:):             }
                   3779:):             $datatable .= '</span></fieldset>'.
                   3780:):                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3781:):                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   3782:):             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   3783:):                 my %custom = %{$settings->{$item}->{'custom'}};
                   3784:):                 if (keys(%custom) > 0) {
                   3785:):                     foreach my $key (sort(keys(%custom))) {
                   3786:):                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3787:):                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   3788:):                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   3789:):                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   3790:):                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   3791:):                     }
                   3792:):                 }
                   3793:):             }
                   3794:):             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3795:):                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   3796:):                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   3797:):                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   3798:):             $datatable .= '</table></fieldset></td></tr>'."\n";
                   3799:):             $itemcount ++;
                   3800:):         }
                   3801:):     }
                   3802:):     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3803:):     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
                   3804:):     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   3805:):                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   3806:):                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   3807:):     for (my $k=0; $k<$maxnum+1; $k++) {
                   3808:):         my $vpos = $k+1;
                   3809:):         my $selstr;
                   3810:):         if ($k == $maxnum) {
                   3811:):             $selstr = ' selected="selected" ';
                   3812:):         }
                   3813:):         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3814:):     }
                   3815:):     $datatable .= '</select>&nbsp;'."\n".
                   3816:):                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
                   3817:):                   '<td colspan="2">'.
                   3818:):                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3819:):                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
                   3820:):                   ('&nbsp;'x2).
                   3821:):                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   3822:):                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   3823:):                   ('&nbsp;'x2).
                   3824:):                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   3825:):                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3826:):                   '<br />'.
                   3827:):                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
                   3828:):                   ('&nbsp;'x2).
                   3829:):                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   3830:):                   ('&nbsp;'x2).
                   3831:):                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   3832:):                   '<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".
                   3833:):                   '</fieldset>'.
                   3834:):                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3835:):                   '<span class="LC_nobreak">'.&mt('Display target:');
                   3836:):     my %defaultdisp;
                   3837:):     $defaultdisp{'iframe'} = ' checked="checked"';
                   3838:):     foreach my $disp ('iframe','tab','window') {
                   3839:):         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   3840:):                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3841:):     }
                   3842:):     $datatable .= ('&nbsp;'x4);
                   3843:):     foreach my $dimen ('width','height') {
                   3844:):         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3845:):                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   3846:):                       ('&nbsp;'x2);
                   3847:):     }
                   3848:):     $datatable .= '<br />'.
                   3849:):                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   3850:):                   '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.
                   3851:):                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   3852:):                   '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.
                   3853:):                   '</div><div style=""></div><br />';
                   3854:):     foreach my $extra ('passback','roster') {
                   3855:):         $datatable .= $lt{$extra}.'&nbsp;'.
                   3856:):                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
                   3857:):                       &mt('Yes').'</label>'.('&nbsp;'x2).
                   3858:):                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
                   3859:):                       &mt('No').'</label>'.('&nbsp;'x4);
                   3860:):     }
                   3861:):     $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
                   3862:):                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3863:):     if ($switchserver) {
                   3864:):         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3865:):     } else {
                   3866:):         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   3867:):     }
                   3868:):     $datatable .= '</span></fieldset>'.
                   3869:):                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3870:):                   '<span class="LC_nobreak">';
                   3871:):     foreach my $field (@fields) {
                   3872:):         $datatable .= '<label>'.
                   3873:):                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
                   3874:):                       $lt{$field}.'</label>'.('&nbsp;' x2);
                   3875:):     }
                   3876:):     $datatable .= '</span></fieldset>'.
                   3877:):                   '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3878:):     foreach my $role (@courseroles) {
                   3879:):         my ($checked,$checkednone);
                   3880:):         $datatable .= '<td align="center">'.
                   3881:):                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3882:):                       '<select name="ltitools_add_roles_'.$role.'">'.
                   3883:):                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   3884:):         foreach my $ltirole (@ltiroles) {
                   3885:):             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   3886:):         }
                   3887:):         $datatable .= '</select></td>';
                   3888:):     }
                   3889:):     $datatable .= '</tr></table></fieldset>'.
                   3890:):                   '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
                   3891:):     foreach my $item ('label','title','target','linktext','explanation') {
                   3892:):         $datatable .= '<label>'.
                   3893:):                       '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
                   3894:):                       $lt{'crs'.$item}.'</label>'.('&nbsp;' x2)."\n";
                   3895:):     }
                   3896:):     $datatable .= '</span></fieldset>'.
                   3897:):                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3898:):                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   3899:):                   '<tr><td><span class="LC_nobreak">'.
                   3900:):                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   3901:):                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   3902:):                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   3903:):                   '</table></fieldset></td></tr>'."\n".
                   3904:):                   '</td>'."\n".
                   3905:):                   '</tr>'."\n";
                   3906:):     $itemcount ++;
                   3907:):     return $datatable;
                   3908:): }
                   3909:): 
                   3910:): sub ltitools_names {
                   3911:):     my %lt = &Apache::lonlocal::texthash(
                   3912:):                                           'title'          => 'Title',
                   3913:):                                           'version'        => 'Version',
                   3914:):                                           'msgtype'        => 'Message Type',
                   3915:):                                           'url'            => 'URL',
                   3916:):                                           'key'            => 'Key',
                   3917:):                                           'secret'         => 'Secret',
                   3918:):                                           'icon'           => 'Icon',
                   3919:):                                           'user'           => 'Username:domain',
                   3920:):                                           'fullname'       => 'Full Name',
                   3921:):                                           'firstname'      => 'First Name',
                   3922:):                                           'lastname'       => 'Last Name',
                   3923:):                                           'email'          => 'E-mail',
                   3924:):                                           'roles'          => 'Role',
                   3925:):                                           'window'         => 'Window',
                   3926:):                                           'tab'            => 'Tab',
                   3927:):                                           'iframe'         => 'iFrame',
                   3928:):                                           'height'         => 'Height',
                   3929:):                                           'width'          => 'Width',
                   3930:):                                           'linktext'       => 'Default Link Text',
                   3931:):                                           'explanation'    => 'Default Explanation',
                   3932:):                                           'passback'       => 'Tool can return grades:',
                   3933:):                                           'roster'         => 'Tool can retrieve roster:',
                   3934:):                                           'crstarget'      => 'Display target',
                   3935:):                                           'crslabel'       => 'Course label',
                   3936:):                                           'crstitle'       => 'Course title',
                   3937:):                                           'crslinktext'    => 'Link Text',
                   3938:):                                           'crsexplanation' => 'Explanation',
                   3939:):                                         );
                   3940:): 
                   3941:):     return %lt;
                   3942:): }
                   3943:): 
1.121     raeburn  3944: sub print_coursedefaults {
1.139     raeburn  3945:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16  raeburn  3946:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  3947:     my $itemcount = 1;
1.160.6.16  raeburn  3948:     my %choices =  &Apache::lonlocal::texthash (
1.160.6.21  raeburn  3949:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16  raeburn  3950:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   3951:         coursecredits        => 'Credits can be specified for courses',
1.160.6.57  raeburn  3952:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   3953:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
                   3954:         postsubmit           => 'Disable submit button/keypress following student submission',
1.160.6.64  raeburn  3955:         canclone             => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70  raeburn  3956:         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.16  raeburn  3957:     );
1.160.6.21  raeburn  3958:     my %staticdefaults = (
                   3959:                            anonsurvey_threshold => 10,
                   3960:                            uploadquota          => 500,
1.160.6.57  raeburn  3961:                            postsubmit           => 60,
1.160.6.70  raeburn  3962:                            mysqltables          => 172800,
1.160.6.21  raeburn  3963:                          );
1.139     raeburn  3964:     if ($position eq 'top') {
1.160.6.57  raeburn  3965:         %defaultchecked = (
                   3966:                             'uselcmath'       => 'on',
                   3967:                             'usejsme'         => 'on',
1.160.6.64  raeburn  3968:                             'canclone'        => 'none',
1.160.6.57  raeburn  3969:                           );
                   3970:         @toggles = ('uselcmath','usejsme');
1.139     raeburn  3971:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  3972:                                                      \%choices,$itemcount);
1.160.6.64  raeburn  3973:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3974:         $datatable .=
                   3975:             '<tr'.$css_class.'><td valign="top">'.
                   3976:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   3977:             '</span></td><td class="LC_left_item">';
                   3978:         my $currcanclone = 'none';
                   3979:         my $onclick;
                   3980:         my @cloneoptions = ('none','domain');
                   3981:         my %clonetitles = (
                   3982:                              none     => 'No additional course requesters',
                   3983:                              domain   => "Any course requester in course's domain",
                   3984:                              instcode => 'Course requests for official courses ...',
                   3985:                           );
                   3986:         my (%codedefaults,@code_order,@posscodes);
                   3987:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   3988:                                                     \@code_order) eq 'ok') {
                   3989:             if (@code_order > 0) {
                   3990:                 push(@cloneoptions,'instcode');
                   3991:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   3992:             }
                   3993:         }
                   3994:         if (ref($settings) eq 'HASH') {
                   3995:             if ($settings->{'canclone'}) {
                   3996:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   3997:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   3998:                         if (@code_order > 0) {
                   3999:                             $currcanclone = 'instcode';
                   4000:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   4001:                         }
                   4002:                     }
                   4003:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   4004:                     $currcanclone = $settings->{'canclone'};
                   4005:                 }
                   4006:             }
                   4007:         }
                   4008:         foreach my $option (@cloneoptions) {
                   4009:             my ($checked,$additional);
                   4010:             if ($currcanclone eq $option) {
                   4011:                 $checked = ' checked="checked"';
                   4012:             }
                   4013:             if ($option eq 'instcode') {
                   4014:                 if (@code_order) {
                   4015:                     my $show = 'none';
                   4016:                     if ($checked) {
                   4017:                         $show = 'block';
                   4018:                     }
                   4019:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   4020:                                   &mt('Institutional codes for new and cloned course have identical:').
                   4021:                                   '<br />';
                   4022:                     foreach my $item (@code_order) {
                   4023:                         my $codechk;
                   4024:                         if ($checked) {
                   4025:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   4026:                                 $codechk = ' checked="checked"';
                   4027:                             }
                   4028:                         }
                   4029:                         $additional .= '<label>'.
                   4030:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   4031:                                        $item.'</label>';
                   4032:                     }
                   4033:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   4034:                 }
                   4035:             }
                   4036:             $datatable .=
                   4037:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   4038:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   4039:                 '</label>&nbsp;'.$additional.'</span><br />';
                   4040:         }
                   4041:         $datatable .= '</td>'.
                   4042:                       '</tr>';
                   4043:         $itemcount ++;
1.139     raeburn  4044:     } else {
                   4045:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71  raeburn  4046:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16  raeburn  4047:         my $currusecredits = 0;
1.160.6.57  raeburn  4048:         my $postsubmitclient = 1;
1.160.6.30  raeburn  4049:         my @types = ('official','unofficial','community','textbook');
1.139     raeburn  4050:         if (ref($settings) eq 'HASH') {
                   4051:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21  raeburn  4052:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   4053:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   4054:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   4055:                 }
                   4056:             }
1.160.6.16  raeburn  4057:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  4058:                 foreach my $type (@types) {
                   4059:                     next if ($type eq 'community');
                   4060:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   4061:                     if ($defcredits{$type} ne '') {
                   4062:                         $currusecredits = 1;
                   4063:                     }
                   4064:                 }
                   4065:             }
                   4066:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   4067:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   4068:                     $postsubmitclient = 0;
                   4069:                     foreach my $type (@types) {
                   4070:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4071:                     }
                   4072:                 } else {
                   4073:                     foreach my $type (@types) {
                   4074:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   4075:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   4076:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
                   4077:                             } else {
                   4078:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4079:                             }
                   4080:                         } else {
                   4081:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4082:                         }
                   4083:                     }
                   4084:                 }
                   4085:             } else {
                   4086:                 foreach my $type (@types) {
                   4087:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16  raeburn  4088:                 }
                   4089:             }
1.160.6.70  raeburn  4090:             if (ref($settings->{'mysqltables'}) eq 'HASH') {
                   4091:                 foreach my $type (keys(%{$settings->{'mysqltables'}})) {
                   4092:                     $currmysql{$type} = $settings->{'mysqltables'}{$type};
                   4093:                 }
                   4094:             } else {
                   4095:                 foreach my $type (@types) {
                   4096:                     $currmysql{$type} = $staticdefaults{'mysqltables'};
                   4097:                 }
                   4098:             }
1.160.6.58  raeburn  4099:         } else {
                   4100:             foreach my $type (@types) {
                   4101:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   4102:             }
1.139     raeburn  4103:         }
                   4104:         if (!$currdefresponder) {
1.160.6.21  raeburn  4105:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  4106:         } elsif ($currdefresponder < 1) {
                   4107:             $currdefresponder = 1;
                   4108:         }
1.160.6.21  raeburn  4109:         foreach my $type (@types) {
                   4110:             if ($curruploadquota{$type} eq '') {
                   4111:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   4112:             }
                   4113:         }
1.139     raeburn  4114:         $datatable .=
1.160.6.16  raeburn  4115:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4116:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  4117:                 '</span></td>'.
                   4118:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   4119:                 '<input type="text" name="anonsurvey_threshold"'.
                   4120:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37  raeburn  4121:                 '</td></tr>'."\n";
                   4122:         $itemcount ++;
                   4123:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4124:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4125:                       $choices{'uploadquota'}.
                   4126:                       '</span></td>'.
                   4127:                       '<td align="right" class="LC_right_item">'.
                   4128:                       '<table><tr>';
1.160.6.21  raeburn  4129:         foreach my $type (@types) {
                   4130:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4131:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   4132:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   4133:         }
                   4134:         $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37  raeburn  4135:         $itemcount ++;
1.160.6.40  raeburn  4136:         my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16  raeburn  4137:         my $display = 'none';
                   4138:         if ($currusecredits) {
                   4139:             $display = 'block';
                   4140:         }
                   4141:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57  raeburn  4142:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   4143:         foreach my $type (@types) {
                   4144:             next if ($type eq 'community');
                   4145:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4146:                            '<input type="text" name="'.$type.'_credits"'.
                   4147:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
                   4148:         }
                   4149:         $additional .= '</tr></table></div>'."\n";
1.160.6.16  raeburn  4150:         %defaultchecked = ('coursecredits' => 'off');
                   4151:         @toggles = ('coursecredits');
                   4152:         my $current = {
                   4153:                         'coursecredits' => $currusecredits,
                   4154:                       };
                   4155:         (my $table,$itemcount) =
                   4156:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57  raeburn  4157:                                \%choices,$itemcount,$onclick,$additional,'left');
                   4158:         $datatable .= $table;
                   4159:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   4160:         my $display = 'none';
                   4161:         if ($postsubmitclient) {
                   4162:             $display = 'block';
                   4163:         }
                   4164:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59  raeburn  4165:                       &mt('Number of seconds submit is disabled').'<br />'.
                   4166:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   4167:                       '<table><tr>';
1.160.6.57  raeburn  4168:         foreach my $type (@types) {
                   4169:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   4170:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   4171:                            $deftimeout{$type}.'" size="5" /></td>';
                   4172:         }
                   4173:         $additional .= '</tr></table></div>'."\n";
                   4174:         %defaultchecked = ('postsubmit' => 'on');
                   4175:         @toggles = ('postsubmit');
1.160.6.70  raeburn  4176:         $current = {
                   4177:                        'postsubmit' => $postsubmitclient,
                   4178:                    };
1.160.6.57  raeburn  4179:         ($table,$itemcount) =
                   4180:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   4181:                                \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16  raeburn  4182:         $datatable .= $table;
1.160.6.70  raeburn  4183:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4184:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4185:                       $choices{'mysqltables'}.
                   4186:                       '</span></td>'.
                   4187:                       '<td align="right" class="LC_right_item">'.
                   4188:                       '<table><tr>';
                   4189:         foreach my $type (@types) {
                   4190:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   4191:                            '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81  raeburn  4192:                            ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70  raeburn  4193:         }
                   4194:         $datatable .= '</tr></table></td></tr>'."\n";
                   4195:         $itemcount ++;
                   4196: 
1.160.6.37  raeburn  4197:     }
                   4198:     $$rowtotal += $itemcount;
                   4199:     return $datatable;
                   4200: }
                   4201: 
                   4202: sub print_selfenrollment {
                   4203:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4204:     my ($css_class,$datatable);
                   4205:     my $itemcount = 1;
                   4206:     my @types = ('official','unofficial','community','textbook');
                   4207:     if (($position eq 'top') || ($position eq 'middle')) {
                   4208:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   4209:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   4210:         my @rows;
                   4211:         my $key;
                   4212:         if ($position eq 'top') {
                   4213:             $key = 'admin'; 
                   4214:             if (ref($rowsref) eq 'ARRAY') {
                   4215:                 @rows = @{$rowsref};
                   4216:             }
                   4217:         } elsif ($position eq 'middle') {
                   4218:             $key = 'default';
                   4219:             @rows = ('types','registered','approval','limit');
                   4220:         }
                   4221:         foreach my $row (@rows) {
                   4222:             if (defined($titlesref->{$row})) {
                   4223:                 $itemcount ++;
                   4224:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4225:                 $datatable .= '<tr'.$css_class.'>'.
                   4226:                               '<td>'.$titlesref->{$row}.'</td>'.
                   4227:                               '<td class="LC_left_item">'.
                   4228:                               '<table><tr>';
                   4229:                 my (%current,%currentcap);
                   4230:                 if (ref($settings) eq 'HASH') {
                   4231:                     if (ref($settings->{$key}) eq 'HASH') {
                   4232:                         foreach my $type (@types) {
                   4233:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4234:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   4235:                             }
                   4236:                             if (($row eq 'limit') && ($key eq 'default')) {
                   4237:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   4238:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   4239:                                 }
                   4240:                             }
                   4241:                         }
                   4242:                     }
                   4243:                 }
                   4244:                 my %roles = (
                   4245:                              '0' => &Apache::lonnet::plaintext('dc'),
                   4246:                             ); 
                   4247:             
                   4248:                 foreach my $type (@types) {
                   4249:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   4250:                         $datatable .= '<th>'.&mt($type).'</th>';
                   4251:                     }
                   4252:                 }
                   4253:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   4254:                     $datatable .= '</tr><tr>';
                   4255:                 }
                   4256:                 foreach my $type (@types) {
                   4257:                     if ($type eq 'community') {
                   4258:                         $roles{'1'} = &mt('Community personnel');
                   4259:                     } else {
                   4260:                         $roles{'1'} = &mt('Course personnel');
                   4261:                     }
                   4262:                     $datatable .= '<td style="vertical-align: top">';
                   4263:                     if ($position eq 'top') {
                   4264:                         my %checked;
                   4265:                         if ($current{$type} eq '0') {
                   4266:                             $checked{'0'} = ' checked="checked"';
                   4267:                         } else {
                   4268:                             $checked{'1'} = ' checked="checked"';
                   4269:                         }
                   4270:                         foreach my $role ('1','0') {
                   4271:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   4272:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   4273:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   4274:                                           $roles{$role}.'</label></span> ';
                   4275:                         }
                   4276:                     } else {
                   4277:                         if ($row eq 'types') {
                   4278:                             my %checked;
                   4279:                             if ($current{$type} =~ /^(all|dom)$/) {
                   4280:                                 $checked{$1} = ' checked="checked"';
                   4281:                             } else {
                   4282:                                 $checked{''} = ' checked="checked"';
                   4283:                             }
                   4284:                             foreach my $val ('','dom','all') {
                   4285:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4286:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4287:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4288:                             }
                   4289:                         } elsif ($row eq 'registered') {
                   4290:                             my %checked;
                   4291:                             if ($current{$type} eq '1') {
                   4292:                                 $checked{'1'} = ' checked="checked"';
                   4293:                             } else {
                   4294:                                 $checked{'0'} = ' checked="checked"';
                   4295:                             }
                   4296:                             foreach my $val ('0','1') {
                   4297:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4298:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4299:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4300:                             }
                   4301:                         } elsif ($row eq 'approval') {
                   4302:                             my %checked;
                   4303:                             if ($current{$type} =~ /^([12])$/) {
                   4304:                                 $checked{$1} = ' checked="checked"';
                   4305:                             } else {
                   4306:                                 $checked{'0'} = ' checked="checked"';
                   4307:                             }
                   4308:                             for my $val (0..2) {
                   4309:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4310:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4311:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4312:                             }
                   4313:                         } elsif ($row eq 'limit') {
                   4314:                             my %checked;
                   4315:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   4316:                                 $checked{$1} = ' checked="checked"';
                   4317:                             } else {
                   4318:                                 $checked{'none'} = ' checked="checked"';
                   4319:                             }
                   4320:                             my $cap;
                   4321:                             if ($currentcap{$type} =~ /^\d+$/) {
                   4322:                                 $cap = $currentcap{$type};
                   4323:                             }
                   4324:                             foreach my $val ('none','allstudents','selfenrolled') {
                   4325:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4326:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   4327:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   4328:                             }
                   4329:                             $datatable .= '<br />'.
                   4330:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   4331:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   4332:                                           '</span>'; 
                   4333:                         }
                   4334:                     }
                   4335:                     $datatable .= '</td>';
                   4336:                 }
                   4337:                 $datatable .= '</tr>';
                   4338:             }
                   4339:             $datatable .= '</table></td></tr>';
                   4340:         }
                   4341:     } elsif ($position eq 'bottom') {
1.160.6.39  raeburn  4342:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   4343:     }
                   4344:     $$rowtotal += $itemcount;
                   4345:     return $datatable;
                   4346: }
                   4347: 
                   4348: sub print_validation_rows {
                   4349:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   4350:     my ($itemsref,$namesref,$fieldsref);
                   4351:     if ($caller eq 'selfenroll') { 
                   4352:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   4353:     } elsif ($caller eq 'requestcourses') {
                   4354:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   4355:     }
                   4356:     my %currvalidation;
                   4357:     if (ref($settings) eq 'HASH') {
                   4358:         if (ref($settings->{'validation'}) eq 'HASH') {
                   4359:             %currvalidation = %{$settings->{'validation'}};
1.160.6.37  raeburn  4360:         }
1.160.6.39  raeburn  4361:     }
                   4362:     my $datatable;
                   4363:     my $itemcount = 0;
                   4364:     foreach my $item (@{$itemsref}) {
                   4365:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4366:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   4367:                       $namesref->{$item}.
                   4368:                       '</span></td>'.
                   4369:                       '<td class="LC_left_item">';
                   4370:         if (($item eq 'url') || ($item eq 'button')) {
                   4371:             $datatable .= '<span class="LC_nobreak">'.
                   4372:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   4373:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   4374:         } elsif ($item eq 'fields') {
                   4375:             my @currfields;
                   4376:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   4377:                 @currfields = @{$currvalidation{$item}};
                   4378:             }
                   4379:             foreach my $field (@{$fieldsref}) {
                   4380:                 my $check = '';
                   4381:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   4382:                     $check = ' checked="checked"';
                   4383:                 }
                   4384:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   4385:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   4386:                               ' value="'.$field.'"'.$check.' />'.$field.
                   4387:                               '</label></span> ';
                   4388:             }
                   4389:         } elsif ($item eq 'markup') {
                   4390:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
                   4391:                            $currvalidation{$item}.
1.160.6.37  raeburn  4392:                               '</textarea>';
1.160.6.39  raeburn  4393:         }
                   4394:         $datatable .= '</td></tr>'."\n";
                   4395:         if (ref($rowtotal)) {
1.160.6.37  raeburn  4396:             $itemcount ++;
                   4397:         }
1.139     raeburn  4398:     }
1.160.6.39  raeburn  4399:     if ($caller eq 'requestcourses') {
                   4400:         my %currhash;
1.160.6.51  raeburn  4401:         if (ref($settings) eq 'HASH') {
                   4402:             if (ref($settings->{'validation'}) eq 'HASH') {
                   4403:                 if ($settings->{'validation'}{'dc'} ne '') {
                   4404:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   4405:                 }
1.160.6.39  raeburn  4406:             }
                   4407:         }
                   4408:         my $numinrow = 2;
                   4409:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   4410:                                                        'validationdc',%currhash);
1.160.6.50  raeburn  4411:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4412:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.160.6.39  raeburn  4413:         if ($numdc > 1) {
1.160.6.50  raeburn  4414:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39  raeburn  4415:         } else {
1.160.6.50  raeburn  4416:             $datatable .=  &mt('Course creation processed as: ');
1.160.6.39  raeburn  4417:         }
1.160.6.50  raeburn  4418:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39  raeburn  4419:         $itemcount ++;
                   4420:     }
                   4421:     if (ref($rowtotal)) {
                   4422:         $$rowtotal += $itemcount;
                   4423:     }
1.121     raeburn  4424:     return $datatable;
1.118     jms      4425: }
                   4426: 
1.137     raeburn  4427: sub print_usersessions {
                   4428:     my ($position,$dom,$settings,$rowtotal) = @_;
                   4429:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  4430:     my (%by_ip,%by_location,@intdoms);
                   4431:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  4432: 
                   4433:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  4434:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  4435:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  4436:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  4437:     my $itemcount = 1;
                   4438:     if ($position eq 'top') {
1.152     raeburn  4439:         if (keys(%serverhomes) > 1) {
1.145     raeburn  4440:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.160.6.61  raeburn  4441:             my $curroffloadnow;
                   4442:             if (ref($settings) eq 'HASH') {
                   4443:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   4444:                     $curroffloadnow = $settings->{'offloadnow'};
                   4445:                 }
                   4446:             }
                   4447:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  4448:         } else {
1.140     raeburn  4449:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4450:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  4451:         }
1.137     raeburn  4452:     } else {
1.145     raeburn  4453:         if (keys(%by_location) == 0) {
                   4454:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  4455:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  4456:         } else {
                   4457:             my %lt = &usersession_titles();
                   4458:             my $numinrow = 5;
                   4459:             my $prefix;
                   4460:             my @types;
                   4461:             if ($position eq 'bottom') {
                   4462:                 $prefix = 'remote';
                   4463:                 @types = ('version','excludedomain','includedomain');
                   4464:             } else {
                   4465:                 $prefix = 'hosted';
                   4466:                 @types = ('excludedomain','includedomain');
                   4467:             }
                   4468:             my (%current,%checkedon,%checkedoff);
                   4469:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   4470:             my @locations = sort(keys(%by_location));
                   4471:             foreach my $type (@types) {
                   4472:                 $checkedon{$type} = '';
                   4473:                 $checkedoff{$type} = ' checked="checked"';
                   4474:             }
                   4475:             if (ref($settings) eq 'HASH') {
                   4476:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   4477:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   4478:                         $current{$key} = $settings->{$prefix}{$key};
                   4479:                         if ($key eq 'version') {
                   4480:                             if ($current{$key} ne '') {
                   4481:                                 $checkedon{$key} = ' checked="checked"';
                   4482:                                 $checkedoff{$key} = '';
                   4483:                             }
                   4484:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   4485:                             $checkedon{$key} = ' checked="checked"';
                   4486:                             $checkedoff{$key} = '';
                   4487:                         }
1.137     raeburn  4488:                     }
                   4489:                 }
                   4490:             }
1.145     raeburn  4491:             foreach my $type (@types) {
                   4492:                 next if ($type ne 'version' && !@locations);
                   4493:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4494:                 $datatable .= '<tr'.$css_class.'>
                   4495:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   4496:                                <span class="LC_nobreak">&nbsp;
                   4497:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   4498:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   4499:                 if ($type eq 'version') {
                   4500:                     my $selector = '<select name="'.$prefix.'_version">';
                   4501:                     foreach my $version (@lcversions) {
                   4502:                         my $selected = '';
                   4503:                         if ($current{'version'} eq $version) {
                   4504:                             $selected = ' selected="selected"';
                   4505:                         }
                   4506:                         $selector .= ' <option value="'.$version.'"'.
                   4507:                                      $selected.'>'.$version.'</option>';
                   4508:                     }
                   4509:                     $selector .= '</select> ';
                   4510:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   4511:                 } else {
                   4512:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   4513:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   4514:                                  ' />'.('&nbsp;'x2).
                   4515:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   4516:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   4517:                                  "\n".
                   4518:                                  '</div><div><table>';
                   4519:                     my $rem;
                   4520:                     for (my $i=0; $i<@locations; $i++) {
                   4521:                         my ($showloc,$value,$checkedtype);
                   4522:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   4523:                             my $ip = $by_location{$locations[$i]}->[0];
                   4524:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   4525:                                  $value = join(':',@{$by_ip{$ip}});
                   4526:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   4527:                                 if (ref($current{$type}) eq 'ARRAY') {
                   4528:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   4529:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   4530:                                             $checkedtype = ' checked="checked"';
                   4531:                                             last;
                   4532:                                         }
                   4533:                                     }
1.138     raeburn  4534:                                 }
                   4535:                             }
                   4536:                         }
1.145     raeburn  4537:                         $rem = $i%($numinrow);
                   4538:                         if ($rem == 0) {
                   4539:                             if ($i > 0) {
                   4540:                                 $datatable .= '</tr>';
                   4541:                             }
                   4542:                             $datatable .= '<tr>';
                   4543:                         }
                   4544:                         $datatable .= '<td class="LC_left_item">'.
                   4545:                                       '<span class="LC_nobreak"><label>'.
                   4546:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   4547:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   4548:                                       '</label></span></td>';
1.137     raeburn  4549:                     }
1.145     raeburn  4550:                     $rem = @locations%($numinrow);
                   4551:                     my $colsleft = $numinrow - $rem;
                   4552:                     if ($colsleft > 1 ) {
                   4553:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4554:                                       '&nbsp;</td>';
                   4555:                     } elsif ($colsleft == 1) {
                   4556:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  4557:                     }
1.145     raeburn  4558:                     $datatable .= '</tr></table>';
1.137     raeburn  4559:                 }
1.145     raeburn  4560:                 $datatable .= '</td></tr>';
                   4561:                 $itemcount ++;
1.137     raeburn  4562:             }
                   4563:         }
                   4564:     }
                   4565:     $$rowtotal += $itemcount;
                   4566:     return $datatable;
                   4567: }
                   4568: 
1.138     raeburn  4569: sub build_location_hashes {
                   4570:     my ($intdoms,$by_ip,$by_location) = @_;
                   4571:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   4572:                   (ref($by_location) eq 'HASH')); 
                   4573:     my %iphost = &Apache::lonnet::get_iphost();
                   4574:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   4575:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   4576:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   4577:         foreach my $id (@{$iphost{$primary_ip}}) {
                   4578:             my $intdom = &Apache::lonnet::internet_dom($id);
                   4579:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   4580:                 push(@{$intdoms},$intdom);
                   4581:             }
                   4582:         }
                   4583:     }
                   4584:     foreach my $ip (keys(%iphost)) {
                   4585:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   4586:             foreach my $id (@{$iphost{$ip}}) {
                   4587:                 my $location = &Apache::lonnet::internet_dom($id);
                   4588:                 if ($location) {
                   4589:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   4590:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4591:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   4592:                             push(@{$by_ip->{$ip}},$location);
                   4593:                         }
                   4594:                     } else {
                   4595:                         $by_ip->{$ip} = [$location];
                   4596:                     }
                   4597:                 }
                   4598:             }
                   4599:         }
                   4600:     }
                   4601:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   4602:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   4603:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   4604:             my $first = $by_ip->{$ip}->[0];
                   4605:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   4606:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   4607:                     push(@{$by_location->{$first}},$ip);
                   4608:                 }
                   4609:             } else {
                   4610:                 $by_location->{$first} = [$ip];
                   4611:             }
                   4612:         }
                   4613:     }
                   4614:     return;
                   4615: }
                   4616: 
1.145     raeburn  4617: sub current_offloads_to {
                   4618:     my ($dom,$settings,$servers) = @_;
                   4619:     my (%spareid,%otherdomconfigs);
1.152     raeburn  4620:     if (ref($servers) eq 'HASH') {
1.145     raeburn  4621:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   4622:             my $gotspares;
1.152     raeburn  4623:             if (ref($settings) eq 'HASH') {
                   4624:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   4625:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   4626:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   4627:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   4628:                         $gotspares = 1;
                   4629:                     }
1.145     raeburn  4630:                 }
                   4631:             }
                   4632:             unless ($gotspares) {
                   4633:                 my $gotspares;
                   4634:                 my $serverhomeID =
                   4635:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   4636:                 my $serverhomedom =
                   4637:                     &Apache::lonnet::host_domain($serverhomeID);
                   4638:                 if ($serverhomedom ne $dom) {
                   4639:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   4640:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4641:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4642:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4643:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4644:                                 $gotspares = 1;
                   4645:                             }
                   4646:                         }
                   4647:                     } else {
                   4648:                         $otherdomconfigs{$serverhomedom} =
                   4649:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   4650:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   4651:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   4652:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   4653:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   4654:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   4655:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   4656:                                         $gotspares = 1;
                   4657:                                     }
                   4658:                                 }
                   4659:                             }
                   4660:                         }
                   4661:                     }
                   4662:                 }
                   4663:             }
                   4664:             unless ($gotspares) {
                   4665:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4666:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4667:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4668:                } else {
                   4669:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   4670:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   4671:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4672:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4673:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4674:                     } else {
1.150     raeburn  4675:                         my %what = (
                   4676:                              spareid => 1,
                   4677:                         );
                   4678:                         my ($result,$returnhash) = 
                   4679:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   4680:                         if ($result eq 'ok') { 
                   4681:                             if (ref($returnhash) eq 'HASH') {
                   4682:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   4683:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   4684:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   4685:                                 }
                   4686:                             }
1.145     raeburn  4687:                         }
                   4688:                     }
                   4689:                 }
                   4690:             }
                   4691:         }
                   4692:     }
                   4693:     return %spareid;
                   4694: }
                   4695: 
                   4696: sub spares_row {
1.160.6.61  raeburn  4697:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  4698:     my $css_class;
                   4699:     my $numinrow = 4;
                   4700:     my $itemcount = 1;
                   4701:     my $datatable;
1.152     raeburn  4702:     my %typetitles = &sparestype_titles();
                   4703:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  4704:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  4705:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   4706:             my ($othercontrol,$serverdom);
                   4707:             if ($serverhome ne $server) {
                   4708:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   4709:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4710:             } else {
                   4711:                 $serverdom = &Apache::lonnet::host_domain($server);
                   4712:                 if ($serverdom ne $dom) {
                   4713:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4714:                 }
                   4715:             }
                   4716:             next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.61  raeburn  4717:             my $checkednow;
                   4718:             if (ref($curroffloadnow) eq 'HASH') {
                   4719:                 if ($curroffloadnow->{$server}) {
                   4720:                     $checkednow = ' checked="checked"';
                   4721:                 }
                   4722:             }
1.145     raeburn  4723:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4724:             $datatable .= '<tr'.$css_class.'>
                   4725:                            <td rowspan="2">
1.160.6.13  raeburn  4726:                             <span class="LC_nobreak">'.
                   4727:                           &mt('[_1] when busy, offloads to:'
1.160.6.61  raeburn  4728:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   4729:                           '<span class="LC_nobreak">'."\n".
                   4730:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   4731:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.160.6.13  raeburn  4732:                           "\n";
1.145     raeburn  4733:             my (%current,%canselect);
1.152     raeburn  4734:             my @choices = 
                   4735:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   4736:             foreach my $type ('primary','default') {
                   4737:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  4738:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   4739:                         my @spares = @{$spareid->{$server}{$type}};
                   4740:                         if (@spares > 0) {
1.152     raeburn  4741:                             if ($othercontrol) {
                   4742:                                 $current{$type} = join(', ',@spares);
                   4743:                             } else {
                   4744:                                 $current{$type} .= '<table>';
                   4745:                                 my $numspares = scalar(@spares);
                   4746:                                 for (my $i=0;  $i<@spares; $i++) {
                   4747:                                     my $rem = $i%($numinrow);
                   4748:                                     if ($rem == 0) {
                   4749:                                         if ($i > 0) {
                   4750:                                             $current{$type} .= '</tr>';
                   4751:                                         }
                   4752:                                         $current{$type} .= '<tr>';
1.145     raeburn  4753:                                     }
1.152     raeburn  4754:                                     $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;'.
                   4755:                                                        $spareid->{$server}{$type}[$i].
                   4756:                                                        '</label></td>'."\n";
                   4757:                                 }
                   4758:                                 my $rem = @spares%($numinrow);
                   4759:                                 my $colsleft = $numinrow - $rem;
                   4760:                                 if ($colsleft > 1 ) {
                   4761:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   4762:                                                        '" class="LC_left_item">'.
                   4763:                                                        '&nbsp;</td>';
                   4764:                                 } elsif ($colsleft == 1) {
                   4765:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  4766:                                 }
1.152     raeburn  4767:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  4768:                             }
1.145     raeburn  4769:                         }
                   4770:                     }
                   4771:                     if ($current{$type} eq '') {
                   4772:                         $current{$type} = &mt('None specified');
                   4773:                     }
1.152     raeburn  4774:                     if ($othercontrol) {
                   4775:                         if ($type eq 'primary') {
                   4776:                             $canselect{$type} = $othercontrol;
                   4777:                         }
                   4778:                     } else {
                   4779:                         $canselect{$type} = 
                   4780:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   4781:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   4782:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   4783:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   4784:                         if (@choices > 0) {
                   4785:                             foreach my $lonhost (@choices) {
                   4786:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   4787:                             }
                   4788:                         }
                   4789:                         $canselect{$type} .= '</select>'."\n";
                   4790:                     }
                   4791:                 } else {
                   4792:                     $current{$type} = &mt('Could not be determined');
                   4793:                     if ($type eq 'primary') {
                   4794:                         $canselect{$type} =  $othercontrol;
                   4795:                     }
1.145     raeburn  4796:                 }
1.152     raeburn  4797:                 if ($type eq 'default') {
                   4798:                     $datatable .= '<tr'.$css_class.'>';
                   4799:                 }
                   4800:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   4801:                               '<td>'.$current{$type}.'</td>'."\n".
                   4802:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  4803:             }
                   4804:             $itemcount ++;
                   4805:         }
                   4806:     }
                   4807:     $$rowtotal += $itemcount;
                   4808:     return $datatable;
                   4809: }
                   4810: 
1.152     raeburn  4811: sub possible_newspares {
                   4812:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   4813:     my $serverhostname = &Apache::lonnet::hostname($server);
                   4814:     my %excluded;
                   4815:     if ($serverhostname ne '') {
                   4816:         %excluded = (
                   4817:                        $serverhostname => 1,
                   4818:                     );
                   4819:     }
                   4820:     if (ref($currspares) eq 'HASH') {
                   4821:         foreach my $type (keys(%{$currspares})) {
                   4822:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   4823:                 if (@{$currspares->{$type}} > 0) {
                   4824:                     foreach my $curr (@{$currspares->{$type}}) {
                   4825:                         my $hostname = &Apache::lonnet::hostname($curr);
                   4826:                         $excluded{$hostname} = 1;
                   4827:                     }
                   4828:                 }
                   4829:             }
                   4830:         }
                   4831:     }
                   4832:     my @choices;
                   4833:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   4834:         if (keys(%{$serverhomes}) > 1) {
                   4835:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   4836:                 unless ($excluded{$name}) {
                   4837:                     if (exists($altids->{$serverhomes->{$name}})) {
                   4838:                         push(@choices,$altids->{$serverhomes->{$name}});
                   4839:                     } else {
                   4840:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  4841:                     }
                   4842:                 }
                   4843:             }
                   4844:         }
                   4845:     }
1.152     raeburn  4846:     return sort(@choices);
1.145     raeburn  4847: }
                   4848: 
1.150     raeburn  4849: sub print_loadbalancing {
                   4850:     my ($dom,$settings,$rowtotal) = @_;
                   4851:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4852:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4853:     my $numinrow = 1;
                   4854:     my $datatable;
                   4855:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.7  raeburn  4856:     my (%currbalancer,%currtargets,%currrules,%existing);
                   4857:     if (ref($settings) eq 'HASH') {
                   4858:         %existing = %{$settings};
                   4859:     }
                   4860:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   4861:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   4862:                                   \%currtargets,\%currrules);
1.150     raeburn  4863:     } else {
                   4864:         return;
                   4865:     }
                   4866:     my ($othertitle,$usertypes,$types) =
                   4867:         &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26  raeburn  4868:     my $rownum = 8;
1.150     raeburn  4869:     if (ref($types) eq 'ARRAY') {
                   4870:         $rownum += scalar(@{$types});
                   4871:     }
1.160.6.7  raeburn  4872:     my @css_class = ('LC_odd_row','LC_even_row');
                   4873:     my $balnum = 0;
                   4874:     my $islast;
                   4875:     my (@toshow,$disabledtext);
                   4876:     if (keys(%currbalancer) > 0) {
                   4877:         @toshow = sort(keys(%currbalancer));
                   4878:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   4879:             push(@toshow,'');
                   4880:         }
                   4881:     } else {
                   4882:         @toshow = ('');
                   4883:         $disabledtext = &mt('No existing load balancer');
                   4884:     }
                   4885:     foreach my $lonhost (@toshow) {
                   4886:         if ($balnum == scalar(@toshow)-1) {
                   4887:             $islast = 1;
                   4888:         } else {
                   4889:             $islast = 0;
                   4890:         }
                   4891:         my $cssidx = $balnum%2;
                   4892:         my $targets_div_style = 'display: none';
                   4893:         my $disabled_div_style = 'display: block';
                   4894:         my $homedom_div_style = 'display: none';
                   4895:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   4896:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   4897:                       '<p>';
                   4898:         if ($lonhost eq '') {
                   4899:             $datatable .= '<span class="LC_nobreak">';
                   4900:             if (keys(%currbalancer) > 0) {
                   4901:                 $datatable .= &mt('Add balancer:');
                   4902:             } else {
                   4903:                 $datatable .= &mt('Enable balancer:');
                   4904:             }
                   4905:             $datatable .= '&nbsp;'.
                   4906:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   4907:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   4908:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   4909:                           '<option value="" selected="selected">'.&mt('None').
                   4910:                           '</option>'."\n";
                   4911:             foreach my $server (sort(keys(%servers))) {
                   4912:                 next if ($currbalancer{$server});
                   4913:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   4914:             }
                   4915:             $datatable .=
                   4916:                 '</select>'."\n".
                   4917:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   4918:         } else {
                   4919:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   4920:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   4921:                            &mt('Stop balancing').'</label>'.
                   4922:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   4923:             $targets_div_style = 'display: block';
                   4924:             $disabled_div_style = 'display: none';
                   4925:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   4926:                 $homedom_div_style = 'display: block';
                   4927:             }
                   4928:         }
                   4929:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   4930:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   4931:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   4932:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   4933:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   4934:         my @sparestypes = ('primary','default');
                   4935:         my %typetitles = &sparestype_titles();
1.160.6.76  raeburn  4936:         my %hostherechecked = (
                   4937:                                   no => ' checked="checked"',
                   4938:                               );
1.160.6.7  raeburn  4939:         foreach my $sparetype (@sparestypes) {
                   4940:             my $targettable;
                   4941:             for (my $i=0; $i<$numspares; $i++) {
                   4942:                 my $checked;
                   4943:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4944:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4945:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4946:                             $checked = ' checked="checked"';
                   4947:                         }
                   4948:                     }
                   4949:                 }
                   4950:                 my ($chkboxval,$disabled);
                   4951:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   4952:                     $chkboxval = $spares[$i];
                   4953:                 }
                   4954:                 if (exists($currbalancer{$spares[$i]})) {
                   4955:                     $disabled = ' disabled="disabled"';
                   4956:                 }
                   4957:                 $targettable .=
1.160.6.55  raeburn  4958:                     '<td><span class="LC_nobreak"><label>'.
                   4959:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7  raeburn  4960:                     $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  4961:                     '</span></label></span></td>';
1.160.6.7  raeburn  4962:                 my $rem = $i%($numinrow);
                   4963:                 if ($rem == 0) {
                   4964:                     if (($i > 0) && ($i < $numspares-1)) {
                   4965:                         $targettable .= '</tr>';
                   4966:                     }
                   4967:                     if ($i < $numspares-1) {
                   4968:                         $targettable .= '<tr>';
1.150     raeburn  4969:                     }
                   4970:                 }
                   4971:             }
1.160.6.7  raeburn  4972:             if ($targettable ne '') {
                   4973:                 my $rem = $numspares%($numinrow);
                   4974:                 my $colsleft = $numinrow - $rem;
                   4975:                 if ($colsleft > 1 ) {
                   4976:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4977:                                     '&nbsp;</td>';
                   4978:                 } elsif ($colsleft == 1) {
                   4979:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   4980:                 }
                   4981:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   4982:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   4983:             }
1.160.6.76  raeburn  4984:             $hostherechecked{$sparetype} = '';
                   4985:             if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4986:                 if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4987:                     if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4988:                         $hostherechecked{$sparetype} = ' checked="checked"';
                   4989:                         $hostherechecked{'no'} = '';
                   4990:                     }
                   4991:                 }
                   4992:             }
                   4993:         }
                   4994:         $datatable .= &mt('Hosting on balancer itself').'<br />'.
                   4995:                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                   4996:                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
                   4997:         foreach my $sparetype (@sparestypes) {
                   4998:             $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
                   4999:                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                   5000:                           '</i></label><br />';
1.160.6.7  raeburn  5001:         }
                   5002:         $datatable .= '</div></td></tr>'.
                   5003:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   5004:                                            $othertitle,$usertypes,$types,\%servers,
                   5005:                                            \%currbalancer,$lonhost,
                   5006:                                            $targets_div_style,$homedom_div_style,
                   5007:                                            $css_class[$cssidx],$balnum,$islast);
                   5008:         $$rowtotal += $rownum;
                   5009:         $balnum ++;
                   5010:     }
                   5011:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   5012:     return $datatable;
                   5013: }
                   5014: 
                   5015: sub get_loadbalancers_config {
                   5016:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   5017:     return unless ((ref($servers) eq 'HASH') &&
                   5018:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   5019:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   5020:     if (keys(%{$existing}) > 0) {
                   5021:         my $oldlonhost;
                   5022:         foreach my $key (sort(keys(%{$existing}))) {
                   5023:             if ($key eq 'lonhost') {
                   5024:                 $oldlonhost = $existing->{'lonhost'};
                   5025:                 $currbalancer->{$oldlonhost} = 1;
                   5026:             } elsif ($key eq 'targets') {
                   5027:                 if ($oldlonhost) {
                   5028:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   5029:                 }
                   5030:             } elsif ($key eq 'rules') {
                   5031:                 if ($oldlonhost) {
                   5032:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   5033:                 }
                   5034:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   5035:                 $currbalancer->{$key} = 1;
                   5036:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   5037:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  5038:             }
                   5039:         }
1.160.6.7  raeburn  5040:     } else {
                   5041:         my ($balancerref,$targetsref) =
                   5042:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   5043:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   5044:             foreach my $server (sort(keys(%{$balancerref}))) {
                   5045:                 $currbalancer->{$server} = 1;
                   5046:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  5047:             }
                   5048:         }
                   5049:     }
1.160.6.7  raeburn  5050:     return;
1.150     raeburn  5051: }
                   5052: 
                   5053: sub loadbalancing_rules {
                   5054:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7  raeburn  5055:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   5056:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  5057:     my $output;
1.160.6.7  raeburn  5058:     my $num = 0;
                   5059:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  5060:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   5061:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   5062:         foreach my $type (@{$alltypes}) {
1.160.6.7  raeburn  5063:             $num ++;
1.150     raeburn  5064:             my $current;
                   5065:             if (ref($currrules) eq 'HASH') {
                   5066:                 $current = $currrules->{$type};
                   5067:             }
1.160.6.55  raeburn  5068:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7  raeburn  5069:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  5070:                     $current = '';
                   5071:                 }
                   5072:             }
                   5073:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7  raeburn  5074:                                              $servers,$currbalancer,$lonhost,$dom,
                   5075:                                              $targets_div_style,$homedom_div_style,
                   5076:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  5077:         }
                   5078:     }
                   5079:     return $output;
                   5080: }
                   5081: 
                   5082: sub loadbalancing_titles {
                   5083:     my ($dom,$intdom,$usertypes,$types) = @_;
                   5084:     my %othertypes = (
                   5085:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   5086:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   5087:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   5088:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.160.6.26  raeburn  5089:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   5090:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  5091:                      );
1.160.6.26  raeburn  5092:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150     raeburn  5093:     if (ref($types) eq 'ARRAY') {
                   5094:         unshift(@alltypes,@{$types},'default');
                   5095:     }
                   5096:     my %titles;
                   5097:     foreach my $type (@alltypes) {
                   5098:         if ($type =~ /^_LC_/) {
                   5099:             $titles{$type} = $othertypes{$type};
                   5100:         } elsif ($type eq 'default') {
                   5101:             $titles{$type} = &mt('All users from [_1]',$dom);
                   5102:             if (ref($types) eq 'ARRAY') {
                   5103:                 if (@{$types} > 0) {
                   5104:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   5105:                 }
                   5106:             }
                   5107:         } elsif (ref($usertypes) eq 'HASH') {
                   5108:             $titles{$type} = $usertypes->{$type};
                   5109:         }
                   5110:     }
                   5111:     return (\@alltypes,\%othertypes,\%titles);
                   5112: }
                   5113: 
                   5114: sub loadbalance_rule_row {
1.160.6.7  raeburn  5115:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   5116:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26  raeburn  5117:     my @rulenames;
1.150     raeburn  5118:     my %ruletitles = &offloadtype_text();
1.160.6.26  raeburn  5119:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55  raeburn  5120:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  5121:     } else {
1.160.6.26  raeburn  5122:         @rulenames = ('default','homeserver');
                   5123:         if ($type eq '_LC_external') {
                   5124:             push(@rulenames,'externalbalancer');
                   5125:         } else {
                   5126:             push(@rulenames,'specific');
                   5127:         }
                   5128:         push(@rulenames,'none');
1.150     raeburn  5129:     }
                   5130:     my $style = $targets_div_style;
1.160.6.55  raeburn  5131:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  5132:         $style = $homedom_div_style;
                   5133:     }
1.160.6.7  raeburn  5134:     my $space;
                   5135:     if ($islast && $num == 1) {
                   5136:         $space = '<div display="inline-block">&nbsp;</div>';
                   5137:     }
                   5138:     my $output =
                   5139:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   5140:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   5141:         '<td valaign="top">'.$space.
                   5142:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  5143:     for (my $i=0; $i<@rulenames; $i++) {
                   5144:         my $rule = $rulenames[$i];
                   5145:         my ($checked,$extra);
                   5146:         if ($rulenames[$i] eq 'default') {
                   5147:             $rule = '';
                   5148:         }
                   5149:         if ($rulenames[$i] eq 'specific') {
                   5150:             if (ref($servers) eq 'HASH') {
                   5151:                 my $default;
                   5152:                 if (($current ne '') && (exists($servers->{$current}))) {
                   5153:                     $checked = ' checked="checked"';
                   5154:                 }
                   5155:                 unless ($checked) {
                   5156:                     $default = ' selected="selected"';
                   5157:                 }
1.160.6.7  raeburn  5158:                 $extra =
                   5159:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5160:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   5161:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   5162:                     '<option value=""'.$default.'></option>'."\n";
                   5163:                 foreach my $server (sort(keys(%{$servers}))) {
                   5164:                     if (ref($currbalancer) eq 'HASH') {
                   5165:                         next if (exists($currbalancer->{$server}));
                   5166:                     }
1.150     raeburn  5167:                     my $selected;
1.160.6.7  raeburn  5168:                     if ($server eq $current) {
1.150     raeburn  5169:                         $selected = ' selected="selected"';
                   5170:                     }
1.160.6.7  raeburn  5171:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  5172:                 }
                   5173:                 $extra .= '</select>';
                   5174:             }
                   5175:         } elsif ($rule eq $current) {
                   5176:             $checked = ' checked="checked"';
                   5177:         }
                   5178:         $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7  raeburn  5179:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   5180:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   5181:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55  raeburn  5182:                    ')"'.$checked.' />&nbsp;';
1.160.6.56  raeburn  5183:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55  raeburn  5184:             $output .= $ruletitles{'particular'};
                   5185:         } else {
                   5186:             $output .= $ruletitles{$rulenames[$i]};
                   5187:         }
                   5188:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  5189:     }
                   5190:     $output .= '</div></td></tr>'."\n";
                   5191:     return $output;
                   5192: }
                   5193: 
                   5194: sub offloadtype_text {
                   5195:     my %ruletitles = &Apache::lonlocal::texthash (
                   5196:            'default'          => 'Offloads to default destinations',
                   5197:            'homeserver'       => "Offloads to user's home server",
                   5198:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   5199:            'specific'         => 'Offloads to specific server',
1.160.6.3  raeburn  5200:            'none'             => 'No offload',
1.160.6.26  raeburn  5201:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   5202:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.160.6.55  raeburn  5203:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  5204:     );
                   5205:     return %ruletitles;
                   5206: }
                   5207: 
                   5208: sub sparestype_titles {
                   5209:     my %typestitles = &Apache::lonlocal::texthash (
                   5210:                           'primary' => 'primary',
                   5211:                           'default' => 'default',
                   5212:                       );
                   5213:     return %typestitles;
                   5214: }
                   5215: 
1.28      raeburn  5216: sub contact_titles {
                   5217:     my %titles = &Apache::lonlocal::texthash (
1.160.6.78  raeburn  5218:                    'supportemail'    => 'Support E-mail address',
                   5219:                    'adminemail'      => 'Default Server Admin E-mail address',
                   5220:                    'errormail'       => 'Error reports to be e-mailed to',
                   5221:                    'packagesmail'    => 'Package update alerts to be e-mailed to',
                   5222:                    'helpdeskmail'    => "Helpdesk requests for this domain's users",
                   5223:                    'otherdomsmail'   => 'Helpdesk requests for other (unconfigured) domains',
                   5224:                    'lonstatusmail'   => 'E-mail from nightly status check (warnings/errors)',
                   5225:                    'requestsmail'    => 'E-mail from course requests requiring approval',
                   5226:                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23  raeburn  5227:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  5228:                  );
                   5229:     my %short_titles = &Apache::lonlocal::texthash (
                   5230:                            adminemail   => 'Admin E-mail address',
                   5231:                            supportemail => 'Support E-mail',
                   5232:                        );   
                   5233:     return (\%titles,\%short_titles);
                   5234: }
                   5235: 
1.160.6.78  raeburn  5236: sub helpform_fields {
                   5237:     my %titles =  &Apache::lonlocal::texthash (
                   5238:                        'username'   => 'Name',
                   5239:                        'user'       => 'Username/domain',
                   5240:                        'phone'      => 'Phone',
                   5241:                        'cc'         => 'Cc e-mail',
                   5242:                        'course'     => 'Course Details',
                   5243:                        'section'    => 'Sections',
                   5244:                        'screenshot' => 'File upload',
                   5245:     );
                   5246:     my @fields = ('username','phone','user','course','section','cc','screenshot');
                   5247:     my %possoptions = (
                   5248:                         username     => ['yes','no','req'],
                   5249:                         phone        => ['yes','no','req'],
                   5250:                         user         => ['yes','no'],
                   5251:                         cc           => ['yes','no'],
                   5252:                         course       => ['yes','no'],
                   5253:                         section      => ['yes','no'],
                   5254:                         screenshot   => ['yes','no'],
                   5255:                       );
                   5256:     my %fieldoptions = &Apache::lonlocal::texthash (
                   5257:                          'yes'  => 'Optional',
                   5258:                          'req'  => 'Required',
                   5259:                          'no'   => "Not shown",
                   5260:     );
                   5261:     return (\@fields,\%titles,\%fieldoptions,\%possoptions);
                   5262: }
                   5263: 
1.72      raeburn  5264: sub tool_titles {
                   5265:     my %titles = &Apache::lonlocal::texthash (
1.160.6.4  raeburn  5266:                      aboutme    => 'Personal web page',
1.86      raeburn  5267:                      blog       => 'Blog',
1.160.6.4  raeburn  5268:                      webdav     => 'WebDAV',
1.86      raeburn  5269:                      portfolio  => 'Portfolio',
1.88      bisitz   5270:                      official   => 'Official courses (with institutional codes)',
                   5271:                      unofficial => 'Unofficial courses',
1.98      raeburn  5272:                      community  => 'Communities',
1.160.6.30  raeburn  5273:                      textbook   => 'Textbook courses',
1.86      raeburn  5274:                  );
1.72      raeburn  5275:     return %titles;
                   5276: }
                   5277: 
1.101     raeburn  5278: sub courserequest_titles {
                   5279:     my %titles = &Apache::lonlocal::texthash (
                   5280:                                    official   => 'Official',
                   5281:                                    unofficial => 'Unofficial',
                   5282:                                    community  => 'Communities',
1.160.6.30  raeburn  5283:                                    textbook   => 'Textbook',
1.101     raeburn  5284:                                    norequest  => 'Not allowed',
1.104     raeburn  5285:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  5286:                                    validate   => 'With validation',
                   5287:                                    autolimit  => 'Numerical limit',
1.103     raeburn  5288:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  5289:                  );
                   5290:     return %titles;
                   5291: }
                   5292: 
1.160.6.5  raeburn  5293: sub authorrequest_titles {
                   5294:     my %titles = &Apache::lonlocal::texthash (
                   5295:                                    norequest  => 'Not allowed',
                   5296:                                    approval   => 'Approval by Dom. Coord.',
                   5297:                                    automatic  => 'Automatic approval',
                   5298:                  );
                   5299:     return %titles;
                   5300: }
                   5301: 
1.101     raeburn  5302: sub courserequest_conditions {
                   5303:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  5304:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17  raeburn  5305:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  5306:                  );
                   5307:     return %conditions;
                   5308: }
                   5309: 
                   5310: 
1.27      raeburn  5311: sub print_usercreation {
1.30      raeburn  5312:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  5313:     my $numinrow = 4;
1.28      raeburn  5314:     my $datatable;
                   5315:     if ($position eq 'top') {
1.30      raeburn  5316:         $$rowtotal ++;
1.34      raeburn  5317:         my $rowcount = 0;
1.32      raeburn  5318:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  5319:         if (ref($rules) eq 'HASH') {
                   5320:             if (keys(%{$rules}) > 0) {
1.32      raeburn  5321:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   5322:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  5323:                 $$rowtotal ++;
1.32      raeburn  5324:                 $rowcount ++;
                   5325:             }
                   5326:         }
                   5327:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   5328:         if (ref($idrules) eq 'HASH') {
                   5329:             if (keys(%{$idrules}) > 0) {
                   5330:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   5331:                                                 $idruleorder,$numinrow,$rowcount);
                   5332:                 $$rowtotal ++;
                   5333:                 $rowcount ++;
1.28      raeburn  5334:             }
                   5335:         }
1.39      raeburn  5336:         if ($rowcount == 0) {
                   5337:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   5338:             $$rowtotal ++;
                   5339:             $rowcount ++;
                   5340:         }
1.34      raeburn  5341:     } elsif ($position eq 'middle') {
1.160.6.34  raeburn  5342:         my @creators = ('author','course','requestcrs');
1.37      raeburn  5343:         my ($rules,$ruleorder) =
                   5344:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  5345:         my %lt = &usercreation_types();
                   5346:         my %checked;
                   5347:         if (ref($settings) eq 'HASH') {
                   5348:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5349:                 foreach my $item (@creators) {
                   5350:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   5351:                 }
                   5352:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   5353:                 foreach my $item (@creators) {
                   5354:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   5355:                         $checked{$item} = 'none';
                   5356:                     }
                   5357:                 }
                   5358:             }
                   5359:         }
                   5360:         my $rownum = 0;
                   5361:         foreach my $item (@creators) {
                   5362:             $rownum ++;
1.160.6.34  raeburn  5363:             if ($checked{$item} eq '') {
                   5364:                 $checked{$item} = 'any';
1.34      raeburn  5365:             }
                   5366:             my $css_class;
                   5367:             if ($rownum%2) {
                   5368:                 $css_class = '';
                   5369:             } else {
                   5370:                 $css_class = ' class="LC_odd_row" ';
                   5371:             }
                   5372:             $datatable .= '<tr'.$css_class.'>'.
                   5373:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   5374:                          '</span></td><td align="right">';
1.160.6.34  raeburn  5375:             my @options = ('any');
                   5376:             if (ref($rules) eq 'HASH') {
                   5377:                 if (keys(%{$rules}) > 0) {
                   5378:                     push(@options,('official','unofficial'));
1.37      raeburn  5379:                 }
                   5380:             }
1.160.6.34  raeburn  5381:             push(@options,'none');
1.37      raeburn  5382:             foreach my $option (@options) {
1.50      raeburn  5383:                 my $type = 'radio';
1.34      raeburn  5384:                 my $check = ' ';
1.160.6.34  raeburn  5385:                 if ($checked{$item} eq $option) {
                   5386:                     $check = ' checked="checked" ';
1.34      raeburn  5387:                 } 
                   5388:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  5389:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  5390:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   5391:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   5392:             }
                   5393:             $datatable .= '</td></tr>';
                   5394:         }
1.28      raeburn  5395:     } else {
                   5396:         my @contexts = ('author','course','domain');
                   5397:         my @authtypes = ('int','krb4','krb5','loc');
                   5398:         my %checked;
                   5399:         if (ref($settings) eq 'HASH') {
                   5400:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   5401:                 foreach my $item (@contexts) {
                   5402:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   5403:                         foreach my $auth (@authtypes) {
                   5404:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   5405:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   5406:                             }
                   5407:                         }
                   5408:                     }
                   5409:                 }
1.27      raeburn  5410:             }
1.35      raeburn  5411:         } else {
                   5412:             foreach my $item (@contexts) {
1.36      raeburn  5413:                 foreach my $auth (@authtypes) {
1.35      raeburn  5414:                     $checked{$item}{$auth} = ' checked="checked" ';
                   5415:                 }
                   5416:             }
1.27      raeburn  5417:         }
1.28      raeburn  5418:         my %title = &context_names();
                   5419:         my %authname = &authtype_names();
                   5420:         my $rownum = 0;
                   5421:         my $css_class; 
                   5422:         foreach my $item (@contexts) {
                   5423:             if ($rownum%2) {
                   5424:                 $css_class = '';
                   5425:             } else {
                   5426:                 $css_class = ' class="LC_odd_row" ';
                   5427:             }
1.30      raeburn  5428:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  5429:                             '<td>'.$title{$item}.
                   5430:                             '</td><td class="LC_left_item">'.
                   5431:                             '<span class="LC_nobreak">';
                   5432:             foreach my $auth (@authtypes) {
                   5433:                 $datatable .= '<label>'. 
                   5434:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   5435:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   5436:                               $authname{$auth}.'</label>&nbsp;';
                   5437:             }
                   5438:             $datatable .= '</span></td></tr>';
                   5439:             $rownum ++;
1.27      raeburn  5440:         }
1.30      raeburn  5441:         $$rowtotal += $rownum;
1.27      raeburn  5442:     }
                   5443:     return $datatable;
                   5444: }
                   5445: 
1.160.6.34  raeburn  5446: sub print_selfcreation {
                   5447:     my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.40  raeburn  5448:     my (@selfcreate,$createsettings,$processing,$datatable);
1.160.6.34  raeburn  5449:     if (ref($settings) eq 'HASH') {
                   5450:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   5451:             $createsettings = $settings->{'cancreate'};
1.160.6.40  raeburn  5452:             if (ref($createsettings) eq 'HASH') {
                   5453:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   5454:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   5455:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   5456:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   5457:                         @selfcreate = ('email','login','sso');
                   5458:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   5459:                         @selfcreate = ($createsettings->{'selfcreate'});
                   5460:                     }
                   5461:                 }
                   5462:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   5463:                     $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34  raeburn  5464:                 }
                   5465:             }
                   5466:         }
                   5467:     }
                   5468:     my %radiohash;
                   5469:     my $numinrow = 4;
                   5470:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
                   5471:     if ($position eq 'top') {
                   5472:         my %choices = &Apache::lonlocal::texthash (
                   5473:                                                       cancreate_login      => 'Institutional Login',
                   5474:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   5475:                                                   );
                   5476:         my @toggles = sort(keys(%choices));
                   5477:         my %defaultchecked = (
                   5478:                                'cancreate_login' => 'off',
                   5479:                                'cancreate_sso'   => 'off',
                   5480:                              );
1.160.6.35  raeburn  5481:         my ($onclick,$itemcount);
1.160.6.34  raeburn  5482:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   5483:                                                      \%choices,$itemcount,$onclick);
1.160.6.35  raeburn  5484:         $$rowtotal += $itemcount;
1.160.6.39  raeburn  5485:         
1.160.6.34  raeburn  5486:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5487: 
                   5488:         if (ref($usertypes) eq 'HASH') {
                   5489:             if (keys(%{$usertypes}) > 0) {
                   5490:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   5491:                                              $dom,$numinrow,$othertitle,
1.160.6.35  raeburn  5492:                                              'statustocreate',$$rowtotal);
1.160.6.34  raeburn  5493:                 $$rowtotal ++;
                   5494:             }
                   5495:         }
1.160.6.44  raeburn  5496:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   5497:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   5498:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   5499:         my $rem;
                   5500:         my $numperrow = 2;
                   5501:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   5502:         $datatable .= '<tr'.$css_class.'>'.
1.160.6.45  raeburn  5503:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44  raeburn  5504:                      '<td class="LC_left_item">'."\n".
                   5505:                      '<table><tr><td>'."\n";
                   5506:         for (my $i=0; $i<@fields; $i++) {
                   5507:             $rem = $i%($numperrow);
                   5508:             if ($rem == 0) {
                   5509:                 if ($i > 0) {
                   5510:                     $datatable .= '</tr>';
                   5511:                 }
                   5512:                 $datatable .= '<tr>';
                   5513:             }
                   5514:             my $currval;
1.160.6.51  raeburn  5515:             if (ref($createsettings) eq 'HASH') {
                   5516:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   5517:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   5518:                 }
1.160.6.44  raeburn  5519:             }
                   5520:             $datatable .= '<td class="LC_left_item">'.
                   5521:                           '<span class="LC_nobreak">'.
                   5522:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   5523:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   5524:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   5525:         }
                   5526:         my $colsleft = $numperrow - $rem;
                   5527:         if ($colsleft > 1 ) {
                   5528:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5529:                          '&nbsp;</td>';
                   5530:         } elsif ($colsleft == 1) {
                   5531:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   5532:         }
                   5533:         $datatable .= '</tr></table></td></tr>';
                   5534:         $$rowtotal ++;
1.160.6.34  raeburn  5535:     } elsif ($position eq 'middle') {
                   5536:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
                   5537:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   5538:         $usertypes->{'default'} = $othertitle;
                   5539:         if (ref($types) eq 'ARRAY') {
                   5540:             push(@{$types},'default');
                   5541:             $usertypes->{'default'} = $othertitle;
                   5542:             foreach my $status (@{$types}) {
                   5543:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.160.6.35  raeburn  5544:                                                        $numinrow,$$rowtotal,$usertypes);
1.160.6.44  raeburn  5545:                 $$rowtotal ++;
1.160.6.34  raeburn  5546:             }
                   5547:         }
                   5548:     } else {
1.160.6.40  raeburn  5549:         my %choices = &Apache::lonlocal::texthash (
                   5550:                                                       cancreate_email => 'E-mail address as username',
                   5551:                                                   );
                   5552:         my @toggles = sort(keys(%choices));
                   5553:         my %defaultchecked = (
                   5554:                                'cancreate_email' => 'off',
                   5555:                              );
                   5556:         my $itemcount = 0;
                   5557:         my $display = 'none';
                   5558:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   5559:             $display = 'block';
                   5560:         }
                   5561:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
                   5562:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
                   5563:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   5564:         my $usertypes = {};
                   5565:         my $order = [];
                   5566:         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
                   5567:             $usertypes = $domdefaults{'inststatustypes'};
                   5568:             $order = $domdefaults{'inststatusguest'};
                   5569:         }
                   5570:         if (ref($order) eq 'ARRAY') {
                   5571:             push(@{$order},'default');
                   5572:             if (@{$order} > 1) {
                   5573:                 $usertypes->{'default'} = &mt('Other users');
                   5574:                 $additional .= '<table><tr>';
                   5575:                 foreach my $status (@{$order}) {
                   5576:                     $additional .= '<th>'.$usertypes->{$status}.'</th>';
                   5577:                 }
                   5578:                 $additional .= '</tr><tr>';
                   5579:                 foreach my $status (@{$order}) {
                   5580:                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.160.6.34  raeburn  5581:                 }
1.160.6.40  raeburn  5582:                 $additional .= '</tr></table>';
1.160.6.34  raeburn  5583:             } else {
1.160.6.40  raeburn  5584:                 $usertypes->{'default'} = &mt('All users');
                   5585:                 $additional .= &email_as_username($rowtotal,$processing);
1.160.6.34  raeburn  5586:             }
                   5587:         }
1.160.6.40  raeburn  5588:         $additional .= '</div>'."\n";
                   5589: 
                   5590:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.160.6.44  raeburn  5591:                                                      \%choices,$$rowtotal,$onclick,$additional);
                   5592:         $$rowtotal ++;
1.160.6.40  raeburn  5593:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.160.6.34  raeburn  5594:         $$rowtotal ++;
1.160.6.35  raeburn  5595:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   5596:         $numinrow = 1;
1.160.6.40  raeburn  5597:         if (ref($order) eq 'ARRAY') {
                   5598:             foreach my $status (@{$order}) {
1.160.6.35  raeburn  5599:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   5600:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
                   5601:                 $$rowtotal ++;
                   5602:             }
                   5603:         }
1.160.6.34  raeburn  5604:         my ($emailrules,$emailruleorder) =
                   5605:             &Apache::lonnet::inst_userrules($dom,'email');
                   5606:         if (ref($emailrules) eq 'HASH') {
                   5607:             if (keys(%{$emailrules}) > 0) {
                   5608:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
1.160.6.35  raeburn  5609:                                                 $emailruleorder,$numinrow,$$rowtotal);
1.160.6.34  raeburn  5610:                 $$rowtotal ++;
                   5611:             }
                   5612:         }
1.160.6.35  raeburn  5613:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.160.6.34  raeburn  5614:     }
                   5615:     return $datatable;
                   5616: }
                   5617: 
1.160.6.40  raeburn  5618: sub email_as_username {
                   5619:     my ($rowtotal,$processing,$type) = @_;
                   5620:     my %choices =
                   5621:         &Apache::lonlocal::texthash (
                   5622:                                       automatic => 'Automatic approval',
                   5623:                                       approval  => 'Queued for approval',
                   5624:                                     );
                   5625:     my $output;
                   5626:     foreach my $option ('automatic','approval') {
                   5627:         my $checked;
                   5628:         if (ref($processing) eq 'HASH') {
                   5629:             if ($type eq '') {   
                   5630:                 if (!exists($processing->{'default'})) {
                   5631:                     if ($option eq 'automatic') {
                   5632:                         $checked = ' checked="checked"';
                   5633:                     }
                   5634:                 } else {
                   5635:                     if ($processing->{'default'} eq $option) {
                   5636:                         $checked = ' checked="checked"';
                   5637:                     }
                   5638:                 }
                   5639:             } else {
                   5640:                 if (!exists($processing->{$type})) {
                   5641:                     if ($option eq 'automatic') {
                   5642:                         $checked = ' checked="checked"';
                   5643:                     }
                   5644:                 } else {
                   5645:                     if ($processing->{$type} eq $option) {
                   5646:                         $checked = ' checked="checked"';
                   5647:                     }
                   5648:                 }
                   5649:             }
                   5650:         } elsif ($option eq 'automatic') {
                   5651:             $checked = ' checked="checked"'; 
                   5652:         }
                   5653:         my $name = 'cancreate_emailprocess';
                   5654:         if (($type ne '') && ($type ne 'default')) {
                   5655:             $name .= '_'.$type;
                   5656:         }
                   5657:         $output .= '<span class="LC_nobreak"><label>'.
                   5658:                    '<input type="radio" name="'.$name.'"'.
                   5659:                    $checked.' value="'.$option.'" />'.
                   5660:                    $choices{$option}.'</label></span>';
                   5661:         if ($type eq '') {
                   5662:             $output .= '&nbsp;';
                   5663:         } else {
                   5664:             $output .= '<br />';
                   5665:         }
                   5666:     }
                   5667:     $$rowtotal ++;
                   5668:     return $output;
                   5669: }
                   5670: 
1.160.6.5  raeburn  5671: sub captcha_choice {
                   5672:     my ($context,$settings,$itemcount) = @_;
1.160.6.69  raeburn  5673:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   5674:         $vertext,$currver); 
1.160.6.5  raeburn  5675:     my %lt = &captcha_phrases();
                   5676:     $keyentry = 'hidden';
                   5677:     if ($context eq 'cancreate') {
1.160.6.34  raeburn  5678:         $rowname = &mt('CAPTCHA validation');
1.160.6.5  raeburn  5679:     } elsif ($context eq 'login') {
                   5680:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
                   5681:     }
                   5682:     if (ref($settings) eq 'HASH') {
                   5683:         if ($settings->{'captcha'}) {
                   5684:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   5685:         } else {
                   5686:             $checked{'original'} = ' checked="checked"';
                   5687:         }
                   5688:         if ($settings->{'captcha'} eq 'recaptcha') {
                   5689:             $pubtext = $lt{'pub'};
                   5690:             $privtext = $lt{'priv'};
                   5691:             $keyentry = 'text';
1.160.6.69  raeburn  5692:             $vertext = $lt{'ver'};
                   5693:             $currver = $settings->{'recaptchaversion'};
                   5694:             if ($currver ne '2') {
                   5695:                 $currver = 1;
                   5696:             }
1.160.6.5  raeburn  5697:         }
                   5698:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   5699:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   5700:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   5701:         }
                   5702:     } else {
                   5703:         $checked{'original'} = ' checked="checked"';
                   5704:     }
                   5705:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5706:     my $output = '<tr'.$css_class.'>'.
                   5707:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
                   5708:                  '<table><tr><td>'."\n";
                   5709:     foreach my $option ('original','recaptcha','notused') {
                   5710:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   5711:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   5712:                    $lt{$option}.'</label></span>';
                   5713:         unless ($option eq 'notused') {
                   5714:             $output .= ('&nbsp;'x2)."\n";
                   5715:         }
                   5716:     }
                   5717: #
                   5718: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   5719: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
                   5720: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
                   5721: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
                   5722: #
                   5723:     $output .= '</td></tr>'."\n".
                   5724:                '<tr><td>'."\n".
                   5725:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   5726:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   5727:                $currpub.'" size="40" /></span><br />'."\n".
                   5728:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   5729:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69  raeburn  5730:                $currpriv.'" size="40" /></span><br />'.
                   5731:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   5732:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   5733:                $currver.'" size="3" /></span><br />'.
                   5734:                '</td></tr></table>'."\n".
1.160.6.5  raeburn  5735:                '</td></tr>';
                   5736:     return $output;
                   5737: }
                   5738: 
1.32      raeburn  5739: sub user_formats_row {
                   5740:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   5741:     my $output;
                   5742:     my %text = (
                   5743:                    'username' => 'new usernames',
                   5744:                    'id'       => 'IDs',
1.45      raeburn  5745:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  5746:                );
                   5747:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   5748:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  5749:               '<td><span class="LC_nobreak">';
                   5750:     if ($type eq 'email') {
                   5751:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   5752:     } else {
                   5753:         $output .= &mt("Format rules to check for $text{$type}: ");
                   5754:     }
                   5755:     $output .= '</span></td>'.
                   5756:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  5757:     my $rem;
                   5758:     if (ref($ruleorder) eq 'ARRAY') {
                   5759:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   5760:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   5761:                 my $rem = $i%($numinrow);
                   5762:                 if ($rem == 0) {
                   5763:                     if ($i > 0) {
                   5764:                         $output .= '</tr>';
                   5765:                     }
                   5766:                     $output .= '<tr>';
                   5767:                 }
                   5768:                 my $check = ' ';
1.39      raeburn  5769:                 if (ref($settings) eq 'HASH') {
                   5770:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   5771:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   5772:                             $check = ' checked="checked" ';
                   5773:                         }
1.27      raeburn  5774:                     }
                   5775:                 }
                   5776:                 $output .= '<td class="LC_left_item">'.
                   5777:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  5778:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  5779:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   5780:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   5781:             }
                   5782:         }
                   5783:         $rem = @{$ruleorder}%($numinrow);
                   5784:     }
                   5785:     my $colsleft = $numinrow - $rem;
                   5786:     if ($colsleft > 1 ) {
                   5787:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5788:                    '&nbsp;</td>';
                   5789:     } elsif ($colsleft == 1) {
                   5790:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   5791:     }
                   5792:     $output .= '</tr></table></td></tr>';
                   5793:     return $output;
                   5794: }
                   5795: 
1.34      raeburn  5796: sub usercreation_types {
                   5797:     my %lt = &Apache::lonlocal::texthash (
                   5798:                     author     => 'When adding a co-author',
                   5799:                     course     => 'When adding a user to a course',
1.100     raeburn  5800:                     requestcrs => 'When requesting a course',
1.34      raeburn  5801:                     any        => 'Any',
                   5802:                     official   => 'Institutional only ',
                   5803:                     unofficial => 'Non-institutional only',
                   5804:                     none       => 'None',
                   5805:     );
                   5806:     return %lt;
1.48      raeburn  5807: }
1.34      raeburn  5808: 
1.160.6.34  raeburn  5809: sub selfcreation_types {
                   5810:     my %lt = &Apache::lonlocal::texthash (
                   5811:                     selfcreate => 'User creates own account',
                   5812:                     any        => 'Any',
                   5813:                     official   => 'Institutional only ',
                   5814:                     unofficial => 'Non-institutional only',
                   5815:                     email      => 'E-mail address',
                   5816:                     login      => 'Institutional Login',
                   5817:                     sso        => 'SSO',
                   5818:              );
                   5819: }
                   5820: 
1.28      raeburn  5821: sub authtype_names {
                   5822:     my %lt = &Apache::lonlocal::texthash(
                   5823:                       int    => 'Internal',
                   5824:                       krb4   => 'Kerberos 4',
                   5825:                       krb5   => 'Kerberos 5',
                   5826:                       loc    => 'Local',
                   5827:                   );
                   5828:     return %lt;
                   5829: }
                   5830: 
                   5831: sub context_names {
                   5832:     my %context_title = &Apache::lonlocal::texthash(
                   5833:        author => 'Creating users when an Author',
                   5834:        course => 'Creating users when in a course',
                   5835:        domain => 'Creating users when a Domain Coordinator',
                   5836:     );
                   5837:     return %context_title;
                   5838: }
                   5839: 
1.33      raeburn  5840: sub print_usermodification {
                   5841:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5842:     my $numinrow = 4;
                   5843:     my ($context,$datatable,$rowcount);
                   5844:     if ($position eq 'top') {
                   5845:         $rowcount = 0;
                   5846:         $context = 'author'; 
                   5847:         foreach my $role ('ca','aa') {
                   5848:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5849:                                                    $numinrow,$rowcount);
                   5850:             $$rowtotal ++;
                   5851:             $rowcount ++;
                   5852:         }
1.160.6.37  raeburn  5853:     } elsif ($position eq 'bottom') {
1.33      raeburn  5854:         $context = 'course';
                   5855:         $rowcount = 0;
                   5856:         foreach my $role ('st','ep','ta','in','cr') {
                   5857:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5858:                                                    $numinrow,$rowcount);
                   5859:             $$rowtotal ++;
                   5860:             $rowcount ++;
                   5861:         }
                   5862:     }
                   5863:     return $datatable;
                   5864: }
                   5865: 
1.43      raeburn  5866: sub print_defaults {
1.160.6.40  raeburn  5867:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  5868:     my $rownum = 0;
1.160.6.80  raeburn  5869:     my ($datatable,$css_class,$titles);
                   5870:     unless ($position eq 'bottom') {
                   5871:         $titles = &defaults_titles($dom);
                   5872:     }
1.160.6.40  raeburn  5873:     if ($position eq 'top') {
                   5874:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   5875:                      'datelocale_def','portal_def');
                   5876:         my %defaults;
                   5877:         if (ref($settings) eq 'HASH') {
                   5878:             %defaults = %{$settings};
1.43      raeburn  5879:         } else {
1.160.6.40  raeburn  5880:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   5881:             foreach my $item (@items) {
                   5882:                 $defaults{$item} = $domdefaults{$item};
                   5883:             }
1.43      raeburn  5884:         }
1.160.6.40  raeburn  5885:         foreach my $item (@items) {
                   5886:             if ($rownum%2) {
                   5887:                 $css_class = '';
                   5888:             } else {
                   5889:                 $css_class = ' class="LC_odd_row" ';
1.43      raeburn  5890:             }
1.160.6.40  raeburn  5891:             $datatable .= '<tr'.$css_class.'>'.
                   5892:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5893:                           '</span></td><td class="LC_right_item" colspan="3">';
                   5894:             if ($item eq 'auth_def') {
                   5895:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   5896:                 my %shortauth = (
                   5897:                                  internal => 'int',
                   5898:                                  krb4 => 'krb4',
                   5899:                                  krb5 => 'krb5',
                   5900:                                  localauth  => 'loc'
                   5901:                                 );
                   5902:                 my %authnames = &authtype_names();
                   5903:                 foreach my $auth (@authtypes) {
                   5904:                     my $checked = ' ';
                   5905:                     if ($defaults{$item} eq $auth) {
                   5906:                         $checked = ' checked="checked" ';
                   5907:                     }
                   5908:                     $datatable .= '<label><input type="radio" name="'.$item.
                   5909:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   5910:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   5911:                 }
                   5912:             } elsif ($item eq 'timezone_def') {
                   5913:                 my $includeempty = 1;
                   5914:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   5915:             } elsif ($item eq 'datelocale_def') {
                   5916:                 my $includeempty = 1;
                   5917:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   5918:             } elsif ($item eq 'lang_def') {
1.160.6.63  raeburn  5919:                 my $includeempty = 1;
                   5920:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.40  raeburn  5921:             } else {
                   5922:                 my $size;
                   5923:                 if ($item eq 'portal_def') {
                   5924:                     $size = ' size="25"';
                   5925:                 }
                   5926:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5927:                               $defaults{$item}.'"'.$size.' />';
                   5928:             }
                   5929:             $datatable .= '</td></tr>';
                   5930:             $rownum ++;
                   5931:         }
1.160.6.80  raeburn  5932:     } elsif ($position eq 'middle') {
                   5933:         my @items = ('intauth_cost','intauth_check','intauth_switch');
                   5934:         my %defaults;
                   5935:         if (ref($settings) eq 'HASH') {
                   5936:             %defaults = %{$settings};
                   5937:             if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   5938:                 $defaults{'intauth_cost'} = 10;
                   5939:             }
                   5940:             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   5941:                 $defaults{'intauth_check'} = 0;
                   5942:             }
                   5943:             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   5944:                 $defaults{'intauth_switch'} = 0;
                   5945:             }
                   5946:         } else {
                   5947:             %defaults = (
                   5948:                           'intauth_cost'   => 10,
                   5949:                           'intauth_check'  => 0,
                   5950:                           'intauth_switch' => 0,
                   5951:                         );
                   5952:         }
                   5953:         foreach my $item (@items) {
                   5954:             if ($rownum%2) {
                   5955:                 $css_class = '';
                   5956:             } else {
                   5957:                 $css_class = ' class="LC_odd_row" ';
                   5958:             }
                   5959:             $datatable .= '<tr'.$css_class.'>'.
                   5960:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5961:                           '</span></td><td class="LC_left_item" colspan="3">';
                   5962:             if ($item eq 'intauth_switch') {
                   5963:                 my @options = (0,1,2);
                   5964:                 my %optiondesc = &Apache::lonlocal::texthash (
                   5965:                                    0 => 'No',
                   5966:                                    1 => 'Yes',
                   5967:                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   5968:                                  );
                   5969:                 $datatable .= '<table width="100%">';
                   5970:                 foreach my $option (@options) {
                   5971:                     my $checked = ' ';
                   5972:                     if ($defaults{$item} eq $option) {
                   5973:                         $checked = ' checked="checked"';
                   5974:                     }
                   5975:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5976:                                   '<label><input type="radio" name="'.$item.
                   5977:                                   '" value="'.$option.'"'.$checked.' />'.
                   5978:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   5979:                 }
                   5980:                 $datatable .= '</table>';
                   5981:             } elsif ($item eq 'intauth_check') {
                   5982:                 my @options = (0,1,2);
                   5983:                 my %optiondesc = &Apache::lonlocal::texthash (
                   5984:                                    0 => 'No',
                   5985:                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   5986:                                    2 => 'Yes, disallow login if stored cost is less than domain default',
                   5987:                                  );
                   5988:                 $datatable .= '<table wisth="100%">';
                   5989:                 foreach my $option (@options) {
                   5990:                     my $checked = ' ';
                   5991:                     my $onclick;
                   5992:                     if ($defaults{$item} eq $option) {
                   5993:                         $checked = ' checked="checked"';
                   5994:                     }
                   5995:                     if ($option == 2) {
                   5996:                         $onclick = ' onclick="javascript:warnIntAuth(this);"';
                   5997:                     }
                   5998:                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                   5999:                                   '<label><input type="radio" name="'.$item.
                   6000:                                   '" value="'.$option.'"'.$checked.$onclick.' />'.
                   6001:                                   $optiondesc{$option}.'</label></span></td></tr>';
                   6002:                 }
                   6003:                 $datatable .= '</table>';
                   6004:             } else {
                   6005:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   6006:                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
                   6007:             }
                   6008:             $datatable .= '</td></tr>';
                   6009:             $rownum ++;
                   6010:         }
1.160.6.40  raeburn  6011:     } else {
1.160.6.80  raeburn  6012:         my %defaults;
1.160.6.40  raeburn  6013:         if (ref($settings) eq 'HASH') {
                   6014:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
                   6015:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
                   6016:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   6017:                 for (my $i=0; $i<$maxnum; $i++) {
                   6018:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6019:                     my $item = $settings->{'inststatusorder'}->[$i];
                   6020:                     my $title = $settings->{'inststatustypes'}->{$item};
                   6021:                     my $guestok;
                   6022:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
                   6023:                         $guestok = 1;
                   6024:                     }
                   6025:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   6026:                     $datatable .= '<tr'.$css_class.'>'.
                   6027:                                   '<td><span class="LC_nobreak">'.
                   6028:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   6029:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6030:                         my $vpos = $k+1;
                   6031:                         my $selstr;
                   6032:                         if ($k == $i) {
                   6033:                             $selstr = ' selected="selected" ';
                   6034:                         }
                   6035:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6036:                     }
                   6037:                     my ($checkedon,$checkedoff);
                   6038:                     $checkedoff = ' checked="checked"';
                   6039:                     if ($guestok) {
                   6040:                         $checkedon = $checkedoff;
                   6041:                         $checkedoff = ''; 
                   6042:                     }
                   6043:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   6044:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   6045:                                   &mt('delete').'</span></td>'.
                   6046:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
                   6047:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   6048:                                   '</span></td>'.
                   6049:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6050:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
                   6051:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
                   6052:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
                   6053:                                   &mt('No').'</label></span></td></tr>';
                   6054:                 }
                   6055:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6056:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   6057:                 $datatable .= '<tr '.$css_class.'>'.
                   6058:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   6059:                 for (my $k=0; $k<=$maxnum; $k++) {
                   6060:                     my $vpos = $k+1;
                   6061:                     my $selstr;
                   6062:                     if ($k == $maxnum) {
                   6063:                         $selstr = ' selected="selected" ';
                   6064:                     }
                   6065:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6066:                 }
                   6067:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.160.6.63  raeburn  6068:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40  raeburn  6069:                               '&nbsp;'.&mt('(new)').
                   6070:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
                   6071:                               &mt('Name displayed:').
                   6072:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   6073:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6074:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
                   6075:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   6076:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
                   6077:                               &mt('No').'</label></span></td></tr>';
                   6078:                               '</tr>'."\n";
                   6079:                 $rownum ++;
1.141     raeburn  6080:             }
1.43      raeburn  6081:         }
                   6082:     }
                   6083:     $$rowtotal += $rownum;
                   6084:     return $datatable;
                   6085: }
                   6086: 
1.160.6.5  raeburn  6087: sub get_languages_hash {
                   6088:     my %langchoices;
                   6089:     foreach my $id (&Apache::loncommon::languageids()) {
                   6090:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   6091:         if ($code ne '') {
                   6092:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   6093:         }
                   6094:     }
                   6095:     return %langchoices;
                   6096: }
                   6097: 
1.43      raeburn  6098: sub defaults_titles {
1.141     raeburn  6099:     my ($dom) = @_;
1.43      raeburn  6100:     my %titles = &Apache::lonlocal::texthash (
                   6101:                    'auth_def'      => 'Default authentication type',
                   6102:                    'auth_arg_def'  => 'Default authentication argument',
                   6103:                    'lang_def'      => 'Default language',
1.54      raeburn  6104:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  6105:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  6106:                    'portal_def'     => 'Portal/Default URL',
1.160.6.80  raeburn  6107:                    'intauth_cost'   => 'Encryption cost for bcrypt (positive integer)',
                   6108:                    'intauth_check'  => 'Check bcrypt cost if authenticated',
                   6109:                    'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43      raeburn  6110:                  );
1.141     raeburn  6111:     if ($dom) {
                   6112:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   6113:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   6114:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   6115:         $protocol = 'http' if ($protocol ne 'https');
                   6116:         if ($uint_dom) {
                   6117:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   6118:                                          $uint_dom);
                   6119:         }
                   6120:     }
1.43      raeburn  6121:     return (\%titles);
                   6122: }
                   6123: 
1.46      raeburn  6124: sub print_scantronformat {
                   6125:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   6126:     my $itemcount = 1;
1.60      raeburn  6127:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   6128:         %confhash);
1.46      raeburn  6129:     my $switchserver = &check_switchserver($dom,$confname);
                   6130:     my %lt = &Apache::lonlocal::texthash (
1.95      www      6131:                 default => 'Default bubblesheet format file error',
                   6132:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  6133:              );
                   6134:     my %scantronfiles = (
                   6135:         default => 'default.tab',
                   6136:         custom => 'custom.tab',
                   6137:     );
                   6138:     foreach my $key (keys(%scantronfiles)) {
                   6139:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   6140:                               .$scantronfiles{$key};
                   6141:     }
                   6142:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   6143:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   6144:         if (!$switchserver) {
                   6145:             my $servadm = $r->dir_config('lonAdmEMail');
                   6146:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   6147:             if ($configuserok eq 'ok') {
                   6148:                 if ($author_ok eq 'ok') {
                   6149:                     my %legacyfile = (
                   6150:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   6151:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   6152:                     );
                   6153:                     my %md5chk;
                   6154:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  6155:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   6156:                         chomp($md5chk{$type});
1.46      raeburn  6157:                     }
                   6158:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   6159:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  6160:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  6161:                                 &legacy_scantronformat($r,$dom,$confname,
                   6162:                                                  $type,$legacyfile{$type},
                   6163:                                                  $scantronurls{$type},
                   6164:                                                  $scantronfiles{$type});
1.60      raeburn  6165:                             if ($error ne '') {
                   6166:                                 $error{$type} = $error;
                   6167:                             }
                   6168:                         }
                   6169:                         if (keys(%error) == 0) {
                   6170:                             $is_custom = 1;
                   6171:                             $confhash{'scantron'}{'scantronformat'} = 
                   6172:                                 $scantronurls{'custom'};
                   6173:                             my $putresult = 
                   6174:                                 &Apache::lonnet::put_dom('configuration',
                   6175:                                                          \%confhash,$dom);
                   6176:                             if ($putresult ne 'ok') {
                   6177:                                 $error{'custom'} = 
                   6178:                                     '<span class="LC_error">'.
                   6179:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   6180:                             }
1.46      raeburn  6181:                         }
                   6182:                     } else {
1.60      raeburn  6183:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  6184:                             &legacy_scantronformat($r,$dom,$confname,
                   6185:                                           'default',$legacyfile{'default'},
                   6186:                                           $scantronurls{'default'},
                   6187:                                           $scantronfiles{'default'});
1.60      raeburn  6188:                         if ($error eq '') {
                   6189:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   6190:                             my $putresult =
                   6191:                                 &Apache::lonnet::put_dom('configuration',
                   6192:                                                          \%confhash,$dom);
                   6193:                             if ($putresult ne 'ok') {
                   6194:                                 $error{'default'} =
                   6195:                                     '<span class="LC_error">'.
                   6196:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   6197:                             }
                   6198:                         } else {
                   6199:                             $error{'default'} = $error;
                   6200:                         }
1.46      raeburn  6201:                     }
                   6202:                 }
                   6203:             }
                   6204:         } else {
1.95      www      6205:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  6206:         }
                   6207:     }
                   6208:     if (ref($settings) eq 'HASH') {
                   6209:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   6210:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
1.160.6.84.2.  (raeburn 6211:):             if ((!@info) || ($info[0] eq 'no_such_dir')) {
1.46      raeburn  6212:                 $scantronurl = '';
                   6213:             } else {
                   6214:                 $scantronurl = $settings->{'scantronformat'};
                   6215:             }
                   6216:             $is_custom = 1;
                   6217:         } else {
                   6218:             $scantronurl = $scantronurls{'default'};
                   6219:         }
                   6220:     } else {
1.60      raeburn  6221:         if ($is_custom) {
                   6222:             $scantronurl = $scantronurls{'custom'};
                   6223:         } else {
                   6224:             $scantronurl = $scantronurls{'default'};
                   6225:         }
1.46      raeburn  6226:     }
                   6227:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6228:     $datatable .= '<tr'.$css_class.'>';
                   6229:     if (!$is_custom) {
1.65      raeburn  6230:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   6231:                       '<span class="LC_nobreak">';
1.46      raeburn  6232:         if ($scantronurl) {
1.160.6.21  raeburn  6233:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   6234:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  6235:         } else {
                   6236:             $datatable = &mt('File unavailable for display');
                   6237:         }
1.65      raeburn  6238:         $datatable .= '</span></td>';
1.60      raeburn  6239:         if (keys(%error) == 0) { 
                   6240:             $datatable .= '<td valign="bottom">';
                   6241:             if (!$switchserver) {
                   6242:                 $datatable .= &mt('Upload:').'<br />';
                   6243:             }
                   6244:         } else {
                   6245:             my $errorstr;
                   6246:             foreach my $key (sort(keys(%error))) {
                   6247:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   6248:             }
                   6249:             $datatable .= '<td>'.$errorstr;
                   6250:         }
1.46      raeburn  6251:     } else {
                   6252:         if (keys(%error) > 0) {
                   6253:             my $errorstr;
                   6254:             foreach my $key (sort(keys(%error))) {
                   6255:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   6256:             } 
1.60      raeburn  6257:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  6258:         } elsif ($scantronurl) {
1.160.6.26  raeburn  6259:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21  raeburn  6260:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  6261:             $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21  raeburn  6262:                           $link.
                   6263:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   6264:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  6265:                           '<td><span class="LC_nobreak">&nbsp;'.
                   6266:                           &mt('Replace:').'</span><br />';
1.46      raeburn  6267:         }
                   6268:     }
                   6269:     if (keys(%error) == 0) {
                   6270:         if ($switchserver) {
                   6271:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   6272:         } else {
1.65      raeburn  6273:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   6274:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  6275:         }
                   6276:     }
                   6277:     $datatable .= '</td></tr>';
                   6278:     $$rowtotal ++;
                   6279:     return $datatable;
                   6280: }
                   6281: 
                   6282: sub legacy_scantronformat {
                   6283:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   6284:     my ($url,$error);
                   6285:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   6286:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   6287:         (my $result,$url) =
                   6288:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   6289:                          '','',$newfile);
                   6290:         if ($result ne 'ok') {
1.130     raeburn  6291:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  6292:         }
                   6293:     }
                   6294:     return ($url,$error);
                   6295: }
1.43      raeburn  6296: 
1.49      raeburn  6297: sub print_coursecategories {
1.57      raeburn  6298:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   6299:     my $datatable;
                   6300:     if ($position eq 'top') {
1.160.6.42  raeburn  6301:         my (%checked);
                   6302:         my @catitems = ('unauth','auth');
                   6303:         my @cattypes = ('std','domonly','codesrch','none');
                   6304:         $checked{'unauth'} = 'std';
                   6305:         $checked{'auth'} = 'std';
                   6306:         if (ref($settings) eq 'HASH') {
                   6307:             foreach my $type (@cattypes) {
                   6308:                 if ($type eq $settings->{'unauth'}) {
                   6309:                     $checked{'unauth'} = $type;
                   6310:                 }
                   6311:                 if ($type eq $settings->{'auth'}) {
                   6312:                     $checked{'auth'} = $type;
                   6313:                 }
                   6314:             }
                   6315:         }
                   6316:         my %lt = &Apache::lonlocal::texthash (
                   6317:                                                unauth   => 'Catalog type for unauthenticated users',
                   6318:                                                auth     => 'Catalog type for authenticated users',
                   6319:                                                none     => 'No catalog',
                   6320:                                                std      => 'Standard catalog',
                   6321:                                                domonly  => 'Domain-only catalog',
                   6322:                                                codesrch => "Code search form",
                   6323:                                              );
                   6324:        my $itemcount = 0;
                   6325:        foreach my $item (@catitems) {
                   6326:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   6327:            $datatable .= '<tr '.$css_class.'>'.
                   6328:                          '<td>'.$lt{$item}.'</td>'.
                   6329:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   6330:            foreach my $type (@cattypes) {
                   6331:                my $ischecked;
                   6332:                if ($checked{$item} eq $type) {
                   6333:                    $ischecked=' checked="checked"';
                   6334:                }
                   6335:                $datatable .= '<label>'.
                   6336:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   6337:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   6338:            }
                   6339:            $datatable .= '</td></tr>';
                   6340:            $itemcount ++;
                   6341:         }
                   6342:         $$rowtotal += $itemcount;
                   6343:     } elsif ($position eq 'middle') {
1.57      raeburn  6344:         my $toggle_cats_crs = ' ';
                   6345:         my $toggle_cats_dom = ' checked="checked" ';
                   6346:         my $can_cat_crs = ' ';
                   6347:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  6348:         my $toggle_catscomm_comm = ' ';
                   6349:         my $toggle_catscomm_dom = ' checked="checked" ';
                   6350:         my $can_catcomm_comm = ' ';
                   6351:         my $can_catcomm_dom = ' checked="checked" ';
                   6352: 
1.57      raeburn  6353:         if (ref($settings) eq 'HASH') {
                   6354:             if ($settings->{'togglecats'} eq 'crs') {
                   6355:                 $toggle_cats_crs = $toggle_cats_dom;
                   6356:                 $toggle_cats_dom = ' ';
                   6357:             }
                   6358:             if ($settings->{'categorize'} eq 'crs') {
                   6359:                 $can_cat_crs = $can_cat_dom;
                   6360:                 $can_cat_dom = ' ';
                   6361:             }
1.120     raeburn  6362:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   6363:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   6364:                 $toggle_catscomm_dom = ' ';
                   6365:             }
                   6366:             if ($settings->{'categorizecomm'} eq 'comm') {
                   6367:                 $can_catcomm_comm = $can_catcomm_dom;
                   6368:                 $can_catcomm_dom = ' ';
                   6369:             }
1.57      raeburn  6370:         }
                   6371:         my %title = &Apache::lonlocal::texthash (
1.120     raeburn  6372:                      togglecats     => 'Show/Hide a course in catalog',
                   6373:                      togglecatscomm => 'Show/Hide a community in catalog',
                   6374:                      categorize     => 'Assign a category to a course',
                   6375:                      categorizecomm => 'Assign a category to a community',
1.57      raeburn  6376:                     );
                   6377:         my %level = &Apache::lonlocal::texthash (
1.120     raeburn  6378:                      dom  => 'Set in Domain',
                   6379:                      crs  => 'Set in Course',
                   6380:                      comm => 'Set in Community',
1.57      raeburn  6381:                     );
                   6382:         $datatable = '<tr class="LC_odd_row">'.
                   6383:                   '<td>'.$title{'togglecats'}.'</td>'.
                   6384:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   6385:                   '<input type="radio" name="togglecats"'.
                   6386:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6387:                   '<label><input type="radio" name="togglecats"'.
                   6388:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   6389:                   '</tr><tr>'.
                   6390:                   '<td>'.$title{'categorize'}.'</td>'.
                   6391:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6392:                   '<label><input type="radio" name="categorize"'.
                   6393:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6394:                   '<label><input type="radio" name="categorize"'.
                   6395:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  6396:                   '</tr><tr class="LC_odd_row">'.
                   6397:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   6398:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   6399:                   '<input type="radio" name="togglecatscomm"'.
                   6400:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6401:                   '<label><input type="radio" name="togglecatscomm"'.
                   6402:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   6403:                   '</tr><tr>'.
                   6404:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   6405:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   6406:                   '<label><input type="radio" name="categorizecomm"'.
                   6407:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   6408:                   '<label><input type="radio" name="categorizecomm"'.
                   6409:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57      raeburn  6410:                   '</tr>';
1.120     raeburn  6411:         $$rowtotal += 4;
1.57      raeburn  6412:     } else {
                   6413:         my $css_class;
                   6414:         my $itemcount = 1;
                   6415:         my $cathash; 
                   6416:         if (ref($settings) eq 'HASH') {
                   6417:             $cathash = $settings->{'cats'};
                   6418:         }
                   6419:         if (ref($cathash) eq 'HASH') {
                   6420:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   6421:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   6422:                                                    \%allitems,\%idx,\@jsarray);
                   6423:             my $maxdepth = scalar(@cats);
                   6424:             my $colattrib = '';
                   6425:             if ($maxdepth > 2) {
                   6426:                 $colattrib = ' colspan="2" ';
                   6427:             }
                   6428:             my @path;
                   6429:             if (@cats > 0) {
                   6430:                 if (ref($cats[0]) eq 'ARRAY') {
                   6431:                     my $numtop = @{$cats[0]};
                   6432:                     my $maxnum = $numtop;
1.120     raeburn  6433:                     my %default_names = (
                   6434:                           instcode    => &mt('Official courses'),
                   6435:                           communities => &mt('Communities'),
                   6436:                     );
                   6437: 
                   6438:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   6439:                         ($cathash->{'instcode::0'} eq '') ||
                   6440:                         (!grep(/^communities$/,@{$cats[0]})) || 
                   6441:                         ($cathash->{'communities::0'} eq '')) {
1.57      raeburn  6442:                         $maxnum ++;
                   6443:                     }
                   6444:                     my $lastidx;
                   6445:                     for (my $i=0; $i<$numtop; $i++) {
                   6446:                         my $parent = $cats[0][$i];
                   6447:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6448:                         my $item = &escape($parent).'::0';
                   6449:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   6450:                         $lastidx = $idx{$item};
                   6451:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6452:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   6453:                         for (my $k=0; $k<=$maxnum; $k++) {
                   6454:                             my $vpos = $k+1;
                   6455:                             my $selstr;
                   6456:                             if ($k == $i) {
                   6457:                                 $selstr = ' selected="selected" ';
                   6458:                             }
                   6459:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6460:                         }
1.160.6.29  raeburn  6461:                         $datatable .= '</select></span></td><td>';
1.120     raeburn  6462:                         if ($parent eq 'instcode' || $parent eq 'communities') {
                   6463:                             $datatable .=  '<span class="LC_nobreak">'
                   6464:                                            .$default_names{$parent}.'</span>';
                   6465:                             if ($parent eq 'instcode') {
                   6466:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   6467:                                               .&mt('with institutional codes')
                   6468:                                               .')</span></td><td'.$colattrib.'>';
                   6469:                             } else {
                   6470:                                 $datatable .= '<table><tr><td>';
                   6471:                             }
                   6472:                             $datatable .= '<span class="LC_nobreak">'
                   6473:                                           .'<label><input type="radio" name="'
                   6474:                                           .$parent.'" value="1" checked="checked" />'
                   6475:                                           .&mt('Display').'</label>';
                   6476:                             if ($parent eq 'instcode') {
                   6477:                                 $datatable .= '&nbsp;';
                   6478:                             } else {
                   6479:                                 $datatable .= '</span></td></tr><tr><td>'
                   6480:                                               .'<span class="LC_nobreak">';
                   6481:                             }
                   6482:                             $datatable .= '<label><input type="radio" name="'
                   6483:                                           .$parent.'" value="0" />'
                   6484:                                           .&mt('Do not display').'</label></span>';
                   6485:                             if ($parent eq 'communities') {
                   6486:                                 $datatable .= '</td></tr></table>';
                   6487:                             }
                   6488:                             $datatable .= '</td>';
1.57      raeburn  6489:                         } else {
                   6490:                             $datatable .= $parent
1.160.6.29  raeburn  6491:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   6492:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  6493:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   6494:                         }
                   6495:                         my $depth = 1;
                   6496:                         push(@path,$parent);
                   6497:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   6498:                         pop(@path);
                   6499:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   6500:                         $itemcount ++;
                   6501:                     }
1.48      raeburn  6502:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  6503:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   6504:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  6505:                     for (my $k=0; $k<=$maxnum; $k++) {
                   6506:                         my $vpos = $k+1;
                   6507:                         my $selstr;
1.57      raeburn  6508:                         if ($k == $numtop) {
1.48      raeburn  6509:                             $selstr = ' selected="selected" ';
                   6510:                         }
                   6511:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   6512:                     }
1.59      bisitz   6513:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  6514:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   6515:                                   .'</tr>'."\n";
1.48      raeburn  6516:                     $itemcount ++;
1.120     raeburn  6517:                     foreach my $default ('instcode','communities') {
                   6518:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   6519:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6520:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   6521:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   6522:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   6523:                             for (my $k=0; $k<=$maxnum; $k++) {
                   6524:                                 my $vpos = $k+1;
                   6525:                                 my $selstr;
                   6526:                                 if ($k == $maxnum) {
                   6527:                                     $selstr = ' selected="selected" ';
                   6528:                                 }
                   6529:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  6530:                             }
1.120     raeburn  6531:                             $datatable .= '</select></span></td>'.
                   6532:                                           '<td><span class="LC_nobreak">'.
                   6533:                                           $default_names{$default}.'</span>';
                   6534:                             if ($default eq 'instcode') {
                   6535:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   6536:                                               .&mt('with institutional codes').')</span>';
                   6537:                             }
                   6538:                             $datatable .= '</td>'
                   6539:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   6540:                                           .&mt('Display').'</label>&nbsp;'
                   6541:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   6542:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  6543:                         }
                   6544:                     }
                   6545:                 }
1.57      raeburn  6546:             } else {
                   6547:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  6548:             }
                   6549:         } else {
1.160.6.42  raeburn  6550:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57      raeburn  6551:                           .&initialize_categories($itemcount);
1.48      raeburn  6552:         }
1.57      raeburn  6553:         $$rowtotal += $itemcount;
1.48      raeburn  6554:     }
                   6555:     return $datatable;
                   6556: }
                   6557: 
1.69      raeburn  6558: sub print_serverstatuses {
                   6559:     my ($dom,$settings,$rowtotal) = @_;
                   6560:     my $datatable;
                   6561:     my @pages = &serverstatus_pages();
                   6562:     my (%namedaccess,%machineaccess);
                   6563:     foreach my $type (@pages) {
                   6564:         $namedaccess{$type} = '';
                   6565:         $machineaccess{$type}= '';
                   6566:     }
                   6567:     if (ref($settings) eq 'HASH') {
                   6568:         foreach my $type (@pages) {
                   6569:             if (exists($settings->{$type})) {
                   6570:                 if (ref($settings->{$type}) eq 'HASH') {
                   6571:                     foreach my $key (keys(%{$settings->{$type}})) {
                   6572:                         if ($key eq 'namedusers') {
                   6573:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   6574:                         } elsif ($key eq 'machines') {
                   6575:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   6576:                         }
                   6577:                     }
                   6578:                 }
                   6579:             }
                   6580:         }
                   6581:     }
1.81      raeburn  6582:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  6583:     my $rownum = 0;
                   6584:     my $css_class;
                   6585:     foreach my $type (@pages) {
                   6586:         $rownum ++;
                   6587:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   6588:         $datatable .= '<tr'.$css_class.'>'.
                   6589:                       '<td><span class="LC_nobreak">'.
                   6590:                       $titles->{$type}.'</span></td>'.
                   6591:                       '<td class="LC_left_item">'.
                   6592:                       '<input type="text" name="'.$type.'_namedusers" '.
                   6593:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   6594:                       '<td class="LC_right_item">'.
                   6595:                       '<span class="LC_nobreak">'.
                   6596:                       '<input type="text" name="'.$type.'_machines" '.
                   6597:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   6598:                       '</td></tr>'."\n";
                   6599:     }
                   6600:     $$rowtotal += $rownum;
                   6601:     return $datatable;
                   6602: }
                   6603: 
                   6604: sub serverstatus_pages {
                   6605:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15  raeburn  6606:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31  raeburn  6607:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62  raeburn  6608:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  6609: }
                   6610: 
1.160.6.40  raeburn  6611: sub defaults_javascript {
                   6612:     my ($settings) = @_;
1.160.6.80  raeburn  6613:     my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');
                   6614:     my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');
                   6615:     &js_escape(\$intauthcheck);
                   6616:     &js_escape(\$intauthcost);
                   6617:     my $intauthjs = <<"ENDSCRIPT";
                   6618: 
                   6619: function warnIntAuth(field) {
                   6620:     if (field.name == 'intauth_check') {
                   6621:         if (field.value == '2') {
                   6622:             alert('$intauthcheck');
                   6623:         }
                   6624:     }
                   6625:     if (field.name == 'intauth_cost') {
                   6626:         field.value.replace(/\s/g,'');
                   6627:         if (field.value != '') {
                   6628:             var regexdigit=/^\\d+\$/;
                   6629:             if (!regexdigit.test(field.value)) {
                   6630:                 alert('$intauthcost');
                   6631:             }
                   6632:         }
                   6633:     }
                   6634:     return;
                   6635: }
                   6636: 
                   6637: ENDSCRIPT
                   6638: 
                   6639:     if (ref($settings) ne 'HASH') {
                   6640:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
                   6641:     }
1.160.6.40  raeburn  6642:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   6643:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   6644:         if ($maxnum eq '') {
                   6645:             $maxnum = 0;
                   6646:         }
                   6647:         $maxnum ++;
1.160.6.51  raeburn  6648:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.160.6.40  raeburn  6649:         return <<"ENDSCRIPT";
                   6650: <script type="text/javascript">
                   6651: // <![CDATA[
                   6652: function reorderTypes(form,caller) {
                   6653:     var changedVal;
                   6654: $jstext 
                   6655:     var newpos = 'addinststatus_pos';
                   6656:     var current = new Array;
                   6657:     var maxh = $maxnum;
                   6658:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6659:     var oldVal;
                   6660:     if (caller == newpos) {
                   6661:         changedVal = newitemVal;
                   6662:     } else {
                   6663:         var curritem = 'inststatus_pos_'+caller;
                   6664:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   6665:         current[newitemVal] = newpos;
                   6666:     }
                   6667:     for (var i=0; i<inststatuses.length; i++) {
                   6668:         if (inststatuses[i] != caller) {
                   6669:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   6670:             if (form.elements[elementName]) {
                   6671:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6672:                 current[currVal] = elementName;
                   6673:             }
                   6674:         }
                   6675:     }
                   6676:     for (var j=0; j<maxh; j++) {
                   6677:         if (current[j] == undefined) {
                   6678:             oldVal = j;
                   6679:         }
                   6680:     }
                   6681:     if (oldVal < changedVal) {
                   6682:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6683:            var elementName = current[k];
                   6684:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6685:         }
                   6686:     } else {
                   6687:         for (var k=changedVal; k<oldVal; k++) {
                   6688:             var elementName = current[k];
                   6689:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6690:         }
                   6691:     }
                   6692:     return;
                   6693: }
                   6694: 
1.160.6.80  raeburn  6695: $intauthjs
                   6696: 
1.160.6.40  raeburn  6697: // ]]>
                   6698: </script>
                   6699: 
                   6700: ENDSCRIPT
1.160.6.80  raeburn  6701:     } else {
                   6702:         return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.160.6.40  raeburn  6703:     }
                   6704: }
                   6705: 
1.49      raeburn  6706: sub coursecategories_javascript {
                   6707:     my ($settings) = @_;
1.57      raeburn  6708:     my ($output,$jstext,$cathash);
1.49      raeburn  6709:     if (ref($settings) eq 'HASH') {
1.57      raeburn  6710:         $cathash = $settings->{'cats'};
                   6711:     }
                   6712:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  6713:         my (@cats,@jsarray,%idx);
1.57      raeburn  6714:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  6715:         if (@jsarray > 0) {
                   6716:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   6717:             for (my $i=0; $i<@jsarray; $i++) {
                   6718:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   6719:                     my $catstr = join('","',@{$jsarray[$i]});
                   6720:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   6721:                 }
                   6722:             }
                   6723:         }
                   6724:     } else {
                   6725:         $jstext  = '    var categories = Array(1);'."\n".
                   6726:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   6727:     }
1.160.6.42  raeburn  6728:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   6729:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66  raeburn  6730:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   6731:     &js_escape(\$instcode_reserved);
                   6732:     &js_escape(\$communities_reserved);
                   6733:     &js_escape(\$choose_again);
1.49      raeburn  6734:     $output = <<"ENDSCRIPT";
                   6735: <script type="text/javascript">
1.109     raeburn  6736: // <![CDATA[
1.49      raeburn  6737: function reorderCats(form,parent,item,idx) {
                   6738:     var changedVal;
                   6739: $jstext
                   6740:     var newpos = 'addcategory_pos';
                   6741:     if (parent == '') {
                   6742:         var has_instcode = 0;
                   6743:         var maxtop = categories[idx].length;
                   6744:         for (var j=0; j<maxtop; j++) {
                   6745:             if (categories[idx][j] == 'instcode::0') {
                   6746:                 has_instcode == 1;
                   6747:             }
                   6748:         }
                   6749:         if (has_instcode == 0) {
                   6750:             categories[idx][maxtop] = 'instcode_pos';
                   6751:         }
                   6752:     } else {
                   6753:         newpos += '_'+parent;
                   6754:     }
                   6755:     var maxh = 1 + categories[idx].length;
                   6756:     var current = new Array;
                   6757:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   6758:     if (item == newpos) {
                   6759:         changedVal = newitemVal;
                   6760:     } else {
                   6761:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   6762:         current[newitemVal] = newpos;
                   6763:     }
                   6764:     for (var i=0; i<categories[idx].length; i++) {
                   6765:         var elementName = categories[idx][i];
                   6766:         if (elementName != item) {
                   6767:             if (form.elements[elementName]) {
                   6768:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   6769:                 current[currVal] = elementName;
                   6770:             }
                   6771:         }
                   6772:     }
                   6773:     var oldVal;
                   6774:     for (var j=0; j<maxh; j++) {
                   6775:         if (current[j] == undefined) {
                   6776:             oldVal = j;
                   6777:         }
                   6778:     }
                   6779:     if (oldVal < changedVal) {
                   6780:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   6781:            var elementName = current[k];
                   6782:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   6783:         }
                   6784:     } else {
                   6785:         for (var k=changedVal; k<oldVal; k++) {
                   6786:             var elementName = current[k];
                   6787:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   6788:         }
                   6789:     }
                   6790:     return;
                   6791: }
1.120     raeburn  6792: 
                   6793: function categoryCheck(form) {
                   6794:     if (form.elements['addcategory_name'].value == 'instcode') {
                   6795:         alert('$instcode_reserved\\n$choose_again');
                   6796:         return false;
                   6797:     }
                   6798:     if (form.elements['addcategory_name'].value == 'communities') {
                   6799:         alert('$communities_reserved\\n$choose_again');
                   6800:         return false;
                   6801:     }
                   6802:     return true;
                   6803: }
                   6804: 
1.109     raeburn  6805: // ]]>
1.49      raeburn  6806: </script>
                   6807: 
                   6808: ENDSCRIPT
                   6809:     return $output;
                   6810: }
                   6811: 
1.48      raeburn  6812: sub initialize_categories {
                   6813:     my ($itemcount) = @_;
1.120     raeburn  6814:     my ($datatable,$css_class,$chgstr);
                   6815:     my %default_names = (
                   6816:                       instcode    => 'Official courses (with institutional codes)',
                   6817:                       communities => 'Communities',
                   6818:                         );
                   6819:     my $select0 = ' selected="selected"';
                   6820:     my $select1 = '';
                   6821:     foreach my $default ('instcode','communities') {
                   6822:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6823:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
                   6824:         if ($default eq 'communities') {
                   6825:             $select1 = $select0;
                   6826:             $select0 = '';
                   6827:         }
                   6828:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6829:                      .'<select name="'.$default.'_pos">'
                   6830:                      .'<option value="0"'.$select0.'>1</option>'
                   6831:                      .'<option value="1"'.$select1.'>2</option>'
                   6832:                      .'<option value="2">3</option></select>&nbsp;'
                   6833:                      .$default_names{$default}
                   6834:                      .'</span></td><td><span class="LC_nobreak">'
                   6835:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   6836:                      .&mt('Display').'</label>&nbsp;<label>'
                   6837:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  6838:                  .'</label></span></td></tr>';
1.120     raeburn  6839:         $itemcount ++;
                   6840:     }
1.48      raeburn  6841:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  6842:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  6843:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  6844:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   6845:                   .'<option value="0">1</option>'
                   6846:                   .'<option value="1">2</option>'
                   6847:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  6848:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   6849:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   6850:     return $datatable;
                   6851: }
                   6852: 
                   6853: sub build_category_rows {
1.49      raeburn  6854:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   6855:     my ($text,$name,$item,$chgstr);
1.48      raeburn  6856:     if (ref($cats) eq 'ARRAY') {
                   6857:         my $maxdepth = scalar(@{$cats});
                   6858:         if (ref($cats->[$depth]) eq 'HASH') {
                   6859:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   6860:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   6861:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23  raeburn  6862:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  6863:                 my ($idxnum,$parent_name,$parent_item);
                   6864:                 my $higher = $depth - 1;
                   6865:                 if ($higher == 0) {
                   6866:                     $parent_name = &escape($parent).'::'.$higher;
                   6867:                 } else {
                   6868:                     if (ref($path) eq 'ARRAY') {
                   6869:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6870:                     }
                   6871:                 }
                   6872:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  6873:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  6874:                     if ($j < $numchildren) {
1.48      raeburn  6875:                         $name = $cats->[$depth]{$parent}[$j];
                   6876:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  6877:                         $idxnum = $idx->{$item};
                   6878:                     } else {
                   6879:                         $name = $parent_name;
                   6880:                         $item = $parent_item;
1.48      raeburn  6881:                     }
1.49      raeburn  6882:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   6883:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  6884:                     for (my $i=0; $i<=$numchildren; $i++) {
                   6885:                         my $vpos = $i+1;
                   6886:                         my $selstr;
                   6887:                         if ($j == $i) {
                   6888:                             $selstr = ' selected="selected" ';
                   6889:                         }
                   6890:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   6891:                     }
                   6892:                     $text .= '</select>&nbsp;';
                   6893:                     if ($j < $numchildren) {
                   6894:                         my $deeper = $depth+1;
                   6895:                         $text .= $name.'&nbsp;'
                   6896:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   6897:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   6898:                         if(ref($path) eq 'ARRAY') {
                   6899:                             push(@{$path},$name);
1.49      raeburn  6900:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  6901:                             pop(@{$path});
                   6902:                         }
                   6903:                     } else {
1.59      bisitz   6904:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  6905:                         if ($j == $numchildren) {
                   6906:                             $text .= $name;
                   6907:                         } else {
                   6908:                             $text .= $item;
                   6909:                         }
                   6910:                         $text .= '" value="" />';
                   6911:                     }
                   6912:                     $text .= '</td></tr>';
                   6913:                 }
                   6914:                 $text .= '</table></td>';
                   6915:             } else {
                   6916:                 my $higher = $depth-1;
                   6917:                 if ($higher == 0) {
                   6918:                     $name = &escape($parent).'::'.$higher;
                   6919:                 } else {
                   6920:                     if (ref($path) eq 'ARRAY') {
                   6921:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6922:                     }
                   6923:                 }
                   6924:                 my $colspan;
                   6925:                 if ($parent ne 'instcode') {
                   6926:                     $colspan = $maxdepth - $depth - 1;
                   6927:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   6928:                 }
                   6929:             }
                   6930:         }
                   6931:     }
                   6932:     return $text;
                   6933: }
                   6934: 
1.33      raeburn  6935: sub modifiable_userdata_row {
1.160.6.35  raeburn  6936:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
                   6937:     my ($role,$rolename,$statustype);
                   6938:     $role = $item;
1.160.6.34  raeburn  6939:     if ($context eq 'cancreate') {
1.160.6.35  raeburn  6940:         if ($item =~ /^emailusername_(.+)$/) {
                   6941:             $statustype = $1;
                   6942:             $role = 'emailusername';
                   6943:             if (ref($usertypes) eq 'HASH') {
                   6944:                 if ($usertypes->{$statustype}) {
                   6945:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   6946:                 } else {
                   6947:                     $rolename = &mt('Data provided by user');
                   6948:                 }
                   6949:             }
1.160.6.34  raeburn  6950:         }
                   6951:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  6952:         if (ref($usertypes) eq 'HASH') {
                   6953:             $rolename = $usertypes->{$role};
                   6954:         } else {
                   6955:             $rolename = $role;
                   6956:         }
1.33      raeburn  6957:     } else {
1.63      raeburn  6958:         if ($role eq 'cr') {
                   6959:             $rolename = &mt('Custom role');
                   6960:         } else {
                   6961:             $rolename = &Apache::lonnet::plaintext($role);
                   6962:         }
1.33      raeburn  6963:     }
1.160.6.34  raeburn  6964:     my (@fields,%fieldtitles);
                   6965:     if (ref($fieldsref) eq 'ARRAY') {
                   6966:         @fields = @{$fieldsref};
                   6967:     } else {
                   6968:         @fields = ('lastname','firstname','middlename','generation',
                   6969:                    'permanentemail','id');
                   6970:     }
                   6971:     if ((ref($titlesref) eq 'HASH')) {
                   6972:         %fieldtitles = %{$titlesref};
                   6973:     } else {
                   6974:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6975:     }
1.33      raeburn  6976:     my $output;
                   6977:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6978:     $output = '<tr '.$css_class.'>'.
                   6979:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   6980:               '<td class="LC_left_item" colspan="2"><table>';
                   6981:     my $rem;
                   6982:     my %checks;
                   6983:     if (ref($settings) eq 'HASH') {
                   6984:         if (ref($settings->{$context}) eq 'HASH') {
                   6985:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35  raeburn  6986:                 my $hashref = $settings->{$context}->{$role};
                   6987:                 if ($role eq 'emailusername') {
                   6988:                     if ($statustype) {
                   6989:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   6990:                             $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39  raeburn  6991:                             if (ref($hashref) eq 'HASH') { 
1.160.6.35  raeburn  6992:                                 foreach my $field (@fields) {
                   6993:                                     if ($hashref->{$field}) {
                   6994:                                         $checks{$field} = $hashref->{$field};
                   6995:                                     }
                   6996:                                 }
                   6997:                             }
                   6998:                         }
                   6999:                     }
                   7000:                 } else {
                   7001:                     if (ref($hashref) eq 'HASH') {
                   7002:                         foreach my $field (@fields) {
                   7003:                             if ($hashref->{$field}) {
                   7004:                                 $checks{$field} = ' checked="checked" ';
                   7005:                             }
                   7006:                         }
1.33      raeburn  7007:                     }
                   7008:                 }
                   7009:             }
                   7010:         }
                   7011:     }
1.160.6.39  raeburn  7012:      
1.33      raeburn  7013:     for (my $i=0; $i<@fields; $i++) {
                   7014:         my $rem = $i%($numinrow);
                   7015:         if ($rem == 0) {
                   7016:             if ($i > 0) {
                   7017:                 $output .= '</tr>';
                   7018:             }
                   7019:             $output .= '<tr>';
                   7020:         }
                   7021:         my $check = ' ';
1.160.6.35  raeburn  7022:         unless ($role eq 'emailusername') {
                   7023:             if (exists($checks{$fields[$i]})) {
                   7024:                 $check = $checks{$fields[$i]}
                   7025:             } else {
                   7026:                 if ($role eq 'st') {
                   7027:                     if (ref($settings) ne 'HASH') {
1.160.6.39  raeburn  7028:                         $check = ' checked="checked" '; 
1.160.6.35  raeburn  7029:                     }
1.33      raeburn  7030:                 }
                   7031:             }
                   7032:         }
                   7033:         $output .= '<td class="LC_left_item">'.
1.160.6.35  raeburn  7034:                    '<span class="LC_nobreak">';
                   7035:         if ($role eq 'emailusername') {
                   7036:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   7037:                 $checks{$fields[$i]} = 'omit';
                   7038:             }
                   7039:             foreach my $option ('required','optional','omit') {
                   7040:                 my $checked='';
                   7041:                 if ($checks{$fields[$i]} eq $option) {
                   7042:                     $checked='checked="checked" ';
                   7043:                 }
                   7044:                 $output .= '<label>'.
                   7045:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   7046:                            &mt($option).'</label>'.('&nbsp;' x2);
                   7047:             }
                   7048:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   7049:         } else {
                   7050:             $output .= '<label>'.
                   7051:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   7052:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   7053:                        '</label>';
                   7054:         }
                   7055:         $output .= '</span></td>';
1.33      raeburn  7056:         $rem = @fields%($numinrow);
                   7057:     }
                   7058:     my $colsleft = $numinrow - $rem;
                   7059:     if ($colsleft > 1 ) {
                   7060:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   7061:                    '&nbsp;</td>';
                   7062:     } elsif ($colsleft == 1) {
                   7063:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   7064:     }
                   7065:     $output .= '</tr></table></td></tr>';
                   7066:     return $output;
                   7067: }
1.28      raeburn  7068: 
1.93      raeburn  7069: sub insttypes_row {
1.160.6.34  raeburn  7070:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93      raeburn  7071:     my %lt = &Apache::lonlocal::texthash (
                   7072:                       cansearch => 'Users allowed to search',
                   7073:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  7074:                       lockablenames => 'User preference to lock name',
1.93      raeburn  7075:              );
                   7076:     my $showdom;
                   7077:     if ($context eq 'cansearch') {
                   7078:         $showdom = ' ('.$dom.')';
                   7079:     }
1.160.6.5  raeburn  7080:     my $class = 'LC_left_item';
                   7081:     if ($context eq 'statustocreate') {
                   7082:         $class = 'LC_right_item';
                   7083:     }
1.160.6.34  raeburn  7084:     my $css_class = ' class="LC_odd_row"';
                   7085:     if ($rownum ne '') { 
                   7086:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
                   7087:     }
                   7088:     my $output = '<tr'.$css_class.'>'.
                   7089:                  '<td>'.$lt{$context}.$showdom.
                   7090:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  7091:     my $rem;
                   7092:     if (ref($types) eq 'ARRAY') {
                   7093:         for (my $i=0; $i<@{$types}; $i++) {
                   7094:             if (defined($usertypes->{$types->[$i]})) {
                   7095:                 my $rem = $i%($numinrow);
                   7096:                 if ($rem == 0) {
                   7097:                     if ($i > 0) {
                   7098:                         $output .= '</tr>';
                   7099:                     }
                   7100:                     $output .= '<tr>';
1.23      raeburn  7101:                 }
1.26      raeburn  7102:                 my $check = ' ';
1.99      raeburn  7103:                 if (ref($settings) eq 'HASH') {
                   7104:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   7105:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   7106:                             $check = ' checked="checked" ';
                   7107:                         }
                   7108:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  7109:                         $check = ' checked="checked" ';
                   7110:                     }
1.23      raeburn  7111:                 }
1.26      raeburn  7112:                 $output .= '<td class="LC_left_item">'.
                   7113:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  7114:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  7115:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   7116:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  7117:             }
                   7118:         }
1.26      raeburn  7119:         $rem = @{$types}%($numinrow);
1.23      raeburn  7120:     }
                   7121:     my $colsleft = $numinrow - $rem;
1.131     raeburn  7122:     if (($rem == 0) && (@{$types} > 0)) {
                   7123:         $output .= '<tr>';
                   7124:     }
1.23      raeburn  7125:     if ($colsleft > 1) {
1.25      raeburn  7126:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  7127:     } else {
1.25      raeburn  7128:         $output .= '<td class="LC_left_item">';
1.23      raeburn  7129:     }
                   7130:     my $defcheck = ' ';
1.99      raeburn  7131:     if (ref($settings) eq 'HASH') {  
                   7132:         if (ref($settings->{$context}) eq 'ARRAY') {
                   7133:             if (grep(/^default$/,@{$settings->{$context}})) {
                   7134:                 $defcheck = ' checked="checked" ';
                   7135:             }
                   7136:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  7137:             $defcheck = ' checked="checked" ';
                   7138:         }
1.23      raeburn  7139:     }
1.25      raeburn  7140:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  7141:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  7142:                'value="default"'.$defcheck.'/>'.
                   7143:                $othertitle.'</label></span></td>'.
                   7144:                '</tr></table></td></tr>';
                   7145:     return $output;
1.23      raeburn  7146: }
                   7147: 
                   7148: sub sorted_searchtitles {
                   7149:     my %searchtitles = &Apache::lonlocal::texthash(
                   7150:                          'uname' => 'username',
                   7151:                          'lastname' => 'last name',
                   7152:                          'lastfirst' => 'last name, first name',
                   7153:                      );
                   7154:     my @titleorder = ('uname','lastname','lastfirst');
                   7155:     return (\%searchtitles,\@titleorder);
                   7156: }
                   7157: 
1.25      raeburn  7158: sub sorted_searchtypes {
                   7159:     my %srchtypes_desc = (
                   7160:                            exact    => 'is exact match',
                   7161:                            contains => 'contains ..',
                   7162:                            begins   => 'begins with ..',
                   7163:                          );
                   7164:     my @srchtypeorder = ('exact','begins','contains');
                   7165:     return (\%srchtypes_desc,\@srchtypeorder);
                   7166: }
                   7167: 
1.3       raeburn  7168: sub usertype_update_row {
                   7169:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   7170:     my $datatable;
                   7171:     my $numinrow = 4;
                   7172:     foreach my $type (@{$types}) {
                   7173:         if (defined($usertypes->{$type})) {
                   7174:             $$rownums ++;
                   7175:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   7176:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   7177:                           '</td><td class="LC_left_item"><table>';
                   7178:             for (my $i=0; $i<@{$fields}; $i++) {
                   7179:                 my $rem = $i%($numinrow);
                   7180:                 if ($rem == 0) {
                   7181:                     if ($i > 0) {
                   7182:                         $datatable .= '</tr>';
                   7183:                     }
                   7184:                     $datatable .= '<tr>';
                   7185:                 }
                   7186:                 my $check = ' ';
1.39      raeburn  7187:                 if (ref($settings) eq 'HASH') {
                   7188:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   7189:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   7190:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   7191:                                 $check = ' checked="checked" ';
                   7192:                             }
1.3       raeburn  7193:                         }
                   7194:                     }
                   7195:                 }
                   7196: 
                   7197:                 if ($i == @{$fields}-1) {
                   7198:                     my $colsleft = $numinrow - $rem;
                   7199:                     if ($colsleft > 1) {
                   7200:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   7201:                     } else {
                   7202:                         $datatable .= '<td>';
                   7203:                     }
                   7204:                 } else {
                   7205:                     $datatable .= '<td>';
                   7206:                 }
1.8       raeburn  7207:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   7208:                               '<input type="checkbox" name="updateable_'.$type.
                   7209:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   7210:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  7211:             }
                   7212:             $datatable .= '</tr></table></td></tr>';
                   7213:         }
                   7214:     }
                   7215:     return $datatable;
1.1       raeburn  7216: }
                   7217: 
                   7218: sub modify_login {
1.160.6.24  raeburn  7219:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  7220:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   7221:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   7222:     %title = ( coursecatalog => 'Display course catalog',
                   7223:                adminmail => 'Display administrator E-mail address',
1.160.6.14  raeburn  7224:                helpdesk  => 'Display "Contact Helpdesk" link',
1.160.6.5  raeburn  7225:                newuser => 'Link for visitors to create a user account',
                   7226:                loginheader => 'Log-in box header');
                   7227:     @offon = ('off','on');
1.112     raeburn  7228:     if (ref($domconfig{login}) eq 'HASH') {
                   7229:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   7230:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   7231:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   7232:             }
                   7233:         }
                   7234:     }
1.9       raeburn  7235:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   7236:                                            \%domconfig,\%loginhash);
1.160.6.14  raeburn  7237:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  7238:     foreach my $item (@toggles) {
                   7239:         $loginhash{login}{$item} = $env{'form.'.$item};
                   7240:     }
1.41      raeburn  7241:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  7242:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   7243:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   7244:                                          \%loginhash);
                   7245:     }
1.110     raeburn  7246: 
1.149     raeburn  7247:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56  raeburn  7248:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  7249:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  7250:     if (keys(%servers) > 1) {
                   7251:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  7252:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   7253:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   7254:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   7255:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   7256:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   7257:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   7258:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   7259:                         $changes{'loginvia'}{$lonhost} = 1;
                   7260:                     } else {
                   7261:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   7262:                         $changes{'loginvia'}{$lonhost} = 1;
                   7263:                     }
                   7264:                 } else {
                   7265:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   7266:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   7267:                         $changes{'loginvia'}{$lonhost} = 1;
                   7268:                     }
                   7269:                 }
                   7270:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   7271:                     foreach my $item (@loginvia_attribs) {
                   7272:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   7273:                     }
                   7274:                 } else {
                   7275:                     foreach my $item (@loginvia_attribs) {
                   7276:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   7277:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   7278:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   7279:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   7280:                                 $new = '/';
                   7281:                             }
                   7282:                         }
                   7283:                         if (($item eq 'custompath') && 
                   7284:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   7285:                             $new = '';
                   7286:                         }
                   7287:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   7288:                             $changes{'loginvia'}{$lonhost} = 1;
                   7289:                         }
                   7290:                         if ($item eq 'exempt') {
1.160.6.56  raeburn  7291:                             $new = &check_exempt_addresses($new);
1.128     raeburn  7292:                         }
                   7293:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   7294:                     }
                   7295:                 }
1.112     raeburn  7296:             } else {
1.128     raeburn  7297:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   7298:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  7299:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  7300:                     foreach my $item (@loginvia_attribs) {
                   7301:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   7302:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   7303:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   7304:                                 $new = '/';
                   7305:                             }
                   7306:                         }
                   7307:                         if (($item eq 'custompath') && 
                   7308:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   7309:                             $new = '';
                   7310:                         }
                   7311:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   7312:                     }
1.110     raeburn  7313:                 }
                   7314:             }
                   7315:         }
                   7316:     }
1.119     raeburn  7317: 
1.160.6.5  raeburn  7318:     my $servadm = $r->dir_config('lonAdmEMail');
                   7319:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   7320:     if (ref($domconfig{'login'}) eq 'HASH') {
                   7321:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   7322:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   7323:                 if ($lang eq 'nolang') {
                   7324:                     push(@currlangs,$lang);
                   7325:                 } elsif (defined($langchoices{$lang})) {
                   7326:                     push(@currlangs,$lang);
                   7327:                 } else {
                   7328:                     next;
                   7329:                 }
                   7330:             }
                   7331:         }
                   7332:     }
                   7333:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   7334:     if (@currlangs > 0) {
                   7335:         foreach my $lang (@currlangs) {
                   7336:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   7337:                 $changes{'helpurl'}{$lang} = 1;
                   7338:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   7339:                 $changes{'helpurl'}{$lang} = 1;
                   7340:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   7341:                 push(@newlangs,$lang);
                   7342:             } else {
                   7343:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   7344:             }
                   7345:         }
                   7346:     }
                   7347:     unless (grep(/^nolang$/,@currlangs)) {
                   7348:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   7349:             $changes{'helpurl'}{'nolang'} = 1;
                   7350:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   7351:             push(@newlangs,'nolang');
                   7352:         }
                   7353:     }
                   7354:     if ($env{'form.loginhelpurl_add_lang'}) {
                   7355:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   7356:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   7357:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   7358:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   7359:         }
                   7360:     }
                   7361:     if ((@newlangs > 0) || ($addedfile)) {
                   7362:         my $error;
                   7363:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   7364:         if ($configuserok eq 'ok') {
                   7365:             if ($switchserver) {
                   7366:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   7367:             } elsif ($author_ok eq 'ok') {
                   7368:                 my @allnew = @newlangs;
                   7369:                 if ($addedfile ne '') {
                   7370:                     push(@allnew,$addedfile);
                   7371:                 }
                   7372:                 foreach my $lang (@allnew) {
                   7373:                     my $formelem = 'loginhelpurl_'.$lang;
                   7374:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   7375:                         $formelem = 'loginhelpurl_add_file';
                   7376:                     }
                   7377:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   7378:                                                                "help/$lang",'','',$newfile{$lang});
                   7379:                     if ($result eq 'ok') {
                   7380:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   7381:                         $changes{'helpurl'}{$lang} = 1;
                   7382:                     } else {
                   7383:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   7384:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   7385:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
                   7386:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   7387:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   7388:                         }
                   7389:                     }
                   7390:                 }
                   7391:             } else {
                   7392:                 $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);
                   7393:             }
                   7394:         } else {
                   7395:             $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);
                   7396:         }
                   7397:         if ($error) {
                   7398:             &Apache::lonnet::logthis($error);
                   7399:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7400:         }
                   7401:     }
1.160.6.56  raeburn  7402: 
                   7403:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   7404:     if (ref($domconfig{'login'}) eq 'HASH') {
                   7405:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   7406:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   7407:                 if ($domservers{$lonhost}) {
                   7408:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   7409:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73  raeburn  7410:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56  raeburn  7411:                     }
                   7412:                 }
                   7413:             }
                   7414:         }
                   7415:     }
                   7416:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   7417:     foreach my $lonhost (sort(keys(%domservers))) {
                   7418:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   7419:             $changes{'headtag'}{$lonhost} = 1;
                   7420:         } else {
                   7421:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   7422:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   7423:             }
                   7424:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   7425:                 push(@newhosts,$lonhost);
                   7426:             } elsif ($currheadtagurls{$lonhost}) {
                   7427:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   7428:                 if ($currexempt{$lonhost}) {
                   7429:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
                   7430:                         $changes{'headtag'}{$lonhost} = 1;
                   7431:                     }
                   7432:                 } elsif ($possexempt{$lonhost}) {
                   7433:                     $changes{'headtag'}{$lonhost} = 1;
                   7434:                 }
                   7435:                 if ($possexempt{$lonhost}) {
                   7436:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7437:                 }
                   7438:             }
                   7439:         }
                   7440:     }
                   7441:     if (@newhosts) {
                   7442:         my $error;
                   7443:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   7444:         if ($configuserok eq 'ok') {
                   7445:             if ($switchserver) {
                   7446:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   7447:             } elsif ($author_ok eq 'ok') {
                   7448:                 foreach my $lonhost (@newhosts) {
                   7449:                     my $formelem = 'loginheadtag_'.$lonhost;
                   7450:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   7451:                                                                           "login/headtag/$lonhost",'','',
                   7452:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   7453:                     if ($result eq 'ok') {
                   7454:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   7455:                         $changes{'headtag'}{$lonhost} = 1;
                   7456:                         if ($possexempt{$lonhost}) {
                   7457:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   7458:                         }
                   7459:                     } else {
                   7460:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   7461:                                            $newheadtagurls{$lonhost},$result);
                   7462:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   7463:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   7464:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   7465:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   7466:                         }
                   7467:                     }
                   7468:                 }
                   7469:             } else {
                   7470:                 $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);
                   7471:             }
                   7472:         } else {
                   7473:             $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);
                   7474:         }
                   7475:         if ($error) {
                   7476:             &Apache::lonnet::logthis($error);
                   7477:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7478:         }
                   7479:     }
1.160.6.5  raeburn  7480:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
                   7481: 
                   7482:     my $defaulthelpfile = '/adm/loginproblems.html';
                   7483:     my $defaulttext = &mt('Default in use');
                   7484: 
1.1       raeburn  7485:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   7486:                                              $dom);
                   7487:     if ($putresult eq 'ok') {
1.160.6.14  raeburn  7488:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  7489:         my %defaultchecked = (
                   7490:                     'coursecatalog' => 'on',
1.160.6.14  raeburn  7491:                     'helpdesk'      => 'on',
1.42      raeburn  7492:                     'adminmail'     => 'off',
1.43      raeburn  7493:                     'newuser'       => 'off',
1.42      raeburn  7494:         );
1.55      raeburn  7495:         if (ref($domconfig{'login'}) eq 'HASH') {
                   7496:             foreach my $item (@toggles) {
                   7497:                 if ($defaultchecked{$item} eq 'on') { 
                   7498:                     if (($domconfig{'login'}{$item} eq '0') &&
                   7499:                         ($env{'form.'.$item} eq '1')) {
                   7500:                         $changes{$item} = 1;
                   7501:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7502:                               $domconfig{'login'}{$item} eq '1') &&
                   7503:                              ($env{'form.'.$item} eq '0')) {
                   7504:                         $changes{$item} = 1;
                   7505:                     }
                   7506:                 } elsif ($defaultchecked{$item} eq 'off') {
                   7507:                     if (($domconfig{'login'}{$item} eq '1') &&
                   7508:                         ($env{'form.'.$item} eq '0')) {
                   7509:                         $changes{$item} = 1;
                   7510:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   7511:                               $domconfig{'login'}{$item} eq '0') &&
                   7512:                              ($env{'form.'.$item} eq '1')) {
                   7513:                         $changes{$item} = 1;
                   7514:                     }
1.42      raeburn  7515:                 }
                   7516:             }
1.41      raeburn  7517:         }
1.6       raeburn  7518:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  7519:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  7520:             if (ref($lastactref) eq 'HASH') {
                   7521:                 $lastactref->{'domainconfig'} = 1;
                   7522:             }
1.1       raeburn  7523:             $resulttext = &mt('Changes made:').'<ul>';
                   7524:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   7525:                 if ($item eq 'loginvia') {
1.112     raeburn  7526:                     if (ref($changes{$item}) eq 'HASH') {
                   7527:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   7528:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  7529:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   7530:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   7531:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   7532:                                     $protocol = 'http' if ($protocol ne 'https');
                   7533:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   7534: 
                   7535:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   7536:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   7537:                                     } else {
                   7538:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   7539:                                     }
                   7540:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   7541:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   7542:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   7543:                                     }
                   7544:                                     $resulttext .= '</li>';
                   7545:                                 } else {
                   7546:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   7547:                                 }
1.112     raeburn  7548:                             } else {
1.128     raeburn  7549:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  7550:                             }
                   7551:                         }
1.128     raeburn  7552:                         $resulttext .= '</ul></li>';
1.112     raeburn  7553:                     }
1.160.6.5  raeburn  7554:                 } elsif ($item eq 'helpurl') {
                   7555:                     if (ref($changes{$item}) eq 'HASH') {
                   7556:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   7557:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   7558:                                 my ($chg,$link);
                   7559:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   7560:                                 if ($lang eq 'nolang') {
                   7561:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   7562:                                 } else {
                   7563:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   7564:                                 }
                   7565:                                 $resulttext .= '<li>'.$chg.'</li>';
                   7566:                             } else {
                   7567:                                 my $chg;
                   7568:                                 if ($lang eq 'nolang') {
                   7569:                                     $chg = &mt('custom log-in help file for no preferred language');
                   7570:                                 } else {
                   7571:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   7572:                                 }
                   7573:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   7574:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   7575:                                                       '?inhibitmenu=yes',$chg,600,500).
                   7576:                                                '</li>';
                   7577:                             }
                   7578:                         }
                   7579:                     }
1.160.6.56  raeburn  7580:                 } elsif ($item eq 'headtag') {
                   7581:                     if (ref($changes{$item}) eq 'HASH') {
                   7582:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   7583:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   7584:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   7585:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   7586:                                 $resulttext .= '<li><a href="'.
                   7587:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   7588:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   7589:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   7590:                                 if ($possexempt{$lonhost}) {
                   7591:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   7592:                                 } else {
                   7593:                                     $resulttext .= &mt('included for any client IP');
                   7594:                                 }
                   7595:                                 $resulttext .= '</li>';
                   7596:                             }
                   7597:                         }
                   7598:                     }
1.160.6.5  raeburn  7599:                 } elsif ($item eq 'captcha') {
                   7600:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7601:                         my $chgtxt;
                   7602:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   7603:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   7604:                         } else {
                   7605:                             my %captchas = &captcha_phrases();
                   7606:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   7607:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   7608:                             } else {
                   7609:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   7610:                             }
                   7611:                         }
                   7612:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7613:                     }
                   7614:                 } elsif ($item eq 'recaptchakeys') {
                   7615:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7616:                         my ($privkey,$pubkey);
                   7617:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   7618:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   7619:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   7620:                         }
                   7621:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   7622:                         if (!$pubkey) {
                   7623:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   7624:                         } else {
                   7625:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   7626:                         }
                   7627:                         if (!$privkey) {
                   7628:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   7629:                         } else {
1.160.6.53  raeburn  7630:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5  raeburn  7631:                         }
                   7632:                         $chgtxt .= '</ul>';
                   7633:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   7634:                     }
1.160.6.69  raeburn  7635:                 } elsif ($item eq 'recaptchaversion') {
                   7636:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   7637:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
                   7638:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
                   7639:                                            '</li>';
                   7640:                         }
                   7641:                     }
1.41      raeburn  7642:                 } else {
                   7643:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   7644:                 }
1.1       raeburn  7645:             }
1.6       raeburn  7646:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  7647:         } else {
                   7648:             $resulttext = &mt('No changes made to log-in page settings');
                   7649:         }
                   7650:     } else {
1.11      albertel 7651:         $resulttext = '<span class="LC_error">'.
                   7652: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  7653:     }
1.6       raeburn  7654:     if ($errors) {
1.9       raeburn  7655:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  7656:                        $errors.'</ul>';
                   7657:     }
                   7658:     return $resulttext;
                   7659: }
                   7660: 
1.160.6.56  raeburn  7661: sub check_exempt_addresses {
                   7662:     my ($iplist) = @_;
                   7663:     $iplist =~ s/^\s+//;
                   7664:     $iplist =~ s/\s+$//;
                   7665:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   7666:     my (@okips,$new);
                   7667:     foreach my $ip (@poss_ips) {
                   7668:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   7669:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   7670:                 push(@okips,$ip);
                   7671:             }
                   7672:         }
                   7673:     }
                   7674:     if (@okips > 0) {
                   7675:         $new = join(',',@okips);
                   7676:     } else {
                   7677:         $new = '';
                   7678:     }
                   7679:     return $new;
                   7680: }
                   7681: 
1.6       raeburn  7682: sub color_font_choices {
                   7683:     my %choices =
                   7684:         &Apache::lonlocal::texthash (
                   7685:             img => "Header",
                   7686:             bgs => "Background colors",
                   7687:             links => "Link colors",
1.55      raeburn  7688:             images => "Images",
1.6       raeburn  7689:             font => "Font color",
1.160.6.22  raeburn  7690:             fontmenu => "Font menu",
1.76      raeburn  7691:             pgbg => "Page",
1.6       raeburn  7692:             tabbg => "Header",
                   7693:             sidebg => "Border",
                   7694:             link => "Link",
                   7695:             alink => "Active link",
                   7696:             vlink => "Visited link",
                   7697:         );
                   7698:     return %choices;
                   7699: }
                   7700: 
                   7701: sub modify_rolecolors {
1.160.6.24  raeburn  7702:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  7703:     my ($resulttext,%rolehash);
                   7704:     $rolehash{'rolecolors'} = {};
1.55      raeburn  7705:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   7706:         if ($domconfig{'rolecolors'} eq '') {
                   7707:             $domconfig{'rolecolors'} = {};
                   7708:         }
                   7709:     }
1.9       raeburn  7710:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  7711:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   7712:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   7713:                                              $dom);
                   7714:     if ($putresult eq 'ok') {
                   7715:         if (keys(%changes) > 0) {
1.41      raeburn  7716:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  7717:             if (ref($lastactref) eq 'HASH') {
                   7718:                 $lastactref->{'domainconfig'} = 1;
                   7719:             }
1.6       raeburn  7720:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   7721:                                              $rolehash{'rolecolors'});
                   7722:         } else {
                   7723:             $resulttext = &mt('No changes made to default color schemes');
                   7724:         }
                   7725:     } else {
1.11      albertel 7726:         $resulttext = '<span class="LC_error">'.
                   7727: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  7728:     }
                   7729:     if ($errors) {
                   7730:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   7731:                        $errors.'</ul>';
                   7732:     }
                   7733:     return $resulttext;
                   7734: }
                   7735: 
                   7736: sub modify_colors {
1.9       raeburn  7737:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  7738:     my (%changes,%choices);
1.51      raeburn  7739:     my @bgs;
1.6       raeburn  7740:     my @links = ('link','alink','vlink');
1.41      raeburn  7741:     my @logintext;
1.6       raeburn  7742:     my @images;
                   7743:     my $servadm = $r->dir_config('lonAdmEMail');
                   7744:     my $errors;
1.160.6.22  raeburn  7745:     my %defaults;
1.6       raeburn  7746:     foreach my $role (@{$roles}) {
                   7747:         if ($role eq 'login') {
1.12      raeburn  7748:             %choices = &login_choices();
1.41      raeburn  7749:             @logintext = ('textcol','bgcol');
1.12      raeburn  7750:         } else {
                   7751:             %choices = &color_font_choices();
                   7752:         }
                   7753:         if ($role eq 'login') {
1.41      raeburn  7754:             @images = ('img','logo','domlogo','login');
1.51      raeburn  7755:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  7756:         } else {
                   7757:             @images = ('img');
1.160.6.22  raeburn  7758:             @bgs = ('pgbg','tabbg','sidebg');
                   7759:         }
                   7760:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   7761:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   7762:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   7763:         }
                   7764:         if ($role eq 'login') {
                   7765:             foreach my $item (@logintext) {
1.160.6.39  raeburn  7766:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7767:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7768:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7769:                 }
                   7770:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22  raeburn  7771:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7772:                 }
                   7773:             }
                   7774:         } else {
1.160.6.39  raeburn  7775:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   7776:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   7777:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   7778:             }
                   7779:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22  raeburn  7780:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   7781:             }
1.6       raeburn  7782:         }
1.160.6.22  raeburn  7783:         foreach my $item (@bgs) {
1.160.6.39  raeburn  7784:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7785:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7786:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7787:             }
                   7788:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22  raeburn  7789:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7790:             }
                   7791:         }
                   7792:         foreach my $item (@links) {
1.160.6.39  raeburn  7793:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7794:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7795:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7796:             }
                   7797:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22  raeburn  7798:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7799:             }
1.6       raeburn  7800:         }
1.46      raeburn  7801:         my ($configuserok,$author_ok,$switchserver) = 
                   7802:             &config_check($dom,$confname,$servadm);
1.9       raeburn  7803:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  7804:         if (ref($domconfig->{$role}) ne 'HASH') {
                   7805:             $domconfig->{$role} = {};
                   7806:         }
1.8       raeburn  7807:         foreach my $img (@images) {
1.70      raeburn  7808:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   7809:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   7810:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   7811:                 } else { 
                   7812:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   7813:                 }
                   7814:             } 
1.18      albertel 7815: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   7816: 		 && !defined($domconfig->{$role}{$img})
                   7817: 		 && !$env{'form.'.$role.'_del_'.$img}
                   7818: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   7819: 		# import the old configured image from the .tab setting
                   7820: 		# if they haven't provided a new one 
                   7821: 		$domconfig->{$role}{$img} = 
                   7822: 		    $env{'form.'.$role.'_import_'.$img};
                   7823: 	    }
1.6       raeburn  7824:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  7825:                 my $error;
1.6       raeburn  7826:                 if ($configuserok eq 'ok') {
1.9       raeburn  7827:                     if ($switchserver) {
1.12      raeburn  7828:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  7829:                     } else {
                   7830:                         if ($author_ok eq 'ok') {
                   7831:                             my ($result,$logourl) = 
                   7832:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   7833:                                            $dom,$confname,$img,$width,$height);
                   7834:                             if ($result eq 'ok') {
                   7835:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  7836:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7837:                             } else {
1.12      raeburn  7838:                                 $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  7839:                             }
                   7840:                         } else {
1.46      raeburn  7841:                             $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  7842:                         }
                   7843:                     }
                   7844:                 } else {
1.46      raeburn  7845:                     $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  7846:                 }
                   7847:                 if ($error) {
1.8       raeburn  7848:                     &Apache::lonnet::logthis($error);
1.11      albertel 7849:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  7850:                 }
                   7851:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  7852:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   7853:                     my $error;
                   7854:                     if ($configuserok eq 'ok') {
                   7855: # is confname an author?
                   7856:                         if ($switchserver eq '') {
                   7857:                             if ($author_ok eq 'ok') {
                   7858:                                 my ($result,$logourl) = 
                   7859:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   7860:                                             $dom,$confname,$img,$width,$height);
                   7861:                                 if ($result eq 'ok') {
                   7862:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 7863: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7864:                                 }
                   7865:                             }
                   7866:                         }
                   7867:                     }
1.6       raeburn  7868:                 }
                   7869:             }
                   7870:         }
                   7871:         if (ref($domconfig) eq 'HASH') {
                   7872:             if (ref($domconfig->{$role}) eq 'HASH') {
                   7873:                 foreach my $img (@images) {
                   7874:                     if ($domconfig->{$role}{$img} ne '') {
                   7875:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7876:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7877:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7878:                         } else {
1.9       raeburn  7879:                             if ($confhash->{$role}{$img} eq '') {
                   7880:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   7881:                             }
1.6       raeburn  7882:                         }
                   7883:                     } else {
                   7884:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7885:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7886:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7887:                         } 
                   7888:                     }
1.70      raeburn  7889:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   7890:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   7891:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   7892:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   7893:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   7894:                             }
                   7895:                         } else {
                   7896:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7897:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   7898:                             }
                   7899:                         }
                   7900:                     }
                   7901:                 }
1.6       raeburn  7902:                 if ($domconfig->{$role}{'font'} ne '') {
                   7903:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   7904:                         $changes{$role}{'font'} = 1;
                   7905:                     }
                   7906:                 } else {
                   7907:                     if ($confhash->{$role}{'font'}) {
                   7908:                         $changes{$role}{'font'} = 1;
                   7909:                     }
                   7910:                 }
1.107     raeburn  7911:                 if ($role ne 'login') {
                   7912:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   7913:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   7914:                             $changes{$role}{'fontmenu'} = 1;
                   7915:                         }
                   7916:                     } else {
                   7917:                         if ($confhash->{$role}{'fontmenu'}) {
                   7918:                             $changes{$role}{'fontmenu'} = 1;
                   7919:                         }
1.97      tempelho 7920:                     }
                   7921:                 }
1.6       raeburn  7922:                 foreach my $item (@bgs) {
                   7923:                     if ($domconfig->{$role}{$item} ne '') {
                   7924:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7925:                             $changes{$role}{'bgs'}{$item} = 1;
                   7926:                         } 
                   7927:                     } else {
                   7928:                         if ($confhash->{$role}{$item}) {
                   7929:                             $changes{$role}{'bgs'}{$item} = 1;
                   7930:                         }
                   7931:                     }
                   7932:                 }
                   7933:                 foreach my $item (@links) {
                   7934:                     if ($domconfig->{$role}{$item} ne '') {
                   7935:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7936:                             $changes{$role}{'links'}{$item} = 1;
                   7937:                         }
                   7938:                     } else {
                   7939:                         if ($confhash->{$role}{$item}) {
                   7940:                             $changes{$role}{'links'}{$item} = 1;
                   7941:                         }
                   7942:                     }
                   7943:                 }
1.41      raeburn  7944:                 foreach my $item (@logintext) {
                   7945:                     if ($domconfig->{$role}{$item} ne '') {
                   7946:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7947:                             $changes{$role}{'logintext'}{$item} = 1;
                   7948:                         }
                   7949:                     } else {
                   7950:                         if ($confhash->{$role}{$item}) {
                   7951:                             $changes{$role}{'logintext'}{$item} = 1;
                   7952:                         }
                   7953:                     }
                   7954:                 }
1.6       raeburn  7955:             } else {
                   7956:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7957:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  7958:             }
                   7959:         } else {
                   7960:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7961:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  7962:         }
                   7963:     }
                   7964:     return ($errors,%changes);
                   7965: }
                   7966: 
1.46      raeburn  7967: sub config_check {
                   7968:     my ($dom,$confname,$servadm) = @_;
                   7969:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   7970:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   7971:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   7972:                                                    $confname,$servadm);
                   7973:     if ($configuserok eq 'ok') {
                   7974:         $switchserver = &check_switchserver($dom,$confname);
                   7975:         if ($switchserver eq '') {
                   7976:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   7977:         }
                   7978:     }
                   7979:     return ($configuserok,$author_ok,$switchserver);
                   7980: }
                   7981: 
1.6       raeburn  7982: sub default_change_checker {
1.41      raeburn  7983:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  7984:     foreach my $item (@{$links}) {
                   7985:         if ($confhash->{$role}{$item}) {
                   7986:             $changes->{$role}{'links'}{$item} = 1;
                   7987:         }
                   7988:     }
                   7989:     foreach my $item (@{$bgs}) {
                   7990:         if ($confhash->{$role}{$item}) {
                   7991:             $changes->{$role}{'bgs'}{$item} = 1;
                   7992:         }
                   7993:     }
1.41      raeburn  7994:     foreach my $item (@{$logintext}) {
                   7995:         if ($confhash->{$role}{$item}) {
                   7996:             $changes->{$role}{'logintext'}{$item} = 1;
                   7997:         }
                   7998:     }
1.6       raeburn  7999:     foreach my $img (@{$images}) {
                   8000:         if ($env{'form.'.$role.'_del_'.$img}) {
                   8001:             $confhash->{$role}{$img} = '';
1.12      raeburn  8002:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  8003:         }
1.70      raeburn  8004:         if ($role eq 'login') {
                   8005:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   8006:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   8007:             }
                   8008:         }
1.6       raeburn  8009:     }
                   8010:     if ($confhash->{$role}{'font'}) {
                   8011:         $changes->{$role}{'font'} = 1;
                   8012:     }
1.48      raeburn  8013: }
1.6       raeburn  8014: 
                   8015: sub display_colorchgs {
                   8016:     my ($dom,$changes,$roles,$confhash) = @_;
                   8017:     my (%choices,$resulttext);
                   8018:     if (!grep(/^login$/,@{$roles})) {
                   8019:         $resulttext = &mt('Changes made:').'<br />';
                   8020:     }
                   8021:     foreach my $role (@{$roles}) {
                   8022:         if ($role eq 'login') {
                   8023:             %choices = &login_choices();
                   8024:         } else {
                   8025:             %choices = &color_font_choices();
                   8026:         }
                   8027:         if (ref($changes->{$role}) eq 'HASH') {
                   8028:             if ($role ne 'login') {
                   8029:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   8030:             }
                   8031:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   8032:                 if ($role ne 'login') {
                   8033:                     $resulttext .= '<ul>';
                   8034:                 }
                   8035:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   8036:                     if ($role ne 'login') {
                   8037:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   8038:                     }
                   8039:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  8040:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   8041:                             if ($confhash->{$role}{$key}{$item}) {
                   8042:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   8043:                             } else {
                   8044:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   8045:                             }
                   8046:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  8047:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   8048:                         } else {
1.12      raeburn  8049:                             my $newitem = $confhash->{$role}{$item};
                   8050:                             if ($key eq 'images') {
                   8051:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   8052:                             }
                   8053:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  8054:                         }
                   8055:                     }
                   8056:                     if ($role ne 'login') {
                   8057:                         $resulttext .= '</ul></li>';
                   8058:                     }
                   8059:                 } else {
                   8060:                     if ($confhash->{$role}{$key} eq '') {
                   8061:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   8062:                     } else {
                   8063:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   8064:                     }
                   8065:                 }
                   8066:                 if ($role ne 'login') {
                   8067:                     $resulttext .= '</ul>';
                   8068:                 }
                   8069:             }
                   8070:         }
                   8071:     }
1.3       raeburn  8072:     return $resulttext;
1.1       raeburn  8073: }
                   8074: 
1.9       raeburn  8075: sub thumb_dimensions {
                   8076:     return ('200','50');
                   8077: }
                   8078: 
1.16      raeburn  8079: sub check_dimensions {
                   8080:     my ($inputfile) = @_;
                   8081:     my ($fullwidth,$fullheight);
                   8082:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   8083:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   8084:             my $imageinfo = <PIPE>;
                   8085:             if (!close(PIPE)) {
                   8086:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   8087:             }
                   8088:             chomp($imageinfo);
                   8089:             my ($fullsize) = 
1.21      raeburn  8090:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  8091:             if ($fullsize) {
                   8092:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   8093:             }
                   8094:         }
                   8095:     }
                   8096:     return ($fullwidth,$fullheight);
                   8097: }
                   8098: 
1.9       raeburn  8099: sub check_configuser {
                   8100:     my ($uhome,$dom,$confname,$servadm) = @_;
                   8101:     my ($configuserok,%currroles);
                   8102:     if ($uhome eq 'no_host') {
                   8103:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   8104:         my $configpass = &LONCAPA::Enrollment::create_password();
                   8105:         $configuserok = 
                   8106:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   8107:                              $configpass,'','','','','',undef,$servadm);
                   8108:     } else {
                   8109:         $configuserok = 'ok';
                   8110:         %currroles = 
                   8111:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   8112:     }
                   8113:     return ($configuserok,%currroles);
                   8114: }
                   8115: 
                   8116: sub check_authorstatus {
                   8117:     my ($dom,$confname,%currroles) = @_;
                   8118:     my $author_ok;
1.40      raeburn  8119:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  8120:         my $start = time;
                   8121:         my $end = 0;
                   8122:         $author_ok = 
                   8123:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  8124:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  8125:     } else {
                   8126:         $author_ok = 'ok';
                   8127:     }
                   8128:     return $author_ok;
                   8129: }
                   8130: 
                   8131: sub publishlogo {
1.46      raeburn  8132:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9       raeburn  8133:     my ($output,$fname,$logourl);
                   8134:     if ($action eq 'upload') {
                   8135:         $fname=$env{'form.'.$formname.'.filename'};
                   8136:         chop($env{'form.'.$formname});
                   8137:     } else {
                   8138:         ($fname) = ($formname =~ /([^\/]+)$/);
                   8139:     }
1.46      raeburn  8140:     if ($savefileas ne '') {
                   8141:         $fname = $savefileas;
                   8142:     }
1.9       raeburn  8143:     $fname=&Apache::lonnet::clean_filename($fname);
                   8144: # See if there is anything left
                   8145:     unless ($fname) { return ('error: no uploaded file'); }
                   8146:     $fname="$subdir/$fname";
1.160.6.5  raeburn  8147:     my $docroot=$r->dir_config('lonDocRoot');
                   8148:     my $filepath="$docroot/priv";
                   8149:     my $relpath = "$dom/$confname";
1.9       raeburn  8150:     my ($fnamepath,$file,$fetchthumb);
                   8151:     $file=$fname;
                   8152:     if ($fname=~m|/|) {
                   8153:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   8154:     }
1.160.6.26  raeburn  8155:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  8156:     my $count;
1.160.6.5  raeburn  8157:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  8158:         $filepath.="/$parts[$count]";
                   8159:         if ((-e $filepath)!=1) {
                   8160:             mkdir($filepath,02770);
                   8161:         }
                   8162:     }
                   8163:     # Check for bad extension and disallow upload
                   8164:     if ($file=~/\.(\w+)$/ &&
                   8165:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8166:         $output = 
1.160.6.25  raeburn  8167:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  8168:     } elsif ($file=~/\.(\w+)$/ &&
                   8169:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   8170:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8171:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18  raeburn  8172:         $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  8173:     } elsif (-d "$filepath/$file") {
1.160.6.18  raeburn  8174:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  8175:     } else {
                   8176:         my $source = $filepath.'/'.$file;
                   8177:         my $logfile;
                   8178:         if (!open($logfile,">>$source".'.log')) {
1.160.6.19  raeburn  8179:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  8180:         }
                   8181:         print $logfile
                   8182: "\n================= Publish ".localtime()." ================\n".
                   8183: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   8184: # Save the file
                   8185:         if (!open(FH,'>'.$source)) {
                   8186:             &Apache::lonnet::logthis('Failed to create '.$source);
                   8187:             return (&mt('Failed to create file'));
                   8188:         }
                   8189:         if ($action eq 'upload') {
                   8190:             if (!print FH ($env{'form.'.$formname})) {
                   8191:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   8192:                 return (&mt('Failed to write file'));
                   8193:             }
                   8194:         } else {
                   8195:             my $original = &Apache::lonnet::filelocation('',$formname);
                   8196:             if(!copy($original,$source)) {
                   8197:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   8198:                 return (&mt('Failed to write file'));
                   8199:             }
                   8200:         }
                   8201:         close(FH);
                   8202:         chmod(0660, $source); # Permissions to rw-rw---.
                   8203: 
                   8204:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   8205:         my $copyfile=$targetdir.'/'.$file;
                   8206: 
                   8207:         my @parts=split(/\//,$targetdir);
                   8208:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   8209:         for (my $count=5;$count<=$#parts;$count++) {
                   8210:             $path.="/$parts[$count]";
                   8211:             if (!-e $path) {
                   8212:                 print $logfile "\nCreating directory ".$path;
                   8213:                 mkdir($path,02770);
                   8214:             }
                   8215:         }
                   8216:         my $versionresult;
                   8217:         if (-e $copyfile) {
                   8218:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   8219:         } else {
                   8220:             $versionresult = 'ok';
                   8221:         }
                   8222:         if ($versionresult eq 'ok') {
                   8223:             if (copy($source,$copyfile)) {
                   8224:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   8225:                 $output = 'ok';
                   8226:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  8227:                 push(@{$modified_urls},[$copyfile,$source]);
                   8228:                 my $metaoutput = 
                   8229:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   8230:                 unless ($registered_cleanup) {
                   8231:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   8232:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   8233:                     $registered_cleanup=1;
                   8234:                 }
1.9       raeburn  8235:             } else {
                   8236:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   8237:                 $output = &mt('Failed to copy file to RES space').", $!";
                   8238:             }
                   8239:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   8240:                 my $inputfile = $filepath.'/'.$file;
                   8241:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  8242:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   8243:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   8244:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   8245:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   8246:                         system("convert -sample $thumbsize $inputfile $outfile");
                   8247:                         chmod(0660, $filepath.'/tn-'.$file);
                   8248:                         if (-e $outfile) {
                   8249:                             my $copyfile=$targetdir.'/tn-'.$file;
                   8250:                             if (copy($outfile,$copyfile)) {
                   8251:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  8252:                                 my $thumb_metaoutput = 
                   8253:                                     &write_metadata($dom,$confname,$formname,
                   8254:                                                     $targetdir,'tn-'.$file,$logfile);
                   8255:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   8256:                                 unless ($registered_cleanup) {
                   8257:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   8258:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   8259:                                     $registered_cleanup=1;
                   8260:                                 }
1.16      raeburn  8261:                             } else {
                   8262:                                 print $logfile "\nUnable to write ".$copyfile.
                   8263:                                                ':'.$!."\n";
                   8264:                             }
                   8265:                         }
1.9       raeburn  8266:                     }
                   8267:                 }
                   8268:             }
                   8269:         } else {
                   8270:             $output = $versionresult;
                   8271:         }
                   8272:     }
                   8273:     return ($output,$logourl);
                   8274: }
                   8275: 
                   8276: sub logo_versioning {
                   8277:     my ($targetdir,$file,$logfile) = @_;
                   8278:     my $target = $targetdir.'/'.$file;
                   8279:     my ($maxversion,$fn,$extn,$output);
                   8280:     $maxversion = 0;
                   8281:     if ($file =~ /^(.+)\.(\w+)$/) {
                   8282:         $fn=$1;
                   8283:         $extn=$2;
                   8284:     }
                   8285:     opendir(DIR,$targetdir);
                   8286:     while (my $filename=readdir(DIR)) {
                   8287:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   8288:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   8289:         }
                   8290:     }
                   8291:     $maxversion++;
                   8292:     print $logfile "\nCreating old version ".$maxversion."\n";
                   8293:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   8294:     if (copy($target,$copyfile)) {
                   8295:         print $logfile "Copied old target to ".$copyfile."\n";
                   8296:         $copyfile=$copyfile.'.meta';
                   8297:         if (copy($target.'.meta',$copyfile)) {
                   8298:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   8299:             $output = 'ok';
                   8300:         } else {
                   8301:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   8302:             $output = &mt('Failed to copy old meta').", $!, ";
                   8303:         }
                   8304:     } else {
                   8305:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   8306:         $output = &mt('Failed to copy old target').", $!, ";
                   8307:     }
                   8308:     return $output;
                   8309: }
                   8310: 
                   8311: sub write_metadata {
                   8312:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   8313:     my (%metadatafields,%metadatakeys,$output);
                   8314:     $metadatafields{'title'}=$formname;
                   8315:     $metadatafields{'creationdate'}=time;
                   8316:     $metadatafields{'lastrevisiondate'}=time;
                   8317:     $metadatafields{'copyright'}='public';
                   8318:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   8319:                                          $env{'user.domain'};
                   8320:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   8321:     $metadatafields{'domain'}=$dom;
                   8322:     {
                   8323:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   8324:         my $mfh;
1.155     raeburn  8325:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.160.6.13  raeburn  8326:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  8327:                 unless ($_=~/\./) {
                   8328:                     my $unikey=$_;
                   8329:                     $unikey=~/^([A-Za-z]+)/;
                   8330:                     my $tag=$1;
                   8331:                     $tag=~tr/A-Z/a-z/;
                   8332:                     print $mfh "\n\<$tag";
                   8333:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   8334:                         my $value=$metadatafields{$unikey.'.'.$_};
                   8335:                         $value=~s/\"/\'\'/g;
                   8336:                         print $mfh ' '.$_.'="'.$value.'"';
                   8337:                     }
                   8338:                     print $mfh '>'.
                   8339:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   8340:                             .'</'.$tag.'>';
                   8341:                 }
                   8342:             }
                   8343:             $output = 'ok';
                   8344:             print $logfile "\nWrote metadata";
                   8345:             close($mfh);
                   8346:         } else {
                   8347:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  8348:             $output = &mt('Could not write metadata');
                   8349:         }
                   8350:     }
1.155     raeburn  8351:     return $output;
                   8352: }
                   8353: 
                   8354: sub notifysubscribed {
                   8355:     foreach my $targetsource (@{$modified_urls}){
                   8356:         next unless (ref($targetsource) eq 'ARRAY');
                   8357:         my ($target,$source)=@{$targetsource};
                   8358:         if ($source ne '') {
                   8359:             if (open(my $logfh,'>>'.$source.'.log')) {
                   8360:                 print $logfh "\nCleanup phase: Notifications\n";
                   8361:                 my @subscribed=&subscribed_hosts($target);
                   8362:                 foreach my $subhost (@subscribed) {
                   8363:                     print $logfh "\nNotifying host ".$subhost.':';
                   8364:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   8365:                     print $logfh $reply;
                   8366:                 }
                   8367:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   8368:                 foreach my $subhost (@subscribedmeta) {
                   8369:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   8370:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   8371:                                                         $subhost);
                   8372:                     print $logfh $reply;
                   8373:                 }
                   8374:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  8375:                 close($logfh);
1.155     raeburn  8376:             }
                   8377:         }
                   8378:     }
                   8379:     return OK;
                   8380: }
                   8381: 
                   8382: sub subscribed_hosts {
                   8383:     my ($target) = @_;
                   8384:     my @subscribed;
                   8385:     if (open(my $fh,"<$target.subscription")) {
                   8386:         while (my $subline=<$fh>) {
                   8387:             if ($subline =~ /^($match_lonid):/) {
                   8388:                 my $host = $1;
                   8389:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   8390:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   8391:                         push(@subscribed,$host);
                   8392:                     }
                   8393:                 }
                   8394:             }
                   8395:         }
                   8396:     }
                   8397:     return @subscribed;
1.9       raeburn  8398: }
                   8399: 
                   8400: sub check_switchserver {
                   8401:     my ($dom,$confname) = @_;
                   8402:     my ($allowed,$switchserver);
                   8403:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   8404:     if ($home eq 'no_host') {
                   8405:         $home = &Apache::lonnet::domain($dom,'primary');
                   8406:     }
                   8407:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 8408:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   8409:     if (!$allowed) {
1.160.6.11  raeburn  8410: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  8411:     }
                   8412:     return $switchserver;
                   8413: }
                   8414: 
1.1       raeburn  8415: sub modify_quotas {
1.160.6.30  raeburn  8416:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  8417:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30  raeburn  8418:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39  raeburn  8419:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   8420:         $validationfieldsref);
1.86      raeburn  8421:     if ($action eq 'quotas') {
                   8422:         $context = 'tools'; 
1.160.6.26  raeburn  8423:     } else {
1.86      raeburn  8424:         $context = $action;
                   8425:     }
                   8426:     if ($context eq 'requestcourses') {
1.160.6.30  raeburn  8427:         @usertools = ('official','unofficial','community','textbook');
1.106     raeburn  8428:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  8429:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   8430:         %titles = &courserequest_titles();
                   8431:         $toolregexp = join('|',@usertools);
                   8432:         %conditions = &courserequest_conditions();
1.160.6.30  raeburn  8433:         $confname = $dom.'-domainconfig';
                   8434:         my $servadm = $r->dir_config('lonAdmEMail');
                   8435:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39  raeburn  8436:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   8437:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5  raeburn  8438:     } elsif ($context eq 'requestauthor') {
                   8439:         @usertools = ('author');
                   8440:         %titles = &authorrequest_titles();
1.86      raeburn  8441:     } else {
1.160.6.4  raeburn  8442:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  8443:         %titles = &tool_titles();
1.86      raeburn  8444:     }
1.160.6.27  raeburn  8445:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  8446:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  8447:     foreach my $key (keys(%env)) {
1.101     raeburn  8448:         if ($context eq 'requestcourses') {
                   8449:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   8450:                 my $item = $1;
                   8451:                 my $type = $2;
                   8452:                 if ($type =~ /^limit_(.+)/) {
                   8453:                     $limithash{$item}{$1} = $env{$key};
                   8454:                 } else {
                   8455:                     $confhash{$item}{$type} = $env{$key};
                   8456:                 }
                   8457:             }
1.160.6.5  raeburn  8458:         } elsif ($context eq 'requestauthor') {
                   8459:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   8460:                 $confhash{$1} = $env{$key};
                   8461:             }
1.101     raeburn  8462:         } else {
1.86      raeburn  8463:             if ($key =~ /^form\.quota_(.+)$/) {
                   8464:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20  raeburn  8465:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   8466:                 $confhash{'authorquota'}{$1} = $env{$key};
                   8467:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  8468:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   8469:             }
1.72      raeburn  8470:         }
                   8471:     }
1.160.6.5  raeburn  8472:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34  raeburn  8473:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  8474:         @approvalnotify = sort(@approvalnotify);
                   8475:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30  raeburn  8476:         my @crstypes = ('official','unofficial','community','textbook');
                   8477:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   8478:         foreach my $type (@hasuniquecode) {
                   8479:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   8480:                 $confhash{'uniquecode'}{$type} = 1;
                   8481:             }
                   8482:         }
1.160.6.46  raeburn  8483:         my (%newbook,%allpos);
1.160.6.30  raeburn  8484:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8485:             foreach my $type ('textbooks','templates') {
                   8486:                 @{$allpos{$type}} = (); 
                   8487:                 my $invalid;
                   8488:                 if ($type eq 'textbooks') {
                   8489:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   8490:                 } else {
                   8491:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   8492:                 }
                   8493:                 if ($env{'form.'.$type.'_addbook'}) {
                   8494:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   8495:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   8496:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   8497:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   8498:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   8499:                         } else {
                   8500:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   8501:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   8502:                             $position =~ s/\D+//g;
                   8503:                             if ($position ne '') {
                   8504:                                 $allpos{$type}[$position] = $newbook{$type};
                   8505:                             }
1.160.6.30  raeburn  8506:                         }
1.160.6.46  raeburn  8507:                     } else {
                   8508:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30  raeburn  8509:                     }
                   8510:                 }
1.160.6.46  raeburn  8511:             } 
1.160.6.30  raeburn  8512:         }
1.102     raeburn  8513:         if (ref($domconfig{$action}) eq 'HASH') {
                   8514:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   8515:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   8516:                     $changes{'notify'}{'approval'} = 1;
                   8517:                 }
                   8518:             } else {
1.144     raeburn  8519:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8520:                     $changes{'notify'}{'approval'} = 1;
                   8521:                 }
                   8522:             }
1.160.6.30  raeburn  8523:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   8524:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8525:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   8526:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   8527:                             $changes{'uniquecode'} = 1;
                   8528:                         }
                   8529:                     }
                   8530:                     unless ($changes{'uniquecode'}) {
                   8531:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   8532:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   8533:                                 $changes{'uniquecode'} = 1;
                   8534:                             }
                   8535:                         }
                   8536:                     }
                   8537:                } else {
                   8538:                    $changes{'uniquecode'} = 1;
                   8539:                }
                   8540:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8541:                 $changes{'uniquecode'} = 1;
                   8542:             }
                   8543:             if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8544:                 foreach my $type ('textbooks','templates') {
                   8545:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8546:                         my %deletions;
                   8547:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   8548:                         if (@todelete) {
                   8549:                             map { $deletions{$_} = 1; } @todelete;
                   8550:                         }
                   8551:                         my %imgdeletions;
                   8552:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   8553:                         if (@todeleteimages) {
                   8554:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   8555:                         }
                   8556:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   8557:                         for (my $i=0; $i<=$maxnum; $i++) {
                   8558:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   8559:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   8560:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   8561:                                 if ($deletions{$key}) {
                   8562:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   8563:                                         #FIXME need to obsolete item in RES space
                   8564:                                     }
                   8565:                                     next;
                   8566:                                 } else {
                   8567:                                     my $newpos = $env{'form.'.$itemid};
                   8568:                                     $newpos =~ s/\D+//g;
1.160.6.47  raeburn  8569:                                     foreach my $item ('subject','title','publisher','author') {
                   8570:                                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8571:                                                  ($type eq 'templates'));
1.160.6.46  raeburn  8572:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   8573:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   8574:                                             $changes{$type}{$key} = 1;
                   8575:                                         }
                   8576:                                     }
                   8577:                                     $allpos{$type}[$newpos] = $key;
1.160.6.30  raeburn  8578:                                 }
1.160.6.46  raeburn  8579:                                 if ($imgdeletions{$key}) {
                   8580:                                     $changes{$type}{$key} = 1;
                   8581:                                     #FIXME need to obsolete item in RES space
                   8582:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   8583:                                     my ($cdom,$cnum) = split(/_/,$key);
                   8584:                                     my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   8585:                                                                                   $cdom,$cnum,$type,$configuserok,
                   8586:                                                                                   $switchserver,$author_ok);
                   8587:                                     if ($imgurl) {
                   8588:                                         $confhash{$type}{$key}{'image'} = $imgurl;
                   8589:                                         $changes{$type}{$key} = 1; 
1.160.6.30  raeburn  8590:                                     }
1.160.6.46  raeburn  8591:                                     if ($error) {
                   8592:                                         &Apache::lonnet::logthis($error);
                   8593:                                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8594:                                     } 
                   8595:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   8596:                                     $confhash{$type}{$key}{'image'} = 
                   8597:                                         $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30  raeburn  8598:                                 }
                   8599:                             }
                   8600:                         }
                   8601:                     }
                   8602:                 }
                   8603:             }
1.102     raeburn  8604:         } else {
1.144     raeburn  8605:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  8606:                 $changes{'notify'}{'approval'} = 1;
                   8607:             }
1.160.6.30  raeburn  8608:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
                   8609:                 $changes{'uniquecode'} = 1;
                   8610:             }
                   8611:         }
                   8612:         if ($context eq 'requestcourses') {
1.160.6.46  raeburn  8613:             foreach my $type ('textbooks','templates') {
                   8614:                 if ($newbook{$type}) {
                   8615:                     $changes{$type}{$newbook{$type}} = 1;
1.160.6.47  raeburn  8616:                     foreach my $item ('subject','title','publisher','author') {
                   8617:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8618:                                  ($type eq 'template'));
1.160.6.46  raeburn  8619:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   8620:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   8621:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   8622:                         }
                   8623:                     }
                   8624:                     if ($type eq 'textbooks') {
                   8625:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   8626:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
                   8627:                             my ($imageurl,$error) =
                   8628:                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   8629:                                                         $configuserok,$switchserver,$author_ok);
                   8630:                             if ($imageurl) {
                   8631:                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   8632:                             }
                   8633:                             if ($error) {
                   8634:                                 &Apache::lonnet::logthis($error);
                   8635:                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8636:                             }
                   8637:                         }
1.160.6.30  raeburn  8638:                     }
                   8639:                 }
1.160.6.46  raeburn  8640:                 if (@{$allpos{$type}} > 0) {
                   8641:                     my $idx = 0;
                   8642:                     foreach my $item (@{$allpos{$type}}) {
                   8643:                         if ($item ne '') {
                   8644:                             $confhash{$type}{$item}{'order'} = $idx;
                   8645:                             if (ref($domconfig{$action}) eq 'HASH') {
                   8646:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   8647:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   8648:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   8649:                                             $changes{$type}{$item} = 1;
                   8650:                                         }
1.160.6.30  raeburn  8651:                                     }
                   8652:                                 }
                   8653:                             }
1.160.6.46  raeburn  8654:                             $idx ++;
1.160.6.30  raeburn  8655:                         }
                   8656:                     }
                   8657:                 }
                   8658:             }
1.160.6.39  raeburn  8659:             if (ref($validationitemsref) eq 'ARRAY') {
                   8660:                 foreach my $item (@{$validationitemsref}) {
                   8661:                     if ($item eq 'fields') {
                   8662:                         my @changed;
                   8663:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   8664:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   8665:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   8666:                         }
1.160.6.65  raeburn  8667:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8668:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8669:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   8670:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   8671:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   8672:                                 } else {
                   8673:                                     @changed = @{$confhash{'validation'}{$item}};
                   8674:                                 }
1.160.6.39  raeburn  8675:                             } else {
                   8676:                                 @changed = @{$confhash{'validation'}{$item}};
                   8677:                             }
                   8678:                         } else {
                   8679:                             @changed = @{$confhash{'validation'}{$item}};
                   8680:                         }
                   8681:                         if (@changed) {
                   8682:                             if ($confhash{'validation'}{$item}) {
                   8683:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   8684:                             } else {
                   8685:                                 $changes{'validation'}{$item} = &mt('None');
                   8686:                             }
                   8687:                         }
                   8688:                     } else {
                   8689:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   8690:                         if ($item eq 'markup') {
                   8691:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   8692:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   8693:                             }
                   8694:                         }
1.160.6.65  raeburn  8695:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8696:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8697:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   8698:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8699:                                 }
                   8700:                             } else {
                   8701:                                 if ($confhash{'validation'}{$item} ne '') {
                   8702:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8703:                                 }
1.160.6.39  raeburn  8704:                             }
                   8705:                         } else {
                   8706:                             if ($confhash{'validation'}{$item} ne '') {
                   8707:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   8708:                             }
                   8709:                         }
                   8710:                     }
                   8711:                 }
                   8712:             }
                   8713:             if ($env{'form.validationdc'}) {
                   8714:                 my $newval = $env{'form.validationdc'};
1.160.6.77  raeburn  8715:                 my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39  raeburn  8716:                 if (exists($domcoords{$newval})) {
                   8717:                     $confhash{'validation'}{'dc'} = $newval;
                   8718:                 }
                   8719:             }
                   8720:             if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65  raeburn  8721:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8722:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8723:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8724:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8725:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   8726:                                     $changes{'validation'}{'dc'} = &mt('None');
                   8727:                                 } else {
                   8728:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8729:                                 }
1.160.6.39  raeburn  8730:                             }
1.160.6.65  raeburn  8731:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8732:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39  raeburn  8733:                         }
                   8734:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8735:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8736:                     }
                   8737:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   8738:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   8739:                 }
1.160.6.65  raeburn  8740:             } else {
                   8741:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   8742:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   8743:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   8744:                             $changes{'validation'}{'dc'} = &mt('None');
                   8745:                         }
                   8746:                     }
1.160.6.39  raeburn  8747:                 }
                   8748:             }
1.102     raeburn  8749:         }
                   8750:     } else {
1.86      raeburn  8751:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20  raeburn  8752:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  8753:     }
1.72      raeburn  8754:     foreach my $item (@usertools) {
                   8755:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  8756:             my $unset; 
1.101     raeburn  8757:             if ($context eq 'requestcourses') {
1.104     raeburn  8758:                 $unset = '0';
                   8759:                 if ($type eq '_LC_adv') {
                   8760:                     $unset = '';
                   8761:                 }
1.101     raeburn  8762:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   8763:                     $confhash{$item}{$type} .= '=';
                   8764:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   8765:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   8766:                     }
                   8767:                 }
1.160.6.5  raeburn  8768:             } elsif ($context eq 'requestauthor') {
                   8769:                 $unset = '0';
                   8770:                 if ($type eq '_LC_adv') {
                   8771:                     $unset = '';
                   8772:                 }
1.72      raeburn  8773:             } else {
1.101     raeburn  8774:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   8775:                     $confhash{$item}{$type} = 1;
                   8776:                 } else {
                   8777:                     $confhash{$item}{$type} = 0;
                   8778:                 }
1.72      raeburn  8779:             }
1.86      raeburn  8780:             if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5  raeburn  8781:                 if ($action eq 'requestauthor') {
                   8782:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   8783:                         $changes{$type} = 1;
                   8784:                     }
                   8785:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  8786:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   8787:                         $changes{$item}{$type} = 1;
                   8788:                     }
                   8789:                 } else {
                   8790:                     if ($context eq 'requestcourses') {
1.104     raeburn  8791:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  8792:                             $changes{$item}{$type} = 1;
                   8793:                         }
                   8794:                     } else {
                   8795:                         if (!$confhash{$item}{$type}) {
                   8796:                             $changes{$item}{$type} = 1;
                   8797:                         }
                   8798:                     }
                   8799:                 }
                   8800:             } else {
                   8801:                 if ($context eq 'requestcourses') {
1.104     raeburn  8802:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  8803:                         $changes{$item}{$type} = 1;
                   8804:                     }
1.160.6.5  raeburn  8805:                 } elsif ($context eq 'requestauthor') {
                   8806:                     if ($confhash{$type} ne $unset) {
                   8807:                         $changes{$type} = 1;
                   8808:                     }
1.72      raeburn  8809:                 } else {
                   8810:                     if (!$confhash{$item}{$type}) {
                   8811:                         $changes{$item}{$type} = 1;
                   8812:                     }
                   8813:                 }
                   8814:             }
1.1       raeburn  8815:         }
                   8816:     }
1.160.6.5  raeburn  8817:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  8818:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8819:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8820:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   8821:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8822:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   8823:                             $changes{'defaultquota'}{$key} = 1;
                   8824:                         }
                   8825:                     } else {
                   8826:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  8827:                     }
                   8828:                 }
1.86      raeburn  8829:             } else {
                   8830:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   8831:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8832:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   8833:                             $changes{'defaultquota'}{$key} = 1;
                   8834:                         }
                   8835:                     } else {
                   8836:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  8837:                     }
1.1       raeburn  8838:                 }
                   8839:             }
1.160.6.20  raeburn  8840:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8841:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   8842:                     if (exists($confhash{'authorquota'}{$key})) {
                   8843:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   8844:                             $changes{'authorquota'}{$key} = 1;
                   8845:                         }
                   8846:                     } else {
                   8847:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   8848:                     }
                   8849:                 }
                   8850:             }
1.1       raeburn  8851:         }
1.86      raeburn  8852:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   8853:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   8854:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8855:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8856:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   8857:                             $changes{'defaultquota'}{$key} = 1;
                   8858:                         }
                   8859:                     } else {
                   8860:                         if (!exists($domconfig{'quotas'}{$key})) {
                   8861:                             $changes{'defaultquota'}{$key} = 1;
                   8862:                         }
1.72      raeburn  8863:                     }
                   8864:                 } else {
1.86      raeburn  8865:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  8866:                 }
1.1       raeburn  8867:             }
                   8868:         }
1.160.6.20  raeburn  8869:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   8870:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   8871:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8872:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8873:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   8874:                             $changes{'authorquota'}{$key} = 1;
                   8875:                         }
                   8876:                     } else {
                   8877:                         $changes{'authorquota'}{$key} = 1;
                   8878:                     }
                   8879:                 } else {
                   8880:                     $changes{'authorquota'}{$key} = 1;
                   8881:                 }
                   8882:             }
                   8883:         }
1.1       raeburn  8884:     }
1.72      raeburn  8885: 
1.160.6.5  raeburn  8886:     if ($context eq 'requestauthor') {
                   8887:         $domdefaults{'requestauthor'} = \%confhash;
                   8888:     } else {
                   8889:         foreach my $key (keys(%confhash)) {
1.160.6.46  raeburn  8890:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30  raeburn  8891:                 $domdefaults{$key} = $confhash{$key};
                   8892:             }
1.160.6.5  raeburn  8893:         }
1.72      raeburn  8894:     }
1.160.6.5  raeburn  8895: 
1.1       raeburn  8896:     my %quotahash = (
1.86      raeburn  8897:                       $action => { %confhash }
1.1       raeburn  8898:                     );
                   8899:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   8900:                                              $dom);
                   8901:     if ($putresult eq 'ok') {
                   8902:         if (keys(%changes) > 0) {
1.72      raeburn  8903:             my $cachetime = 24*60*60;
                   8904:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  8905:             if (ref($lastactref) eq 'HASH') {
                   8906:                 $lastactref->{'domdefaults'} = 1;
                   8907:             }
1.1       raeburn  8908:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5  raeburn  8909:             unless (($context eq 'requestcourses') ||
                   8910:                     ($context eq 'requestauthor')) {
1.86      raeburn  8911:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   8912:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   8913:                     foreach my $type (@{$types},'default') {
                   8914:                         if (defined($changes{'defaultquota'}{$type})) {
                   8915:                             my $typetitle = $usertypes->{$type};
                   8916:                             if ($type eq 'default') {
                   8917:                                 $typetitle = $othertitle;
                   8918:                             }
1.160.6.28  raeburn  8919:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  8920:                         }
                   8921:                     }
1.86      raeburn  8922:                     $resulttext .= '</ul></li>';
1.72      raeburn  8923:                 }
1.160.6.20  raeburn  8924:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34  raeburn  8925:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20  raeburn  8926:                     foreach my $type (@{$types},'default') {
                   8927:                         if (defined($changes{'authorquota'}{$type})) {
                   8928:                             my $typetitle = $usertypes->{$type};
                   8929:                             if ($type eq 'default') {
                   8930:                                 $typetitle = $othertitle;
                   8931:                             }
1.160.6.28  raeburn  8932:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20  raeburn  8933:                         }
                   8934:                     }
                   8935:                     $resulttext .= '</ul></li>';
                   8936:                 }
1.72      raeburn  8937:             }
1.80      raeburn  8938:             my %newenv;
1.72      raeburn  8939:             foreach my $item (@usertools) {
1.160.6.5  raeburn  8940:                 my (%haschgs,%inconf);
                   8941:                 if ($context eq 'requestauthor') {
                   8942:                     %haschgs = %changes;
                   8943:                     %inconf = %confhash;
                   8944:                 } else {
                   8945:                     if (ref($changes{$item}) eq 'HASH') {
                   8946:                         %haschgs = %{$changes{$item}};
                   8947:                     }
                   8948:                     if (ref($confhash{$item}) eq 'HASH') {
                   8949:                         %inconf = %{$confhash{$item}};
                   8950:                     }
                   8951:                 }
                   8952:                 if (keys(%haschgs) > 0) {
1.80      raeburn  8953:                     my $newacc = 
                   8954:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   8955:                                                           $env{'user.domain'},
1.86      raeburn  8956:                                                           $item,'reload',$context);
1.160.6.5  raeburn  8957:                     if (($context eq 'requestcourses') ||
                   8958:                         ($context eq 'requestauthor')) {
1.108     raeburn  8959:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   8960:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  8961:                         }
                   8962:                     } else {
                   8963:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   8964:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   8965:                         }
1.80      raeburn  8966:                     }
1.160.6.5  raeburn  8967:                     unless ($context eq 'requestauthor') {
                   8968:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   8969:                     }
1.72      raeburn  8970:                     foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5  raeburn  8971:                         if ($haschgs{$type}) {
1.72      raeburn  8972:                             my $typetitle = $usertypes->{$type};
                   8973:                             if ($type eq 'default') {
                   8974:                                 $typetitle = $othertitle;
                   8975:                             } elsif ($type eq '_LC_adv') {
                   8976:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   8977:                             }
1.160.6.5  raeburn  8978:                             if ($inconf{$type}) {
1.101     raeburn  8979:                                 if ($context eq 'requestcourses') {
                   8980:                                     my $cond;
1.160.6.5  raeburn  8981:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  8982:                                         if ($1 eq '') {
                   8983:                                             $cond = &mt('(Automatic processing of any request).');
                   8984:                                         } else {
                   8985:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   8986:                                         }
                   8987:                                     } else { 
1.160.6.5  raeburn  8988:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  8989:                                     }
                   8990:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8  raeburn  8991:                                 } elsif ($context eq 'requestauthor') {
                   8992:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   8993:                                                              $titles{$inconf{$type}},$typetitle);
                   8994: 
1.101     raeburn  8995:                                 } else {
                   8996:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   8997:                                 }
1.72      raeburn  8998:                             } else {
1.104     raeburn  8999:                                 if ($type eq '_LC_adv') {
1.160.6.5  raeburn  9000:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  9001:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9002:                                     } else { 
                   9003:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   9004:                                     }
                   9005:                                 } else {
                   9006:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   9007:                                 }
1.72      raeburn  9008:                             }
                   9009:                         }
1.26      raeburn  9010:                     }
1.160.6.5  raeburn  9011:                     unless ($context eq 'requestauthor') {
                   9012:                         $resulttext .= '</ul></li>';
                   9013:                     }
1.26      raeburn  9014:                 }
1.1       raeburn  9015:             }
1.160.6.5  raeburn  9016:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  9017:                 if (ref($changes{'notify'}) eq 'HASH') {
                   9018:                     if ($changes{'notify'}{'approval'}) {
                   9019:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   9020:                             if ($confhash{'notify'}{'approval'}) {
                   9021:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   9022:                             } else {
1.160.6.5  raeburn  9023:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  9024:                             }
                   9025:                         }
                   9026:                     }
                   9027:                 }
                   9028:             }
1.160.6.30  raeburn  9029:             if ($action eq 'requestcourses') {
                   9030:                 my @offon = ('off','on');
                   9031:                 if ($changes{'uniquecode'}) {
                   9032:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   9033:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   9034:                         $resulttext .= '<li>'.
                   9035:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   9036:                                        '</li>';
                   9037:                     } else {
                   9038:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   9039:                                        '</li>';
                   9040:                     }
                   9041:                 }
1.160.6.46  raeburn  9042:                 foreach my $type ('textbooks','templates') {
                   9043:                     if (ref($changes{$type}) eq 'HASH') {
                   9044:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   9045:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   9046:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   9047:                             my $coursetitle = $coursehash{'description'};
                   9048:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   9049:                             $resulttext .= '<li>';
1.160.6.47  raeburn  9050:                             foreach my $item ('subject','title','publisher','author') {
                   9051:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   9052:                                          ($type eq 'templates'));
1.160.6.46  raeburn  9053:                                 my $name = $item.':';
                   9054:                                 $name =~ s/^(\w)/\U$1/;
                   9055:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   9056:                             }
                   9057:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   9058:                             if ($type eq 'textbooks') {
                   9059:                                 if ($confhash{$type}{$key}{'image'}) {
                   9060:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   9061:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   9062:                                                    ' alt="Textbook cover" />').'<br />';
                   9063:                                 }
                   9064:                             }
                   9065:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30  raeburn  9066:                         }
1.160.6.46  raeburn  9067:                         $resulttext .= '</ul></li>';
1.160.6.30  raeburn  9068:                     }
                   9069:                 }
1.160.6.39  raeburn  9070:                 if (ref($changes{'validation'}) eq 'HASH') {
                   9071:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   9072:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   9073:                         foreach my $item (@{$validationitemsref}) {
                   9074:                             if (exists($changes{'validation'}{$item})) {
                   9075:                                 if ($item eq 'markup') {
                   9076:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9077:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   9078:                                 } else {
                   9079:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   9080:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   9081:                                 }
                   9082:                             }
                   9083:                         }
                   9084:                         if (exists($changes{'validation'}{'dc'})) {
                   9085:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   9086:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   9087:                         }
                   9088:                     }
                   9089:                 }
1.160.6.30  raeburn  9090:             }
1.1       raeburn  9091:             $resulttext .= '</ul>';
1.80      raeburn  9092:             if (keys(%newenv)) {
                   9093:                 &Apache::lonnet::appenv(\%newenv);
                   9094:             }
1.1       raeburn  9095:         } else {
1.86      raeburn  9096:             if ($context eq 'requestcourses') {
                   9097:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5  raeburn  9098:             } elsif ($context eq 'requestauthor') {
                   9099:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  9100:             } else {
1.90      weissno  9101:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  9102:             }
1.1       raeburn  9103:         }
                   9104:     } else {
1.11      albertel 9105:         $resulttext = '<span class="LC_error">'.
                   9106: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9107:     }
1.160.6.30  raeburn  9108:     if ($errors) {
                   9109:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   9110:                        '<ul>'.$errors.'</ul></p>';
                   9111:     }
1.3       raeburn  9112:     return $resulttext;
1.1       raeburn  9113: }
                   9114: 
1.160.6.30  raeburn  9115: sub process_textbook_image {
1.160.6.46  raeburn  9116:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30  raeburn  9117:     my $filename = $env{'form.'.$caller.'.filename'};
                   9118:     my ($error,$url);
                   9119:     my ($width,$height) = (50,50);
                   9120:     if ($configuserok eq 'ok') {
                   9121:         if ($switchserver) {
                   9122:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   9123:                          $switchserver);
                   9124:         } elsif ($author_ok eq 'ok') {
                   9125:             my ($result,$imageurl) =
                   9126:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.46  raeburn  9127:                              "$type/$dom/$cnum/cover",$width,$height);
1.160.6.30  raeburn  9128:             if ($result eq 'ok') {
                   9129:                 $url = $imageurl;
                   9130:             } else {
                   9131:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   9132:             }
                   9133:         } else {
                   9134:             $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);
                   9135:         }
                   9136:     } else {
                   9137:         $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);
                   9138:     }
                   9139:     return ($url,$error);
                   9140: }
                   9141: 
1.160.6.84.2.  (raeburn 9142:): sub modify_ltitools {
                   9143:):     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   9144:):     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   9145:):     my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
                   9146:):     my $confname = $dom.'-domainconfig';
                   9147:):     my $servadm = $r->dir_config('lonAdmEMail');
                   9148:):     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   9149:):     my (%posslti,%possfield);
                   9150:):     my @courseroles = ('cc','in','ta','ep','st');
                   9151:):     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   9152:):     map { $posslti{$_} = 1; } @ltiroles;
                   9153:):     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   9154:):     map { $possfield{$_} = 1; } @allfields;
                   9155:):     my %lt = &ltitools_names();
                   9156:):     if ($env{'form.ltitools_add'}) {
                   9157:):         my $title = $env{'form.ltitools_add_title'};
                   9158:):         $title =~ s/(`)/'/g;
                   9159:):         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   9160:):         if ($newid) {
                   9161:):             my $position = $env{'form.ltitools_add_pos'};
                   9162:):             $position =~ s/\D+//g;
                   9163:):             if ($position ne '') {
                   9164:):                 $allpos[$position] = $newid;
                   9165:):             }
                   9166:):             $changes{$newid} = 1;
                   9167:):             foreach my $item ('title','url','key','secret') {
                   9168:):                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
                   9169:):                 if ($env{'form.ltitools_add_'.$item}) {
                   9170:):                     if (($item eq 'key') || ($item eq 'secret')) {
                   9171:):                         $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   9172:):                     } else {
                   9173:):                         $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   9174:):                     }
                   9175:):                 }
                   9176:):             }
                   9177:):             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   9178:):                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   9179:):             }
                   9180:):             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   9181:):                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   9182:):             }
                   9183:):             foreach my $item ('width','height','linktext','explanation') {
                   9184:):                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   9185:):                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
                   9186:):                 if (($item eq 'width') || ($item eq 'height')) {
                   9187:):                     if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   9188:):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   9189:):                     }
                   9190:):                 } else {
                   9191:):                     if ($env{'form.ltitools_add_'.$item} ne '') {
                   9192:):                         $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   9193:):                     }
                   9194:):                 }
                   9195:):             }
                   9196:):             if ($env{'form.ltitools_add_target'} eq 'window') {
                   9197:):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   9198:):             } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
                   9199:):                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   9200:):             } else {
                   9201:):                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   9202:):             }
                   9203:):             foreach my $item ('passback','roster') {
                   9204:):                 if ($env{'form.ltitools_add_'.$item}) {
                   9205:):                     $confhash{$newid}{$item} = 1;
                   9206:):                 }
                   9207:):             }
                   9208:):             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   9209:):                 my ($imageurl,$error) =
                   9210:):                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
                   9211:):                                             $configuserok,$switchserver,$author_ok);
                   9212:):                 if ($imageurl) {
                   9213:):                     $confhash{$newid}{'image'} = $imageurl;
                   9214:):                 }
                   9215:):                 if ($error) {
                   9216:):                     &Apache::lonnet::logthis($error);
                   9217:):                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9218:):                 }
                   9219:):             }
                   9220:):             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   9221:):             foreach my $field (@fields) {
                   9222:):                 if ($possfield{$field}) {
                   9223:):                     if ($field eq 'roles') {
                   9224:):                         foreach my $role (@courseroles) {
                   9225:):                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   9226:):                             if (($choice ne '') && ($posslti{$choice})) {
                   9227:):                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   9228:):                                 if ($role eq 'cc') {
                   9229:):                                     $confhash{$newid}{'roles'}{'co'} = $choice;
                   9230:):                                 }
                   9231:):                             }
                   9232:):                         }
                   9233:):                     } else {
                   9234:):                         $confhash{$newid}{'fields'}{$field} = 1;
                   9235:):                     }
                   9236:):                 }
                   9237:):             }
                   9238:):             my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
                   9239:):             foreach my $item (@courseconfig) {
                   9240:):                 $confhash{$newid}{'crsconf'}{$item} = 1;
                   9241:):             }
                   9242:):             if ($env{'form.ltitools_add_custom'}) {
                   9243:):                 my $name = $env{'form.ltitools_add_custom_name'};
                   9244:):                 my $value = $env{'form.ltitools_add_custom_value'};
                   9245:):                 $value =~ s/(`)/'/g;
                   9246:):                 $name =~ s/(`)/'/g;
                   9247:):                 $confhash{$newid}{'custom'}{$name} = $value;
                   9248:):             }
                   9249:):         } else {
                   9250:):             my $error = &mt('Failed to acquire unique ID for new external tool');
                   9251:):             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9252:):         }
                   9253:):     }
                   9254:):     if (ref($domconfig{$action}) eq 'HASH') {
                   9255:):         my %deletions;
                   9256:):         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   9257:):         if (@todelete) {
                   9258:):             map { $deletions{$_} = 1; } @todelete;
                   9259:):         }
                   9260:):         my %customadds;
                   9261:):         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   9262:):         if (@newcustom) {
                   9263:):             map { $customadds{$_} = 1; } @newcustom;
                   9264:):         }
                   9265:):         my %imgdeletions;
                   9266:):         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   9267:):         if (@todeleteimages) {
                   9268:):             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   9269:):         }
                   9270:):         my $maxnum = $env{'form.ltitools_maxnum'};
                   9271:):         for (my $i=0; $i<=$maxnum; $i++) {
                   9272:):             my $itemid = $env{'form.ltitools_id_'.$i};
                   9273:):             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   9274:):                 if ($deletions{$itemid}) {
                   9275:):                     if ($domconfig{$action}{$itemid}{'image'}) {
                   9276:):                         #FIXME need to obsolete item in RES space
                   9277:):                     }
                   9278:):                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   9279:):                     next;
                   9280:):                 } else {
                   9281:):                     my $newpos = $env{'form.ltitools_'.$itemid};
                   9282:):                     $newpos =~ s/\D+//g;
                   9283:):                     foreach my $item ('title','url') {
                   9284:):                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   9285:):                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   9286:):                             $changes{$itemid} = 1;
                   9287:):                         }
                   9288:):                     }
                   9289:):                     foreach my $item ('key','secret') {
                   9290:):                         $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   9291:):                         if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
                   9292:):                             $changes{$itemid} = 1;
                   9293:):                         }
                   9294:):                     }
                   9295:):                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   9296:):                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   9297:):                     }
                   9298:):                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   9299:):                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   9300:):                     }
                   9301:):                     foreach my $size ('width','height') {
                   9302:):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   9303:):                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   9304:):                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   9305:):                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   9306:):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   9307:):                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   9308:):                                     $changes{$itemid} = 1;
                   9309:):                                 }
                   9310:):                             } else {
                   9311:):                                 $changes{$itemid} = 1;
                   9312:):                             }
                   9313:):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   9314:):                             if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
                   9315:):                                 $changes{$itemid} = 1;
                   9316:):                             }
                   9317:):                         }
                   9318:):                     }
                   9319:):                     foreach my $item ('linktext','explanation') {
                   9320:):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
                   9321:):                         $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
                   9322:):                         if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
                   9323:):                             $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   9324:):                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   9325:):                                 if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
                   9326:):                                     $changes{$itemid} = 1;
                   9327:):                                 }
                   9328:):                             } else {
                   9329:):                                 $changes{$itemid} = 1;
                   9330:):                             }
                   9331:):                         } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   9332:):                             if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
                   9333:):                                 $changes{$itemid} = 1;
                   9334:):                             }
                   9335:):                         }
                   9336:):                     }
                   9337:):                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   9338:):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   9339:):                     } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
                   9340:):                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   9341:):                     } else {
                   9342:):                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   9343:):                     }
                   9344:):                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   9345:):                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   9346:):                             $changes{$itemid} = 1;
                   9347:):                         }
                   9348:):                     } else {
                   9349:):                         $changes{$itemid} = 1;
                   9350:):                     }
                   9351:):                     foreach my $extra ('passback','roster') {
                   9352:):                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   9353:):                             $confhash{$itemid}{$extra} = 1;
                   9354:):                         }
                   9355:):                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   9356:):                             $changes{$itemid} = 1;
                   9357:):                         }
                   9358:):                     }
                   9359:):                     my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
                   9360:):                     foreach my $item ('label','title','target','linktext','explanation') {
                   9361:):                         if (grep(/^\Q$item\E$/,@courseconfig)) {
                   9362:):                             $confhash{$itemid}{'crsconf'}{$item} = 1;
                   9363:):                             if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
                   9364:):                                 if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
                   9365:):                                     $changes{$itemid} = 1;
                   9366:):                                 }
                   9367:):                             } else {
                   9368:):                                 $changes{$itemid} = 1;
                   9369:):                             }
                   9370:):                         }
                   9371:):                     }
                   9372:):                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   9373:):                     foreach my $field (@fields) {
                   9374:):                         if ($possfield{$field}) {
                   9375:):                             if ($field eq 'roles') {
                   9376:):                                 foreach my $role (@courseroles) {
                   9377:):                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   9378:):                                     if (($choice ne '') && ($posslti{$choice})) {
                   9379:):                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   9380:):                                         if ($role eq 'cc') {
                   9381:):                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   9382:):                                         }
                   9383:):                                     }
                   9384:):                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   9385:):                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   9386:):                                             $changes{$itemid} = 1;
                   9387:):                                         }
                   9388:):                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   9389:):                                         $changes{$itemid} = 1;
                   9390:):                                     }
                   9391:):                                 }
                   9392:):                             } else {
                   9393:):                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   9394:):                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   9395:):                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   9396:):                                         $changes{$itemid} = 1;
                   9397:):                                     }
                   9398:):                                 } else {
                   9399:):                                     $changes{$itemid} = 1;
                   9400:):                                 }
                   9401:):                             }
                   9402:):                         }
                   9403:):                     }
                   9404:):                     $allpos[$newpos] = $itemid;
                   9405:):                 }
                   9406:):                 if ($imgdeletions{$itemid}) {
                   9407:):                     $changes{$itemid} = 1;
                   9408:):                     #FIXME need to obsolete item in RES space
                   9409:):                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   9410:):                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   9411:):                                                                  $itemid,$configuserok,$switchserver,
                   9412:):                                                                  $author_ok);
                   9413:):                     if ($imgurl) {
                   9414:):                         $confhash{$itemid}{'image'} = $imgurl;
                   9415:):                         $changes{$itemid} = 1;
                   9416:):                     }
                   9417:):                     if ($error) {
                   9418:):                         &Apache::lonnet::logthis($error);
                   9419:):                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   9420:):                     }
                   9421:):                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   9422:):                     $confhash{$itemid}{'image'} =
                   9423:):                        $domconfig{$action}{$itemid}{'image'};
                   9424:):                 }
                   9425:):                 if ($customadds{$i}) {
                   9426:):                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   9427:):                     $name =~ s/(`)/'/g;
                   9428:):                     $name =~ s/^\s+//;
                   9429:):                     $name =~ s/\s+$//;
                   9430:):                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   9431:):                     $value =~ s/(`)/'/g;
                   9432:):                     $value =~ s/^\s+//;
                   9433:):                     $value =~ s/\s+$//;
                   9434:):                     if ($name ne '') {
                   9435:):                         $confhash{$itemid}{'custom'}{$name} = $value;
                   9436:):                         $changes{$itemid} = 1;
                   9437:):                     }
                   9438:):                 }
                   9439:):                 my %customdels;
                   9440:):                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
                   9441:):                 if (@customdeletions) {
                   9442:):                     $changes{$itemid} = 1;
                   9443:):                 }
                   9444:):                 map { $customdels{$_} = 1; } @customdeletions;
                   9445:):                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   9446:):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   9447:):                         unless ($customdels{$key}) {
                   9448:):                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   9449:):                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
                   9450:):                             }
                   9451:):                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   9452:):                                 $changes{$itemid} = 1;
                   9453:):                             }
                   9454:):                         }
                   9455:):                     }
                   9456:):                 }
                   9457:):                 unless ($changes{$itemid}) {
                   9458:):                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   9459:):                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   9460:):                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   9461:):                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   9462:):                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   9463:):                                         $changes{$itemid} = 1;
                   9464:):                                         last;
                   9465:):                                     }
                   9466:):                                 }
                   9467:):                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   9468:):                                 $changes{$itemid} = 1;
                   9469:):                             }
                   9470:):                         }
                   9471:):                         last if ($changes{$itemid});
                   9472:):                     }
                   9473:):                 }
                   9474:):             }
                   9475:):         }
                   9476:):     }
                   9477:):     if (@allpos > 0) {
                   9478:):         my $idx = 0;
                   9479:):         foreach my $itemid (@allpos) {
                   9480:):             if ($itemid ne '') {
                   9481:):                 $confhash{$itemid}{'order'} = $idx;
                   9482:):                 if (ref($domconfig{$action}) eq 'HASH') {
                   9483:):                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   9484:):                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   9485:):                             $changes{$itemid} = 1;
                   9486:):                         }
                   9487:):                     }
                   9488:):                 }
                   9489:):                 $idx ++;
                   9490:):             }
                   9491:):         }
                   9492:):     }
                   9493:):     my %ltitoolshash = (
                   9494:):                           $action => { %confhash }
                   9495:):                        );
                   9496:):     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   9497:):                                              $dom);
                   9498:):     if ($putresult eq 'ok') {
                   9499:):         my %ltienchash = (
                   9500:):                              $action => { %encconfig }
                   9501:):                          );
                   9502:):         &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom);
                   9503:):         if (keys(%changes) > 0) {
                   9504:):             my $cachetime = 24*60*60;
                   9505:):             my %ltiall = %confhash;
                   9506:):             foreach my $id (keys(%ltiall)) {
                   9507:):                 if (ref($encconfig{$id}) eq 'HASH') {
                   9508:):                     foreach my $item ('key','secret') {
                   9509:):                         $ltiall{$id}{$item} = $encconfig{$id}{$item};
                   9510:):                     }
                   9511:):                 }
                   9512:):             }
                   9513:):             &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
                   9514:):             if (ref($lastactref) eq 'HASH') {
                   9515:):                 $lastactref->{'ltitools'} = 1;
                   9516:):             }
                   9517:):             $resulttext = &mt('Changes made:').'<ul>';
                   9518:):             my %bynum;
                   9519:):             foreach my $itemid (sort(keys(%changes))) {
                   9520:):                 my $position = $confhash{$itemid}{'order'};
                   9521:):                 $bynum{$position} = $itemid;
                   9522:):             }
                   9523:):             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   9524:):                 my $itemid = $bynum{$pos};
                   9525:):                 if (ref($confhash{$itemid}) ne 'HASH') {
                   9526:):                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   9527:):                 } else {
                   9528:):                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   9529:):                     if ($confhash{$itemid}{'image'}) {
                   9530:):                         $resulttext .= '&nbsp;'.
                   9531:):                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   9532:):                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   9533:):                     }
                   9534:):                     $resulttext .= '</li><ul>';
                   9535:):                     my $position = $pos + 1;
                   9536:):                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   9537:):                     foreach my $item ('version','msgtype','url') {
                   9538:):                         if ($confhash{$itemid}{$item} ne '') {
                   9539:):                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   9540:):                         }
                   9541:):                     }
                   9542:):                     if ($encconfig{$itemid}{'key'} ne '') {
                   9543:):                         $resulttext .= '<li>'.$lt{'key'}.':&nbsp;'.$encconfig{$itemid}{'key'}.'</li>';
                   9544:):                     }
                   9545:):                     if ($encconfig{$itemid}{'secret'} ne '') {
                   9546:):                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   9547:):                         my $num = length($encconfig{$itemid}{'secret'});
                   9548:):                         $resulttext .= ('*'x$num).'</li>';
                   9549:):                     }
                   9550:):                     $resulttext .= '<li>'.&mt('Configurable in course:');
                   9551:):                     my @possconfig = ('label','title','target','linktext','explanation');
                   9552:):                     my $numconfig = 0;
                   9553:):                     if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
                   9554:):                         foreach my $item (@possconfig) {
                   9555:):                             if ($confhash{$itemid}{'crsconf'}{$item}) {
                   9556:):                                 $numconfig ++;
                   9557:):                                 $resulttext .= ' "'.$lt{'crs'.$item}.'"';
                   9558:):                             }
                   9559:):                         }
                   9560:):                     }
                   9561:):                     if (!$numconfig) {
                   9562:):                         $resulttext .= &mt('None');
                   9563:):                     }
                   9564:):                     $resulttext .= '</li>';
                   9565:):                     foreach my $item ('passback','roster') {
                   9566:):                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   9567:):                         if ($confhash{$itemid}{$item}) {
                   9568:):                             $resulttext .= &mt('Yes');
                   9569:):                         } else {
                   9570:):                             $resulttext .= &mt('No');
                   9571:):                         }
                   9572:):                         $resulttext .= '</li>';
                   9573:):                     }
                   9574:):                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   9575:):                         my $displaylist;
                   9576:):                         if ($confhash{$itemid}{'display'}{'target'}) {
                   9577:):                             $displaylist = &mt('Display target').':&nbsp;'.
                   9578:):                                            $confhash{$itemid}{'display'}{'target'}.',';
                   9579:):                         }
                   9580:):                         foreach my $size ('width','height') {
                   9581:):                             if ($confhash{$itemid}{'display'}{$size}) {
                   9582:):                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   9583:):                                                 $confhash{$itemid}{'display'}{$size}.',';
                   9584:):                             }
                   9585:):                         }
                   9586:):                         if ($displaylist) {
                   9587:):                             $displaylist =~ s/,$//;
                   9588:):                             $resulttext .= '<li>'.$displaylist.'</li>';
                   9589:):                         }
                   9590:):                         foreach my $item ('linktext','explanation') {
                   9591:):                             if ($confhash{$itemid}{'display'}{$item}) {
                   9592:):                                 $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{'display'}{$item}.'</li>';
                   9593:):                             }
                   9594:):                         }
                   9595:):                     }
                   9596:):                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   9597:):                         my $fieldlist;
                   9598:):                         foreach my $field (@allfields) {
                   9599:):                             if ($confhash{$itemid}{'fields'}{$field}) {
                   9600:):                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   9601:):                             }
                   9602:):                         }
                   9603:):                         if ($fieldlist) {
                   9604:):                             $fieldlist =~ s/,$//;
                   9605:):                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   9606:):                         }
                   9607:):                     }
                   9608:):                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   9609:):                         my $rolemaps;
                   9610:):                         foreach my $role (@courseroles) {
                   9611:):                             if ($confhash{$itemid}{'roles'}{$role}) {
                   9612:):                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   9613:):                                              $confhash{$itemid}{'roles'}{$role}.',';
                   9614:):                             }
                   9615:):                         }
                   9616:):                         if ($rolemaps) {
                   9617:):                             $rolemaps =~ s/,$//;
                   9618:):                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   9619:):                         }
                   9620:):                     }
                   9621:):                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   9622:):                         my $customlist;
                   9623:):                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   9624:):                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   9625:):                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   9626:):                             }
                   9627:):                         }
                   9628:):                         if ($customlist) {
                   9629:):                             $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
                   9630:):                         }
                   9631:):                     }
                   9632:):                     $resulttext .= '</ul></li>';
                   9633:):                 }
                   9634:):             }
                   9635:):             $resulttext .= '</ul>';
                   9636:):         } else {
                   9637:):             $resulttext = &mt('No changes made.');
                   9638:):         }
                   9639:):     } else {
                   9640:):         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   9641:):     }
                   9642:):     if ($errors) {
                   9643:):         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   9644:):                        $errors.'</ul>';
                   9645:):     }
                   9646:):     return $resulttext;
                   9647:): }
                   9648:): 
                   9649:): sub process_ltitools_image {
                   9650:):     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   9651:):     my $filename = $env{'form.'.$caller.'.filename'};
                   9652:):     my ($error,$url);
                   9653:):     my ($width,$height) = (21,21);
                   9654:):     if ($configuserok eq 'ok') {
                   9655:):         if ($switchserver) {
                   9656:):             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   9657:):                          $switchserver);
                   9658:):         } elsif ($author_ok eq 'ok') {
                   9659:):             my ($result,$imageurl,$madethumb) =
                   9660:):                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   9661:):                              "ltitools/$itemid/icon",$width,$height);
                   9662:):             if ($result eq 'ok') {
                   9663:):                 if ($madethumb) {
                   9664:):                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   9665:):                     my $imagethumb = "$path/tn-".$imagefile;
                   9666:):                     $url = $imagethumb;
                   9667:):                 } else {
                   9668:):                     $url = $imageurl;
                   9669:):                 }
                   9670:):             } else {
                   9671:):                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   9672:):             }
                   9673:):         } else {
                   9674:):             $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);
                   9675:):         }
                   9676:):     } else {
                   9677:):         $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);
                   9678:):     }
                   9679:):     return ($url,$error);
                   9680:): }
                   9681:): 
                   9682:): sub get_ltitools_id {
                   9683:):     my ($cdom,$title) = @_;
                   9684:):     # get lock on ltitools db
                   9685:):     my $lockhash = {
                   9686:):                       lock => $env{'user.name'}.
                   9687:):                               ':'.$env{'user.domain'},
                   9688:):                    };
                   9689:):     my $tries = 0;
                   9690:):     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   9691:):     my ($id,$error);
                   9692:): 
                   9693:):     while (($gotlock ne 'ok') && ($tries<10)) {
                   9694:):         $tries ++;
                   9695:):         sleep (0.1);
                   9696:):         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   9697:):     }
                   9698:):     if ($gotlock eq 'ok') {
                   9699:):         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   9700:):         if ($currids{'lock'}) {
                   9701:):             delete($currids{'lock'});
                   9702:):             if (keys(%currids)) {
                   9703:):                 my @curr = sort { $a <=> $b } keys(%currids);
                   9704:):                 if ($curr[-1] =~ /^\d+$/) {
                   9705:):                     $id = 1 + $curr[-1];
                   9706:):                 }
                   9707:):             } else {
                   9708:):                 $id = 1;
                   9709:):             }
                   9710:):             if ($id) {
                   9711:):                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   9712:):                     $error = 'nostore';
                   9713:):                 }
                   9714:):             } else {
                   9715:):                 $error = 'nonumber';
                   9716:):             }
                   9717:):         }
                   9718:):         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   9719:):     } else {
                   9720:):         $error = 'nolock';
                   9721:):     }
                   9722:):     return ($id,$error);
                   9723:): }
                   9724:): 
1.3       raeburn  9725: sub modify_autoenroll {
1.160.6.24  raeburn  9726:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  9727:     my ($resulttext,%changes);
                   9728:     my %currautoenroll;
                   9729:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   9730:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   9731:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   9732:         }
                   9733:     }
                   9734:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   9735:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  9736:                   sender => 'Sender for notification messages',
1.160.6.68  raeburn  9737:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
                   9738:                   failsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1       raeburn  9739:     my @offon = ('off','on');
1.17      raeburn  9740:     my $sender_uname = $env{'form.sender_uname'};
                   9741:     my $sender_domain = $env{'form.sender_domain'};
                   9742:     if ($sender_domain eq '') {
                   9743:         $sender_uname = '';
                   9744:     } elsif ($sender_uname eq '') {
                   9745:         $sender_domain = '';
                   9746:     }
1.129     raeburn  9747:     my $coowners = $env{'form.autoassign_coowners'};
1.160.6.68  raeburn  9748:     my $failsafe = $env{'form.autoenroll_failsafe'};
                   9749:     $failsafe =~ s{^\s+|\s+$}{}g;
                   9750:     if ($failsafe =~ /\D/) {
                   9751:         undef($failsafe);
                   9752:     }
1.1       raeburn  9753:     my %autoenrollhash =  (
1.129     raeburn  9754:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   9755:                                        'sender_uname' => $sender_uname,
                   9756:                                        'sender_domain' => $sender_domain,
                   9757:                                        'co-owners' => $coowners,
1.160.6.68  raeburn  9758:                                        'autofailsafe' => $failsafe,
1.1       raeburn  9759:                                 }
                   9760:                      );
1.4       raeburn  9761:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   9762:                                              $dom);
1.1       raeburn  9763:     if ($putresult eq 'ok') {
                   9764:         if (exists($currautoenroll{'run'})) {
                   9765:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   9766:                  $changes{'run'} = 1;
                   9767:              }
                   9768:         } elsif ($autorun) {
                   9769:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  9770:                  $changes{'run'} = 1;
1.1       raeburn  9771:             }
                   9772:         }
1.17      raeburn  9773:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  9774:             $changes{'sender'} = 1;
                   9775:         }
1.17      raeburn  9776:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  9777:             $changes{'sender'} = 1;
                   9778:         }
1.129     raeburn  9779:         if ($currautoenroll{'co-owners'} ne '') {
                   9780:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   9781:                 $changes{'coowners'} = 1;
                   9782:             }
                   9783:         } elsif ($coowners) {
                   9784:             $changes{'coowners'} = 1;
1.160.6.68  raeburn  9785:         }
                   9786:         if ($currautoenroll{'autofailsafe'} ne $failsafe) {
                   9787:             $changes{'autofailsafe'} = 1;
                   9788:         }
1.1       raeburn  9789:         if (keys(%changes) > 0) {
                   9790:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  9791:             if ($changes{'run'}) {
1.1       raeburn  9792:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   9793:             }
                   9794:             if ($changes{'sender'}) {
1.17      raeburn  9795:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   9796:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   9797:                 } else {
                   9798:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   9799:                 }
1.1       raeburn  9800:             }
1.129     raeburn  9801:             if ($changes{'coowners'}) {
                   9802:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   9803:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  9804:                 if (ref($lastactref) eq 'HASH') {
                   9805:                     $lastactref->{'domainconfig'} = 1;
                   9806:                 }
1.129     raeburn  9807:             }
1.160.6.68  raeburn  9808:             if ($changes{'autofailsafe'}) {
                   9809:                 if ($failsafe ne '') {
1.160.6.82  raeburn  9810:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$failsafe).'</li>';
1.160.6.68  raeburn  9811:                 } else {
1.160.6.82  raeburn  9812:                     $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section: deleted');
1.160.6.68  raeburn  9813:                 }
                   9814:                 &Apache::lonnet::get_domain_defaults($dom,1);
                   9815:                 if (ref($lastactref) eq 'HASH') {
                   9816:                     $lastactref->{'domdefaults'} = 1;
                   9817:                 }
                   9818:             }
1.1       raeburn  9819:             $resulttext .= '</ul>';
                   9820:         } else {
                   9821:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   9822:         }
                   9823:     } else {
1.11      albertel 9824:         $resulttext = '<span class="LC_error">'.
                   9825: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9826:     }
1.3       raeburn  9827:     return $resulttext;
1.1       raeburn  9828: }
                   9829: 
                   9830: sub modify_autoupdate {
1.3       raeburn  9831:     my ($dom,%domconfig) = @_;
1.1       raeburn  9832:     my ($resulttext,%currautoupdate,%fields,%changes);
                   9833:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   9834:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   9835:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   9836:         }
                   9837:     }
                   9838:     my @offon = ('off','on');
                   9839:     my %title = &Apache::lonlocal::texthash (
                   9840:                    run => 'Auto-update:',
                   9841:                    classlists => 'Updates to user information in classlists?'
                   9842:                 );
1.44      raeburn  9843:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  9844:     my %fieldtitles = &Apache::lonlocal::texthash (
                   9845:                         id => 'Student/Employee ID',
1.20      raeburn  9846:                         permanentemail => 'E-mail address',
1.1       raeburn  9847:                         lastname => 'Last Name',
                   9848:                         firstname => 'First Name',
                   9849:                         middlename => 'Middle Name',
1.132     raeburn  9850:                         generation => 'Generation',
1.1       raeburn  9851:                       );
1.142     raeburn  9852:     $othertitle = &mt('All users');
1.1       raeburn  9853:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  9854:         $othertitle = &mt('Other users');
1.1       raeburn  9855:     }
                   9856:     foreach my $key (keys(%env)) {
                   9857:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  9858:             my ($usertype,$item) = ($1,$2);
                   9859:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   9860:                 if ($usertype eq 'default') {   
                   9861:                     push(@{$fields{$1}},$2);
                   9862:                 } elsif (ref($types) eq 'ARRAY') {
                   9863:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   9864:                         push(@{$fields{$1}},$2);
                   9865:                     }
                   9866:                 }
                   9867:             }
1.1       raeburn  9868:         }
                   9869:     }
1.131     raeburn  9870:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   9871:     @lockablenames = sort(@lockablenames);
                   9872:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   9873:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   9874:         if (@changed) {
                   9875:             $changes{'lockablenames'} = 1;
                   9876:         }
                   9877:     } else {
                   9878:         if (@lockablenames) {
                   9879:             $changes{'lockablenames'} = 1;
                   9880:         }
                   9881:     }
1.1       raeburn  9882:     my %updatehash = (
                   9883:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   9884:                                       classlists => $env{'form.classlists'},
                   9885:                                       fields => {%fields},
1.131     raeburn  9886:                                       lockablenames => \@lockablenames,
1.1       raeburn  9887:                                     }
                   9888:                      );
                   9889:     foreach my $key (keys(%currautoupdate)) {
                   9890:         if (($key eq 'run') || ($key eq 'classlists')) {
                   9891:             if (exists($updatehash{autoupdate}{$key})) {
                   9892:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   9893:                     $changes{$key} = 1;
                   9894:                 }
                   9895:             }
                   9896:         } elsif ($key eq 'fields') {
                   9897:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  9898:                 foreach my $item (@{$types},'default') {
1.1       raeburn  9899:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   9900:                         my $change = 0;
                   9901:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   9902:                             if (!exists($fields{$item})) {
                   9903:                                 $change = 1;
1.132     raeburn  9904:                                 last;
1.1       raeburn  9905:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  9906:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  9907:                                     $change = 1;
1.132     raeburn  9908:                                     last;
1.1       raeburn  9909:                                 }
                   9910:                             }
                   9911:                         }
                   9912:                         if ($change) {
                   9913:                             push(@{$changes{$key}},$item);
                   9914:                         }
1.26      raeburn  9915:                     } 
1.1       raeburn  9916:                 }
                   9917:             }
1.131     raeburn  9918:         } elsif ($key eq 'lockablenames') {
                   9919:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   9920:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   9921:                 if (@changed) {
                   9922:                     $changes{'lockablenames'} = 1;
                   9923:                 }
                   9924:             } else {
                   9925:                 if (@lockablenames) {
                   9926:                     $changes{'lockablenames'} = 1;
                   9927:                 }
                   9928:             }
                   9929:         }
                   9930:     }
                   9931:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   9932:         if (@lockablenames) {
                   9933:             $changes{'lockablenames'} = 1;
1.1       raeburn  9934:         }
                   9935:     }
1.26      raeburn  9936:     foreach my $item (@{$types},'default') {
                   9937:         if (defined($fields{$item})) {
                   9938:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  9939:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   9940:                     my $change = 0;
                   9941:                     if (ref($fields{$item}) eq 'ARRAY') {
                   9942:                         foreach my $type (@{$fields{$item}}) {
                   9943:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   9944:                                 $change = 1;
                   9945:                                 last;
                   9946:                             }
                   9947:                         }
                   9948:                     }
                   9949:                     if ($change) {
                   9950:                         push(@{$changes{'fields'}},$item);
                   9951:                     }
                   9952:                 } else {
1.26      raeburn  9953:                     push(@{$changes{'fields'}},$item);
                   9954:                 }
                   9955:             } else {
                   9956:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  9957:             }
                   9958:         }
                   9959:     }
                   9960:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   9961:                                              $dom);
                   9962:     if ($putresult eq 'ok') {
                   9963:         if (keys(%changes) > 0) {
                   9964:             $resulttext = &mt('Changes made:').'<ul>';
                   9965:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  9966:                 if ($key eq 'lockablenames') {
                   9967:                     $resulttext .= '<li>';
                   9968:                     if (@lockablenames) {
                   9969:                         $usertypes->{'default'} = $othertitle;
                   9970:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   9971:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   9972:                     } else {
                   9973:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   9974:                     }
                   9975:                     $resulttext .= '</li>';
                   9976:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  9977:                     foreach my $item (@{$changes{$key}}) {
                   9978:                         my @newvalues;
                   9979:                         foreach my $type (@{$fields{$item}}) {
                   9980:                             push(@newvalues,$fieldtitles{$type});
                   9981:                         }
1.3       raeburn  9982:                         my $newvaluestr;
                   9983:                         if (@newvalues > 0) {
                   9984:                             $newvaluestr = join(', ',@newvalues);
                   9985:                         } else {
                   9986:                             $newvaluestr = &mt('none');
1.6       raeburn  9987:                         }
1.1       raeburn  9988:                         if ($item eq 'default') {
1.26      raeburn  9989:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  9990:                         } else {
1.26      raeburn  9991:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  9992:                         }
                   9993:                     }
                   9994:                 } else {
                   9995:                     my $newvalue;
                   9996:                     if ($key eq 'run') {
                   9997:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   9998:                     } else {
                   9999:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  10000:                     }
1.1       raeburn  10001:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   10002:                 }
                   10003:             }
                   10004:             $resulttext .= '</ul>';
                   10005:         } else {
1.3       raeburn  10006:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  10007:         }
                   10008:     } else {
1.11      albertel 10009:         $resulttext = '<span class="LC_error">'.
                   10010: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  10011:     }
1.3       raeburn  10012:     return $resulttext;
1.1       raeburn  10013: }
                   10014: 
1.125     raeburn  10015: sub modify_autocreate {
                   10016:     my ($dom,%domconfig) = @_;
                   10017:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   10018:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   10019:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   10020:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   10021:         }
                   10022:     }
                   10023:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   10024:                  req => 'Auto-creation of validated requests for official courses',
                   10025:                  xmldc => 'Identity of course creator of courses from XML files',
                   10026:                );
                   10027:     my @types = ('xml','req');
                   10028:     foreach my $item (@types) {
                   10029:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   10030:         $newvals{$item} =~ s/\D//g;
                   10031:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   10032:     }
                   10033:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77  raeburn  10034:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125     raeburn  10035:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   10036:         $newvals{'xmldc'} = '';
                   10037:     } 
                   10038:     %autocreatehash =  (
                   10039:                         autocreate => { xml => $newvals{'xml'},
                   10040:                                         req => $newvals{'req'},
                   10041:                                       }
                   10042:                        );
                   10043:     if ($newvals{'xmldc'} ne '') {
                   10044:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   10045:     }
                   10046:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   10047:                                              $dom);
                   10048:     if ($putresult eq 'ok') {
                   10049:         my @items = @types;
                   10050:         if ($newvals{'xml'}) {
                   10051:             push(@items,'xmldc');
                   10052:         }
                   10053:         foreach my $item (@items) {
                   10054:             if (exists($currautocreate{$item})) {
                   10055:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   10056:                     $changes{$item} = 1;
                   10057:                 }
                   10058:             } elsif ($newvals{$item}) {
                   10059:                 $changes{$item} = 1;
                   10060:             }
                   10061:         }
                   10062:         if (keys(%changes) > 0) {
                   10063:             my @offon = ('off','on'); 
                   10064:             $resulttext = &mt('Changes made:').'<ul>';
                   10065:             foreach my $item (@types) {
                   10066:                 if ($changes{$item}) {
                   10067:                     my $newtxt = $offon[$newvals{$item}];
1.160.6.13  raeburn  10068:                     $resulttext .= '<li>'.
                   10069:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   10070:                                        '<b>','</b>').
                   10071:                                    '</li>';
1.125     raeburn  10072:                 }
                   10073:             }
                   10074:             if ($changes{'xmldc'}) {
                   10075:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   10076:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13  raeburn  10077:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  10078:             }
                   10079:             $resulttext .= '</ul>';
                   10080:         } else {
                   10081:             $resulttext = &mt('No changes made to auto-creation settings');
                   10082:         }
                   10083:     } else {
                   10084:         $resulttext = '<span class="LC_error">'.
                   10085:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10086:     }
                   10087:     return $resulttext;
                   10088: }
                   10089: 
1.23      raeburn  10090: sub modify_directorysrch {
1.160.6.81  raeburn  10091:     my ($dom,$lastactref,%domconfig) = @_;
1.23      raeburn  10092:     my ($resulttext,%changes);
                   10093:     my %currdirsrch;
                   10094:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   10095:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   10096:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   10097:         }
                   10098:     }
1.160.6.72  raeburn  10099:     my %title = ( available => 'Institutional directory search available',
                   10100:                   localonly => 'Other domains can search institution',
                   10101:                   lcavailable => 'LON-CAPA directory search available',
                   10102:                   lclocalonly => 'Other domains can search LON-CAPA domain',
1.23      raeburn  10103:                   searchby => 'Search types',
                   10104:                   searchtypes => 'Search latitude');
                   10105:     my @offon = ('off','on');
1.24      raeburn  10106:     my @otherdoms = ('Yes','No');
1.23      raeburn  10107: 
1.25      raeburn  10108:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  10109:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   10110:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   10111: 
1.44      raeburn  10112:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  10113:     if (keys(%{$usertypes}) == 0) {
                   10114:         @cansearch = ('default');
                   10115:     } else {
                   10116:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   10117:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   10118:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   10119:                     push(@{$changes{'cansearch'}},$type);
                   10120:                 }
1.23      raeburn  10121:             }
1.26      raeburn  10122:             foreach my $type (@cansearch) {
                   10123:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   10124:                     push(@{$changes{'cansearch'}},$type);
                   10125:                 }
1.23      raeburn  10126:             }
1.26      raeburn  10127:         } else {
                   10128:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  10129:         }
                   10130:     }
                   10131: 
                   10132:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   10133:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   10134:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   10135:                 push(@{$changes{'searchby'}},$by);
                   10136:             }
                   10137:         }
                   10138:         foreach my $by (@searchby) {
                   10139:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   10140:                 push(@{$changes{'searchby'}},$by);
                   10141:             }
                   10142:         }
                   10143:     } else {
                   10144:         push(@{$changes{'searchby'}},@searchby);
                   10145:     }
1.25      raeburn  10146: 
                   10147:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   10148:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   10149:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   10150:                 push(@{$changes{'searchtypes'}},$type);
                   10151:             }
                   10152:         }
                   10153:         foreach my $type (@searchtypes) {
                   10154:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   10155:                 push(@{$changes{'searchtypes'}},$type);
                   10156:             }
                   10157:         }
                   10158:     } else {
                   10159:         if (exists($currdirsrch{'searchtypes'})) {
                   10160:             foreach my $type (@searchtypes) {  
                   10161:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   10162:                     push(@{$changes{'searchtypes'}},$type);
                   10163:                 }
                   10164:             }
                   10165:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   10166:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   10167:             }   
                   10168:         } else {
                   10169:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   10170:         }
                   10171:     }
                   10172: 
1.23      raeburn  10173:     my %dirsrch_hash =  (
                   10174:             directorysrch => { available => $env{'form.dirsrch_available'},
                   10175:                                cansearch => \@cansearch,
1.160.6.72  raeburn  10176:                                localonly => $env{'form.dirsrch_instlocalonly'},
                   10177:                                lclocalonly => $env{'form.dirsrch_domlocalonly'},
                   10178:                                lcavailable => $env{'form.dirsrch_domavailable'},
1.23      raeburn  10179:                                searchby => \@searchby,
1.25      raeburn  10180:                                searchtypes => \@searchtypes,
1.23      raeburn  10181:                              }
                   10182:             );
                   10183:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   10184:                                              $dom);
                   10185:     if ($putresult eq 'ok') {
                   10186:         if (exists($currdirsrch{'available'})) {
                   10187:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   10188:                  $changes{'available'} = 1;
                   10189:              }
                   10190:         } else {
                   10191:             if ($env{'form.dirsrch_available'} eq '1') {
                   10192:                 $changes{'available'} = 1;
                   10193:             }
                   10194:         }
1.160.6.72  raeburn  10195:         if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78  raeburn  10196:             if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
                   10197:                 $changes{'lcavailable'} = 1;
                   10198:             }
1.24      raeburn  10199:         } else {
1.160.6.72  raeburn  10200:             if ($env{'form.dirsrch_lcavailable'} eq '1') {
                   10201:                 $changes{'lcavailable'} = 1;
                   10202:             }
                   10203:         }
                   10204:         if (exists($currdirsrch{'localonly'})) {
                   10205:             if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24      raeburn  10206:                 $changes{'localonly'} = 1;
                   10207:             }
1.160.6.72  raeburn  10208:         } else {
                   10209:             if ($env{'form.dirsrch_instlocalonly'} eq '1') {
                   10210:                 $changes{'localonly'} = 1;
                   10211:             }
                   10212:         }
                   10213:         if (exists($currdirsrch{'lclocalonly'})) {
                   10214:             if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
                   10215:                 $changes{'lclocalonly'} = 1;
                   10216:             }
                   10217:         } else {
                   10218:             if ($env{'form.dirsrch_domlocalonly'} eq '1') {
                   10219:                 $changes{'lclocalonly'} = 1;
                   10220:             }
1.24      raeburn  10221:         }
1.23      raeburn  10222:         if (keys(%changes) > 0) {
                   10223:             $resulttext = &mt('Changes made:').'<ul>';
                   10224:             if ($changes{'available'}) {
                   10225:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   10226:             }
1.160.6.72  raeburn  10227:             if ($changes{'lcavailable'}) {
                   10228:                 $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
                   10229:             }
1.24      raeburn  10230:             if ($changes{'localonly'}) {
1.160.6.72  raeburn  10231:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
                   10232:             }
                   10233:             if ($changes{'lclocalonly'}) {
                   10234:                 $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24      raeburn  10235:             }
1.23      raeburn  10236:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   10237:                 my $chgtext;
1.26      raeburn  10238:                 if (ref($usertypes) eq 'HASH') {
                   10239:                     if (keys(%{$usertypes}) > 0) {
                   10240:                         foreach my $type (@{$types}) {
                   10241:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   10242:                                 $chgtext .= $usertypes->{$type}.'; ';
                   10243:                             }
                   10244:                         }
                   10245:                         if (grep(/^default$/,@cansearch)) {
                   10246:                             $chgtext .= $othertitle;
                   10247:                         } else {
                   10248:                             $chgtext =~ s/\; $//;
                   10249:                         }
1.160.6.13  raeburn  10250:                         $resulttext .=
                   10251:                             '<li>'.
                   10252:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   10253:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   10254:                             '</li>';
1.23      raeburn  10255:                     }
                   10256:                 }
                   10257:             }
                   10258:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   10259:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   10260:                 my $chgtext;
                   10261:                 foreach my $type (@{$titleorder}) {
                   10262:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   10263:                         if (defined($searchtitles->{$type})) {
                   10264:                             $chgtext .= $searchtitles->{$type}.'; ';
                   10265:                         }
                   10266:                     }
                   10267:                 }
                   10268:                 $chgtext =~ s/\; $//;
                   10269:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   10270:             }
1.25      raeburn  10271:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   10272:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   10273:                 my $chgtext;
                   10274:                 foreach my $type (@{$srchtypeorder}) {
                   10275:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   10276:                         if (defined($srchtypes_desc->{$type})) {
                   10277:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   10278:                         }
                   10279:                     }
                   10280:                 }
                   10281:                 $chgtext =~ s/\; $//;
1.160.6.13  raeburn  10282:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  10283:             }
                   10284:             $resulttext .= '</ul>';
1.160.6.81  raeburn  10285:             &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
                   10286:             if (ref($lastactref) eq 'HASH') {
                   10287:                 $lastactref->{'directorysrch'} = 1;
                   10288:             }
1.23      raeburn  10289:         } else {
1.160.6.72  raeburn  10290:             $resulttext = &mt('No changes made to directory search settings');
1.23      raeburn  10291:         }
                   10292:     } else {
                   10293:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  10294:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   10295:     }
                   10296:     return $resulttext;
                   10297: }
                   10298: 
1.28      raeburn  10299: sub modify_contacts {
1.160.6.24  raeburn  10300:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  10301:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   10302:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   10303:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   10304:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   10305:         }
                   10306:     }
1.160.6.78  raeburn  10307:     my (%others,%to,%bcc,%includestr,%includeloc);
1.28      raeburn  10308:     my @contacts = ('supportemail','adminemail');
1.160.6.78  raeburn  10309:     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                   10310:                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail');
1.160.6.23  raeburn  10311:     my @toggles = ('reporterrors','reportupdates');
1.160.6.78  raeburn  10312:     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28      raeburn  10313:     foreach my $type (@mailings) {
                   10314:         @{$newsetting{$type}} = 
                   10315:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   10316:         foreach my $item (@contacts) {
                   10317:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   10318:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   10319:             } else {
                   10320:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   10321:             }
1.160.6.78  raeburn  10322:         }
1.28      raeburn  10323:         $others{$type} = $env{'form.'.$type.'_others'};
                   10324:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78  raeburn  10325:         if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10326:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   10327:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78  raeburn  10328:             if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
                   10329:                 $includestr{$type} = $env{'form.'.$type.'_includestr'};
                   10330:                 $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
                   10331:                 $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
                   10332:             }
1.134     raeburn  10333:         }
1.28      raeburn  10334:     }
                   10335:     foreach my $item (@contacts) {
                   10336:         $to{$item} = $env{'form.'.$item};
                   10337:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   10338:     }
1.160.6.23  raeburn  10339:     foreach my $item (@toggles) {
                   10340:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   10341:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   10342:         }
                   10343:     }
1.160.6.78  raeburn  10344:     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
                   10345:         foreach my $field (@{$fields}) {
                   10346:             if (ref($possoptions->{$field}) eq 'ARRAY') {
                   10347:                 my $value = $env{'form.helpform_'.$field};
                   10348:                 $value =~ s/^\s+|\s+$//g;
                   10349:                 if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
                   10350:                     $contacts_hash{contacts}{'helpform'}{$field} = $value;
                   10351:                     if ($field eq 'screenshot') {
                   10352:                         $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
                   10353:                         if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
                   10354:                             $contacts_hash{contacts}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
                   10355:                         }
                   10356:                     }
                   10357:                 }
                   10358:             }
                   10359:         }
                   10360:     }
1.28      raeburn  10361:     if (keys(%currsetting) > 0) {
                   10362:         foreach my $item (@contacts) {
                   10363:             if ($to{$item} ne $currsetting{$item}) {
                   10364:                 $changes{$item} = 1;
                   10365:             }
                   10366:         }
                   10367:         foreach my $type (@mailings) {
                   10368:             foreach my $item (@contacts) {
                   10369:                 if (ref($currsetting{$type}) eq 'HASH') {
                   10370:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   10371:                         push(@{$changes{$type}},$item);
                   10372:                     }
                   10373:                 } else {
                   10374:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   10375:                 }
                   10376:             }
                   10377:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   10378:                 push(@{$changes{$type}},'others');
                   10379:             }
1.160.6.78  raeburn  10380:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10381:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   10382:                     push(@{$changes{$type}},'bcc'); 
                   10383:                 }
1.160.6.78  raeburn  10384:                 my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
                   10385:                 if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
                   10386:                     push(@{$changes{$type}},'include');
                   10387:                 }
                   10388:             }
                   10389:         }
                   10390:         if (ref($fields) eq 'ARRAY') {
                   10391:             if (ref($currsetting{'helpform'}) eq 'HASH') {
                   10392:                 foreach my $field (@{$fields}) {
                   10393:                     if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
                   10394:                         push(@{$changes{'helpform'}},$field);
                   10395:                     }
                   10396:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10397:                         if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
                   10398:                             push(@{$changes{'helpform'}},'maxsize');
                   10399:                         }
                   10400:                     }
                   10401:                 }
                   10402:             } else {
                   10403:                 foreach my $field (@{$fields}) {
                   10404:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   10405:                         push(@{$changes{'helpform'}},$field);
                   10406:                     }
                   10407:                     if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10408:                         if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   10409:                             push(@{$changes{'helpform'}},'maxsize');
                   10410:                         }
                   10411:                     }
                   10412:                 }
1.134     raeburn  10413:             }
1.28      raeburn  10414:         }
                   10415:     } else {
                   10416:         my %default;
                   10417:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   10418:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   10419:         $default{'errormail'} = 'adminemail';
                   10420:         $default{'packagesmail'} = 'adminemail';
                   10421:         $default{'helpdeskmail'} = 'supportemail';
1.160.6.78  raeburn  10422:         $default{'otherdomsmail'} = 'supportemail';
1.89      raeburn  10423:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  10424:         $default{'requestsmail'} = 'adminemail';
1.160.6.15  raeburn  10425:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  10426:         foreach my $item (@contacts) {
                   10427:            if ($to{$item} ne $default{$item}) {
1.160.6.78  raeburn  10428:                $changes{$item} = 1;
1.160.6.23  raeburn  10429:            }
1.28      raeburn  10430:         }
                   10431:         foreach my $type (@mailings) {
                   10432:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   10433:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   10434:             }
                   10435:             if ($others{$type} ne '') {
                   10436:                 push(@{$changes{$type}},'others');
1.134     raeburn  10437:             }
1.160.6.78  raeburn  10438:             if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10439:                 if ($bcc{$type} ne '') {
                   10440:                     push(@{$changes{$type}},'bcc');
                   10441:                 }
1.160.6.78  raeburn  10442:                 if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
                   10443:                     push(@{$changes{$type}},'include');
                   10444:                 }
                   10445:             }
                   10446:         }
                   10447:         if (ref($fields) eq 'ARRAY') {
                   10448:             foreach my $field (@{$fields}) {
                   10449:                 if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
                   10450:                     push(@{$changes{'helpform'}},$field);
                   10451:                 }
                   10452:                 if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
                   10453:                     if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
                   10454:                         push(@{$changes{'helpform'}},'maxsize');
                   10455:                     }
                   10456:                 }
1.134     raeburn  10457:             }
1.28      raeburn  10458:         }
                   10459:     }
1.160.6.23  raeburn  10460:     foreach my $item (@toggles) {
                   10461:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   10462:             $changes{$item} = 1;
                   10463:         } elsif ((!$env{'form.'.$item}) &&
                   10464:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   10465:             $changes{$item} = 1;
                   10466:         }
                   10467:     }
1.28      raeburn  10468:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   10469:                                              $dom);
                   10470:     if ($putresult eq 'ok') {
                   10471:         if (keys(%changes) > 0) {
1.160.6.24  raeburn  10472:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  10473:             if (ref($lastactref) eq 'HASH') {
                   10474:                 $lastactref->{'domainconfig'} = 1;
                   10475:             }
1.28      raeburn  10476:             my ($titles,$short_titles)  = &contact_titles();
                   10477:             $resulttext = &mt('Changes made:').'<ul>';
                   10478:             foreach my $item (@contacts) {
                   10479:                 if ($changes{$item}) {
                   10480:                     $resulttext .= '<li>'.$titles->{$item}.
                   10481:                                     &mt(' set to: ').
                   10482:                                     '<span class="LC_cusr_emph">'.
                   10483:                                     $to{$item}.'</span></li>';
                   10484:                 }
                   10485:             }
                   10486:             foreach my $type (@mailings) {
                   10487:                 if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78  raeburn  10488:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
                   10489:                         $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
                   10490:                     } else {
                   10491:                         $resulttext .= '<li>'.$titles->{$type}.': ';
                   10492:                     }
1.28      raeburn  10493:                     my @text;
                   10494:                     foreach my $item (@{$newsetting{$type}}) {
                   10495:                         push(@text,$short_titles->{$item});
                   10496:                     }
                   10497:                     if ($others{$type} ne '') {
                   10498:                         push(@text,$others{$type});
                   10499:                     }
1.160.6.78  raeburn  10500:                     if (@text) {
                   10501:                         $resulttext .= '<span class="LC_cusr_emph">'.
                   10502:                                        join(', ',@text).'</span>';
                   10503:                     }
                   10504:                     if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134     raeburn  10505:                         if ($bcc{$type} ne '') {
1.160.6.78  raeburn  10506:                             my $bcctext;
                   10507:                             if (@text) {
                   10508:                                 $bcctext = '&nbsp;'.&mt('with Bcc to');
                   10509:                             } else {
                   10510:                                 $bcctext = '(Bcc)';
                   10511:                             }
                   10512:                             $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   10513:                         } elsif (!@text) {
                   10514:                             $resulttext .= &mt('No one');
1.134     raeburn  10515:                         }
1.160.6.78  raeburn  10516:                         if ($includestr{$type} ne '') {
                   10517:                             if ($includeloc{$type} eq 'b') {
                   10518:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
                   10519:                             } elsif ($includeloc{$type} eq 's') {
                   10520:                                 $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
                   10521:                             }
                   10522:                         }
                   10523:                     } elsif (!@text) {
                   10524:                         $resulttext .= &mt('No recipients');
1.134     raeburn  10525:                     }
                   10526:                     $resulttext .= '</li>';
1.28      raeburn  10527:                 }
                   10528:             }
1.160.6.23  raeburn  10529:             my @offon = ('off','on');
                   10530:             if ($changes{'reporterrors'}) {
                   10531:                 $resulttext .= '<li>'.
                   10532:                                &mt('E-mail error reports to [_1] set to "'.
                   10533:                                    $offon[$env{'form.reporterrors'}].'".',
                   10534:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   10535:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   10536:                                '</li>';
                   10537:             }
                   10538:             if ($changes{'reportupdates'}) {
                   10539:                 $resulttext .= '<li>'.
                   10540:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   10541:                                     $offon[$env{'form.reportupdates'}].'".',
                   10542:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   10543:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   10544:                                 '</li>';
                   10545:             }
1.160.6.78  raeburn  10546:             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                   10547:                 my (@optional,@required,@unused,$maxsizechg);
                   10548:                 foreach my $field (@{$changes{'helpform'}}) {
                   10549:                     if ($field eq 'maxsize') {
                   10550:                         $maxsizechg = 1;
                   10551:                         next;
                   10552:                     }
                   10553:                     if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
                   10554:                         push(@optional,$field);
                   10555:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
                   10556:                         push(@unused,$field);
                   10557:                     } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
                   10558:                         push(@required,$field);
                   10559:                     }
                   10560:                 }
                   10561:                 if (@optional) {
                   10562:                     $resulttext .= '<li>'.
                   10563:                                    &mt('Help form fields changed to "Optional": [_1].',
                   10564:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
                   10565:                                    '</li>';
                   10566:                 }
                   10567:                 if (@required) {
                   10568:                     $resulttext .= '<li>'.
                   10569:                                    &mt('Help form fields changed to "Required": [_1].',
                   10570:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
                   10571:                                    '</li>';
                   10572:                 }
                   10573:                 if (@unused) {
                   10574:                     $resulttext .= '<li>'.
                   10575:                                    &mt('Help form fields changed to "Not shown": [_1].',
                   10576:                                        '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
                   10577:                                    '</li>';
                   10578:                 }
                   10579:                 if ($maxsizechg) {
                   10580:                     $resulttext .= '<li>'.
                   10581:                                    &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
                   10582:                                        $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
                   10583:                                    '</li>';
                   10584: 
                   10585:                 }
                   10586:             }
1.28      raeburn  10587:             $resulttext .= '</ul>';
                   10588:         } else {
1.160.6.78  raeburn  10589:             $resulttext = &mt('No changes made to contacts and form settings');
1.28      raeburn  10590:         }
                   10591:     } else {
                   10592:         $resulttext = '<span class="LC_error">'.
                   10593:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   10594:     }
                   10595:     return $resulttext;
                   10596: }
                   10597: 
                   10598: sub modify_usercreation {
1.27      raeburn  10599:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  10600:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  10601:     my $warningmsg;
1.27      raeburn  10602:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   10603:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34  raeburn  10604:             if ($key eq 'cancreate') {
                   10605:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   10606:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   10607:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.69  raeburn  10608:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   10609:                             ($item eq 'recaptchaversion')) {
1.160.6.34  raeburn  10610:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10611:                         } else {
                   10612:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10613:                         }
1.50      raeburn  10614:                     }
1.43      raeburn  10615:                 }
1.160.6.34  raeburn  10616:             } elsif ($key eq 'email_rule') {
                   10617:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   10618:             } else {
                   10619:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43      raeburn  10620:             }
                   10621:         }
1.34      raeburn  10622:     }
1.160.6.34  raeburn  10623:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
                   10624:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
                   10625:     my @contexts = ('author','course','requestcrs');
                   10626:     foreach my $item(@contexts) {
                   10627:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  10628:     }
1.34      raeburn  10629:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10630:         foreach my $item (@contexts) {
1.160.6.34  raeburn  10631:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   10632:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  10633:             }
1.27      raeburn  10634:         }
1.34      raeburn  10635:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   10636:         foreach my $item (@contexts) {
1.43      raeburn  10637:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  10638:                 if ($cancreate{$item} ne 'any') {
                   10639:                     push(@{$changes{'cancreate'}},$item);
                   10640:                 }
                   10641:             } else {
                   10642:                 if ($cancreate{$item} ne 'none') {
                   10643:                     push(@{$changes{'cancreate'}},$item);
                   10644:                 }
1.27      raeburn  10645:             }
                   10646:         }
                   10647:     } else {
1.43      raeburn  10648:         foreach my $item (@contexts)  {
1.34      raeburn  10649:             push(@{$changes{'cancreate'}},$item);
                   10650:         }
1.27      raeburn  10651:     }
1.34      raeburn  10652: 
1.27      raeburn  10653:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   10654:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   10655:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   10656:                 push(@{$changes{'username_rule'}},$type);
                   10657:             }
                   10658:         }
                   10659:         foreach my $type (@username_rule) {
                   10660:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   10661:                 push(@{$changes{'username_rule'}},$type);
                   10662:             }
                   10663:         }
                   10664:     } else {
                   10665:         push(@{$changes{'username_rule'}},@username_rule);
                   10666:     }
                   10667: 
1.32      raeburn  10668:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   10669:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   10670:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   10671:                 push(@{$changes{'id_rule'}},$type);
                   10672:             }
                   10673:         }
                   10674:         foreach my $type (@id_rule) {
                   10675:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   10676:                 push(@{$changes{'id_rule'}},$type);
                   10677:             }
                   10678:         }
                   10679:     } else {
                   10680:         push(@{$changes{'id_rule'}},@id_rule);
                   10681:     }
                   10682: 
1.43      raeburn  10683:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  10684:     my @authtypes = ('int','krb4','krb5','loc');
                   10685:     my %authhash;
1.43      raeburn  10686:     foreach my $item (@authen_contexts) {
1.28      raeburn  10687:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   10688:         foreach my $auth (@authtypes) {
                   10689:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   10690:                 $authhash{$item}{$auth} = 1;
                   10691:             } else {
                   10692:                 $authhash{$item}{$auth} = 0;
                   10693:             }
                   10694:         }
                   10695:     }
                   10696:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  10697:         foreach my $item (@authen_contexts) {
1.28      raeburn  10698:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   10699:                 foreach my $auth (@authtypes) {
                   10700:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   10701:                         push(@{$changes{'authtypes'}},$item);
                   10702:                         last;
                   10703:                     }
                   10704:                 }
                   10705:             }
                   10706:         }
                   10707:     } else {
1.43      raeburn  10708:         foreach my $item (@authen_contexts) {
1.28      raeburn  10709:             push(@{$changes{'authtypes'}},$item);
                   10710:         }
                   10711:     }
                   10712: 
1.160.6.34  raeburn  10713:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   10714:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   10715:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   10716:     $save_usercreate{'id_rule'} = \@id_rule;
                   10717:     $save_usercreate{'username_rule'} = \@username_rule,
                   10718:     $save_usercreate{'authtypes'} = \%authhash;
                   10719: 
1.27      raeburn  10720:     my %usercreation_hash =  (
1.160.6.34  raeburn  10721:         usercreation     => \%save_usercreate,
                   10722:     );
1.27      raeburn  10723: 
                   10724:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   10725:                                              $dom);
1.50      raeburn  10726: 
1.160.6.34  raeburn  10727:     if ($putresult eq 'ok') {
                   10728:         if (keys(%changes) > 0) {
                   10729:             $resulttext = &mt('Changes made:').'<ul>';
                   10730:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   10731:                 my %lt = &usercreation_types();
                   10732:                 foreach my $type (@{$changes{'cancreate'}}) {
                   10733:                     my $chgtext = $lt{$type}.', ';
                   10734:                     if ($cancreate{$type} eq 'none') {
                   10735:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   10736:                     } elsif ($cancreate{$type} eq 'any') {
                   10737:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   10738:                     } elsif ($cancreate{$type} eq 'official') {
                   10739:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   10740:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   10741:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   10742:                     }
                   10743:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   10744:                 }
                   10745:             }
                   10746:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   10747:                 my ($rules,$ruleorder) = 
                   10748:                     &Apache::lonnet::inst_userrules($dom,'username');
                   10749:                 my $chgtext = '<ul>';
                   10750:                 foreach my $type (@username_rule) {
                   10751:                     if (ref($rules->{$type}) eq 'HASH') {
                   10752:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   10753:                     }
                   10754:                 }
                   10755:                 $chgtext .= '</ul>';
                   10756:                 if (@username_rule > 0) {
                   10757:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   10758:                 } else {
                   10759:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   10760:                 }
                   10761:             }
                   10762:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   10763:                 my ($idrules,$idruleorder) = 
                   10764:                     &Apache::lonnet::inst_userrules($dom,'id');
                   10765:                 my $chgtext = '<ul>';
                   10766:                 foreach my $type (@id_rule) {
                   10767:                     if (ref($idrules->{$type}) eq 'HASH') {
                   10768:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   10769:                     }
                   10770:                 }
                   10771:                 $chgtext .= '</ul>';
                   10772:                 if (@id_rule > 0) {
                   10773:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   10774:                 } else {
                   10775:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   10776:                 }
                   10777:             }
                   10778:             my %authname = &authtype_names();
                   10779:             my %context_title = &context_names();
                   10780:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   10781:                 my $chgtext = '<ul>';
                   10782:                 foreach my $type (@{$changes{'authtypes'}}) {
                   10783:                     my @allowed;
                   10784:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   10785:                     foreach my $auth (@authtypes) {
                   10786:                         if ($authhash{$type}{$auth}) {
                   10787:                             push(@allowed,$authname{$auth});
                   10788:                         }
                   10789:                     }
                   10790:                     if (@allowed > 0) {
                   10791:                         $chgtext .= join(', ',@allowed).'</li>';
                   10792:                     } else {
                   10793:                         $chgtext .= &mt('none').'</li>';
                   10794:                     }
                   10795:                 }
                   10796:                 $chgtext .= '</ul>';
                   10797:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   10798:                 $resulttext .= '</li>';
                   10799:             }
                   10800:             $resulttext .= '</ul>';
                   10801:         } else {
                   10802:             $resulttext = &mt('No changes made to user creation settings');
                   10803:         }
                   10804:     } else {
                   10805:         $resulttext = '<span class="LC_error">'.
                   10806:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10807:     }
                   10808:     if ($warningmsg ne '') {
                   10809:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   10810:     }
                   10811:     return $resulttext;
                   10812: }
                   10813: 
                   10814: sub modify_selfcreation {
                   10815:     my ($dom,%domconfig) = @_;
                   10816:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
                   10817:     my (%save_usercreate,%save_usermodify);
1.160.6.35  raeburn  10818:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   10819:     if (ref($types) eq 'ARRAY') {
                   10820:         $usertypes->{'default'} = $othertitle;
                   10821:         push(@{$types},'default');
                   10822:     }
1.160.6.34  raeburn  10823: #
                   10824: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   10825: #
                   10826:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   10827:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   10828:             if ($key eq 'cancreate') {
                   10829:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   10830:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   10831:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   10832:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
1.160.6.69  raeburn  10833:                             ($item eq 'recaptchaversion') ||
1.160.6.40  raeburn  10834:                             ($item eq 'emailusername') || ($item eq 'notify') ||
1.160.6.44  raeburn  10835:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.160.6.34  raeburn  10836:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10837:                         } else {
                   10838:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   10839:                         }
                   10840:                     }
                   10841:                 }
                   10842:             } elsif ($key eq 'email_rule') {
                   10843:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   10844:             } else {
                   10845:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   10846:             }
                   10847:         }
                   10848:     }
                   10849: #
                   10850: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   10851: #
                   10852:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   10853:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   10854:             if ($key eq 'selfcreate') {
                   10855:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   10856:             } else {
                   10857:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   10858:             }
                   10859:         }
                   10860:     }
                   10861: 
                   10862:     my @contexts = ('selfcreate');
                   10863:     @{$cancreate{'selfcreate'}} = ();
                   10864:     %{$cancreate{'emailusername'}} = ();
                   10865:     @{$cancreate{'statustocreate'}} = ();
1.160.6.40  raeburn  10866:     %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44  raeburn  10867:     %{$cancreate{'shibenv'}} = ();
1.50      raeburn  10868:     my %selfcreatetypes = (
                   10869:                              sso   => 'users authenticated by institutional single sign on',
                   10870:                              login => 'users authenticated by institutional log-in',
1.160.6.40  raeburn  10871:                              email => 'users who provide a valid e-mail address for use as username',
1.50      raeburn  10872:                           );
1.160.6.34  raeburn  10873: #
                   10874: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   10875: # is permitted.
                   10876: #
1.160.6.40  raeburn  10877: 
                   10878:     my @statuses;
                   10879:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   10880:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
                   10881:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
                   10882:         }
                   10883:     }
                   10884:     push(@statuses,'default');
                   10885: 
1.160.6.35  raeburn  10886:     foreach my $item ('login','sso','email') {
1.160.6.34  raeburn  10887:         if ($item eq 'email') {
1.160.6.40  raeburn  10888:             if ($env{'form.cancreate_email'}) {
1.160.6.34  raeburn  10889:                 push(@{$cancreate{'selfcreate'}},'email');
1.160.6.40  raeburn  10890:                 push(@contexts,'selfcreateprocessing');
                   10891:                 foreach my $type (@statuses) {
                   10892:                     if ($type eq 'default') {
                   10893:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
                   10894:                     } else { 
                   10895:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   10896:                     }
                   10897:                 }
1.160.6.34  raeburn  10898:             }
                   10899:         } else {
                   10900:             if ($env{'form.cancreate_'.$item}) {
                   10901:                 push(@{$cancreate{'selfcreate'}},$item);
                   10902:             }
                   10903:         }
                   10904:     }
                   10905:     my (@email_rule,%userinfo,%savecaptcha);
                   10906:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   10907: #
1.160.6.35  raeburn  10908: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   10909: # 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  10910: #
1.160.6.40  raeburn  10911: 
1.160.6.48  raeburn  10912:     if ($env{'form.cancreate_email'}) {
1.160.6.37  raeburn  10913:         push(@contexts,'emailusername');
1.160.6.35  raeburn  10914:         if (ref($types) eq 'ARRAY') {
                   10915:             foreach my $type (@{$types}) {
                   10916:                 if (ref($infofields) eq 'ARRAY') {
                   10917:                     foreach my $field (@{$infofields}) {
                   10918:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   10919:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   10920:                         }
                   10921:                     }
1.160.6.34  raeburn  10922:                 }
                   10923:             }
                   10924:         }
                   10925: #
                   10926: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
                   10927: # queued requests for self-creation of account using e-mail address as username
                   10928: #
                   10929: 
                   10930:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   10931:         @approvalnotify = sort(@approvalnotify);
                   10932:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   10933:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   10934:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   10935:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   10936:                     push(@{$changes{'cancreate'}},'notify');
                   10937:                 }
                   10938:             } else {
                   10939:                 if ($cancreate{'notify'}{'approval'}) {
                   10940:                     push(@{$changes{'cancreate'}},'notify');
                   10941:                 }
                   10942:             }
                   10943:         } elsif ($cancreate{'notify'}{'approval'}) {
                   10944:             push(@{$changes{'cancreate'}},'notify');
                   10945:         }
                   10946: 
                   10947: #
                   10948: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
                   10949: #
                   10950:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
                   10951:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   10952:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   10953:             if (@{$curr_usercreation{'email_rule'}} > 0) {
                   10954:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   10955:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
                   10956:                         push(@{$changes{'email_rule'}},$type);
                   10957:                     }
                   10958:                 }
                   10959:             }
                   10960:             if (@email_rule > 0) {
                   10961:                 foreach my $type (@email_rule) {
                   10962:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   10963:                         push(@{$changes{'email_rule'}},$type);
                   10964:                     }
                   10965:                 }
                   10966:             }
                   10967:         } elsif (@email_rule > 0) {
                   10968:             push(@{$changes{'email_rule'}},@email_rule);
                   10969:         }
                   10970:     }
                   10971: #  
1.160.6.40  raeburn  10972: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34  raeburn  10973: # institutional log-in.
                   10974: #
                   10975:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   10976:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   10977:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   10978:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   10979:             $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.').' '.
                   10980:                           &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.');
                   10981:         }
                   10982:     }
                   10983:     my @fields = ('lastname','firstname','middlename','generation',
                   10984:                   'permanentemail','id');
1.160.6.44  raeburn  10985:     my @shibfields = (@fields,'inststatus');
1.160.6.34  raeburn  10986:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10987: #
                   10988: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   10989: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   10990: # may self-create accounts 
                   10991: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   10992: # which the user may supply, if institutional data is unavailable.
                   10993: #
                   10994:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
                   10995:         if (ref($types) eq 'ARRAY') {
1.160.6.35  raeburn  10996:             if (@{$types} > 1) {
1.160.6.34  raeburn  10997:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   10998:                 push(@contexts,'statustocreate');
                   10999:             } else {
                   11000:                 undef($cancreate{'statustocreate'});
                   11001:             } 
                   11002:             foreach my $type (@{$types}) {
                   11003:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   11004:                 foreach my $field (@fields) {
                   11005:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   11006:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   11007:                     } else {
                   11008:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   11009:                     }
                   11010:                 }
                   11011:             }
                   11012:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
                   11013:                 foreach my $type (@{$types}) {
                   11014:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   11015:                         foreach my $field (@fields) {
                   11016:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   11017:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   11018:                                 push(@{$changes{'selfcreate'}},$type);
                   11019:                                 last;
                   11020:                             }
                   11021:                         }
                   11022:                     }
                   11023:                 }
                   11024:             } else {
                   11025:                 foreach my $type (@{$types}) {
                   11026:                     push(@{$changes{'selfcreate'}},$type);
                   11027:                 }
                   11028:             }
                   11029:         }
1.160.6.44  raeburn  11030:         foreach my $field (@shibfields) {
                   11031:             if ($env{'form.shibenv_'.$field} ne '') {
                   11032:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   11033:             }
                   11034:         }
                   11035:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   11036:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   11037:                 foreach my $field (@shibfields) {
                   11038:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   11039:                         push(@{$changes{'cancreate'}},'shibenv');
                   11040:                     }
                   11041:                 }
                   11042:             } else {
                   11043:                 foreach my $field (@shibfields) {
                   11044:                     if ($env{'form.shibenv_'.$field}) {
                   11045:                         push(@{$changes{'cancreate'}},'shibenv');
                   11046:                         last;
                   11047:                     }
                   11048:                 }
                   11049:             }
                   11050:         }
1.160.6.34  raeburn  11051:     }
                   11052:     foreach my $item (@contexts) {
                   11053:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   11054:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   11055:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   11056:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   11057:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11058:                             push(@{$changes{'cancreate'}},$item);
                   11059:                         }
                   11060:                     }
                   11061:                 }
                   11062:             }
                   11063:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   11064:                 foreach my $type (@{$cancreate{$item}}) {
                   11065:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   11066:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11067:                             push(@{$changes{'cancreate'}},$item);
                   11068:                         }
                   11069:                     }
                   11070:                 }
                   11071:             }
                   11072:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   11073:             if (ref($cancreate{$item}) eq 'HASH') {
                   11074:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.160.6.35  raeburn  11075:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
                   11076:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
                   11077:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
                   11078:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11079:                                     push(@{$changes{'cancreate'}},$item);
                   11080:                                 }
                   11081:                             }
                   11082:                         }
1.160.6.40  raeburn  11083:                     } elsif ($item eq 'selfcreateprocessing') {
                   11084:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
                   11085:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11086:                                 push(@{$changes{'cancreate'}},$item);
                   11087:                             }
                   11088:                         }
1.160.6.35  raeburn  11089:                     } else {
                   11090:                         if (!$cancreate{$item}{$curr}) {
                   11091:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11092:                                 push(@{$changes{'cancreate'}},$item);
                   11093:                             }
1.160.6.34  raeburn  11094:                         }
                   11095:                     }
                   11096:                 }
                   11097:                 foreach my $field (keys(%{$cancreate{$item}})) {
1.160.6.35  raeburn  11098:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
                   11099:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
                   11100:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
                   11101:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
                   11102:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11103:                                         push(@{$changes{'cancreate'}},$item);
                   11104:                                     }
                   11105:                                 }
                   11106:                             } else {
                   11107:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11108:                                     push(@{$changes{'cancreate'}},$item);
                   11109:                                 }
                   11110:                             }
                   11111:                         }
1.160.6.40  raeburn  11112:                     } elsif ($item eq 'selfcreateprocessing') {
                   11113:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
                   11114:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11115:                                 push(@{$changes{'cancreate'}},$item);
                   11116:                             }
                   11117:                         }
1.160.6.35  raeburn  11118:                     } else {
                   11119:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
                   11120:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11121:                                 push(@{$changes{'cancreate'}},$item);
                   11122:                             }
1.160.6.34  raeburn  11123:                         }
                   11124:                     }
                   11125:                 }
                   11126:             }
                   11127:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   11128:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   11129:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   11130:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11131:                         push(@{$changes{'cancreate'}},$item);
                   11132:                     }
                   11133:                 }
                   11134:             } elsif (ref($cancreate{$item}) eq 'HASH') {
                   11135:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
                   11136:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11137:                         push(@{$changes{'cancreate'}},$item);
                   11138:                     }
                   11139:                 }
                   11140:             }
                   11141:         } elsif ($item eq 'emailusername') {
1.160.6.35  raeburn  11142:             if (ref($cancreate{$item}) eq 'HASH') {
                   11143:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   11144:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   11145:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   11146:                             if ($cancreate{$item}{$type}{$field}) {
                   11147:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   11148:                                     push(@{$changes{'cancreate'}},$item);
                   11149:                                 }
                   11150:                                 last;
                   11151:                             }
                   11152:                         }
                   11153:                     }
                   11154:                 }
1.160.6.34  raeburn  11155:             }
                   11156:         }
                   11157:     }
                   11158: #
                   11159: # Populate %save_usercreate hash with updates to self-creation configuration.
                   11160: #
                   11161:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   11162:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69  raeburn  11163:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34  raeburn  11164:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   11165:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   11166:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   11167:     }
1.160.6.40  raeburn  11168:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   11169:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   11170:     }
1.160.6.34  raeburn  11171:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   11172:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   11173:     }
1.160.6.44  raeburn  11174:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   11175:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   11176:     }
1.160.6.34  raeburn  11177:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
                   11178:     $save_usercreate{'emailrule'} = \@email_rule;
                   11179: 
                   11180:     my %userconfig_hash = (
                   11181:             usercreation     => \%save_usercreate,
                   11182:             usermodification => \%save_usermodify,
                   11183:     );
                   11184:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   11185:                                              $dom);
                   11186: #
                   11187: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
                   11188: #
1.27      raeburn  11189:     if ($putresult eq 'ok') {
                   11190:         if (keys(%changes) > 0) {
                   11191:             $resulttext = &mt('Changes made:').'<ul>';
                   11192:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34  raeburn  11193:                 my %lt = &selfcreation_types();
1.34      raeburn  11194:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  11195:                     my $chgtext;
1.45      raeburn  11196:                     if ($type eq 'selfcreate') {
1.50      raeburn  11197:                         if (@{$cancreate{$type}} == 0) {
1.160.6.34  raeburn  11198:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  11199:                         } else {
1.160.6.34  raeburn  11200:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   11201:                                         '<ul>';
1.50      raeburn  11202:                             foreach my $case (@{$cancreate{$type}}) {
                   11203:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   11204:                             }
                   11205:                             $chgtext .= '</ul>';
1.100     raeburn  11206:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   11207:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   11208:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   11209:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.34  raeburn  11210:                                             $chgtext .= '<br />'.
                   11211:                                                         '<span class="LC_warning">'.
                   11212:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   11213:                                                         '</span>';
1.100     raeburn  11214:                                         }
                   11215:                                     }
                   11216:                                 }
                   11217:                             }
1.43      raeburn  11218:                         }
1.160.6.44  raeburn  11219:                     } elsif ($type eq 'shibenv') {
                   11220:                         if (keys(%{$cancreate{$type}}) == 0) {
                   11221:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
                   11222:                         } else {
                   11223:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   11224:                                         '<ul>';
                   11225:                             foreach my $field (@shibfields) {
                   11226:                                 next if ($cancreate{$type}{$field} eq '');
                   11227:                                 if ($field eq 'inststatus') {
                   11228:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   11229:                                 } else {
                   11230:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   11231:                                 }
                   11232:                             }
                   11233:                             $chgtext .= '</ul>';
                   11234:                         }  
1.93      raeburn  11235:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  11236:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   11237:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   11238:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   11239:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  11240:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  11241:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  11242:                                         $chgtext .= '<br />'.
                   11243:                                                     '<span class="LC_warning">'.
                   11244:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   11245:                                                     '</span>';
                   11246:                                     }
1.96      raeburn  11247:                                 } elsif (ref($usertypes) eq 'HASH') {
                   11248:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  11249:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   11250:                                     } else {
                   11251:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   11252:                                     }
                   11253:                                     $chgtext .= '<ul>';
                   11254:                                     foreach my $case (@{$cancreate{$type}}) {
                   11255:                                         if ($case eq 'default') {
                   11256:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   11257:                                         } else {
                   11258:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  11259:                                         }
                   11260:                                     }
1.100     raeburn  11261:                                     $chgtext .= '</ul>';
                   11262:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34  raeburn  11263:                                         $chgtext .= '<br /><span class="LC_warning">'.
                   11264:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   11265:                                                     '</span>';
1.100     raeburn  11266:                                     }
                   11267:                                 }
                   11268:                             } else {
                   11269:                                 if (@{$cancreate{$type}} == 0) {
                   11270:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   11271:                                 } else {
                   11272:                                     $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  11273:                                 }
                   11274:                             }
                   11275:                         }
1.160.6.40  raeburn  11276:                     } elsif ($type eq 'selfcreateprocessing') {
                   11277:                         my %choices = &Apache::lonlocal::texthash (
                   11278:                                                                     automatic => 'Automatic approval',
                   11279:                                                                     approval  => 'Queued for approval',
                   11280:                                                                   );
                   11281:                         if (@statuses > 1) {
                   11282:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
                   11283:                                         '<ul>';
                   11284:                            foreach my $type (@statuses) {
                   11285:                                if ($type eq 'default') {
                   11286:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   11287:                                } else {
                   11288:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   11289:                                }
                   11290:                            }
                   11291:                            $chgtext .= '</ul>';
                   11292:                         } else {
                   11293:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
                   11294:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   11295:                         }
1.160.6.5  raeburn  11296:                     } elsif ($type eq 'captcha') {
1.160.6.34  raeburn  11297:                         if ($savecaptcha{$type} eq 'notused') {
1.160.6.5  raeburn  11298:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   11299:                         } else {
                   11300:                             my %captchas = &captcha_phrases();
1.160.6.34  raeburn  11301:                             if ($captchas{$savecaptcha{$type}}) {
                   11302:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5  raeburn  11303:                             } else {
                   11304:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
                   11305:                             }
                   11306:                         }
                   11307:                     } elsif ($type eq 'recaptchakeys') {
                   11308:                         my ($privkey,$pubkey);
1.160.6.34  raeburn  11309:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   11310:                             $pubkey = $savecaptcha{$type}{'public'};
                   11311:                             $privkey = $savecaptcha{$type}{'private'};
1.160.6.5  raeburn  11312:                         }
                   11313:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   11314:                         if (!$pubkey) {
                   11315:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   11316:                         } else {
                   11317:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   11318:                         }
                   11319:                         if (!$privkey) {
                   11320:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   11321:                         } else {
                   11322:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   11323:                         }
                   11324:                         $chgtext .= '</ul>';
1.160.6.69  raeburn  11325:                     } elsif ($type eq 'recaptchaversion') {
                   11326:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
                   11327:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
                   11328:                         }
1.160.6.34  raeburn  11329:                     } elsif ($type eq 'emailusername') {
                   11330:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.35  raeburn  11331:                             if (ref($types) eq 'ARRAY') {
                   11332:                                 foreach my $type (@{$types}) {
                   11333:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   11334:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.50  raeburn  11335:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.160.6.35  raeburn  11336:                                                     '<ul>';
                   11337:                                             foreach my $field (@{$infofields}) {
                   11338:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   11339:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   11340:                                                 }
                   11341:                                             }
1.160.6.50  raeburn  11342:                                             $chgtext .= '</ul>';
                   11343:                                         } else {
                   11344:                                             $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.35  raeburn  11345:                                         }
                   11346:                                     } else {
1.160.6.50  raeburn  11347:                                         $chgtext .= &mt('When self creating account with e-mail as username, no information besides e-mail address will be provided by [_1].',"'$usertypes->{$type}'").'<br />';
1.160.6.34  raeburn  11348:                                     }
                   11349:                                 }
                   11350:                             }
                   11351:                         }
                   11352:                     } elsif ($type eq 'notify') {
                   11353:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   11354:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   11355:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   11356:                                 if ($cancreate{'notify'}{'approval'}) {
                   11357:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   11358:                                 }
                   11359:                             }
1.43      raeburn  11360:                         }
1.34      raeburn  11361:                     }
1.160.6.34  raeburn  11362:                     if ($chgtext) {
                   11363:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  11364:                     }
                   11365:                 }
                   11366:             }
1.43      raeburn  11367:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   11368:                 my ($emailrules,$emailruleorder) =
                   11369:                     &Apache::lonnet::inst_userrules($dom,'email');
                   11370:                 my $chgtext = '<ul>';
                   11371:                 foreach my $type (@email_rule) {
                   11372:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   11373:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   11374:                     }
                   11375:                 }
                   11376:                 $chgtext .= '</ul>';
                   11377:                 if (@email_rule > 0) {
1.160.6.34  raeburn  11378:                     $resulttext .= '<li>'.
                   11379:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
                   11380:                                        $chgtext.
                   11381:                                    '</li>';
1.43      raeburn  11382:                 } else {
1.160.6.34  raeburn  11383:                     $resulttext .= '<li>'.
                   11384:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
                   11385:                                    '</li>';
1.43      raeburn  11386:                 }
                   11387:             }
1.160.6.34  raeburn  11388:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   11389:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   11390:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   11391:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   11392:                     my $typename = $type;
                   11393:                     if (ref($usertypes) eq 'HASH') {
                   11394:                         if ($usertypes->{$type} ne '') {
                   11395:                             $typename = $usertypes->{$type};
1.28      raeburn  11396:                         }
                   11397:                     }
1.160.6.34  raeburn  11398:                     my @modifiable;
                   11399:                     $resulttext .= '<li>'.
                   11400:                                     &mt('Self-creation of account by users with status: [_1]',
                   11401:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   11402:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   11403:                     foreach my $field (@fields) {
                   11404:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   11405:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
                   11406:                         }
                   11407:                     }
                   11408:                     if (@modifiable > 0) {
                   11409:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  11410:                     } else {
1.160.6.34  raeburn  11411:                         $resulttext .= &mt('none');
1.43      raeburn  11412:                     }
1.160.6.34  raeburn  11413:                     $resulttext .= '</li>';
1.28      raeburn  11414:                 }
1.160.6.34  raeburn  11415:                 $resulttext .= '</ul></li>';
1.28      raeburn  11416:             }
1.27      raeburn  11417:             $resulttext .= '</ul>';
                   11418:         } else {
1.160.6.34  raeburn  11419:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  11420:         }
                   11421:     } else {
                   11422:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  11423:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11424:     }
1.43      raeburn  11425:     if ($warningmsg ne '') {
                   11426:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   11427:     }
1.23      raeburn  11428:     return $resulttext;
                   11429: }
                   11430: 
1.160.6.5  raeburn  11431: sub process_captcha {
                   11432:     my ($container,$changes,$newsettings,$current) = @_;
                   11433:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   11434:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   11435:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   11436:         $newsettings->{'captcha'} = 'original';
                   11437:     }
                   11438:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
                   11439:         if ($container eq 'cancreate') {
                   11440:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   11441:                 push(@{$changes->{'cancreate'}},'captcha');
                   11442:             } elsif (!defined($changes->{'cancreate'})) {
                   11443:                 $changes->{'cancreate'} = ['captcha'];
                   11444:             }
                   11445:         } else {
                   11446:             $changes->{'captcha'} = 1;
                   11447:         }
                   11448:     }
1.160.6.69  raeburn  11449:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5  raeburn  11450:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   11451:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   11452:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52  raeburn  11453:         $newpub =~ s/[^\w\-]//g;
                   11454:         $newpriv =~ s/[^\w\-]//g;
1.160.6.5  raeburn  11455:         $newsettings->{'recaptchakeys'} = {
                   11456:                                              public  => $newpub,
                   11457:                                              private => $newpriv,
                   11458:                                           };
1.160.6.69  raeburn  11459:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   11460:         $newversion =~ s/\D//g;
                   11461:         if ($newversion ne '2') {
                   11462:             $newversion = 1;
                   11463:         }
                   11464:         $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5  raeburn  11465:     }
                   11466:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   11467:         $currpub = $current->{'recaptchakeys'}{'public'};
                   11468:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.160.6.10  raeburn  11469:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   11470:             $newsettings->{'recaptchakeys'} = {
                   11471:                                                  public  => '',
                   11472:                                                  private => '',
                   11473:                                               }
                   11474:         }
1.160.6.5  raeburn  11475:     }
1.160.6.69  raeburn  11476:     if ($current->{'captcha'} eq 'recaptcha') {
                   11477:         $currversion = $current->{'recaptchaversion'};
                   11478:         if ($currversion ne '2') {
                   11479:             $currversion = 1;
                   11480:         }
                   11481:     }
                   11482:     if ($currversion ne $newversion) {
                   11483:         if ($container eq 'cancreate') {
                   11484:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   11485:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   11486:             } elsif (!defined($changes->{'cancreate'})) {
                   11487:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   11488:             }
                   11489:         } else {
                   11490:             $changes->{'recaptchaversion'} = 1;
                   11491:         }
                   11492:     }
1.160.6.5  raeburn  11493:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
                   11494:         if ($container eq 'cancreate') {
                   11495:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   11496:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   11497:             } elsif (!defined($changes->{'cancreate'})) {
                   11498:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   11499:             }
                   11500:         } else {
                   11501:             $changes->{'recaptchakeys'} = 1;
                   11502:         }
                   11503:     }
                   11504:     return;
                   11505: }
                   11506: 
1.33      raeburn  11507: sub modify_usermodification {
                   11508:     my ($dom,%domconfig) = @_;
1.160.6.34  raeburn  11509:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  11510:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   11511:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34  raeburn  11512:             if ($key eq 'selfcreate') {
                   11513:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   11514:             } else {  
                   11515:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   11516:             }
1.33      raeburn  11517:         }
                   11518:     }
1.160.6.34  raeburn  11519:     my @contexts = ('author','course');
1.33      raeburn  11520:     my %context_title = (
                   11521:                            author => 'In author context',
                   11522:                            course => 'In course context',
                   11523:                         );
                   11524:     my @fields = ('lastname','firstname','middlename','generation',
                   11525:                   'permanentemail','id');
                   11526:     my %roles = (
                   11527:                   author => ['ca','aa'],
                   11528:                   course => ['st','ep','ta','in','cr'],
                   11529:                 );
                   11530:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   11531:     foreach my $context (@contexts) {
                   11532:         foreach my $role (@{$roles{$context}}) {
                   11533:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   11534:             foreach my $item (@fields) {
                   11535:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   11536:                     $modifyhash{$context}{$role}{$item} = 1;
                   11537:                 } else {
                   11538:                     $modifyhash{$context}{$role}{$item} = 0;
                   11539:                 }
                   11540:             }
                   11541:         }
                   11542:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   11543:             foreach my $role (@{$roles{$context}}) {
                   11544:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   11545:                     foreach my $field (@fields) {
                   11546:                         if ($modifyhash{$context}{$role}{$field} ne 
                   11547:                                 $curr_usermodification{$context}{$role}{$field}) {
                   11548:                             push(@{$changes{$context}},$role);
                   11549:                             last;
                   11550:                         }
                   11551:                     }
                   11552:                 }
                   11553:             }
                   11554:         } else {
                   11555:             foreach my $context (@contexts) {
                   11556:                 foreach my $role (@{$roles{$context}}) {
                   11557:                     push(@{$changes{$context}},$role);
                   11558:                 }
                   11559:             }
                   11560:         }
                   11561:     }
                   11562:     my %usermodification_hash =  (
                   11563:                                    usermodification => \%modifyhash,
                   11564:                                  );
                   11565:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   11566:                                              \%usermodification_hash,$dom);
                   11567:     if ($putresult eq 'ok') {
                   11568:         if (keys(%changes) > 0) {
                   11569:             $resulttext = &mt('Changes made: ').'<ul>';
                   11570:             foreach my $context (@contexts) {
                   11571:                 if (ref($changes{$context}) eq 'ARRAY') {
                   11572:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   11573:                     if (ref($changes{$context}) eq 'ARRAY') {
                   11574:                         foreach my $role (@{$changes{$context}}) {
                   11575:                             my $rolename;
1.160.6.34  raeburn  11576:                             if ($role eq 'cr') {
                   11577:                                 $rolename = &mt('Custom');
1.33      raeburn  11578:                             } else {
1.160.6.34  raeburn  11579:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  11580:                             }
                   11581:                             my @modifiable;
1.160.6.34  raeburn  11582:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  11583:                             foreach my $field (@fields) {
                   11584:                                 if ($modifyhash{$context}{$role}{$field}) {
                   11585:                                     push(@modifiable,$fieldtitles{$field});
                   11586:                                 }
                   11587:                             }
                   11588:                             if (@modifiable > 0) {
                   11589:                                 $resulttext .= join(', ',@modifiable);
                   11590:                             } else {
                   11591:                                 $resulttext .= &mt('none'); 
                   11592:                             }
                   11593:                             $resulttext .= '</li>';
                   11594:                         }
                   11595:                         $resulttext .= '</ul></li>';
                   11596:                     }
                   11597:                 }
                   11598:             }
                   11599:             $resulttext .= '</ul>';
                   11600:         } else {
                   11601:             $resulttext = &mt('No changes made to user modification settings');
                   11602:         }
                   11603:     } else {
                   11604:         $resulttext = '<span class="LC_error">'.
                   11605:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11606:     }
                   11607:     return $resulttext;
                   11608: }
                   11609: 
1.43      raeburn  11610: sub modify_defaults {
1.160.6.27  raeburn  11611:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  11612:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27  raeburn  11613:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80  raeburn  11614:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
                   11615:                  'portal_def','intauth_cost','intauth_check','intauth_switch');
1.43      raeburn  11616:     my @authtypes = ('internal','krb4','krb5','localauth');
                   11617:     foreach my $item (@items) {
                   11618:         $newvalues{$item} = $env{'form.'.$item};
                   11619:         if ($item eq 'auth_def') {
                   11620:             if ($newvalues{$item} ne '') {
                   11621:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   11622:                     push(@errors,$item);
                   11623:                 }
                   11624:             }
                   11625:         } elsif ($item eq 'lang_def') {
                   11626:             if ($newvalues{$item} ne '') {
                   11627:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   11628:                     my $langcode = $1;
1.103     raeburn  11629:                     if ($langcode ne 'x_chef') {
                   11630:                         if (code2language($langcode) eq '') {
                   11631:                             push(@errors,$item);
                   11632:                         }
1.43      raeburn  11633:                     }
                   11634:                 } else {
                   11635:                     push(@errors,$item);
                   11636:                 }
                   11637:             }
1.54      raeburn  11638:         } elsif ($item eq 'timezone_def') {
                   11639:             if ($newvalues{$item} ne '') {
1.62      raeburn  11640:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  11641:                     push(@errors,$item);   
                   11642:                 }
                   11643:             }
1.68      raeburn  11644:         } elsif ($item eq 'datelocale_def') {
                   11645:             if ($newvalues{$item} ne '') {
                   11646:                 my @datelocale_ids = DateTime::Locale->ids();
                   11647:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   11648:                     push(@errors,$item);
                   11649:                 }
                   11650:             }
1.141     raeburn  11651:         } elsif ($item eq 'portal_def') {
                   11652:             if ($newvalues{$item} ne '') {
                   11653:                 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])\/?$/) {
                   11654:                     push(@errors,$item);
                   11655:                 }
                   11656:             }
1.160.6.80  raeburn  11657:         } elsif ($item eq 'intauth_cost') {
                   11658:             if ($newvalues{$item} ne '') {
                   11659:                 if ($newvalues{$item} =~ /\D/) {
                   11660:                     push(@errors,$item);
                   11661:                 }
                   11662:             }
                   11663:         } elsif ($item eq 'intauth_check') {
                   11664:             if ($newvalues{$item} ne '') {
                   11665:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   11666:                     push(@errors,$item);
                   11667:                 }
                   11668:             }
                   11669:         } elsif ($item eq 'intauth_switch') {
                   11670:             if ($newvalues{$item} ne '') {
                   11671:                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {
                   11672:                     push(@errors,$item);
                   11673:                 }
                   11674:             }
1.43      raeburn  11675:         }
                   11676:         if (grep(/^\Q$item\E$/,@errors)) {
                   11677:             $newvalues{$item} = $domdefaults{$item};
                   11678:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   11679:             $changes{$item} = 1;
                   11680:         }
1.72      raeburn  11681:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  11682:     }
                   11683:     my %defaults_hash = (
1.72      raeburn  11684:                          defaults => \%newvalues,
                   11685:                         );
1.43      raeburn  11686:     my $title = &defaults_titles();
1.160.6.40  raeburn  11687: 
                   11688:     my $currinststatus;
                   11689:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   11690:         $currinststatus = $domconfig{'inststatus'};
                   11691:     } else {
                   11692:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   11693:         $currinststatus = {
                   11694:                              inststatustypes => $usertypes,
                   11695:                              inststatusorder => $types,
                   11696:                              inststatusguest => [],
                   11697:                           };
                   11698:     }
                   11699:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   11700:     my @allpos;
                   11701:     my %guests;
                   11702:     my %alltypes;
                   11703:     my ($currtitles,$currguests,$currorder);
                   11704:     if (ref($currinststatus) eq 'HASH') {
                   11705:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   11706:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   11707:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   11708:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   11709:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   11710:                     }
                   11711:                 }
                   11712:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   11713:                     my $position = $env{'form.inststatus_pos_'.$type};
                   11714:                     $position =~ s/\D+//g;
                   11715:                     $allpos[$position] = $type;
                   11716:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   11717:                     $alltypes{$type} =~ s/`//g;
                   11718:                     if ($env{'form.inststatus_guest_'.$type}) {
                   11719:                         $guests{$type} = 1;
                   11720:                     }
                   11721:                 }
                   11722:             }
                   11723:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   11724:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
                   11725:             }
                   11726:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   11727:             $currtitles =~ s/,$//;
                   11728:         }
                   11729:     }
                   11730:     if ($env{'form.addinststatus'}) {
                   11731:         my $newtype = $env{'form.addinststatus'};
                   11732:         $newtype =~ s/\W//g;
                   11733:         unless (exists($alltypes{$newtype})) {
                   11734:             if ($env{'form.addinststatus_guest'}) {
                   11735:                 $guests{$newtype} = 1;
                   11736:             }
                   11737:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   11738:             $alltypes{$newtype} =~ s/`//g; 
                   11739:             my $position = $env{'form.addinststatus_pos'};
                   11740:             $position =~ s/\D+//g;
                   11741:             if ($position ne '') {
                   11742:                 $allpos[$position] = $newtype;
                   11743:             }
                   11744:         }
                   11745:     }
                   11746:     my (@orderedstatus,@orderedguests);
                   11747:     foreach my $type (@allpos) {
                   11748:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   11749:             push(@orderedstatus,$type);
                   11750:             if ($guests{$type}) {
                   11751:                 push(@orderedguests,$type);
                   11752:             }
                   11753:         }
                   11754:     }
                   11755:     foreach my $type (keys(%alltypes)) {
                   11756:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   11757:             delete($alltypes{$type});
                   11758:         }
                   11759:     }
                   11760:     $defaults_hash{'inststatus'} = {
                   11761:                                      inststatustypes => \%alltypes,
                   11762:                                      inststatusorder => \@orderedstatus,
                   11763:                                      inststatusguest => \@orderedguests,
                   11764:                                    };
                   11765:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   11766:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   11767:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   11768:         }
                   11769:     }
                   11770:     if ($currorder ne join(',',@orderedstatus)) {
                   11771:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   11772:     }
                   11773:     if ($currguests ne join(',',@orderedguests)) {
                   11774:         $changes{'inststatus'}{'inststatusguest'} = 1;
                   11775:     }
                   11776:     my $newtitles;
                   11777:     foreach my $item (@orderedstatus) {
                   11778:         $newtitles .= $alltypes{$item}.',';
                   11779:     }
                   11780:     $newtitles =~ s/,$//;
                   11781:     if ($currtitles ne $newtitles) {
                   11782:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   11783:     }
1.43      raeburn  11784:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   11785:                                              $dom);
                   11786:     if ($putresult eq 'ok') {
                   11787:         if (keys(%changes) > 0) {
                   11788:             $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27  raeburn  11789:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  11790:             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";
                   11791:             foreach my $item (sort(keys(%changes))) {
1.160.6.40  raeburn  11792:                 if ($item eq 'inststatus') {
                   11793:                     if (ref($changes{'inststatus'}) eq 'HASH') {
                   11794:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
                   11795:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   11796:                             foreach my $type (@orderedstatus) { 
                   11797:                                 $resulttext .= $alltypes{$type}.', ';
                   11798:                             }
                   11799:                             $resulttext =~ s/, $//;
                   11800:                             $resulttext .= '</li>';
                   11801:                         }
                   11802:                         if ($changes{'inststatus'}{'inststatusguest'}) {
                   11803:                             $resulttext .= '<li>'; 
                   11804:                             if (@orderedguests) {
                   11805:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
                   11806:                                 foreach my $type (@orderedguests) {
                   11807:                                     $resulttext .= $alltypes{$type}.', ';
                   11808:                                 }
                   11809:                                 $resulttext =~ s/, $//;
                   11810:                             } else {
                   11811:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
                   11812:                             }
                   11813:                             $resulttext .= '</li>';
                   11814:                         }
                   11815:                     }
                   11816:                 } else {
                   11817:                     my $value = $env{'form.'.$item};
                   11818:                     if ($value eq '') {
                   11819:                         $value = &mt('none');
                   11820:                     } elsif ($item eq 'auth_def') {
                   11821:                         my %authnames = &authtype_names();
                   11822:                         my %shortauth = (
                   11823:                                           internal   => 'int',
                   11824:                                           krb4       => 'krb4',
                   11825:                                           krb5       => 'krb5',
                   11826:                                           localauth  => 'loc',
                   11827:                         );
                   11828:                         $value = $authnames{$shortauth{$value}};
1.160.6.80  raeburn  11829:                     } elsif ($item eq 'intauth_switch') {
                   11830:                         my %optiondesc = &Apache::lonlocal::texthash (
                   11831:                                             0 => 'No',
                   11832:                                             1 => 'Yes',
                   11833:                                             2 => 'Yes, and copy existing passwd file to passwd.bak file',
                   11834:                                          );
                   11835:                         if ($value =~ /^(0|1|2)$/) {
                   11836:                             $value = $optiondesc{$value};
                   11837:                         } else {
                   11838:                             $value = &mt('none -- defaults to No');
                   11839:                         }
                   11840:                     } elsif ($item eq 'intauth_check') {
                   11841:                         my %optiondesc = &Apache::lonlocal::texthash (
                   11842:                                              0 => 'No',
                   11843:                                              1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                   11844:                                              2 => 'Yes, disallow login if stored cost is less than domain default',
                   11845:                                          );
                   11846:                         if ($value =~ /^(0|1|2)$/) {
                   11847:                             $value = $optiondesc{$value};
                   11848:                         } else {
                   11849:                             $value = &mt('none -- defaults to No');
                   11850:                         }
1.160.6.40  raeburn  11851:                     }
                   11852:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   11853:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  11854:                 }
                   11855:             }
                   11856:             $resulttext .= '</ul>';
                   11857:             $mailmsgtext .= "\n";
                   11858:             my $cachetime = 24*60*60;
1.72      raeburn  11859:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  11860:             if (ref($lastactref) eq 'HASH') {
                   11861:                 $lastactref->{'domdefaults'} = 1;
                   11862:             }
1.68      raeburn  11863:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23  raeburn  11864:                 my $notify = 1;
                   11865:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   11866:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   11867:                         $notify = 0;
                   11868:                     }
                   11869:                 }
                   11870:                 if ($notify) {
                   11871:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   11872:                                                "LON-CAPA Domain Settings Change - $dom",
                   11873:                                                $mailmsgtext);
                   11874:                 }
1.54      raeburn  11875:             }
1.43      raeburn  11876:         } else {
1.54      raeburn  11877:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  11878:         }
                   11879:     } else {
                   11880:         $resulttext = '<span class="LC_error">'.
                   11881:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11882:     }
                   11883:     if (@errors > 0) {
                   11884:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   11885:         foreach my $item (@errors) {
                   11886:             $resulttext .= ' "'.$title->{$item}.'",';
                   11887:         }
                   11888:         $resulttext =~ s/,$//;
                   11889:     }
                   11890:     return $resulttext;
                   11891: }
                   11892: 
1.46      raeburn  11893: sub modify_scantron {
1.160.6.24  raeburn  11894:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  11895:     my ($resulttext,%confhash,%changes,$errors);
                   11896:     my $custom = 'custom.tab';
                   11897:     my $default = 'default.tab';
                   11898:     my $servadm = $r->dir_config('lonAdmEMail');
                   11899:     my ($configuserok,$author_ok,$switchserver) = 
                   11900:         &config_check($dom,$confname,$servadm);
                   11901:     if ($env{'form.scantronformat.filename'} ne '') {
                   11902:         my $error;
                   11903:         if ($configuserok eq 'ok') {
                   11904:             if ($switchserver) {
1.130     raeburn  11905:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  11906:             } else {
                   11907:                 if ($author_ok eq 'ok') {
                   11908:                     my ($result,$scantronurl) =
                   11909:                         &publishlogo($r,'upload','scantronformat',$dom,
                   11910:                                      $confname,'scantron','','',$custom);
                   11911:                     if ($result eq 'ok') {
                   11912:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  11913:                         $changes{'scantronformat'} = 1;
1.46      raeburn  11914:                     } else {
                   11915:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   11916:                     }
                   11917:                 } else {
                   11918:                     $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);
                   11919:                 }
                   11920:             }
                   11921:         } else {
                   11922:             $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);
                   11923:         }
                   11924:         if ($error) {
                   11925:             &Apache::lonnet::logthis($error);
                   11926:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   11927:         }
                   11928:     }
1.48      raeburn  11929:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   11930:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   11931:             if ($env{'form.scantronformat_del'}) {
                   11932:                 $confhash{'scantron'}{'scantronformat'} = '';
                   11933:                 $changes{'scantronformat'} = 1;
1.46      raeburn  11934:             }
                   11935:         }
                   11936:     }
                   11937:     if (keys(%confhash) > 0) {
                   11938:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   11939:                                                  $dom);
                   11940:         if ($putresult eq 'ok') {
                   11941:             if (keys(%changes) > 0) {
1.48      raeburn  11942:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   11943:                     $resulttext = &mt('Changes made:').'<ul>';
                   11944:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  11945:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  11946:                     } else {
1.130     raeburn  11947:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  11948:                     }
1.48      raeburn  11949:                     $resulttext .= '</ul>';
                   11950:                 } else {
1.130     raeburn  11951:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  11952:                 }
                   11953:                 $resulttext .= '</ul>';
                   11954:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27  raeburn  11955:                 if (ref($lastactref) eq 'HASH') {
                   11956:                     $lastactref->{'domainconfig'} = 1;
                   11957:                 }
1.46      raeburn  11958:             } else {
1.130     raeburn  11959:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  11960:             }
                   11961:         } else {
                   11962:             $resulttext = '<span class="LC_error">'.
                   11963:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   11964:         }
                   11965:     } else {
1.130     raeburn  11966:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  11967:     }
                   11968:     if ($errors) {
                   11969:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   11970:                        $errors.'</ul>';
                   11971:     }
                   11972:     return $resulttext;
                   11973: }
                   11974: 
1.48      raeburn  11975: sub modify_coursecategories {
1.160.6.43  raeburn  11976:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  11977:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   11978:         $cathash);
1.48      raeburn  11979:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42  raeburn  11980:     my @catitems = ('unauth','auth');
                   11981:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  11982:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  11983:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   11984:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   11985:             $changes{'togglecats'} = 1;
                   11986:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   11987:         }
                   11988:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   11989:             $changes{'categorize'} = 1;
                   11990:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   11991:         }
1.120     raeburn  11992:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   11993:             $changes{'togglecatscomm'} = 1;
                   11994:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   11995:         }
                   11996:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   11997:             $changes{'categorizecomm'} = 1;
                   11998:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
                   11999:         }
1.160.6.42  raeburn  12000:         foreach my $item (@catitems) {
                   12001:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   12002:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   12003:                     $changes{$item} = 1;
                   12004:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   12005:                 }
                   12006:             }
                   12007:         }
1.57      raeburn  12008:     } else {
                   12009:         $changes{'togglecats'} = 1;
                   12010:         $changes{'categorize'} = 1;
1.124     raeburn  12011:         $changes{'togglecatscomm'} = 1;
                   12012:         $changes{'categorizecomm'} = 1;
1.87      raeburn  12013:         $domconfig{'coursecategories'} = {
                   12014:                                              togglecats => $env{'form.togglecats'},
                   12015:                                              categorize => $env{'form.categorize'},
1.124     raeburn  12016:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   12017:                                              categorizecomm => $env{'form.categorizecomm'},
1.120     raeburn  12018:                                          };
1.160.6.42  raeburn  12019:         foreach my $item (@catitems) {
                   12020:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   12021:                 $changes{$item} = 1;
                   12022:             }
                   12023:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   12024:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   12025:             }
                   12026:         }
1.57      raeburn  12027:     }
                   12028:     if (ref($cathash) eq 'HASH') {
                   12029:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  12030:             push (@deletecategory,'instcode::0');
                   12031:         }
1.120     raeburn  12032:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   12033:             push(@deletecategory,'communities::0');
                   12034:         }
1.48      raeburn  12035:     }
1.57      raeburn  12036:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   12037:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  12038:         if (@deletecategory > 0) {
                   12039:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  12040:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  12041:             foreach my $item (@deletecategory) {
1.57      raeburn  12042:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   12043:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  12044:                     $deletions{$item} = 1;
1.57      raeburn  12045:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  12046:                 }
                   12047:             }
                   12048:         }
1.57      raeburn  12049:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  12050:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  12051:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  12052:                 $reorderings{$item} = 1;
1.57      raeburn  12053:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  12054:             }
                   12055:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   12056:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   12057:                 my $newdepth = $depth+1;
                   12058:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  12059:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  12060:                 $adds{$newitem} = 1; 
                   12061:             }
                   12062:             if ($env{'form.subcat_'.$item} ne '') {
                   12063:                 my $newcat = $env{'form.subcat_'.$item};
                   12064:                 my $newdepth = $depth+1;
                   12065:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  12066:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  12067:                 $adds{$newitem} = 1;
                   12068:             }
                   12069:         }
                   12070:     }
                   12071:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  12072:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  12073:             my $newitem = 'instcode::0';
1.57      raeburn  12074:             if ($cathash->{$newitem} eq '') {  
                   12075:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  12076:                 $adds{$newitem} = 1;
                   12077:             }
                   12078:         } else {
                   12079:             my $newitem = 'instcode::0';
1.57      raeburn  12080:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  12081:             $adds{$newitem} = 1;
                   12082:         }
                   12083:     }
1.120     raeburn  12084:     if ($env{'form.communities'} eq '1') {
                   12085:         if (ref($cathash) eq 'HASH') {
                   12086:             my $newitem = 'communities::0';
                   12087:             if ($cathash->{$newitem} eq '') {
                   12088:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   12089:                 $adds{$newitem} = 1;
                   12090:             }
                   12091:         } else {
                   12092:             my $newitem = 'communities::0';
                   12093:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   12094:             $adds{$newitem} = 1;
                   12095:         }
                   12096:     }
1.48      raeburn  12097:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  12098:         if (($env{'form.addcategory_name'} ne 'instcode') &&
                   12099:             ($env{'form.addcategory_name'} ne 'communities')) {
                   12100:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   12101:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   12102:             $adds{$newitem} = 1;
                   12103:         }
1.48      raeburn  12104:     }
1.57      raeburn  12105:     my $putresult;
1.48      raeburn  12106:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   12107:         if (keys(%deletions) > 0) {
                   12108:             foreach my $key (keys(%deletions)) {
                   12109:                 if ($predelallitems{$key} ne '') {
                   12110:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   12111:                 }
                   12112:             }
                   12113:         }
                   12114:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  12115:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  12116:         if (ref($chkcats[0]) eq 'ARRAY') {
                   12117:             my $depth = 0;
                   12118:             my $chg = 0;
                   12119:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   12120:                 my $name = $chkcats[0][$i];
                   12121:                 my $item;
                   12122:                 if ($name eq '') {
                   12123:                     $chg ++;
                   12124:                 } else {
                   12125:                     $item = &escape($name).'::0';
                   12126:                     if ($chg) {
1.57      raeburn  12127:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  12128:                     }
                   12129:                     $depth ++; 
1.57      raeburn  12130:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  12131:                     $depth --;
                   12132:                 }
                   12133:             }
                   12134:         }
1.57      raeburn  12135:     }
                   12136:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   12137:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  12138:         if ($putresult eq 'ok') {
1.57      raeburn  12139:             my %title = (
1.120     raeburn  12140:                          togglecats     => 'Show/Hide a course in catalog',
                   12141:                          categorize     => 'Assign a category to a course',
                   12142:                          togglecatscomm => 'Show/Hide a community in catalog',
                   12143:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  12144:                         );
                   12145:             my %level = (
1.120     raeburn  12146:                          dom  => 'set in Domain ("Modify Course/Community")',
                   12147:                          crs  => 'set in Course ("Course Configuration")',
                   12148:                          comm => 'set in Community ("Community Configuration")',
1.160.6.42  raeburn  12149:                          none     => 'No catalog',
                   12150:                          std      => 'Standard catalog',
                   12151:                          domonly  => 'Domain-only catalog',
                   12152:                          codesrch => 'Code search form',
1.57      raeburn  12153:                         );
1.48      raeburn  12154:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  12155:             if ($changes{'togglecats'}) {
                   12156:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   12157:             }
                   12158:             if ($changes{'categorize'}) {
                   12159:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  12160:             }
1.120     raeburn  12161:             if ($changes{'togglecatscomm'}) {
                   12162:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   12163:             }
                   12164:             if ($changes{'categorizecomm'}) {
                   12165:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   12166:             }
1.160.6.42  raeburn  12167:             if ($changes{'unauth'}) {
                   12168:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   12169:             }
                   12170:             if ($changes{'auth'}) {
                   12171:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   12172:             }
1.57      raeburn  12173:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   12174:                 my $cathash;
                   12175:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   12176:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   12177:                 } else {
                   12178:                     $cathash = {};
                   12179:                 } 
                   12180:                 my (@cats,@trails,%allitems);
                   12181:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   12182:                 if (keys(%deletions) > 0) {
                   12183:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   12184:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   12185:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   12186:                     }
                   12187:                     $resulttext .= '</ul></li>';
                   12188:                 }
                   12189:                 if (keys(%reorderings) > 0) {
                   12190:                     my %sort_by_trail;
                   12191:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   12192:                     foreach my $key (keys(%reorderings)) {
                   12193:                         if ($allitems{$key} ne '') {
                   12194:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   12195:                         }
1.48      raeburn  12196:                     }
1.57      raeburn  12197:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   12198:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   12199:                     }
                   12200:                     $resulttext .= '</ul></li>';
1.48      raeburn  12201:                 }
1.57      raeburn  12202:                 if (keys(%adds) > 0) {
                   12203:                     my %sort_by_trail;
                   12204:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   12205:                     foreach my $key (keys(%adds)) {
                   12206:                         if ($allitems{$key} ne '') {
                   12207:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   12208:                         }
                   12209:                     }
                   12210:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   12211:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  12212:                     }
1.57      raeburn  12213:                     $resulttext .= '</ul></li>';
1.48      raeburn  12214:                 }
                   12215:             }
                   12216:             $resulttext .= '</ul>';
1.160.6.43  raeburn  12217:             if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50  raeburn  12218:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   12219:                 if ($changes{'auth'}) {
                   12220:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   12221:                 }
                   12222:                 if ($changes{'unauth'}) {
                   12223:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   12224:                 }
                   12225:                 my $cachetime = 24*60*60;
                   12226:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43  raeburn  12227:                 if (ref($lastactref) eq 'HASH') {
1.160.6.50  raeburn  12228:                     $lastactref->{'domdefaults'} = 1;
1.160.6.43  raeburn  12229:                 }
                   12230:             }
1.48      raeburn  12231:         } else {
                   12232:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  12233:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  12234:         }
                   12235:     } else {
1.120     raeburn  12236:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  12237:     }
                   12238:     return $resulttext;
                   12239: }
                   12240: 
1.69      raeburn  12241: sub modify_serverstatuses {
                   12242:     my ($dom,%domconfig) = @_;
                   12243:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   12244:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   12245:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   12246:     }
                   12247:     my @pages = &serverstatus_pages();
                   12248:     foreach my $type (@pages) {
                   12249:         $newserverstatus{$type}{'namedusers'} = '';
                   12250:         $newserverstatus{$type}{'machines'} = '';
                   12251:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   12252:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   12253:             my @okusers;
                   12254:             foreach my $user (@users) {
                   12255:                 my ($uname,$udom) = split(/:/,$user);
                   12256:                 if (($udom =~ /^$match_domain$/) &&   
                   12257:                     (&Apache::lonnet::domain($udom)) &&
                   12258:                     ($uname =~ /^$match_username$/)) {
                   12259:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   12260:                         push(@okusers,$user);
                   12261:                     }
                   12262:                 }
                   12263:             }
                   12264:             if (@okusers > 0) {
                   12265:                  @okusers = sort(@okusers);
                   12266:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   12267:             }
                   12268:         }
                   12269:         if (defined($env{'form.'.$type.'_machines'})) {
                   12270:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   12271:             my @okmachines;
                   12272:             foreach my $ip (@machines) {
                   12273:                 my @parts = split(/\./,$ip);
                   12274:                 next if (@parts < 4);
                   12275:                 my $badip = 0;
                   12276:                 for (my $i=0; $i<4; $i++) {
                   12277:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   12278:                         $badip = 1;
                   12279:                         last;
                   12280:                     }
                   12281:                 }
                   12282:                 if (!$badip) {
                   12283:                     push(@okmachines,$ip);     
                   12284:                 }
                   12285:             }
                   12286:             @okmachines = sort(@okmachines);
                   12287:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   12288:         }
                   12289:     }
                   12290:     my %serverstatushash =  (
                   12291:                                 serverstatuses => \%newserverstatus,
                   12292:                             );
                   12293:     foreach my $type (@pages) {
1.83      raeburn  12294:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  12295:             my (@current,@new);
1.83      raeburn  12296:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  12297:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   12298:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   12299:                 }
                   12300:             }
                   12301:             if ($newserverstatus{$type}{$setting} ne '') {
                   12302:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  12303:             }
                   12304:             if (@current > 0) {
                   12305:                 if (@new > 0) {
                   12306:                     foreach my $item (@current) {
                   12307:                         if (!grep(/^\Q$item\E$/,@new)) {
                   12308:                             $changes{$type}{$setting} = 1;
1.82      raeburn  12309:                             last;
                   12310:                         }
                   12311:                     }
1.84      raeburn  12312:                     foreach my $item (@new) {
                   12313:                         if (!grep(/^\Q$item\E$/,@current)) {
                   12314:                             $changes{$type}{$setting} = 1;
                   12315:                             last;
1.82      raeburn  12316:                         }
                   12317:                     }
                   12318:                 } else {
1.83      raeburn  12319:                     $changes{$type}{$setting} = 1;
1.69      raeburn  12320:                 }
1.83      raeburn  12321:             } elsif (@new > 0) {
                   12322:                 $changes{$type}{$setting} = 1;
1.69      raeburn  12323:             }
                   12324:         }
                   12325:     }
                   12326:     if (keys(%changes) > 0) {
1.81      raeburn  12327:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  12328:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   12329:                                                  \%serverstatushash,$dom);
                   12330:         if ($putresult eq 'ok') {
                   12331:             $resulttext .= &mt('Changes made:').'<ul>';
                   12332:             foreach my $type (@pages) {
1.84      raeburn  12333:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  12334:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  12335:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  12336:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   12337:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   12338:                         } else {
                   12339:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   12340:                         }
1.84      raeburn  12341:                     }
                   12342:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  12343:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   12344:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   12345:                         } else {
                   12346:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   12347:                         }
                   12348: 
                   12349:                     }
                   12350:                     $resulttext .= '</ul></li>';
                   12351:                 }
                   12352:             }
                   12353:             $resulttext .= '</ul>';
                   12354:         } else {
                   12355:             $resulttext = '<span class="LC_error">'.
                   12356:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   12357: 
                   12358:         }
                   12359:     } else {
                   12360:         $resulttext = &mt('No changes made to access to server status pages');
                   12361:     }
                   12362:     return $resulttext;
                   12363: }
                   12364: 
1.118     jms      12365: sub modify_helpsettings {
1.160.6.77  raeburn  12366:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5  raeburn  12367:     my ($resulttext,$errors,%changes,%helphash);
                   12368:     my %defaultchecked = ('submitbugs' => 'on');
                   12369:     my @offon = ('off','on');
1.118     jms      12370:     my @toggles = ('submitbugs');
1.160.6.77  raeburn  12371:     my %current = ('submitbugs' => '',
                   12372:                    'adhoc'      => {},
                   12373:                   );
1.118     jms      12374:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73  raeburn  12375:         %current = %{$domconfig{'helpsettings'}};
                   12376:     }
1.160.6.77  raeburn  12377:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73  raeburn  12378:     foreach my $item (@toggles) {
                   12379:         if ($defaultchecked{$item} eq 'on') { 
                   12380:             if ($current{$item} eq '') {
                   12381:                 if ($env{'form.'.$item} eq '0') {
1.160.6.5  raeburn  12382:                     $changes{$item} = 1;
                   12383:                 }
1.160.6.73  raeburn  12384:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   12385:                 $changes{$item} = 1;
                   12386:             }
                   12387:         } elsif ($defaultchecked{$item} eq 'off') {
                   12388:             if ($current{$item} eq '') {
                   12389:                 if ($env{'form.'.$item} eq '1') {
1.160.6.5  raeburn  12390:                     $changes{$item} = 1;
                   12391:                 }
1.160.6.73  raeburn  12392:             } elsif ($current{$item} ne $env{'form.'.$item}) {
                   12393:                 $changes{$item} = 1;
                   12394:             }
                   12395:         }
                   12396:         if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
                   12397:             $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   12398:         }
                   12399:     }
1.160.6.77  raeburn  12400:     my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73  raeburn  12401:     my $confname = $dom.'-domainconfig';
                   12402:     my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77  raeburn  12403:     my (@allpos,%newsettings,%changedprivs,$newrole);
                   12404:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79  raeburn  12405:     my @accesstypes = ('all','dh','da','none','status','inc','exc');
                   12406:     my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77  raeburn  12407:     my %lt = &Apache::lonlocal::texthash(
                   12408:                     s      => 'system',
                   12409:                     d      => 'domain',
                   12410:                     order  => 'Display order',
                   12411:                     access => 'Role usage',
1.160.6.79  raeburn  12412:                     all    => 'All with domain helpdesk or helpdesk assistant role',
                   12413:                     dh     => 'All with domain helpdesk role',
                   12414:                     da     => 'All with domain helpdesk assistant role',
1.160.6.77  raeburn  12415:                     none   => 'None',
                   12416:                     status => 'Determined based on institutional status',
                   12417:                     inc    => 'Include all, but exclude specific personnel',
                   12418:                     exc    => 'Exclude all, but include specific personnel',
                   12419:     );
                   12420:     for (my $num=0; $num<=$maxnum; $num++) {
                   12421:         my ($prefix,$identifier,$rolename,%curr);
                   12422:         if ($num == $maxnum) {
                   12423:             next unless ($env{'form.newcusthelp'} == $maxnum);
                   12424:             $identifier = 'custhelp'.$num;
                   12425:             $prefix = 'helproles_'.$num;
                   12426:             $rolename = $env{'form.custhelpname'.$num};
                   12427:             $rolename=~s/[^A-Za-z0-9]//gs;
                   12428:             next if ($rolename eq '');
                   12429:             next if (exists($existing{'rolesdef_'.$rolename}));
                   12430:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   12431:             my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   12432:                                                      $newprivs{'c'},$confname,$dom);
                   12433:             if ($result ne 'ok') {
                   12434:                 $errors .= '<li><span class="LC_error">'.
                   12435:                            &mt('An error occurred storing the new custom role: [_1]',
                   12436:                            $result).'</span></li>';
                   12437:                 next;
                   12438:             } else {
                   12439:                 $changedprivs{$rolename} = \%newprivs;
                   12440:                 $newrole = $rolename;
                   12441:             }
                   12442:         } else {
                   12443:             $prefix = 'helproles_'.$num;
                   12444:             $rolename = $env{'form.'.$prefix};
                   12445:             next if ($rolename eq '');
                   12446:             next unless (exists($existing{'rolesdef_'.$rolename}));
                   12447:             $identifier = 'custhelp'.$num;
                   12448:             my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
                   12449:             my %currprivs;
                   12450:             ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
                   12451:                 split(/\_/,$existing{'rolesdef_'.$rolename});
                   12452:             foreach my $level ('c','d','s') {
                   12453:                 if ($newprivs{$level} ne $currprivs{$level}) {
                   12454:                     my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
                   12455:                                                              $newprivs{'c'},$confname,$dom);
                   12456:                     if ($result ne 'ok') {
                   12457:                         $errors .= '<li><span class="LC_error">'.
                   12458:                                    &mt('An error occurred storing privileges for existing role [_1]: [_2]',
                   12459:                                        $rolename,$result).'</span></li>';
                   12460:                     } else {
                   12461:                         $changedprivs{$rolename} = \%newprivs;
                   12462:                     }
                   12463:                     last;
                   12464:                 }
                   12465:             }
                   12466:             if (ref($current{'adhoc'}) eq 'HASH') {
                   12467:                 if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   12468:                     %curr = %{$current{'adhoc'}{$rolename}};
                   12469:                 }
                   12470:             }
                   12471:         }
                   12472:         my $newpos = $env{'form.'.$prefix.'_pos'};
                   12473:         $newpos =~ s/\D+//g;
                   12474:         $allpos[$newpos] = $rolename;
                   12475:         my $newdesc = $env{'form.'.$prefix.'_desc'};
                   12476:         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
                   12477:         if ($curr{'desc'}) {
                   12478:             if ($curr{'desc'} ne $newdesc) {
                   12479:                 $changes{'customrole'}{$rolename}{'desc'} = 1;
                   12480:                 $newsettings{$rolename}{'desc'} = $newdesc;
                   12481:             }
                   12482:         } elsif ($newdesc ne '') {
                   12483:             $changes{'customrole'}{$rolename}{'desc'} = 1;
                   12484:             $newsettings{$rolename}{'desc'} = $newdesc;
                   12485:         }
                   12486:         my $access = $env{'form.'.$prefix.'_access'};
                   12487:         if (grep(/^\Q$access\E$/,@accesstypes)) {
                   12488:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
                   12489:             if ($access eq 'status') {
                   12490:                 my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
                   12491:                 if (scalar(@statuses) == 0) {
                   12492:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
                   12493:                 } else {
                   12494:                     my (@shownstatus,$numtypes);
                   12495:                     $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   12496:                     if (ref($types) eq 'ARRAY') {
                   12497:                         $numtypes = scalar(@{$types});
                   12498:                         foreach my $type (sort(@statuses)) {
                   12499:                             if ($type eq 'default') {
                   12500:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   12501:                             } elsif (grep(/^\Q$type\E$/,@{$types})) {
                   12502:                                 push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
                   12503:                                 push(@shownstatus,$usertypes->{$type});
                   12504:                             }
1.160.6.73  raeburn  12505:                         }
                   12506:                     }
1.160.6.77  raeburn  12507:                     if (grep(/^default$/,@statuses)) {
                   12508:                         push(@shownstatus,$othertitle);
                   12509:                     }
                   12510:                     if (scalar(@shownstatus) == 1+$numtypes) {
                   12511:                         $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
                   12512:                         delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
                   12513:                     } else {
                   12514:                         $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
                   12515:                         if (ref($curr{'status'}) eq 'ARRAY') {
                   12516:                             my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   12517:                             if (@diffs) {
                   12518:                                 $changes{'customrole'}{$rolename}{$access} = 1;
                   12519:                             }
                   12520:                         } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   12521:                             $changes{'customrole'}{$rolename}{$access} = 1;
                   12522:                         }
                   12523:                     }
                   12524:                 }
                   12525:             } elsif (($access eq 'inc') || ($access eq 'exc')) {
                   12526:                 my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
                   12527:                 my @newspecstaff;
                   12528:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
                   12529:                 foreach my $person (sort(@personnel)) {
                   12530:                     if ($domhelpdesk{$person}) {
                   12531:                         push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
                   12532:                     }
                   12533:                 }
                   12534:                 if (ref($curr{$access}) eq 'ARRAY') {
                   12535:                     my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
                   12536:                     if (@diffs) {
                   12537:                         $changes{'customrole'}{$rolename}{$access} = 1;
                   12538:                     }
                   12539:                 } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   12540:                     $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73  raeburn  12541:                 }
1.160.6.77  raeburn  12542:                 foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
                   12543:                     my ($uname,$udom) = split(/:/,$person);
                   12544:                         push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
                   12545:                 }
                   12546:                 $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26  raeburn  12547:             }
1.160.6.77  raeburn  12548:         } else {
                   12549:             $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
                   12550:         }
                   12551:         unless ($curr{'access'} eq $access) {
                   12552:             $changes{'customrole'}{$rolename}{'access'} = 1;
                   12553:             $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73  raeburn  12554:         }
                   12555:     }
1.160.6.77  raeburn  12556:     if (@allpos > 0) {
                   12557:         my $idx = 0;
                   12558:         foreach my $rolename (@allpos) {
                   12559:             if ($rolename ne '') {
                   12560:                 $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
                   12561:                 if (ref($current{'adhoc'}) eq 'HASH') {
                   12562:                     if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
                   12563:                         if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
                   12564:                             $changes{'customrole'}{$rolename}{'order'} = 1;
                   12565:                             $newsettings{$rolename}{'order'} = $idx+1;
                   12566:                         }
                   12567:                     }
1.160.6.73  raeburn  12568:                 }
1.160.6.77  raeburn  12569:                 $idx ++;
1.122     jms      12570:             }
                   12571:         }
1.118     jms      12572:     }
1.123     jms      12573:     my $putresult;
                   12574:     if (keys(%changes) > 0) {
1.160.6.5  raeburn  12575:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
                   12576:         if ($putresult eq 'ok') {
1.160.6.77  raeburn  12577:             if (ref($helphash{'helpsettings'}) eq 'HASH') {
                   12578:                 $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
                   12579:                 if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
                   12580:                     $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
                   12581:                 }
                   12582:             }
                   12583:             my $cachetime = 24*60*60;
                   12584:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   12585:             if (ref($lastactref) eq 'HASH') {
                   12586:                 $lastactref->{'domdefaults'} = 1;
                   12587:             }
                   12588:         } else {
                   12589:             $errors .= '<li><span class="LC_error">'.
                   12590:                        &mt('An error occurred storing the settings: [_1]',
                   12591:                            $putresult).'</span></li>';
                   12592:         }
                   12593:     }
                   12594:     if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
                   12595:         $resulttext = &mt('Changes made:').'<ul>';
                   12596:         my (%shownprivs,@levelorder);
                   12597:         @levelorder = ('c','d','s');
                   12598:         if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5  raeburn  12599:             foreach my $item (sort(keys(%changes))) {
                   12600:                 if ($item eq 'submitbugs') {
                   12601:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   12602:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   12603:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73  raeburn  12604:                 } elsif ($item eq 'customrole') {
                   12605:                     if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77  raeburn  12606:                         my @keyorder = ('order','desc','access','status','exc','inc');
                   12607:                         my %keytext = &Apache::lonlocal::texthash(
                   12608:                                                                    order  => 'Order',
                   12609:                                                                    desc   => 'Role description',
                   12610:                                                                    access => 'Role usage',
1.160.6.83  raeburn  12611:                                                                    status => 'Allowed institutional types',
1.160.6.77  raeburn  12612:                                                                    exc    => 'Allowed personnel',
                   12613:                                                                    inc    => 'Disallowed personnel',
                   12614:                         );
1.160.6.73  raeburn  12615:                         foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77  raeburn  12616:                             if (ref($changes{'customrole'}{$role}) eq 'HASH') {
                   12617:                                 if ($role eq $newrole) {
                   12618:                                     $resulttext .= '<li>'.&mt('New custom role added: [_1]',
                   12619:                                                               $role).'<ul>';
                   12620:                                 } else {
                   12621:                                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   12622:                                                               $role).'<ul>';
                   12623:                                 }
                   12624:                                 foreach my $key (@keyorder) {
                   12625:                                     if ($changes{'customrole'}{$role}{$key}) {
                   12626:                                         $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
                   12627:                                                                   $keytext{$key},$newsettings{$role}{$key}).
                   12628:                                                        '</li>';
                   12629:                                     }
                   12630:                                 }
                   12631:                                 if (ref($changedprivs{$role}) eq 'HASH') {
                   12632:                                     $shownprivs{$role} = 1;
                   12633:                                     $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
                   12634:                                     foreach my $level (@levelorder) {
                   12635:                                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   12636:                                             next if ($item eq '');
                   12637:                                             my ($priv) = split(/\&/,$item,2);
                   12638:                                             if (&Apache::lonnet::plaintext($priv)) {
                   12639:                                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   12640:                                                 unless ($level eq 'c') {
                   12641:                                                     $resulttext .= ' ('.$lt{$level}.')';
                   12642:                                                 }
                   12643:                                                 $resulttext .= '</li>';
                   12644:                                             }
                   12645:                                         }
                   12646:                                     }
                   12647:                                     $resulttext .= '</ul>';
                   12648:                                 }
                   12649:                                 $resulttext .= '</ul></li>';
                   12650:                             }
1.160.6.73  raeburn  12651:                         }
                   12652:                     }
1.160.6.5  raeburn  12653:                 }
                   12654:             }
                   12655:         }
1.160.6.77  raeburn  12656:         if (keys(%changedprivs)) {
                   12657:             foreach my $role (sort(keys(%changedprivs))) {
                   12658:                 unless ($shownprivs{$role}) {
                   12659:                     $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
                   12660:                                               $role).'<ul>'.
                   12661:                                    '<li>'.&mt('Privileges set to :').'<ul>';
                   12662:                     foreach my $level (@levelorder) {
                   12663:                         foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
                   12664:                             next if ($item eq '');
                   12665:                             my ($priv) = split(/\&/,$item,2);
                   12666:                             if (&Apache::lonnet::plaintext($priv)) {
                   12667:                                 $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
                   12668:                                 unless ($level eq 'c') {
                   12669:                                     $resulttext .= ' ('.$lt{$level}.')';
                   12670:                                 }
                   12671:                                 $resulttext .= '</li>';
                   12672:                             }
                   12673:                         }
                   12674:                     }
                   12675:                     $resulttext .= '</ul></li></ul></li>';
                   12676:                 }
                   12677:             }
                   12678:         }
                   12679:         $resulttext .= '</ul>';
                   12680:     } else {
                   12681:         $resulttext = &mt('No changes made to help settings');
1.118     jms      12682:     }
                   12683:     if ($errors) {
1.160.6.5  raeburn  12684:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77  raeburn  12685:                                     $errors.'</ul>';
1.118     jms      12686:     }
                   12687:     return $resulttext;
                   12688: }
                   12689: 
1.121     raeburn  12690: sub modify_coursedefaults {
1.160.6.27  raeburn  12691:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  12692:     my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57  raeburn  12693:     my %defaultchecked = (
                   12694:                            'uselcmath'       => 'on',
                   12695:                            'usejsme'         => 'on'
                   12696:                          );
                   12697:     my @toggles = ('uselcmath','usejsme');
1.160.6.21  raeburn  12698:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70  raeburn  12699:                    'uploadquota_community','uploadquota_textbook','mysqltables_official',
                   12700:                    'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30  raeburn  12701:     my @types = ('official','unofficial','community','textbook');
1.160.6.21  raeburn  12702:     my %staticdefaults = (
                   12703:                            anonsurvey_threshold => 10,
                   12704:                            uploadquota          => 500,
1.160.6.57  raeburn  12705:                            postsubmit           => 60,
1.160.6.70  raeburn  12706:                            mysqltables          => 172800,
1.160.6.21  raeburn  12707:                          );
1.121     raeburn  12708: 
                   12709:     $defaultshash{'coursedefaults'} = {};
                   12710: 
                   12711:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   12712:         if ($domconfig{'coursedefaults'} eq '') {
                   12713:             $domconfig{'coursedefaults'} = {};
                   12714:         }
                   12715:     }
                   12716: 
                   12717:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   12718:         foreach my $item (@toggles) {
                   12719:             if ($defaultchecked{$item} eq 'on') {
                   12720:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   12721:                     ($env{'form.'.$item} eq '0')) {
                   12722:                     $changes{$item} = 1;
1.160.6.16  raeburn  12723:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  12724:                     $changes{$item} = 1;
                   12725:                 }
                   12726:             } elsif ($defaultchecked{$item} eq 'off') {
                   12727:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   12728:                     ($env{'form.'.$item} eq '1')) {
                   12729:                     $changes{$item} = 1;
                   12730:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   12731:                     $changes{$item} = 1;
                   12732:                 }
                   12733:             }
                   12734:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   12735:         }
1.160.6.21  raeburn  12736:         foreach my $item (@numbers) {
                   12737:             my ($currdef,$newdef);
1.160.6.26  raeburn  12738:             $newdef = $env{'form.'.$item};
1.160.6.21  raeburn  12739:             if ($item eq 'anonsurvey_threshold') {
                   12740:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   12741:                 $newdef =~ s/\D//g;
                   12742:                 if ($newdef eq '' || $newdef < 1) {
                   12743:                     $newdef = 1;
                   12744:                 }
                   12745:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   12746:             } else {
1.160.6.70  raeburn  12747:                 my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
                   12748:                 if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
                   12749:                     $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21  raeburn  12750:                 }
                   12751:                 $newdef =~ s/[^\w.\-]//g;
1.160.6.70  raeburn  12752:                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21  raeburn  12753:             }
                   12754:             if ($currdef ne $newdef) {
                   12755:                 my $staticdef;
                   12756:                 if ($item eq 'anonsurvey_threshold') {
                   12757:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   12758:                         $changes{$item} = 1;
                   12759:                     }
1.160.6.70  raeburn  12760:                 } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
                   12761:                     my $setting = $1;
                   12762:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
                   12763:                         $changes{$setting} = 1;
1.160.6.21  raeburn  12764:                     }
                   12765:                 }
1.139     raeburn  12766:             }
                   12767:         }
1.160.6.64  raeburn  12768:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   12769:         my @currclonecode;
                   12770:         if (ref($currclone) eq 'HASH') {
                   12771:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   12772:                 @currclonecode = @{$currclone->{'instcode'}};
                   12773:             }
                   12774:         }
                   12775:         my $newclone;
                   12776:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
                   12777:             $newclone = $env{'form.canclone'};
                   12778:         }
                   12779:         if ($newclone eq 'instcode') {
                   12780:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   12781:             my (%codedefaults,@code_order,@clonecode);
                   12782:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   12783:                                                     \@code_order);
                   12784:             foreach my $item (@code_order) {
                   12785:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   12786:                     push(@clonecode,$item);
                   12787:                 }
                   12788:             }
                   12789:             if (@clonecode) {
                   12790:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   12791:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   12792:                 if (@diffs) {
                   12793:                     $changes{'canclone'} = 1;
                   12794:                 }
                   12795:             } else {
                   12796:                 $newclone eq '';
                   12797:             }
                   12798:         } elsif ($newclone ne '') {
                   12799:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
                   12800:         }
                   12801:         if ($newclone ne $currclone) {
                   12802:             $changes{'canclone'} = 1;
                   12803:         }
1.160.6.57  raeburn  12804:         my %credits;
                   12805:         foreach my $type (@types) {
                   12806:             unless ($type eq 'community') {
                   12807:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   12808:                 $credits{$type} =~ s/[^\d.]+//g;
                   12809:             }
                   12810:         }
                   12811:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   12812:             ($env{'form.coursecredits'} eq '1')) {
                   12813:             $changes{'coursecredits'} = 1;
                   12814:             foreach my $type (keys(%credits)) {
                   12815:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   12816:             }
                   12817:         } else {
                   12818:             if ($env{'form.coursecredits'} eq '1') {
                   12819:                 foreach my $type (@types) {
                   12820:                     unless ($type eq 'community') {
                   12821:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
                   12822:                             $changes{'coursecredits'} = 1;
                   12823:                         }
                   12824:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   12825:                     }
                   12826:                 }
                   12827:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   12828:                 foreach my $type (@types) {
                   12829:                     unless ($type eq 'community') {
                   12830:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   12831:                             $changes{'coursecredits'} = 1;
                   12832:                             last;
                   12833:                         }
                   12834:                     }
                   12835:                 }
                   12836:             }
                   12837:         }
                   12838:         if ($env{'form.postsubmit'} eq '1') {
                   12839:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   12840:             my %currtimeout;
                   12841:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12842:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   12843:                     $changes{'postsubmit'} = 1;
                   12844:                 }
                   12845:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12846:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   12847:                 }
                   12848:             } else {
                   12849:                 $changes{'postsubmit'} = 1;
                   12850:             }
                   12851:             foreach my $type (@types) {
                   12852:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   12853:                 $timeout =~ s/\D//g;
                   12854:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   12855:                     $timeout = '';
                   12856:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   12857:                     $timeout = '0';
                   12858:                 }
                   12859:                 unless ($timeout eq '') {
                   12860:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   12861:                 }
                   12862:                 if (exists($currtimeout{$type})) {
                   12863:                     if ($timeout ne $currtimeout{$type}) {
                   12864:                         $changes{'postsubmit'} = 1;
                   12865:                     }
                   12866:                 } elsif ($timeout ne '') {
                   12867:                     $changes{'postsubmit'} = 1;
                   12868:                 }
                   12869:             }
                   12870:         } else {
                   12871:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   12872:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12873:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   12874:                     $changes{'postsubmit'} = 1;
                   12875:                 }
                   12876:             } else {
                   12877:                 $changes{'postsubmit'} = 1;
                   12878:             }
1.160.6.16  raeburn  12879:         }
1.121     raeburn  12880:     }
                   12881:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12882:                                              $dom);
                   12883:     if ($putresult eq 'ok') {
                   12884:         if (keys(%changes) > 0) {
1.160.6.27  raeburn  12885:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57  raeburn  12886:             if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64  raeburn  12887:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.70  raeburn  12888:                 ($changes{'canclone'}) || ($changes{'mysqltables'})) {
1.160.6.57  raeburn  12889:                 foreach my $item ('uselcmath','usejsme') {
                   12890:                     if ($changes{$item}) {
                   12891:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   12892:                     }
1.160.6.16  raeburn  12893:                 }
                   12894:                 if ($changes{'coursecredits'}) {
                   12895:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57  raeburn  12896:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   12897:                             $domdefaults{$type.'credits'} =
                   12898:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   12899:                         }
                   12900:                     }
                   12901:                 }
                   12902:                 if ($changes{'postsubmit'}) {
                   12903:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12904:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   12905:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12906:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   12907:                                 $domdefaults{$type.'postsubtimeout'} =
                   12908:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   12909:                             }
                   12910:                         }
1.160.6.16  raeburn  12911:                     }
                   12912:                 }
1.160.6.21  raeburn  12913:                 if ($changes{'uploadquota'}) {
                   12914:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   12915:                         foreach my $type (@types) {
                   12916:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   12917:                         }
                   12918:                     }
                   12919:                 }
1.160.6.64  raeburn  12920:                 if ($changes{'canclone'}) {
                   12921:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   12922:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   12923:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   12924:                             if (@clonecodes) {
                   12925:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   12926:                             }
                   12927:                         }
                   12928:                     } else {
                   12929:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   12930:                     }
                   12931:                 }
1.121     raeburn  12932:                 my $cachetime = 24*60*60;
                   12933:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27  raeburn  12934:                 if (ref($lastactref) eq 'HASH') {
                   12935:                     $lastactref->{'domdefaults'} = 1;
                   12936:                 }
1.121     raeburn  12937:             }
                   12938:             $resulttext = &mt('Changes made:').'<ul>';
                   12939:             foreach my $item (sort(keys(%changes))) {
1.160.6.57  raeburn  12940:                 if ($item eq 'uselcmath') {
1.121     raeburn  12941:                     if ($env{'form.'.$item} eq '1') {
1.160.6.57  raeburn  12942:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121     raeburn  12943:                     } else {
1.160.6.57  raeburn  12944:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   12945:                     }
                   12946:                 } elsif ($item eq 'usejsme') {
                   12947:                     if ($env{'form.'.$item} eq '1') {
                   12948:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   12949:                     } else {
                   12950:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121     raeburn  12951:                     }
1.139     raeburn  12952:                 } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26  raeburn  12953:                     $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  12954:                 } elsif ($item eq 'uploadquota') {
                   12955:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   12956:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   12957:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   12958:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30  raeburn  12959:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
                   12960: 
1.160.6.21  raeburn  12961:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   12962:                                        '</ul>'.
                   12963:                                        '</li>';
                   12964:                     } else {
                   12965:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   12966:                     }
1.160.6.70  raeburn  12967:                 } elsif ($item eq 'mysqltables') {
                   12968:                     if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
                   12969:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
                   12970:                                        '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
                   12971:                                        '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
                   12972:                                        '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
                   12973:                                        '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
                   12974:                                        '</ul>'.
                   12975:                                        '</li>';
                   12976:                     } else {
                   12977:                         $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
                   12978:                     }
1.160.6.57  raeburn  12979:                 } elsif ($item eq 'postsubmit') {
                   12980:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   12981:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   12982:                     } else {
                   12983:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   12984:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   12985:                             $resulttext .= &mt('durations:').'<ul>';
                   12986:                             foreach my $type (@types) {
                   12987:                                 $resulttext .= '<li>';
                   12988:                                 my $timeout;
                   12989:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   12990:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   12991:                                 }
                   12992:                                 my $display;
                   12993:                                 if ($timeout eq '0') {
                   12994:                                     $display = &mt('unlimited');
                   12995:                                 } elsif ($timeout eq '') {
                   12996:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   12997:                                 } else {
                   12998:                                     $display = &mt('[quant,_1,second]',$timeout);
                   12999:                                 }
                   13000:                                 if ($type eq 'community') {
                   13001:                                     $resulttext .= &mt('Communities');
                   13002:                                 } elsif ($type eq 'official') {
                   13003:                                     $resulttext .= &mt('Official courses');
                   13004:                                 } elsif ($type eq 'unofficial') {
                   13005:                                     $resulttext .= &mt('Unofficial courses');
                   13006:                                 } elsif ($type eq 'textbook') {
                   13007:                                     $resulttext .= &mt('Textbook courses');
                   13008:                                 }
                   13009:                                 $resulttext .= ' -- '.$display.'</li>';
                   13010:                             }
                   13011:                             $resulttext .= '</ul>';
                   13012:                         }
                   13013:                         $resulttext .= '</li>';
                   13014:                     }
1.160.6.16  raeburn  13015:                 } elsif ($item eq 'coursecredits') {
                   13016:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   13017:                         if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30  raeburn  13018:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   13019:                             ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16  raeburn  13020:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   13021:                         } else {
                   13022:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   13023:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   13024:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30  raeburn  13025:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16  raeburn  13026:                                            '</ul>'.
                   13027:                                            '</li>';
                   13028:                         }
                   13029:                     } else {
                   13030:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   13031:                     }
1.160.6.64  raeburn  13032:                 } elsif ($item eq 'canclone') {
                   13033:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   13034:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   13035:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   13036:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   13037:                         }
                   13038:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   13039:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   13040:                     } else {
                   13041:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
                   13042:                     }
1.140     raeburn  13043:                 }
1.121     raeburn  13044:             }
                   13045:             $resulttext .= '</ul>';
                   13046:         } else {
                   13047:             $resulttext = &mt('No changes made to course defaults');
                   13048:         }
                   13049:     } else {
                   13050:         $resulttext = '<span class="LC_error">'.
                   13051:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13052:     }
                   13053:     return $resulttext;
                   13054: }
                   13055: 
1.160.6.37  raeburn  13056: sub modify_selfenrollment {
                   13057:     my ($dom,$lastactref,%domconfig) = @_;
                   13058:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
                   13059:     my @types = ('official','unofficial','community','textbook');
                   13060:     my %titles = &tool_titles();
                   13061:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   13062:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   13063:     $ordered{'default'} = ['types','registered','approval','limit'];
                   13064: 
                   13065:     my (%roles,%shown,%toplevel);
                   13066:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   13067: 
                   13068:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   13069:         if ($domconfig{'selfenrollment'} eq '') {
                   13070:             $domconfig{'selfenrollment'} = {};
                   13071:         }
                   13072:     }
                   13073:     %toplevel = (
                   13074:                   admin      => 'Configuration Rights',
                   13075:                   default    => 'Default settings',
                   13076:                   validation => 'Validation of self-enrollment requests',
                   13077:                 );
                   13078:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   13079: 
                   13080:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   13081:         foreach my $item (@{$ordered{'admin'}}) {
                   13082:             foreach my $type (@types) {
                   13083:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   13084:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   13085:                 } else {
                   13086:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   13087:                 }
                   13088:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   13089:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   13090:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   13091:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   13092:                             push(@{$changes{'admin'}{$type}},$item);
                   13093:                         }
                   13094:                     } else {
                   13095:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   13096:                             push(@{$changes{'admin'}{$type}},$item);
                   13097:                         }
                   13098:                     }
                   13099:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   13100:                     push(@{$changes{'admin'}{$type}},$item);
                   13101:                 }
                   13102:             }
                   13103:         }
                   13104:     }
                   13105: 
                   13106:     foreach my $item (@{$ordered{'default'}}) {
                   13107:         foreach my $type (@types) {
                   13108:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   13109:             if ($item eq 'types') {
                   13110:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   13111:                     $value = '';
                   13112:                 }
                   13113:             } elsif ($item eq 'registered') {
                   13114:                 unless ($value eq '1') {
                   13115:                     $value = 0;
                   13116:                 }
                   13117:             } elsif ($item eq 'approval') {
                   13118:                 unless ($value =~ /^[012]$/) {
                   13119:                     $value = 0;
                   13120:                 }
                   13121:             } else {
                   13122:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   13123:                     $value = 'none';
                   13124:                 }
                   13125:             }
                   13126:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   13127:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   13128:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   13129:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   13130:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   13131:                          push(@{$changes{'default'}{$type}},$item);
                   13132:                     }
                   13133:                 } else {
                   13134:                     push(@{$changes{'default'}{$type}},$item);
                   13135:                 }
                   13136:             } else {
                   13137:                 push(@{$changes{'default'}{$type}},$item);
                   13138:             }
                   13139:             if ($item eq 'limit') {
                   13140:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   13141:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   13142:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   13143:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   13144:                     }
                   13145:                 } else {
                   13146:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   13147:                 }
                   13148:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   13149:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   13150:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   13151:                          push(@{$changes{'default'}{$type}},'cap');
                   13152:                     }
                   13153:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   13154:                     push(@{$changes{'default'}{$type}},'cap');
                   13155:                 }
                   13156:             }
                   13157:         }
                   13158:     }
                   13159: 
                   13160:     foreach my $item (@{$itemsref}) {
                   13161:         if ($item eq 'fields') {
                   13162:             my @changed;
                   13163:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   13164:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   13165:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   13166:             }
                   13167:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   13168:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   13169:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   13170:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   13171:                 } else {
                   13172:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   13173:                 }
                   13174:             } else {
                   13175:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   13176:             }
                   13177:             if (@changed) {
                   13178:                 if ($selfenrollhash{'validation'}{$item}) { 
                   13179:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   13180:                 } else {
                   13181:                     $changes{'validation'}{$item} = &mt('None');
                   13182:                 }
                   13183:             }
                   13184:         } else {
                   13185:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   13186:             if ($item eq 'markup') {
                   13187:                if ($env{'form.selfenroll_validation_'.$item}) {
                   13188:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   13189:                }
                   13190:             }
                   13191:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   13192:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   13193:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   13194:                 }
                   13195:             }
                   13196:         }
                   13197:     }
                   13198: 
                   13199:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   13200:                                              $dom);
                   13201:     if ($putresult eq 'ok') {
                   13202:         if (keys(%changes) > 0) {
                   13203:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   13204:             $resulttext = &mt('Changes made:').'<ul>';
                   13205:             foreach my $key ('admin','default','validation') {
                   13206:                 if (ref($changes{$key}) eq 'HASH') {
                   13207:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   13208:                     if ($key eq 'validation') {
                   13209:                         foreach my $item (@{$itemsref}) {
                   13210:                             if (exists($changes{$key}{$item})) {
                   13211:                                 if ($item eq 'markup') {
                   13212:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   13213:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   13214:                                 } else {  
                   13215:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   13216:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   13217:                                 }
                   13218:                             }
                   13219:                         }
                   13220:                     } else {
                   13221:                         foreach my $type (@types) {
                   13222:                             if ($type eq 'community') {
                   13223:                                 $roles{'1'} = &mt('Community personnel');
                   13224:                             } else {
                   13225:                                 $roles{'1'} = &mt('Course personnel');
                   13226:                             }
                   13227:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
                   13228:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   13229:                                     if ($key eq 'admin') {
                   13230:                                         my @mgrdc = ();
                   13231:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   13232:                                             foreach my $item (@{$ordered{'admin'}}) {
                   13233:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   13234:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   13235:                                                         push(@mgrdc,$item);
                   13236:                                                     }
                   13237:                                                 }
                   13238:                                             }
                   13239:                                             if (@mgrdc) {
                   13240:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   13241:                                             } else {
                   13242:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   13243:                                             }
                   13244:                                         }
                   13245:                                     } else {
                   13246:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   13247:                                             foreach my $item (@{$ordered{$key}}) {
                   13248:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   13249:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   13250:                                                         $selfenrollhash{$key}{$type}{$item};
                   13251:                                                 }
                   13252:                                             }
                   13253:                                         }
                   13254:                                     }
                   13255:                                 }
                   13256:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   13257:                                 foreach my $item (@{$ordered{$key}}) {
                   13258:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   13259:                                         $resulttext .= '<li>';
                   13260:                                         if ($key eq 'admin') {
                   13261:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   13262:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   13263:                                         } else {
                   13264:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   13265:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   13266:                                         }
                   13267:                                         $resulttext .= '</li>';
                   13268:                                     }
                   13269:                                 }
                   13270:                                 $resulttext .= '</ul></li>';
                   13271:                             }
                   13272:                         }
                   13273:                         $resulttext .= '</ul></li>'; 
                   13274:                     }
                   13275:                 }
                   13276:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   13277:                     my $cachetime = 24*60*60;
                   13278:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   13279:                     if (ref($lastactref) eq 'HASH') {
                   13280:                         $lastactref->{'domdefaults'} = 1;
                   13281:                     }
                   13282:                 }
                   13283:             }
                   13284:             $resulttext .= '</ul>';
                   13285:         } else {
                   13286:             $resulttext = &mt('No changes made to self-enrollment settings');
                   13287:         }
                   13288:     } else {
                   13289:         $resulttext = '<span class="LC_error">'.
                   13290:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   13291:     }
                   13292:     return $resulttext;
                   13293: }
                   13294: 
1.137     raeburn  13295: sub modify_usersessions {
1.160.6.27  raeburn  13296:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  13297:     my @hostingtypes = ('version','excludedomain','includedomain');
                   13298:     my @offloadtypes = ('primary','default');
                   13299:     my %types = (
                   13300:                   remote => \@hostingtypes,
                   13301:                   hosted => \@hostingtypes,
                   13302:                   spares => \@offloadtypes,
                   13303:                 );
                   13304:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  13305:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  13306:     my (%by_ip,%by_location,@intdoms);
                   13307:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   13308:     my @locations = sort(keys(%by_location));
1.137     raeburn  13309:     my (%defaultshash,%changes);
                   13310:     foreach my $prefix (@prefixes) {
                   13311:         $defaultshash{'usersessions'}{$prefix} = {};
                   13312:     }
1.160.6.27  raeburn  13313:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  13314:     my $resulttext;
1.138     raeburn  13315:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  13316:     foreach my $prefix (@prefixes) {
1.145     raeburn  13317:         next if ($prefix eq 'spares');
                   13318:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  13319:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   13320:             if ($type eq 'version') {
                   13321:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   13322:                 my $okvalue;
                   13323:                 if ($value ne '') {
                   13324:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   13325:                         $okvalue = $value;
                   13326:                     }
                   13327:                 }
                   13328:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   13329:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   13330:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   13331:                             if ($inuse == 0) {
                   13332:                                 $changes{$prefix}{$type} = 1;
                   13333:                             } else {
                   13334:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   13335:                                     $changes{$prefix}{$type} = 1;
                   13336:                                 }
                   13337:                                 if ($okvalue ne '') {
                   13338:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   13339:                                 } 
                   13340:                             }
                   13341:                         } else {
                   13342:                             if (($inuse == 1) && ($okvalue ne '')) {
                   13343:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   13344:                                 $changes{$prefix}{$type} = 1;
                   13345:                             }
                   13346:                         }
                   13347:                     } else {
                   13348:                         if (($inuse == 1) && ($okvalue ne '')) {
                   13349:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   13350:                             $changes{$prefix}{$type} = 1;
                   13351:                         }
                   13352:                     }
                   13353:                 } else {
                   13354:                     if (($inuse == 1) && ($okvalue ne '')) {
                   13355:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   13356:                         $changes{$prefix}{$type} = 1;
                   13357:                     }
                   13358:                 }
                   13359:             } else {
                   13360:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   13361:                 my @okvals;
                   13362:                 foreach my $val (@vals) {
1.138     raeburn  13363:                     if ($val =~ /:/) {
                   13364:                         my @items = split(/:/,$val);
                   13365:                         foreach my $item (@items) {
                   13366:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   13367:                                 push(@okvals,$item);
                   13368:                             }
                   13369:                         }
                   13370:                     } else {
                   13371:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   13372:                             push(@okvals,$val);
                   13373:                         }
1.137     raeburn  13374:                     }
                   13375:                 }
                   13376:                 @okvals = sort(@okvals);
                   13377:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   13378:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   13379:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   13380:                             if ($inuse == 0) {
                   13381:                                 $changes{$prefix}{$type} = 1; 
                   13382:                             } else {
                   13383:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   13384:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   13385:                                 if (@changed > 0) {
                   13386:                                     $changes{$prefix}{$type} = 1;
                   13387:                                 }
                   13388:                             }
                   13389:                         } else {
                   13390:                             if ($inuse == 1) {
                   13391:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   13392:                                 $changes{$prefix}{$type} = 1;
                   13393:                             }
                   13394:                         } 
                   13395:                     } else {
                   13396:                         if ($inuse == 1) {
                   13397:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   13398:                             $changes{$prefix}{$type} = 1;
                   13399:                         }
                   13400:                     }
                   13401:                 } else {
                   13402:                     if ($inuse == 1) {
                   13403:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   13404:                         $changes{$prefix}{$type} = 1;
                   13405:                     }
                   13406:                 }
                   13407:             }
                   13408:         }
                   13409:     }
1.145     raeburn  13410: 
                   13411:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  13412:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  13413:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   13414:     my $savespares;
                   13415: 
                   13416:     foreach my $lonhost (sort(keys(%servers))) {
                   13417:         my $serverhomeID =
                   13418:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  13419:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  13420:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   13421:         my %spareschg;
                   13422:         foreach my $type (@{$types{'spares'}}) {
                   13423:             my @okspares;
                   13424:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   13425:             foreach my $server (@checked) {
1.152     raeburn  13426:                 if (&Apache::lonnet::hostname($server) ne '') {
                   13427:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   13428:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   13429:                             push(@okspares,$server);
                   13430:                         }
1.145     raeburn  13431:                     }
                   13432:                 }
                   13433:             }
                   13434:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   13435:             my $newspare;
1.152     raeburn  13436:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   13437:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  13438:                     $newspare = $new;
                   13439:                 }
                   13440:             }
1.152     raeburn  13441:             my @spares;
                   13442:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   13443:                 @spares = sort(@okspares,$newspare);
                   13444:             } else {
                   13445:                 @spares = sort(@okspares);
                   13446:             }
                   13447:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  13448:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   13449:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  13450:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  13451:                     if (@diffs > 0) {
                   13452:                         $spareschg{$type} = 1;
                   13453:                     }
                   13454:                 }
                   13455:             }
                   13456:         }
                   13457:         if (keys(%spareschg) > 0) {
                   13458:             $changes{'spares'}{$lonhost} = \%spareschg;
                   13459:         }
                   13460:     }
1.160.6.61  raeburn  13461:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   13462:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   13463:     my @okoffload;
                   13464:     if (@offloadnow) {
                   13465:         foreach my $server (@offloadnow) {
                   13466:             if (&Apache::lonnet::hostname($server) ne '') {
                   13467:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   13468:                     push(@okoffload,$server);
                   13469:                 }
                   13470:             }
                   13471:         }
                   13472:         if (@okoffload) {
                   13473:             foreach my $lonhost (@okoffload) {
                   13474:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   13475:             }
                   13476:         }
                   13477:     }
1.145     raeburn  13478:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   13479:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   13480:             if (ref($changes{'spares'}) eq 'HASH') {
                   13481:                 if (keys(%{$changes{'spares'}}) > 0) {
                   13482:                     $savespares = 1;
                   13483:                 }
                   13484:             }
                   13485:         } else {
                   13486:             $savespares = 1;
                   13487:         }
1.160.6.61  raeburn  13488:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   13489:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   13490:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   13491:                     $changes{'offloadnow'} = 1;
                   13492:                     last;
                   13493:                 }
                   13494:             }
                   13495:             unless ($changes{'offloadnow'}) {
                   13496:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) {
                   13497:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   13498:                         $changes{'offloadnow'} = 1;
                   13499:                         last;
                   13500:                     }
                   13501:                 }
                   13502:             }
                   13503:         } elsif (@okoffload) {
                   13504:             $changes{'offloadnow'} = 1;
                   13505:         }
                   13506:     } elsif (@okoffload) {
                   13507:         $changes{'offloadnow'} = 1;
1.145     raeburn  13508:     }
1.147     raeburn  13509:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   13510:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  13511:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   13512:                                                  $dom);
                   13513:         if ($putresult eq 'ok') {
                   13514:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   13515:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   13516:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   13517:                 }
                   13518:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   13519:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   13520:                 }
1.160.6.61  raeburn  13521:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   13522:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   13523:                 }
1.137     raeburn  13524:             }
                   13525:             my $cachetime = 24*60*60;
                   13526:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81  raeburn  13527:             &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27  raeburn  13528:             if (ref($lastactref) eq 'HASH') {
                   13529:                 $lastactref->{'domdefaults'} = 1;
1.160.6.81  raeburn  13530:                 $lastactref->{'usersessions'} = 1;
1.160.6.27  raeburn  13531:             }
1.147     raeburn  13532:             if (keys(%changes) > 0) {
                   13533:                 my %lt = &usersession_titles();
                   13534:                 $resulttext = &mt('Changes made:').'<ul>';
                   13535:                 foreach my $prefix (@prefixes) {
                   13536:                     if (ref($changes{$prefix}) eq 'HASH') {
                   13537:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   13538:                         if ($prefix eq 'spares') {
                   13539:                             if (ref($changes{$prefix}) eq 'HASH') {
                   13540:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   13541:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  13542:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27  raeburn  13543:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   13544:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  13545:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   13546:                                         foreach my $type (@{$types{$prefix}}) {
                   13547:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   13548:                                                 my $offloadto = &mt('None');
                   13549:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   13550:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   13551:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   13552:                                                     }
1.145     raeburn  13553:                                                 }
1.147     raeburn  13554:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  13555:                                             }
1.137     raeburn  13556:                                         }
                   13557:                                     }
1.147     raeburn  13558:                                     $resulttext .= '</li>';
1.137     raeburn  13559:                                 }
                   13560:                             }
1.147     raeburn  13561:                         } else {
                   13562:                             foreach my $type (@{$types{$prefix}}) {
                   13563:                                 if (defined($changes{$prefix}{$type})) {
                   13564:                                     my $newvalue;
                   13565:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   13566:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   13567:                                             if ($type eq 'version') {
                   13568:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   13569:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   13570:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   13571:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   13572:                                                 }
1.145     raeburn  13573:                                             }
                   13574:                                         }
                   13575:                                     }
1.147     raeburn  13576:                                     if ($newvalue eq '') {
                   13577:                                         if ($type eq 'version') {
                   13578:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   13579:                                         } else {
                   13580:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   13581:                                         }
1.145     raeburn  13582:                                     } else {
1.147     raeburn  13583:                                         if ($type eq 'version') {
                   13584:                                             $newvalue .= ' '.&mt('(or later)'); 
                   13585:                                         }
                   13586:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  13587:                                     }
1.137     raeburn  13588:                                 }
                   13589:                             }
                   13590:                         }
1.147     raeburn  13591:                         $resulttext .= '</ul>';
1.137     raeburn  13592:                     }
                   13593:                 }
1.160.6.61  raeburn  13594:                 if ($changes{'offloadnow'}) {
                   13595:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   13596:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   13597:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   13598:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   13599:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   13600:                             }
                   13601:                             $resulttext .= '</ul>';
                   13602:                         } else {
                   13603:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   13604:                         }
                   13605:                     } else {
                   13606:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   13607:                     }
                   13608:                 }
1.147     raeburn  13609:                 $resulttext .= '</ul>';
                   13610:             } else {
                   13611:                 $resulttext = $nochgmsg;
1.137     raeburn  13612:             }
                   13613:         } else {
                   13614:             $resulttext = '<span class="LC_error">'.
                   13615:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   13616:         }
                   13617:     } else {
1.147     raeburn  13618:         $resulttext = $nochgmsg;
1.137     raeburn  13619:     }
                   13620:     return $resulttext;
                   13621: }
                   13622: 
1.150     raeburn  13623: sub modify_loadbalancing {
                   13624:     my ($dom,%domconfig) = @_;
                   13625:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   13626:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   13627:     my ($othertitle,$usertypes,$types) =
                   13628:         &Apache::loncommon::sorted_inst_types($dom);
                   13629:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55  raeburn  13630:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  13631:     my @sparestypes = ('primary','default');
                   13632:     my %typetitles = &sparestype_titles();
                   13633:     my $resulttext;
1.160.6.7  raeburn  13634:     my (%currbalancer,%currtargets,%currrules,%existing);
                   13635:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   13636:         %existing = %{$domconfig{'loadbalancing'}};
                   13637:     }
                   13638:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   13639:                               \%currtargets,\%currrules);
                   13640:     my ($saveloadbalancing,%defaultshash,%changes);
                   13641:     my ($alltypes,$othertypes,$titles) =
                   13642:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   13643:     my %ruletitles = &offloadtype_text();
                   13644:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   13645:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   13646:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   13647:         if ($balancer eq '') {
                   13648:             next;
                   13649:         }
                   13650:         if (!exists($servers{$balancer})) {
                   13651:             if (exists($currbalancer{$balancer})) {
                   13652:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  13653:             }
1.160.6.7  raeburn  13654:             next;
                   13655:         }
                   13656:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   13657:             push(@{$changes{'delete'}},$balancer);
                   13658:             next;
                   13659:         }
                   13660:         if (!exists($currbalancer{$balancer})) {
                   13661:             push(@{$changes{'add'}},$balancer);
                   13662:         }
                   13663:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   13664:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   13665:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   13666:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   13667:             $saveloadbalancing = 1;
                   13668:         }
                   13669:         foreach my $sparetype (@sparestypes) {
                   13670:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   13671:             my @offloadto;
                   13672:             foreach my $target (@targets) {
                   13673:                 if (($servers{$target}) && ($target ne $balancer)) {
                   13674:                     if ($sparetype eq 'default') {
                   13675:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   13676:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  13677:                         }
                   13678:                     }
1.160.6.7  raeburn  13679:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   13680:                         push(@offloadto,$target);
                   13681:                     }
1.150     raeburn  13682:                 }
                   13683:             }
1.160.6.76  raeburn  13684:             if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
                   13685:                 unless(grep(/^\Q$balancer\E$/,@offloadto)) {
                   13686:                     push(@offloadto,$balancer);
                   13687:                 }
                   13688:             }
                   13689:             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  13690:         }
1.160.6.7  raeburn  13691:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  13692:             foreach my $sparetype (@sparestypes) {
1.160.6.7  raeburn  13693:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   13694:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  13695:                     if (@targetdiffs > 0) {
1.160.6.7  raeburn  13696:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  13697:                     }
1.160.6.7  raeburn  13698:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13699:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13700:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  13701:                     }
                   13702:                 }
                   13703:             }
                   13704:         } else {
1.160.6.7  raeburn  13705:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
                   13706:                 foreach my $sparetype (@sparestypes) {
                   13707:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13708:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13709:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   13710:                         }
1.150     raeburn  13711:                     }
                   13712:                 }
1.160.6.7  raeburn  13713:             }
1.150     raeburn  13714:         }
                   13715:         my $ishomedom;
1.160.6.7  raeburn  13716:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   13717:             $ishomedom = 1;
1.150     raeburn  13718:         }
                   13719:         if (ref($alltypes) eq 'ARRAY') {
                   13720:             foreach my $type (@{$alltypes}) {
                   13721:                 my $rule;
1.160.6.7  raeburn  13722:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  13723:                          (!$ishomedom)) {
1.160.6.7  raeburn  13724:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   13725:                 }
                   13726:                 if ($rule eq 'specific') {
1.160.6.55  raeburn  13727:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   13728:                     if (exists($servers{$specifiedhost})) {
                   13729:                         $rule = $specifiedhost;
                   13730:                     }
1.150     raeburn  13731:                 }
1.160.6.7  raeburn  13732:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   13733:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   13734:                     if ($rule ne $currrules{$balancer}{$type}) {
                   13735:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  13736:                     }
                   13737:                 } elsif ($rule ne '') {
1.160.6.7  raeburn  13738:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  13739:                 }
                   13740:             }
                   13741:         }
1.160.6.7  raeburn  13742:     }
                   13743:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   13744:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   13745:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   13746:             $defaultshash{'loadbalancing'} = {};
                   13747:         }
                   13748:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   13749:                                                  \%defaultshash,$dom);
                   13750:         if ($putresult eq 'ok') {
                   13751:             if (keys(%changes) > 0) {
1.160.6.54  raeburn  13752:                 my %toupdate;
1.160.6.7  raeburn  13753:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   13754:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   13755:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54  raeburn  13756:                         $toupdate{$balancer} = 1;
1.150     raeburn  13757:                     }
1.160.6.7  raeburn  13758:                 }
                   13759:                 if (ref($changes{'add'}) eq 'ARRAY') {
                   13760:                     foreach my $balancer (sort(@{$changes{'add'}})) {
                   13761:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54  raeburn  13762:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  13763:                     }
                   13764:                 }
                   13765:                 if (ref($changes{'curr'}) eq 'HASH') {
                   13766:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55  raeburn  13767:                         $toupdate{$balancer} = 1;
1.160.6.7  raeburn  13768:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   13769:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   13770:                                 my %offloadstr;
                   13771:                                 foreach my $sparetype (@sparestypes) {
                   13772:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13773:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   13774:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   13775:                                         }
                   13776:                                     }
1.150     raeburn  13777:                                 }
1.160.6.7  raeburn  13778:                                 if (keys(%offloadstr) == 0) {
                   13779:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  13780:                                 } else {
1.160.6.7  raeburn  13781:                                     my $showoffload;
                   13782:                                     foreach my $sparetype (@sparestypes) {
                   13783:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   13784:                                         if (defined($offloadstr{$sparetype})) {
                   13785:                                             $showoffload .= $offloadstr{$sparetype};
                   13786:                                         } else {
                   13787:                                             $showoffload .= &mt('None');
                   13788:                                         }
                   13789:                                         $showoffload .= ('&nbsp;'x3);
                   13790:                                     }
                   13791:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  13792:                                 }
                   13793:                             }
                   13794:                         }
1.160.6.7  raeburn  13795:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   13796:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   13797:                                 foreach my $type (@{$alltypes}) {
                   13798:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   13799:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   13800:                                         my $balancetext;
                   13801:                                         if ($rule eq '') {
                   13802:                                             $balancetext =  $ruletitles{'default'};
1.160.6.26  raeburn  13803:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55  raeburn  13804:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
                   13805:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54  raeburn  13806:                                                 foreach my $sparetype (@sparestypes) {
                   13807:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   13808:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   13809:                                                     }
                   13810:                                                 }
1.160.6.55  raeburn  13811:                                                 foreach my $item (@{$alltypes}) {
                   13812:                                                     next if ($item =~  /^_LC_ipchange/);
                   13813:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   13814:                                                     if ($hasrule eq 'homeserver') {
                   13815:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   13816:                                                     } else {
                   13817:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   13818:                                                             if ($servers{$hasrule}) {
                   13819:                                                                 $toupdate{$hasrule} = 1;
                   13820:                                                             }
                   13821:                                                         }
                   13822:                                                     }
                   13823:                                                 }
                   13824:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   13825:                                                     $balancetext =  $ruletitles{$rule};
                   13826:                                                 } else {
                   13827:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   13828:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   13829:                                                     if ($receiver) {
                   13830:                                                         $toupdate{$receiver};
                   13831:                                                     }
                   13832:                                                 }
                   13833:                                             } else {
                   13834:                                                 $balancetext =  $ruletitles{$rule};
1.160.6.54  raeburn  13835:                                             }
1.160.6.7  raeburn  13836:                                         } else {
                   13837:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   13838:                                         }
1.160.6.26  raeburn  13839:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  13840:                                     }
                   13841:                                 }
                   13842:                             }
                   13843:                         }
1.160.6.54  raeburn  13844:                         if (keys(%toupdate)) {
                   13845:                             my %thismachine;
                   13846:                             my $updatedhere;
                   13847:                             my $cachetime = 60*60*24;
                   13848:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   13849:                             foreach my $lonhost (keys(%toupdate)) {
                   13850:                                 if ($thismachine{$lonhost}) {
                   13851:                                     unless ($updatedhere) {
                   13852:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   13853:                                                                       $defaultshash{'loadbalancing'},
                   13854:                                                                       $cachetime);
                   13855:                                         $updatedhere = 1;
                   13856:                                     }
                   13857:                                 } else {
                   13858:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   13859:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   13860:                                 }
                   13861:                             }
                   13862:                         }
1.150     raeburn  13863:                     }
1.160.6.7  raeburn  13864:                 }
                   13865:                 if ($resulttext ne '') {
                   13866:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  13867:                 } else {
                   13868:                     $resulttext = $nochgmsg;
                   13869:                 }
                   13870:             } else {
1.160.6.7  raeburn  13871:                 $resulttext = $nochgmsg;
1.150     raeburn  13872:             }
                   13873:         } else {
1.160.6.7  raeburn  13874:             $resulttext = '<span class="LC_error">'.
                   13875:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  13876:         }
                   13877:     } else {
1.160.6.7  raeburn  13878:         $resulttext = $nochgmsg;
1.150     raeburn  13879:     }
                   13880:     return $resulttext;
                   13881: }
                   13882: 
1.48      raeburn  13883: sub recurse_check {
                   13884:     my ($chkcats,$categories,$depth,$name) = @_;
                   13885:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   13886:         my $chg = 0;
                   13887:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   13888:             my $category = $chkcats->[$depth]{$name}[$j];
                   13889:             my $item;
                   13890:             if ($category eq '') {
                   13891:                 $chg ++;
                   13892:             } else {
                   13893:                 my $deeper = $depth + 1;
                   13894:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   13895:                 if ($chg) {
                   13896:                     $categories->{$item} -= $chg;
                   13897:                 }
                   13898:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   13899:                 $deeper --;
                   13900:             }
                   13901:         }
                   13902:     }
                   13903:     return;
                   13904: }
                   13905: 
                   13906: sub recurse_cat_deletes {
                   13907:     my ($item,$coursecategories,$deletions) = @_;
                   13908:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   13909:     my $subdepth = $depth + 1;
                   13910:     if (ref($coursecategories) eq 'HASH') {
                   13911:         foreach my $subitem (keys(%{$coursecategories})) {
                   13912:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   13913:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   13914:                 delete($coursecategories->{$subitem});
                   13915:                 $deletions->{$subitem} = 1;
                   13916:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26  raeburn  13917:             }
1.48      raeburn  13918:         }
                   13919:     }
                   13920:     return;
                   13921: }
                   13922: 
1.125     raeburn  13923: sub active_dc_picker {
1.160.6.16  raeburn  13924:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77  raeburn  13925:     my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16  raeburn  13926:     my @domcoord = keys(%domcoords);
                   13927:     if (keys(%currhash)) {
                   13928:         foreach my $dc (keys(%currhash)) {
                   13929:             unless (exists($domcoords{$dc})) {
                   13930:                 push(@domcoord,$dc);
                   13931:             }
                   13932:         }
                   13933:     }
                   13934:     @domcoord = sort(@domcoord);
                   13935:     my $numdcs = scalar(@domcoord);
                   13936:     my $rows = 0;
                   13937:     my $table;
1.125     raeburn  13938:     if ($numdcs > 1) {
1.160.6.16  raeburn  13939:         $table = '<table>';
                   13940:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  13941:             my $rem = $i%($numinrow);
                   13942:             if ($rem == 0) {
                   13943:                 if ($i > 0) {
1.160.6.16  raeburn  13944:                     $table .= '</tr>';
1.125     raeburn  13945:                 }
1.160.6.16  raeburn  13946:                 $table .= '<tr>';
                   13947:                 $rows ++;
1.125     raeburn  13948:             }
1.160.6.16  raeburn  13949:             my $check = '';
                   13950:             if ($inputtype eq 'radio') {
                   13951:                 if (keys(%currhash) == 0) {
                   13952:                     if (!$i) {
                   13953:                         $check = ' checked="checked"';
                   13954:                     }
                   13955:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   13956:                     $check = ' checked="checked"';
                   13957:                 }
                   13958:             } else {
                   13959:                 if (exists($currhash{$domcoord[$i]})) {
                   13960:                     $check = ' checked="checked"';
1.125     raeburn  13961:                 }
                   13962:             }
1.160.6.16  raeburn  13963:             if ($i == @domcoord - 1) {
1.125     raeburn  13964:                 my $colsleft = $numinrow - $rem;
                   13965:                 if ($colsleft > 1) {
1.160.6.16  raeburn  13966:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  13967:                 } else {
1.160.6.16  raeburn  13968:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  13969:                 }
                   13970:             } else {
1.160.6.16  raeburn  13971:                 $table .= '<td class="LC_left_item">';
                   13972:             }
                   13973:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   13974:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   13975:             $table .= '<span class="LC_nobreak"><label>'.
                   13976:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   13977:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   13978:             if ($user ne $dcname.':'.$dcdom) {
1.160.6.32  raeburn  13979:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.125     raeburn  13980:             }
1.160.6.33  raeburn  13981:             $table .= '</label></span></td>';
1.125     raeburn  13982:         }
1.160.6.16  raeburn  13983:         $table .= '</tr></table>';
                   13984:     } elsif ($numdcs == 1) {
1.160.6.32  raeburn  13985:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   13986:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16  raeburn  13987:         if ($inputtype eq 'radio') {
1.160.6.50  raeburn  13988:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31  raeburn  13989:             if ($user ne $dcname.':'.$dcdom) {
                   13990:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   13991:             }
1.160.6.16  raeburn  13992:         } else {
                   13993:             my $check;
                   13994:             if (exists($currhash{$domcoord[0]})) {
                   13995:                 $check = ' checked="checked"';
                   13996:             }
1.160.6.50  raeburn  13997:             $table = '<span class="LC_nobreak"><label>'.
                   13998:                      '<input type="checkbox" name="'.$name.'" '.
                   13999:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31  raeburn  14000:             if ($user ne $dcname.':'.$dcdom) {
                   14001:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   14002:             }
                   14003:             $table .= '</label></span>';
1.160.6.16  raeburn  14004:             $rows ++;
                   14005:         }
1.125     raeburn  14006:     }
1.160.6.16  raeburn  14007:     return ($numdcs,$table,$rows);
1.125     raeburn  14008: }
                   14009: 
1.137     raeburn  14010: sub usersession_titles {
                   14011:     return &Apache::lonlocal::texthash(
                   14012:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   14013:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  14014:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  14015:                version => 'LON-CAPA version requirement',
1.138     raeburn  14016:                excludedomain => 'Allow all, but exclude specific domains',
                   14017:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  14018:                primary => 'Primary (checked first)',
1.154     raeburn  14019:                default => 'Default',
1.137     raeburn  14020:            );
                   14021: }
                   14022: 
1.152     raeburn  14023: sub id_for_thisdom {
                   14024:     my (%servers) = @_;
                   14025:     my %altids;
                   14026:     foreach my $server (keys(%servers)) {
                   14027:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   14028:         if ($serverhome ne $server) {
                   14029:             $altids{$serverhome} = $server;
                   14030:         }
                   14031:     }
                   14032:     return %altids;
                   14033: }
                   14034: 
1.150     raeburn  14035: sub count_servers {
                   14036:     my ($currbalancer,%servers) = @_;
                   14037:     my (@spares,$numspares);
                   14038:     foreach my $lonhost (sort(keys(%servers))) {
                   14039:         next if ($currbalancer eq $lonhost);
                   14040:         push(@spares,$lonhost);
                   14041:     }
                   14042:     if ($currbalancer) {
                   14043:         $numspares = scalar(@spares);
                   14044:     } else {
                   14045:         $numspares = scalar(@spares) - 1;
                   14046:     }
                   14047:     return ($numspares,@spares);
                   14048: }
                   14049: 
                   14050: sub lonbalance_targets_js {
1.160.6.7  raeburn  14051:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  14052:     my $select = &mt('Select');
                   14053:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   14054:     if (ref($servers) eq 'HASH') {
                   14055:         $alltargets = join("','",sort(keys(%{$servers})));
                   14056:         my @homedoms;
                   14057:         foreach my $server (sort(keys(%{$servers}))) {
                   14058:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   14059:                 push(@homedoms,'1');
                   14060:             } else {
                   14061:                 push(@homedoms,'0');
                   14062:             }
                   14063:         }
                   14064:         $allishome = join("','",@homedoms);
                   14065:     }
                   14066:     if (ref($types) eq 'ARRAY') {
                   14067:         if (@{$types} > 0) {
                   14068:             @alltypes = @{$types};
                   14069:         }
                   14070:     }
                   14071:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   14072:     $allinsttypes = join("','",@alltypes);
1.160.6.7  raeburn  14073:     my (%currbalancer,%currtargets,%currrules,%existing);
                   14074:     if (ref($settings) eq 'HASH') {
                   14075:         %existing = %{$settings};
                   14076:     }
                   14077:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   14078:                               \%currtargets,\%currrules);
                   14079:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  14080:     return <<"END";
                   14081: 
                   14082: <script type="text/javascript">
                   14083: // <![CDATA[
                   14084: 
1.160.6.7  raeburn  14085: currBalancers = new Array('$balancers');
                   14086: 
                   14087: function toggleTargets(balnum) {
                   14088:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   14089:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   14090:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   14091:     var prevbalancer = prevhostitem.value;
                   14092:     var baltotal = document.getElementById('loadbalancing_total').value;
                   14093:     prevhostitem.value = balancer;
                   14094:     if (prevbalancer != '') {
                   14095:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   14096:         if (prevIdx != -1) {
                   14097:             currBalancers.splice(prevIdx,1);
                   14098:         }
                   14099:     }
1.150     raeburn  14100:     if (balancer == '') {
1.160.6.7  raeburn  14101:         hideSpares(balnum);
1.150     raeburn  14102:     } else {
1.160.6.7  raeburn  14103:         var currIdx = currBalancers.indexOf(balancer);
                   14104:         if (currIdx == -1) {
                   14105:             currBalancers.push(balancer);
                   14106:         }
1.150     raeburn  14107:         var homedoms = new Array('$allishome');
1.160.6.7  raeburn  14108:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   14109:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  14110:     }
1.160.6.7  raeburn  14111:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  14112:     return;
                   14113: }
                   14114: 
1.160.6.7  raeburn  14115: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  14116:     var alltargets = new Array('$alltargets');
                   14117:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  14118:     var offloadtypes = new Array('primary','default');
                   14119: 
1.160.6.7  raeburn  14120:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   14121:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  14122:  
1.151     raeburn  14123:     for (var i=0; i<offloadtypes.length; i++) {
                   14124:         var count = 0;
                   14125:         for (var j=0; j<alltargets.length; j++) {
                   14126:             if (alltargets[j] != balancer) {
1.160.6.7  raeburn  14127:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   14128:                 item.value = alltargets[j];
                   14129:                 item.style.textAlign='left';
                   14130:                 item.style.textFace='normal';
                   14131:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   14132:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   14133:                     item.disabled = '';
                   14134:                 } else {
                   14135:                     item.disabled = 'disabled';
                   14136:                     item.checked = false;
                   14137:                 }
1.151     raeburn  14138:                 count ++;
                   14139:             }
1.150     raeburn  14140:         }
                   14141:     }
1.151     raeburn  14142:     for (var k=0; k<insttypes.length; k++) {
                   14143:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  14144:             if (ishomedom == 1) {
1.160.6.7  raeburn  14145:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   14146:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  14147:             } else {
1.160.6.7  raeburn  14148:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   14149:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  14150:             }
                   14151:         } else {
1.160.6.7  raeburn  14152:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   14153:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  14154:         }
1.151     raeburn  14155:         if ((insttypes[k] != '_LC_external') && 
                   14156:             ((insttypes[k] != '_LC_internetdom') ||
                   14157:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7  raeburn  14158:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   14159:             item.options.length = 0;
                   14160:             item.options[0] = new Option("","",true,true);
                   14161:             var idx = 0;
1.151     raeburn  14162:             for (var m=0; m<alltargets.length; m++) {
1.160.6.7  raeburn  14163:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   14164:                     idx ++;
                   14165:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  14166:                 }
                   14167:             }
                   14168:         }
                   14169:     }
                   14170:     return;
                   14171: }
                   14172: 
1.160.6.7  raeburn  14173: function hideSpares(balnum) {
1.150     raeburn  14174:     var alltargets = new Array('$alltargets');
                   14175:     var insttypes = new Array('$allinsttypes');
                   14176:     var offloadtypes = new Array('primary','default');
                   14177: 
1.160.6.7  raeburn  14178:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   14179:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  14180: 
                   14181:     var total = alltargets.length - 1;
                   14182:     for (var i=0; i<offloadtypes; i++) {
                   14183:         for (var j=0; j<total; j++) {
1.160.6.7  raeburn  14184:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   14185:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   14186:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  14187:         }
1.150     raeburn  14188:     }
                   14189:     for (var k=0; k<insttypes.length; k++) {
1.160.6.7  raeburn  14190:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   14191:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  14192:         if (insttypes[k] != '_LC_external') {
1.160.6.7  raeburn  14193:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   14194:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  14195:         }
                   14196:     }
                   14197:     return;
                   14198: }
                   14199: 
1.160.6.7  raeburn  14200: function checkOffloads(item,balnum,type) {
1.150     raeburn  14201:     var alltargets = new Array('$alltargets');
                   14202:     var offloadtypes = new Array('primary','default');
                   14203:     if (item.checked) {
                   14204:         var total = alltargets.length - 1;
                   14205:         var other;
                   14206:         if (type == offloadtypes[0]) {
1.151     raeburn  14207:             other = offloadtypes[1];
1.150     raeburn  14208:         } else {
1.151     raeburn  14209:             other = offloadtypes[0];
1.150     raeburn  14210:         }
                   14211:         for (var i=0; i<total; i++) {
1.160.6.7  raeburn  14212:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  14213:             if (server == item.value) {
1.160.6.7  raeburn  14214:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   14215:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  14216:                 }
                   14217:             }
                   14218:         }
                   14219:     }
                   14220:     return;
                   14221: }
                   14222: 
1.160.6.7  raeburn  14223: function singleServerToggle(balnum,type) {
                   14224:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  14225:     if (offloadtoSelIdx == 0) {
1.160.6.7  raeburn  14226:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   14227:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  14228: 
                   14229:     } else {
1.160.6.7  raeburn  14230:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   14231:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  14232:     }
                   14233:     return;
                   14234: }
                   14235: 
1.160.6.7  raeburn  14236: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  14237:     if (type == '_LC_external') {
1.160.6.26  raeburn  14238:         return;
1.150     raeburn  14239:     }
1.160.6.7  raeburn  14240:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  14241:     for (var i=0; i<typesRules.length; i++) {
                   14242:         if (formname.elements[typesRules[i]].checked) {
                   14243:             if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7  raeburn  14244:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   14245:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  14246:             } else {
1.160.6.7  raeburn  14247:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   14248:             }
                   14249:         }
                   14250:     }
                   14251:     return;
                   14252: }
                   14253: 
                   14254: function balancerDeleteChange(balnum) {
                   14255:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   14256:     var baltotal = document.getElementById('loadbalancing_total').value;
                   14257:     var addtarget;
                   14258:     var removetarget;
                   14259:     var action = 'delete';
                   14260:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   14261:         var lonhost = hostitem.value;
                   14262:         var currIdx = currBalancers.indexOf(lonhost);
                   14263:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   14264:             if (currIdx != -1) {
                   14265:                 currBalancers.splice(currIdx,1);
                   14266:             }
                   14267:             addtarget = lonhost;
                   14268:         } else {
                   14269:             if (currIdx == -1) {
                   14270:                 currBalancers.push(lonhost);
                   14271:             }
                   14272:             removetarget = lonhost;
                   14273:             action = 'undelete';
                   14274:         }
                   14275:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   14276:     }
                   14277:     return;
                   14278: }
                   14279: 
                   14280: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   14281:     if (baltotal > 1) {
                   14282:         var offloadtypes = new Array('primary','default');
                   14283:         var alltargets = new Array('$alltargets');
                   14284:         var insttypes = new Array('$allinsttypes');
                   14285:         for (var i=0; i<baltotal; i++) {
                   14286:             if (i != balnum) {
                   14287:                 for (var j=0; j<offloadtypes.length; j++) {
                   14288:                     var total = alltargets.length - 1;
                   14289:                     for (var k=0; k<total; k++) {
                   14290:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   14291:                         var server = serveritem.value;
                   14292:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   14293:                             if (server == addtarget) {
                   14294:                                 serveritem.disabled = '';
                   14295:                             }
                   14296:                         }
                   14297:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   14298:                             if (server == removetarget) {
                   14299:                                 serveritem.disabled = 'disabled';
                   14300:                                 serveritem.checked = false;
                   14301:                             }
                   14302:                         }
                   14303:                     }
                   14304:                 }
                   14305:                 for (var j=0; j<insttypes.length; j++) {
                   14306:                     if (insttypes[j] != '_LC_external') {
                   14307:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   14308:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   14309:                             var currSel = singleserver.selectedIndex;
                   14310:                             var currVal = singleserver.options[currSel].value;
                   14311:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   14312:                                 var numoptions = singleserver.options.length;
                   14313:                                 var needsnew = 1;
                   14314:                                 for (var k=0; k<numoptions; k++) {
                   14315:                                     if (singleserver.options[k] == addtarget) {
                   14316:                                         needsnew = 0;
                   14317:                                         break;
                   14318:                                     }
                   14319:                                 }
                   14320:                                 if (needsnew == 1) {
                   14321:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   14322:                                 }
                   14323:                             }
                   14324:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   14325:                                 singleserver.options.length = 0;
                   14326:                                 if ((currVal) && (currVal != removetarget)) {
                   14327:                                     singleserver.options[0] = new Option("","",false,false);
                   14328:                                 } else {
                   14329:                                     singleserver.options[0] = new Option("","",true,true);
                   14330:                                 }
                   14331:                                 var idx = 0;
                   14332:                                 for (var m=0; m<alltargets.length; m++) {
                   14333:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   14334:                                         idx ++;
                   14335:                                         if (currVal == alltargets[m]) {
                   14336:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   14337:                                         } else {
                   14338:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   14339:                                         }
                   14340:                                     }
                   14341:                                 }
                   14342:                             }
                   14343:                         }
                   14344:                     }
                   14345:                 }
1.150     raeburn  14346:             }
                   14347:         }
                   14348:     }
                   14349:     return;
                   14350: }
                   14351: 
1.152     raeburn  14352: // ]]>
                   14353: </script>
                   14354: 
                   14355: END
                   14356: }
                   14357: 
                   14358: sub new_spares_js {
                   14359:     my @sparestypes = ('primary','default');
                   14360:     my $types = join("','",@sparestypes);
                   14361:     my $select = &mt('Select');
                   14362:     return <<"END";
                   14363: 
                   14364: <script type="text/javascript">
                   14365: // <![CDATA[
                   14366: 
                   14367: function updateNewSpares(formname,lonhost) {
                   14368:     var types = new Array('$types');
                   14369:     var include = new Array();
                   14370:     var exclude = new Array();
                   14371:     for (var i=0; i<types.length; i++) {
                   14372:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   14373:         for (var j=0; j<spareboxes.length; j++) {
                   14374:             if (formname.elements[spareboxes[j]].checked) {
                   14375:                 exclude.push(formname.elements[spareboxes[j]].value);
                   14376:             } else {
                   14377:                 include.push(formname.elements[spareboxes[j]].value);
                   14378:             }
                   14379:         }
                   14380:     }
                   14381:     for (var i=0; i<types.length; i++) {
                   14382:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   14383:         var selIdx = newSpare.selectedIndex;
                   14384:         var currnew = newSpare.options[selIdx].value;
                   14385:         var okSpares = new Array();
                   14386:         for (var j=0; j<newSpare.options.length; j++) {
                   14387:             var possible = newSpare.options[j].value;
                   14388:             if (possible != '') {
                   14389:                 if (exclude.indexOf(possible) == -1) {
                   14390:                     okSpares.push(possible);
                   14391:                 } else {
                   14392:                     if (currnew == possible) {
                   14393:                         selIdx = 0;
                   14394:                     }
                   14395:                 }
                   14396:             }
                   14397:         }
                   14398:         for (var k=0; k<include.length; k++) {
                   14399:             if (okSpares.indexOf(include[k]) == -1) {
                   14400:                 okSpares.push(include[k]);
                   14401:             }
                   14402:         }
                   14403:         okSpares.sort();
                   14404:         newSpare.options.length = 0;
                   14405:         if (selIdx == 0) {
                   14406:             newSpare.options[0] = new Option("$select","",true,true);
                   14407:         } else {
                   14408:             newSpare.options[0] = new Option("$select","",false,false);
                   14409:         }
                   14410:         for (var m=0; m<okSpares.length; m++) {
                   14411:             var idx = m+1;
                   14412:             var selThis = 0;
                   14413:             if (selIdx != 0) {
                   14414:                 if (okSpares[m] == currnew) {
                   14415:                     selThis = 1;
                   14416:                 }
                   14417:             }
                   14418:             if (selThis == 1) {
                   14419:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   14420:             } else {
                   14421:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   14422:             }
                   14423:         }
                   14424:     }
                   14425:     return;
                   14426: }
                   14427: 
                   14428: function checkNewSpares(lonhost,type) {
                   14429:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   14430:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   14431:     if (chosen != '') { 
                   14432:         var othertype;
                   14433:         var othernewSpare;
                   14434:         if (type == 'primary') {
                   14435:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   14436:         }
                   14437:         if (type == 'default') {
                   14438:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   14439:         }
                   14440:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   14441:             othernewSpare.selectedIndex = 0;
                   14442:         }
                   14443:     }
                   14444:     return;
                   14445: }
                   14446: 
                   14447: // ]]>
                   14448: </script>
                   14449: 
                   14450: END
                   14451: 
                   14452: }
                   14453: 
                   14454: sub common_domprefs_js {
                   14455:     return <<"END";
                   14456: 
                   14457: <script type="text/javascript">
                   14458: // <![CDATA[
                   14459: 
1.150     raeburn  14460: function getIndicesByName(formname,item) {
1.152     raeburn  14461:     var group = new Array();
1.150     raeburn  14462:     for (var i=0;i<formname.elements.length;i++) {
                   14463:         if (formname.elements[i].name == item) {
1.152     raeburn  14464:             group.push(formname.elements[i].id);
1.150     raeburn  14465:         }
                   14466:     }
1.152     raeburn  14467:     return group;
1.150     raeburn  14468: }
                   14469: 
                   14470: // ]]>
                   14471: </script>
                   14472: 
                   14473: END
1.152     raeburn  14474: 
1.150     raeburn  14475: }
                   14476: 
1.160.6.5  raeburn  14477: sub recaptcha_js {
                   14478:     my %lt = &captcha_phrases();
                   14479:     return <<"END";
                   14480: 
                   14481: <script type="text/javascript">
                   14482: // <![CDATA[
                   14483: 
                   14484: function updateCaptcha(caller,context) {
                   14485:     var privitem;
                   14486:     var pubitem;
                   14487:     var privtext;
                   14488:     var pubtext;
1.160.6.69  raeburn  14489:     var versionitem;
                   14490:     var versiontext;
1.160.6.5  raeburn  14491:     if (document.getElementById(context+'_recaptchapub')) {
                   14492:         pubitem = document.getElementById(context+'_recaptchapub');
                   14493:     } else {
                   14494:         return;
                   14495:     }
                   14496:     if (document.getElementById(context+'_recaptchapriv')) {
                   14497:         privitem = document.getElementById(context+'_recaptchapriv');
                   14498:     } else {
                   14499:         return;
                   14500:     }
                   14501:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   14502:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   14503:     } else {
                   14504:         return;
                   14505:     }
                   14506:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   14507:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   14508:     } else {
                   14509:         return;
                   14510:     }
1.160.6.69  raeburn  14511:     if (document.getElementById(context+'_recaptchaversion')) {
                   14512:         versionitem = document.getElementById(context+'_recaptchaversion');
                   14513:     } else {
                   14514:         return;
                   14515:     }
                   14516:     if (document.getElementById(context+'_recaptchavertxt')) {
                   14517:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   14518:     } else {
                   14519:         return;
                   14520:     }
1.160.6.5  raeburn  14521:     if (caller.checked) {
                   14522:         if (caller.value == 'recaptcha') {
                   14523:             pubitem.type = 'text';
                   14524:             privitem.type = 'text';
                   14525:             pubitem.size = '40';
                   14526:             privitem.size = '40';
                   14527:             pubtext.innerHTML = "$lt{'pub'}";
                   14528:             privtext.innerHTML = "$lt{'priv'}";
1.160.6.69  raeburn  14529:             versionitem.type = 'text';
                   14530:             versionitem.size = '3';
                   14531:             versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5  raeburn  14532:         } else {
                   14533:             pubitem.type = 'hidden';
                   14534:             privitem.type = 'hidden';
1.160.6.69  raeburn  14535:             versionitem.type = 'hidden';
1.160.6.5  raeburn  14536:             pubtext.innerHTML = '';
                   14537:             privtext.innerHTML = '';
1.160.6.69  raeburn  14538:             versiontext.innerHTML = '';
1.160.6.5  raeburn  14539:         }
                   14540:     }
                   14541:     return;
                   14542: }
                   14543: 
                   14544: // ]]>
                   14545: </script>
                   14546: 
                   14547: END
                   14548: 
                   14549: }
                   14550: 
1.160.6.40  raeburn  14551: sub toggle_display_js {
1.160.6.16  raeburn  14552:     return <<"END";
                   14553: 
                   14554: <script type="text/javascript">
                   14555: // <![CDATA[
                   14556: 
1.160.6.40  raeburn  14557: function toggleDisplay(domForm,caller) {
                   14558:     if (document.getElementById(caller)) {
                   14559:         var divitem = document.getElementById(caller);
                   14560:         var optionsElement = domForm.coursecredits;
1.160.6.64  raeburn  14561:         var checkval = 1;
                   14562:         var dispval = 'block';
1.160.6.40  raeburn  14563:         if (caller == 'emailoptions') {
                   14564:             optionsElement = domForm.cancreate_email; 
                   14565:         }
1.160.6.57  raeburn  14566:         if (caller == 'studentsubmission') {
                   14567:             optionsElement = domForm.postsubmit;
                   14568:         }
1.160.6.64  raeburn  14569:         if (caller == 'cloneinstcode') {
                   14570:             optionsElement = domForm.canclone;
                   14571:             checkval = 'instcode';
                   14572:         }
1.160.6.40  raeburn  14573:         if (optionsElement.length) {
1.160.6.16  raeburn  14574:             var currval;
1.160.6.40  raeburn  14575:             for (var i=0; i<optionsElement.length; i++) {
                   14576:                 if (optionsElement[i].checked) {
                   14577:                    currval = optionsElement[i].value;
1.160.6.16  raeburn  14578:                 }
                   14579:             }
1.160.6.64  raeburn  14580:             if (currval == checkval) {
                   14581:                 divitem.style.display = dispval;
1.160.6.16  raeburn  14582:             } else {
1.160.6.40  raeburn  14583:                 divitem.style.display = 'none';
1.160.6.16  raeburn  14584:             }
                   14585:         }
                   14586:     }
                   14587:     return;
                   14588: }
                   14589: 
                   14590: // ]]>
                   14591: </script>
                   14592: 
                   14593: END
                   14594: 
                   14595: }
                   14596: 
1.160.6.5  raeburn  14597: sub captcha_phrases {
                   14598:     return &Apache::lonlocal::texthash (
                   14599:                  priv => 'Private key',
                   14600:                  pub  => 'Public key',
                   14601:                  original  => 'original (CAPTCHA)',
                   14602:                  recaptcha => 'successor (ReCAPTCHA)',
                   14603:                  notused   => 'unused',
1.160.6.69  raeburn  14604:                  ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5  raeburn  14605:     );
                   14606: }
                   14607: 
1.160.6.24  raeburn  14608: sub devalidate_remote_domconfs {
1.160.6.27  raeburn  14609:     my ($dom,$cachekeys) = @_;
                   14610:     return unless (ref($cachekeys) eq 'HASH');
1.160.6.24  raeburn  14611:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   14612:     my %thismachine;
                   14613:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.84.2.  (raeburn 14614:):     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');
1.160.6.61  raeburn  14615:     if (keys(%servers)) {
1.160.6.24  raeburn  14616:         foreach my $server (keys(%servers)) {
                   14617:             next if ($thismachine{$server});
1.160.6.27  raeburn  14618:             my @cached;
                   14619:             foreach my $name (@posscached) {
                   14620:                 if ($cachekeys->{$name}) {
                   14621:                     push(@cached,&escape($name).':'.&escape($dom));
                   14622:                 }
                   14623:             }
                   14624:             if (@cached) {
                   14625:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   14626:             }
1.160.6.24  raeburn  14627:         }
                   14628:     }
                   14629:     return;
                   14630: }
                   14631: 
1.3       raeburn  14632: 1;

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