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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.272   ! raeburn     4: # $Id: domainprefs.pm,v 1.271 2016/04/02 04:30:19 raeburn Exp $
1.2       albertel    5: #
1.1       raeburn     6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
                     23: # /home/httpd/html/adm/gpl.txt
                     24: #
                     25: # http://www.lon-capa.org/
                     26: #
                     27: #
                     28: ###############################################################
                     29: ##############################################################
                     30: 
1.101     raeburn    31: =pod
                     32: 
                     33: =head1 NAME
                     34: 
                     35: Apache::domainprefs.pm
                     36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Handles configuration of a LON-CAPA domain.  
                     40: 
                     41: This is part of the LearningOnline Network with CAPA project
                     42: described at http://www.lon-capa.org.
                     43: 
                     44: 
                     45: =head1 OVERVIEW
                     46: 
                     47: Each institution using LON-CAPA will typically have a single domain designated 
1.183     bisitz     48: for use by individuals affiliated with the institution.  Accordingly, each domain
1.101     raeburn    49: may define a default set of logos and a color scheme which can be used to "brand"
                     50: the LON-CAPA instance. In addition, an institution will typically have a language
                     51: and timezone which are used for the majority of courses.
                     52: 
                     53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a 
                     54: host of other domain-wide settings which determine the types of functionality
                     55: available to users and courses in the domain.
                     56: 
                     57: There is also a mechanism to configure cataloging of courses in the domain, and
                     58: controls on the operation of automated processes which govern such things as
                     59: roster updates, user directory updates and processing of course requests.
                     60: 
                     61: The domain coordination manual which is built dynamically on install/update of 
                     62: LON-CAPA from the relevant help items provides more information about domain 
                     63: configuration.
                     64: 
                     65: Most of the domain settings are stored in the configuration.db GDBM file which is
                     66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
                     67: where $dom is the domain.  The configuration.db stores settings in a number of 
                     68: frozen hashes of hashes.  In a few cases, domain information must be uploaded to
                     69: the domain as files (e.g., image files for logos etc., or plain text files for
                     70: bubblesheet formats).  In this case the domainprefs.pm must be running in a user
                     71: session hosted on the primary library server in the domain, as these files are 
                     72: stored in author space belonging to a special $dom-domainconfig user.   
                     73: 
                     74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
                     75: the current settings, and provides an interface to make modifications.
                     76: 
                     77: =head1 SUBROUTINES
                     78: 
                     79: =over
                     80: 
                     81: =item print_quotas()
                     82: 
                     83: Inputs: 4 
                     84: 
                     85: $dom,$settings,$rowtotal,$action.
                     86: 
                     87: $dom is the domain, $settings is a reference to a hash of current settings for
                     88: the current context, $rowtotal is a reference to the scalar used to record the 
1.210     raeburn    89: number of rows displayed on the page, and $action is the context (quotas, 
1.163     raeburn    90: requestcourses or requestauthor).
1.101     raeburn    91: 
                     92: The print_quotas routine was orginally created to display/store information
                     93: about default quota sizes for portfolio spaces for the different types of 
                     94: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.), 
                     95: but is now also used to manage availability of user tools: 
                     96: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.197     raeburn    97: used by course owners to request creation of a course, and to display/store
1.223     bisitz     98: default quota sizes for Authoring Spaces.
1.101     raeburn    99: 
                    100: Outputs: 1
                    101: 
                    102: $datatable  - HTML containing form elements which allow settings to be changed. 
                    103: 
                    104: In the case of course requests, radio buttons are displayed for each institutional
                    105: affiliate type (and also default, and _LC_adv) for each of the course types 
1.271     raeburn   106: (official, unofficial, community, textbook, and placement).  
                    107: In each case the radio buttons allow the selection of one of four values:  
1.101     raeburn   108: 
1.104     raeburn   109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101     raeburn   110: which have the following effects:
                    111: 
                    112: 0
                    113: 
                    114: =over
                    115: 
                    116: - course requests are not allowed for this course types/affiliation
                    117: 
                    118: =back
                    119: 
1.104     raeburn   120: approval 
1.101     raeburn   121: 
                    122: =over 
                    123: 
                    124: - course requests must be approved by a Doman Coordinator in the 
                    125: course's domain
                    126: 
                    127: =back
                    128: 
                    129: validate 
                    130: 
                    131: =over
                    132: 
                    133: - an institutional validation (e.g., check requestor is instructor
                    134: of record) needs to be passed before the course will be created.  The required
                    135: validation is in localenroll.pm on the primary library server for the course 
                    136: domain.
                    137: 
                    138: =back
                    139: 
                    140: autolimit 
                    141: 
                    142: =over
                    143:  
1.143     raeburn   144: - course requests will be processed automatically up to a limit of
1.101     raeburn   145: N requests for the course type for the particular requestor.
                    146: If N is undefined, there is no limit to the number of course requests
                    147: which a course owner may submit and have processed automatically. 
                    148: 
                    149: =back
                    150: 
                    151: =item modify_quotas() 
                    152: 
                    153: =back
                    154: 
                    155: =cut
                    156: 
1.1       raeburn   157: package Apache::domainprefs;
                    158: 
                    159: use strict;
                    160: use Apache::Constants qw(:common :http);
                    161: use Apache::lonnet;
                    162: use Apache::loncommon();
                    163: use Apache::lonhtmlcommon();
                    164: use Apache::lonlocal;
1.43      raeburn   165: use Apache::lonmsg();
1.91      raeburn   166: use Apache::lonconfigsettings;
1.232     raeburn   167: use Apache::lonuserutils();
1.235     raeburn   168: use Apache::loncoursequeueadmin();
1.69      raeburn   169: use LONCAPA qw(:DEFAULT :match);
1.6       raeburn   170: use LONCAPA::Enrollment;
1.81      raeburn   171: use LONCAPA::lonauthcgi();
1.9       raeburn   172: use File::Copy;
1.43      raeburn   173: use Locale::Language;
1.62      raeburn   174: use DateTime::TimeZone;
1.68      raeburn   175: use DateTime::Locale;
1.267     raeburn   176: use Time::HiRes qw( sleep );
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',
                    217:                 'serverstatuses','requestcourses','helpsettings',
1.163     raeburn   218:                 'coursedefaults','usersessions','loadbalancing',
1.267     raeburn   219:                 'requestauthor','selfenrollment','inststatus',
                    220:                 'ltitools'],$dom);
1.43      raeburn   221:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125     raeburn   222:                        'autoupdate','autocreate','directorysrch','contacts',
1.224     raeburn   223:                        'usercreation','selfcreation','usermodification','scantron',
1.163     raeburn   224:                        'requestcourses','requestauthor','coursecategories',
1.267     raeburn   225:                        'serverstatuses','helpsettings','coursedefaults',
                    226:                        'ltitools','selfenrollment','usersessions');
1.171     raeburn   227:     my %existing;
                    228:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                    229:         %existing = %{$domconfig{'loadbalancing'}};
                    230:     }
                    231:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150     raeburn   232:         push(@prefs_order,'loadbalancing');
                    233:     }
1.30      raeburn   234:     my %prefs = (
                    235:         'rolecolors' =>
                    236:                    { text => 'Default color schemes',
1.67      raeburn   237:                      help => 'Domain_Configuration_Color_Schemes',
1.30      raeburn   238:                      header => [{col1 => 'Student Settings',
                    239:                                  col2 => '',},
                    240:                                 {col1 => 'Coordinator Settings',
                    241:                                  col2 => '',},
                    242:                                 {col1 => 'Author Settings',
                    243:                                  col2 => '',},
                    244:                                 {col1 => 'Administrator Settings',
                    245:                                  col2 => '',}],
1.230     raeburn   246:                       print => \&print_rolecolors,
                    247:                       modify => \&modify_rolecolors,
1.30      raeburn   248:                     },
1.110     raeburn   249:         'login' =>
1.30      raeburn   250:                     { text => 'Log-in page options',
1.67      raeburn   251:                       help => 'Domain_Configuration_Login_Page',
1.168     raeburn   252:                       header => [{col1 => 'Log-in Page Items',
                    253:                                   col2 => '',},
                    254:                                  {col1 => 'Log-in Help',
1.256     raeburn   255:                                   col2 => 'Value'},
                    256:                                  {col1 => 'Custom HTML in document head',
1.168     raeburn   257:                                   col2 => 'Value'}],
1.230     raeburn   258:                       print => \&print_login,
                    259:                       modify => \&modify_login,
1.30      raeburn   260:                     },
1.43      raeburn   261:         'defaults' => 
1.236     raeburn   262:                     { text => 'Default authentication/language/timezone/portal/types',
1.67      raeburn   263:                       help => 'Domain_Configuration_LangTZAuth',
1.43      raeburn   264:                       header => [{col1 => 'Setting',
1.236     raeburn   265:                                   col2 => 'Value'},
                    266:                                  {col1 => 'Institutional user types',
                    267:                                   col2 => 'Assignable to e-mail usernames'}],
1.230     raeburn   268:                       print => \&print_defaults,
                    269:                       modify => \&modify_defaults,
1.43      raeburn   270:                     },
1.30      raeburn   271:         'quotas' => 
1.197     raeburn   272:                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67      raeburn   273:                       help => 'Domain_Configuration_Quotas',
1.77      raeburn   274:                       header => [{col1 => 'User affiliation',
1.72      raeburn   275:                                   col2 => 'Available tools',
1.213     raeburn   276:                                   col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230     raeburn   277:                       print => \&print_quotas,
                    278:                       modify => \&modify_quotas,
1.30      raeburn   279:                     },
                    280:         'autoenroll' =>
                    281:                    { text => 'Auto-enrollment settings',
1.67      raeburn   282:                      help => 'Domain_Configuration_Auto_Enrollment',
1.30      raeburn   283:                      header => [{col1 => 'Configuration setting',
                    284:                                  col2 => 'Value(s)'}],
1.230     raeburn   285:                      print => \&print_autoenroll,
                    286:                      modify => \&modify_autoenroll,
1.30      raeburn   287:                    },
                    288:         'autoupdate' => 
                    289:                    { text => 'Auto-update settings',
1.67      raeburn   290:                      help => 'Domain_Configuration_Auto_Updates',
1.30      raeburn   291:                      header => [{col1 => 'Setting',
                    292:                                  col2 => 'Value',},
1.131     raeburn   293:                                 {col1 => 'Setting',
                    294:                                  col2 => 'Affiliation'},
1.43      raeburn   295:                                 {col1 => 'User population',
1.227     bisitz    296:                                  col2 => 'Updatable user data'}],
1.230     raeburn   297:                      print => \&print_autoupdate,
                    298:                      modify => \&modify_autoupdate,
1.30      raeburn   299:                   },
1.125     raeburn   300:         'autocreate' => 
                    301:                   { text => 'Auto-course creation settings',
                    302:                      help => 'Domain_Configuration_Auto_Creation',
                    303:                      header => [{col1 => 'Configuration Setting',
                    304:                                  col2 => 'Value',}],
1.230     raeburn   305:                      print => \&print_autocreate,
                    306:                      modify => \&modify_autocreate,
1.125     raeburn   307:                   },
1.30      raeburn   308:         'directorysrch' => 
                    309:                   { text => 'Institutional directory searches',
1.67      raeburn   310:                     help => 'Domain_Configuration_InstDirectory_Search',
1.30      raeburn   311:                     header => [{col1 => 'Setting',
                    312:                                 col2 => 'Value',}],
1.230     raeburn   313:                     print => \&print_directorysrch,
                    314:                     modify => \&modify_directorysrch,
1.30      raeburn   315:                   },
                    316:         'contacts' =>
                    317:                   { text => 'Contact Information',
1.67      raeburn   318:                     help => 'Domain_Configuration_Contact_Info',
1.30      raeburn   319:                     header => [{col1 => 'Setting',
                    320:                                 col2 => 'Value',}],
1.230     raeburn   321:                     print => \&print_contacts,
                    322:                     modify => \&modify_contacts,
1.30      raeburn   323:                   },
                    324:         'usercreation' => 
                    325:                   { text => 'User creation',
1.67      raeburn   326:                     help => 'Domain_Configuration_User_Creation',
1.43      raeburn   327:                     header => [{col1 => 'Format rule type',
                    328:                                 col2 => 'Format rules in force'},
1.34      raeburn   329:                                {col1 => 'User account creation',
                    330:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   331:                                {col1 => 'Context',
1.43      raeburn   332:                                 col2 => 'Assignable authentication types'}],
1.230     raeburn   333:                     print => \&print_usercreation,
                    334:                     modify => \&modify_usercreation,
1.30      raeburn   335:                   },
1.224     raeburn   336:         'selfcreation' => 
                    337:                   { text => 'Users self-creating accounts',
                    338:                     help => 'Domain_Configuration_Self_Creation', 
                    339:                     header => [{col1 => 'Self-creation with institutional username',
                    340:                                 col2 => 'Enabled?'},
                    341:                                {col1 => 'Institutional user type (login/SSO self-creation)',
                    342:                                 col2 => 'Information user can enter'},
                    343:                                {col1 => 'Self-creation with e-mail as username',
                    344:                                 col2 => 'Settings'}],
1.230     raeburn   345:                     print => \&print_selfcreation,
                    346:                     modify => \&modify_selfcreation,
1.224     raeburn   347:                   },
1.69      raeburn   348:         'usermodification' =>
1.33      raeburn   349:                   { text => 'User modification',
1.67      raeburn   350:                     help => 'Domain_Configuration_User_Modification',
1.33      raeburn   351:                     header => [{col1 => 'Target user has role',
1.227     bisitz    352:                                 col2 => 'User information updatable in author context'},
1.33      raeburn   353:                                {col1 => 'Target user has role',
1.227     bisitz    354:                                 col2 => 'User information updatable in course context'}],
1.230     raeburn   355:                     print => \&print_usermodification,
                    356:                     modify => \&modify_usermodification,
1.33      raeburn   357:                   },
1.69      raeburn   358:         'scantron' =>
1.95      www       359:                   { text => 'Bubblesheet format file',
1.67      raeburn   360:                     help => 'Domain_Configuration_Scantron_Format',
1.46      raeburn   361:                     header => [ {col1 => 'Item',
                    362:                                  col2 => '',
                    363:                               }],
1.230     raeburn   364:                     print => \&print_scantron,
                    365:                     modify => \&modify_scantron,
1.46      raeburn   366:                   },
1.86      raeburn   367:         'requestcourses' => 
                    368:                  {text => 'Request creation of courses',
                    369:                   help => 'Domain_Configuration_Request_Courses',
                    370:                   header => [{col1 => 'User affiliation',
1.102     raeburn   371:                               col2 => 'Availability/Processing of requests',},
                    372:                              {col1 => 'Setting',
1.216     raeburn   373:                               col2 => 'Value'},
                    374:                              {col1 => 'Available textbooks',
1.235     raeburn   375:                               col2 => ''},
1.242     raeburn   376:                              {col1 => 'Available templates',
                    377:                               col2 => ''},
1.235     raeburn   378:                              {col1 => 'Validation (not official courses)',
                    379:                               col2 => 'Value'},],
1.230     raeburn   380:                   print => \&print_quotas,
                    381:                   modify => \&modify_quotas,
1.86      raeburn   382:                  },
1.163     raeburn   383:         'requestauthor' =>
1.223     bisitz    384:                  {text => 'Request Authoring Space',
1.163     raeburn   385:                   help => 'Domain_Configuration_Request_Author',
                    386:                   header => [{col1 => 'User affiliation',
                    387:                               col2 => 'Availability/Processing of requests',},
                    388:                              {col1 => 'Setting',
                    389:                               col2 => 'Value'}],
1.230     raeburn   390:                   print => \&print_quotas,
                    391:                   modify => \&modify_quotas,
1.163     raeburn   392:                  },
1.69      raeburn   393:         'coursecategories' =>
1.120     raeburn   394:                   { text => 'Cataloging of courses/communities',
1.67      raeburn   395:                     help => 'Domain_Configuration_Cataloging_Courses',
1.238     raeburn   396:                     header => [{col1 => 'Catalog type/availability',
                    397:                                 col2 => '',},
                    398:                                {col1 => 'Category settings for standard catalog',
1.57      raeburn   399:                                 col2 => '',},
                    400:                                {col1 => 'Categories',
                    401:                                 col2 => '',
                    402:                                }],
1.230     raeburn   403:                     print => \&print_coursecategories,
                    404:                     modify => \&modify_coursecategories,
1.69      raeburn   405:                   },
                    406:         'serverstatuses' =>
1.77      raeburn   407:                  {text   => 'Access to server status pages',
1.69      raeburn   408:                   help   => 'Domain_Configuration_Server_Status',
                    409:                   header => [{col1 => 'Status Page',
                    410:                               col2 => 'Other named users',
                    411:                               col3 => 'Specific IPs',
                    412:                             }],
1.230     raeburn   413:                   print => \&print_serverstatuses,
                    414:                   modify => \&modify_serverstatuses,
1.69      raeburn   415:                  },
1.118     jms       416:         'helpsettings' =>
                    417:                  {text   => 'Help page settings',
                    418:                   help   => 'Domain_Configuration_Help_Settings',
1.166     raeburn   419:                   header => [{col1 => 'Help Settings (logged-in users)',
                    420:                               col2 => 'Value'}],
1.230     raeburn   421:                   print  => \&print_helpsettings,
                    422:                   modify => \&modify_helpsettings,
1.118     jms       423:                  },
1.121     raeburn   424:         'coursedefaults' => 
                    425:                  {text => 'Course/Community defaults',
                    426:                   help => 'Domain_Configuration_Course_Defaults',
1.139     raeburn   427:                   header => [{col1 => 'Defaults which can be overridden in each course by a CC',
                    428:                               col2 => 'Value',},
                    429:                              {col1 => 'Defaults which can be overridden for each course by a DC',
                    430:                               col2 => 'Value',},],
1.230     raeburn   431:                   print => \&print_coursedefaults,
                    432:                   modify => \&modify_coursedefaults,
1.121     raeburn   433:                  },
1.231     raeburn   434:         'selfenrollment' => 
                    435:                  {text   => 'Self-enrollment in Course/Community',
                    436:                   help   => 'Domain_Configuration_Selfenrollment',
                    437:                   header => [{col1 => 'Configuration Rights',
                    438:                               col2 => 'Configured by Course Personnel or Domain Coordinator?'},
                    439:                              {col1 => 'Defaults',
                    440:                               col2 => 'Value'},
                    441:                              {col1 => 'Self-enrollment validation (optional)',
                    442:                               col2 => 'Value'},],
                    443:                   print => \&print_selfenrollment,
                    444:                   modify => \&modify_selfenrollment,
                    445:                  },
1.120     raeburn   446:         'privacy' => 
                    447:                  {text   => 'User Privacy',
                    448:                   help   => 'Domain_Configuration_User_Privacy',
                    449:                   header => [{col1 => 'Setting',
                    450:                               col2 => 'Value',}],
1.230     raeburn   451:                   print => \&print_privacy,
                    452:                   modify => \&modify_privacy,
1.120     raeburn   453:                  },
1.141     raeburn   454:         'usersessions' =>
1.145     raeburn   455:                  {text  => 'User session hosting/offloading',
1.137     raeburn   456:                   help  => 'Domain_Configuration_User_Sessions',
1.145     raeburn   457:                   header => [{col1 => 'Domain server',
                    458:                               col2 => 'Servers to offload sessions to when busy'},
                    459:                              {col1 => 'Hosting of users from other domains',
1.137     raeburn   460:                               col2 => 'Rules'},
                    461:                              {col1 => "Hosting domain's own users elsewhere",
                    462:                               col2 => 'Rules'}],
1.230     raeburn   463:                   print => \&print_usersessions,
                    464:                   modify => \&modify_usersessions,
1.137     raeburn   465:                  },
1.150     raeburn   466:          'loadbalancing' =>
1.185     raeburn   467:                  {text  => 'Dedicated Load Balancer(s)',
1.150     raeburn   468:                   help  => 'Domain_Configuration_Load_Balancing',
1.171     raeburn   469:                   header => [{col1 => 'Balancers',
1.150     raeburn   470:                               col2 => 'Default destinations',
1.183     bisitz    471:                               col3 => 'User affiliation',
1.150     raeburn   472:                               col4 => 'Overrides'},
                    473:                             ],
1.230     raeburn   474:                   print => \&print_loadbalancing,
                    475:                   modify => \&modify_loadbalancing,
1.150     raeburn   476:                  },
1.267     raeburn   477:          'ltitools' => 
                    478:                  {text => 'External Tools (LTI)',
                    479:                   help => 'Domain_configuration_LTI_Tools',
                    480:                   header => [{col1 => 'Setting',
                    481:                               col2 => 'Value',}],
                    482:                   print => \&print_ltitools,
                    483:                   modify => \&modify_ltitools,
                    484:                  },
                    485:  
1.3       raeburn   486:     );
1.110     raeburn   487:     if (keys(%servers) > 1) {
                    488:         $prefs{'login'}  = { text   => 'Log-in page options',
                    489:                              help   => 'Domain_Configuration_Login_Page',
                    490:                             header => [{col1 => 'Log-in Service',
                    491:                                         col2 => 'Server Setting',},
                    492:                                        {col1 => 'Log-in Page Items',
1.168     raeburn   493:                                         col2 => ''},
                    494:                                        {col1 => 'Log-in Help',
1.256     raeburn   495:                                         col2 => 'Value'},
                    496:                                        {col1 => 'Custom HTML in document head',
1.168     raeburn   497:                                         col2 => 'Value'}],
1.230     raeburn   498:                             print => \&print_login,
                    499:                             modify => \&modify_login,
1.110     raeburn   500:                            };
                    501:     }
1.174     foxr      502: 
1.6       raeburn   503:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   504:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   505:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   506:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133     raeburn   507:       text=>"Settings to display/modify"});
1.9       raeburn   508:     my $confname = $dom.'-domainconfig';
1.174     foxr      509: 
1.3       raeburn   510:     if ($phase eq 'process') {
1.212     raeburn   511:         my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
                    512:                                                               \%prefs,\%domconfig,$confname,\@roles);
1.224     raeburn   513:         if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205     raeburn   514:             $r->rflush();
1.212     raeburn   515:             &devalidate_remote_domconfs($dom,$result);
1.205     raeburn   516:         }
1.30      raeburn   517:     } elsif ($phase eq 'display') {
1.192     raeburn   518:         my $js = &recaptcha_js().
1.236     raeburn   519:                  &toggle_display_js();
1.171     raeburn   520:         if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152     raeburn   521:             my ($othertitle,$usertypes,$types) =
                    522:                 &Apache::loncommon::sorted_inst_types($dom);
1.171     raeburn   523:             $js .= &lonbalance_targets_js($dom,$types,\%servers,
                    524:                                           $domconfig{'loadbalancing'}).
1.170     raeburn   525:                    &new_spares_js().
                    526:                    &common_domprefs_js().
                    527:                    &Apache::loncommon::javascript_array_indexof();
1.152     raeburn   528:         }
1.216     raeburn   529:         if (grep(/^requestcourses$/,@actions)) {
                    530:             my $javascript_validations;
                    531:             my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}); 
                    532:             $js .= <<END;
                    533: <script type="text/javascript">
                    534: $javascript_validations
                    535: </script>
                    536: $coursebrowserjs
                    537: END
                    538:         }
1.150     raeburn   539:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1       raeburn   540:     } else {
1.180     raeburn   541: # check if domconfig user exists for the domain.
                    542:         my $servadm = $r->dir_config('lonAdmEMail');
                    543:         my ($configuserok,$author_ok,$switchserver) =
                    544:             &config_check($dom,$confname,$servadm);
                    545:         unless ($configuserok eq 'ok') {
1.181     raeburn   546:             &Apache::lonconfigsettings::print_header($r,$phase,$context);
                    547:             $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210     raeburn   548:                           $confname).
1.181     raeburn   549:                       '<br />'
                    550:             );
1.180     raeburn   551:             if ($switchserver) {
1.181     raeburn   552:                 $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
                    553:                           '<br />'.
                    554:                           &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
                    555:                           '<br />'.
                    556:                           &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).
                    557:                           '<br />'.
                    558:                           &mt('To do that now, use the following link: [_1]',$switchserver)
                    559:                 );
                    560:             } else {
                    561:                 $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.').
                    562:                           '<br />'.
                    563:                           &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
                    564:                 );
1.180     raeburn   565:             }
                    566:             $r->print(&Apache::loncommon::end_page());
                    567:             return OK;
                    568:         }
1.21      raeburn   569:         if (keys(%domconfig) == 0) {
                    570:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   571:             my @ids=&Apache::lonnet::current_machine_ids();
                    572:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   573:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41      raeburn   574:                 my @loginimages = ('img','logo','domlogo','login');
1.21      raeburn   575:                 my $custom_img_count = 0;
                    576:                 foreach my $img (@loginimages) {
                    577:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    578:                         $custom_img_count ++;
                    579:                     }
                    580:                 }
                    581:                 foreach my $role (@roles) {
                    582:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    583:                         $custom_img_count ++;
                    584:                     }
                    585:                 }
                    586:                 if ($custom_img_count > 0) {
1.94      raeburn   587:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21      raeburn   588:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   589:                     $r->print(
                    590:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    591:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    592:     &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 />'.
                    593:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    594:                     if ($switch_server) {
1.30      raeburn   595:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   596:                     }
1.91      raeburn   597:                     $r->print(&Apache::loncommon::end_page());
1.21      raeburn   598:                     return OK;
                    599:                 }
                    600:             }
                    601:         }
1.91      raeburn   602:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3       raeburn   603:     }
                    604:     return OK;
                    605: }
                    606: 
                    607: sub process_changes {
1.205     raeburn   608:     my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92      raeburn   609:     my %domconfig;
                    610:     if (ref($values) eq 'HASH') {
                    611:         %domconfig = %{$values};
                    612:     }
1.3       raeburn   613:     my $output;
                    614:     if ($action eq 'login') {
1.205     raeburn   615:         $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6       raeburn   616:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   617:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205     raeburn   618:                                      $lastactref,%domconfig);
1.3       raeburn   619:     } elsif ($action eq 'quotas') {
1.216     raeburn   620:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   621:     } elsif ($action eq 'autoenroll') {
1.205     raeburn   622:         $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3       raeburn   623:     } elsif ($action eq 'autoupdate') {
                    624:         $output = &modify_autoupdate($dom,%domconfig);
1.125     raeburn   625:     } elsif ($action eq 'autocreate') {
                    626:         $output = &modify_autocreate($dom,%domconfig);
1.23      raeburn   627:     } elsif ($action eq 'directorysrch') {
                    628:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   629:     } elsif ($action eq 'usercreation') {
1.28      raeburn   630:         $output = &modify_usercreation($dom,%domconfig);
1.224     raeburn   631:     } elsif ($action eq 'selfcreation') {
                    632:         $output = &modify_selfcreation($dom,%domconfig);
1.33      raeburn   633:     } elsif ($action eq 'usermodification') {
                    634:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   635:     } elsif ($action eq 'contacts') {
1.205     raeburn   636:         $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43      raeburn   637:     } elsif ($action eq 'defaults') {
1.212     raeburn   638:         $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46      raeburn   639:     } elsif ($action eq 'scantron') {
1.205     raeburn   640:         $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48      raeburn   641:     } elsif ($action eq 'coursecategories') {
1.239     raeburn   642:         $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69      raeburn   643:     } elsif ($action eq 'serverstatuses') {
                    644:         $output = &modify_serverstatuses($dom,%domconfig);
1.86      raeburn   645:     } elsif ($action eq 'requestcourses') {
1.216     raeburn   646:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163     raeburn   647:     } elsif ($action eq 'requestauthor') {
1.216     raeburn   648:         $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118     jms       649:     } elsif ($action eq 'helpsettings') {
1.122     jms       650:         $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121     raeburn   651:     } elsif ($action eq 'coursedefaults') {
1.212     raeburn   652:         $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231     raeburn   653:     } elsif ($action eq 'selfenrollment') {
                    654:         $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137     raeburn   655:     } elsif ($action eq 'usersessions') {
1.212     raeburn   656:         $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150     raeburn   657:     } elsif ($action eq 'loadbalancing') {
                    658:         $output = &modify_loadbalancing($dom,%domconfig);
1.267     raeburn   659:     } elsif ($action eq 'ltitools') {
                    660:         $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.3       raeburn   661:     }
                    662:     return $output;
                    663: }
                    664: 
                    665: sub print_config_box {
1.9       raeburn   666:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   667:     my $rowtotal = 0;
1.49      raeburn   668:     my $output;
                    669:     if ($action eq 'coursecategories') {
                    670:         $output = &coursecategories_javascript($settings);
1.236     raeburn   671:     } elsif ($action eq 'defaults') {
                    672:         $output = &defaults_javascript($settings); 
1.91      raeburn   673:     }
1.236     raeburn   674:     $output .=
1.30      raeburn   675:          '<table class="LC_nested_outer">
1.3       raeburn   676:           <tr>
1.66      raeburn   677:            <th align="left" valign="middle"><span class="LC_nobreak">'.
                    678:            &mt($item->{text}).'&nbsp;'.
                    679:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
                    680:           '</tr>';
1.30      raeburn   681:     $rowtotal ++;
1.110     raeburn   682:     my $numheaders = 1;
                    683:     if (ref($item->{'header'}) eq 'ARRAY') {
                    684:         $numheaders = scalar(@{$item->{'header'}});
                    685:     }
                    686:     if ($numheaders > 1) {
1.64      raeburn   687:         my $colspan = '';
1.145     raeburn   688:         my $rightcolspan = '';
1.238     raeburn   689:         if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.256     raeburn   690:             (($action eq 'login') && ($numheaders < 4))) {
1.64      raeburn   691:             $colspan = ' colspan="2"';
                    692:         }
1.145     raeburn   693:         if ($action eq 'usersessions') {
                    694:             $rightcolspan = ' colspan="3"'; 
                    695:         }
1.30      raeburn   696:         $output .= '
1.3       raeburn   697:           <tr>
                    698:            <td>
                    699:             <table class="LC_nested">
                    700:              <tr class="LC_info_row">
1.59      bisitz    701:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145     raeburn   702:               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30      raeburn   703:              </tr>';
1.69      raeburn   704:         $rowtotal ++;
1.230     raeburn   705:         if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236     raeburn   706:             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.230     raeburn   707:             ($action eq 'selfenrollment') || ($action eq 'usersessions')) {
                    708:             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.57      raeburn   709:         } elsif ($action eq 'coursecategories') {
1.230     raeburn   710:             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.110     raeburn   711:         } elsif ($action eq 'login') {
1.256     raeburn   712:             if ($numheaders == 4) {
1.168     raeburn   713:                 $colspan = ' colspan="2"';
                    714:                 $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
                    715:             } else {
                    716:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
                    717:             }
1.230     raeburn   718:         } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163     raeburn   719:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122     jms       720:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   721:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   722:         }
1.30      raeburn   723:         $output .= '
1.6       raeburn   724:            </table>
                    725:           </td>
                    726:          </tr>
                    727:          <tr>
                    728:            <td>
                    729:             <table class="LC_nested">
                    730:              <tr class="LC_info_row">
1.230     raeburn   731:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59      bisitz    732:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30      raeburn   733:              </tr>';
                    734:             $rowtotal ++;
1.230     raeburn   735:         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
                    736:             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.238     raeburn   737:             ($action eq 'usersessions') || ($action eq 'coursecategories')) {
                    738:             if ($action eq 'coursecategories') {
                    739:                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                    740:                 $colspan = ' colspan="2"';
                    741:             } else {
                    742:                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
                    743:             }
                    744:             $output .= '
1.63      raeburn   745:            </table>
                    746:           </td>
                    747:          </tr>
                    748:          <tr>
                    749:            <td>
                    750:             <table class="LC_nested">
                    751:              <tr class="LC_info_row">
                    752:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224     raeburn   753:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238     raeburn   754:              </tr>'."\n";
                    755:             if ($action eq 'coursecategories') {
                    756:                 $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                    757:             } else {
                    758:                 $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                    759:             }
1.63      raeburn   760:             $rowtotal ++;
1.236     raeburn   761:         } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
                    762:                   ($action eq 'defaults')) {
1.230     raeburn   763:             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110     raeburn   764:         } elsif ($action eq 'login') {
1.256     raeburn   765:             if ($numheaders == 4) {
1.168     raeburn   766:                 $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
                    767:            </table>
                    768:           </td>
                    769:          </tr>
                    770:          <tr>
                    771:            <td>
                    772:             <table class="LC_nested">
                    773:              <tr class="LC_info_row">
                    774:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216     raeburn   775:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168     raeburn   776:                        &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    777:                 $rowtotal ++;
                    778:             } else {
                    779:                 $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
                    780:             }
1.256     raeburn   781:             $output .= '
                    782:            </table>
                    783:           </td>
                    784:          </tr>
                    785:          <tr>
                    786:            <td>
                    787:             <table class="LC_nested">
                    788:              <tr class="LC_info_row">';
                    789:             if ($numheaders == 4) {
                    790:                 $output .= '
                    791:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    792:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
                    793:              </tr>';
                    794:             } else {
                    795:                 $output .= '
                    796:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    797:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
                    798:              </tr>';
                    799:             }
                    800:             $rowtotal ++;
                    801:             $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal);
1.102     raeburn   802:         } elsif ($action eq 'requestcourses') {
1.247     raeburn   803:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
                    804:             $rowtotal ++;
                    805:             $output .= &print_studentcode($settings,\$rowtotal).'
1.216     raeburn   806:            </table>
                    807:           </td>
                    808:          </tr>
                    809:          <tr>
                    810:            <td>
                    811:             <table class="LC_nested">
                    812:              <tr class="LC_info_row">
                    813:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                    814:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242     raeburn   815:                        &textbookcourses_javascript($settings).
                    816:                        &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
                    817:             </table>
                    818:            </td>
                    819:           </tr>
                    820:          <tr>
                    821:            <td>
                    822:             <table class="LC_nested">
                    823:              <tr class="LC_info_row">
                    824:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    825:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
                    826:                        &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235     raeburn   827:             </table>
                    828:            </td>
                    829:           </tr>
                    830:           <tr>
                    831:            <td>
                    832:             <table class="LC_nested">
                    833:              <tr class="LC_info_row">
1.242     raeburn   834:               <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
                    835:               <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235     raeburn   836:              </tr>'.
                    837:             &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163     raeburn   838:         } elsif ($action eq 'requestauthor') {
                    839:             $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247     raeburn   840:             $rowtotal ++;
1.122     jms       841:         } elsif ($action eq 'rolecolors') {
1.30      raeburn   842:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   843:            </table>
                    844:           </td>
                    845:          </tr>
                    846:          <tr>
                    847:            <td>
                    848:             <table class="LC_nested">
                    849:              <tr class="LC_info_row">
1.69      raeburn   850:               <td class="LC_left_item"'.$colspan.' valign="top">'.
                    851:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
                    852:               <td class="LC_right_item" valign="top">'.
                    853:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3       raeburn   854:              </tr>'.
1.30      raeburn   855:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   856:            </table>
                    857:           </td>
                    858:          </tr>
                    859:          <tr>
                    860:            <td>
                    861:             <table class="LC_nested">
                    862:              <tr class="LC_info_row">
1.59      bisitz    863:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                    864:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3       raeburn   865:              </tr>'.
1.30      raeburn   866:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    867:             $rowtotal += 2;
1.6       raeburn   868:         }
1.3       raeburn   869:     } else {
1.30      raeburn   870:         $output .= '
1.3       raeburn   871:           <tr>
                    872:            <td>
                    873:             <table class="LC_nested">
1.30      raeburn   874:              <tr class="LC_info_row">';
1.24      raeburn   875:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   876:             $output .= '  
1.59      bisitz    877:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69      raeburn   878:         } elsif ($action eq 'serverstatuses') {
                    879:             $output .= '
                    880:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                    881:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
                    882: 
1.6       raeburn   883:         } else {
1.30      raeburn   884:             $output .= '
1.69      raeburn   885:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
                    886:         }
1.72      raeburn   887:         if (defined($item->{'header'}->[0]->{'col3'})) {
                    888:             $output .= '<td class="LC_left_item" valign="top">'.
                    889:                        &mt($item->{'header'}->[0]->{'col2'});
                    890:             if ($action eq 'serverstatuses') {
                    891:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
                    892:             } 
1.69      raeburn   893:         } else {
                    894:             $output .= '<td class="LC_right_item" valign="top">'.
                    895:                        &mt($item->{'header'}->[0]->{'col2'});
                    896:         }
                    897:         $output .= '</td>';
                    898:         if ($item->{'header'}->[0]->{'col3'}) {
1.150     raeburn   899:             if (defined($item->{'header'}->[0]->{'col4'})) {
                    900:                 $output .= '<td class="LC_left_item" valign="top">'.
                    901:                             &mt($item->{'header'}->[0]->{'col3'});
                    902:             } else {
                    903:                 $output .= '<td class="LC_right_item" valign="top">'.
                    904:                            &mt($item->{'header'}->[0]->{'col3'});
                    905:             }
1.69      raeburn   906:             if ($action eq 'serverstatuses') {
                    907:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
                    908:             }
                    909:             $output .= '</td>';
1.6       raeburn   910:         }
1.150     raeburn   911:         if ($item->{'header'}->[0]->{'col4'}) {
                    912:             $output .= '<td class="LC_right_item" valign="top">'.
                    913:                        &mt($item->{'header'}->[0]->{'col4'});
                    914:         }
1.69      raeburn   915:         $output .= '</tr>';
1.48      raeburn   916:         $rowtotal ++;
1.168     raeburn   917:         if ($action eq 'quotas') {
1.86      raeburn   918:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.230     raeburn   919:         } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') || ($action eq 'directorysrch') ||
1.267     raeburn   920:                  ($action eq 'contacts') || ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
                    921:                  ($action eq 'ltitools')) {
1.230     raeburn   922:             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.46      raeburn   923:         } elsif ($action eq 'scantron') {
                    924:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.118     jms       925:         } elsif ($action eq 'helpsettings') {
1.168     raeburn   926:             $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.121     raeburn   927:         }
1.3       raeburn   928:     }
1.30      raeburn   929:     $output .= '
1.3       raeburn   930:    </table>
                    931:   </td>
                    932:  </tr>
1.30      raeburn   933: </table><br />';
                    934:     return ($output,$rowtotal);
1.1       raeburn   935: }
                    936: 
1.3       raeburn   937: sub print_login {
1.168     raeburn   938:     my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110     raeburn   939:     my ($css_class,$datatable);
1.6       raeburn   940:     my %choices = &login_choices();
1.110     raeburn   941: 
1.168     raeburn   942:     if ($caller eq 'service') {
1.149     raeburn   943:         my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110     raeburn   944:         my $choice = $choices{'disallowlogin'};
                    945:         $css_class = ' class="LC_odd_row"';
1.128     raeburn   946:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110     raeburn   947:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128     raeburn   948:                       '<th>'.$choices{'server'}.'</th>'.
                    949:                       '<th>'.$choices{'serverpath'}.'</th>'.
                    950:                       '<th>'.$choices{'custompath'}.'</th>'.
                    951:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110     raeburn   952:         my %disallowed;
                    953:         if (ref($settings) eq 'HASH') {
                    954:             if (ref($settings->{'loginvia'}) eq 'HASH') {
                    955:                %disallowed = %{$settings->{'loginvia'}};
                    956:             }
                    957:         }
                    958:         foreach my $lonhost (sort(keys(%servers))) {
                    959:             my $direct = 'selected="selected"';
1.128     raeburn   960:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                    961:                 if ($disallowed{$lonhost}{'server'} ne '') {
                    962:                     $direct = '';
                    963:                 }
1.110     raeburn   964:             }
1.115     raeburn   965:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128     raeburn   966:                           '<td><select name="'.$lonhost.'_server">'.
1.110     raeburn   967:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
                    968:                           '</option>';
1.184     raeburn   969:             foreach my $hostid (sort(keys(%servers))) {
1.115     raeburn   970:                 next if ($servers{$hostid} eq $servers{$lonhost});
1.110     raeburn   971:                 my $selected = '';
1.128     raeburn   972:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    973:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
                    974:                         $selected = 'selected="selected"';
                    975:                     }
1.110     raeburn   976:                 }
                    977:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
                    978:                               $servers{$hostid}.'</option>';
                    979:             }
1.128     raeburn   980:             $datatable .= '</select></td>'.
                    981:                           '<td><select name="'.$lonhost.'_serverpath">';
                    982:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
                    983:                 my $pathname = $path;
                    984:                 if ($path eq 'custom') {
                    985:                     $pathname = &mt('Custom Path').' ->';
                    986:                 }
                    987:                 my $selected = '';
                    988:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
                    989:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
                    990:                         $selected = 'selected="selected"';
                    991:                     }
                    992:                 } elsif ($path eq '') {
                    993:                     $selected = 'selected="selected"';
                    994:                 }
                    995:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
                    996:             }
                    997:             $datatable .= '</select></td>';
                    998:             my ($custom,$exempt);
                    999:             if (ref($disallowed{$lonhost}) eq 'HASH') {
                   1000:                 $custom = $disallowed{$lonhost}{'custompath'};
                   1001:                 $exempt = $disallowed{$lonhost}{'exempt'};
                   1002:             }
                   1003:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
                   1004:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
                   1005:                           '</tr>';
1.110     raeburn  1006:         }
                   1007:         $datatable .= '</table></td></tr>';
                   1008:         return $datatable;
1.168     raeburn  1009:     } elsif ($caller eq 'page') {
                   1010:         my %defaultchecked = ( 
                   1011:                                'coursecatalog' => 'on',
1.188     raeburn  1012:                                'helpdesk'      => 'on',
1.168     raeburn  1013:                                'adminmail'     => 'off',
                   1014:                                'newuser'       => 'off',
                   1015:                              );
1.188     raeburn  1016:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168     raeburn  1017:         my (%checkedon,%checkedoff);
1.42      raeburn  1018:         foreach my $item (@toggles) {
1.168     raeburn  1019:             if ($defaultchecked{$item} eq 'on') { 
                   1020:                 $checkedon{$item} = ' checked="checked" ';
1.42      raeburn  1021:                 $checkedoff{$item} = ' ';
1.168     raeburn  1022:             } elsif ($defaultchecked{$item} eq 'off') {
                   1023:                 $checkedoff{$item} = ' checked="checked" ';
1.42      raeburn  1024:                 $checkedon{$item} = ' ';
                   1025:             }
1.1       raeburn  1026:         }
1.168     raeburn  1027:         my @images = ('img','logo','domlogo','login');
                   1028:         my @logintext = ('textcol','bgcol');
                   1029:         my @bgs = ('pgbg','mainbg','sidebg');
                   1030:         my @links = ('link','alink','vlink');
                   1031:         my %designhash = &Apache::loncommon::get_domainconf($dom);
                   1032:         my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1033:         my (%is_custom,%designs);
                   1034:         my %defaults = (
                   1035:                        font => $defaultdesign{'login.font'},
                   1036:                        );
1.6       raeburn  1037:         foreach my $item (@images) {
1.168     raeburn  1038:             $defaults{$item} = $defaultdesign{'login.'.$item};
                   1039:             $defaults{'showlogo'}{$item} = 1;
                   1040:         }
                   1041:         foreach my $item (@bgs) {
                   1042:             $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1043:         }
1.41      raeburn  1044:         foreach my $item (@logintext) {
1.168     raeburn  1045:             $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41      raeburn  1046:         }
1.168     raeburn  1047:         foreach my $item (@links) {
                   1048:             $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6       raeburn  1049:         }
1.168     raeburn  1050:         if (ref($settings) eq 'HASH') {
                   1051:             foreach my $item (@toggles) {
                   1052:                 if ($settings->{$item} eq '1') {
                   1053:                     $checkedon{$item} =  ' checked="checked" ';
                   1054:                     $checkedoff{$item} = ' ';
                   1055:                 } elsif ($settings->{$item} eq '0') {
                   1056:                     $checkedoff{$item} =  ' checked="checked" ';
                   1057:                     $checkedon{$item} = ' ';
                   1058:                 }
                   1059:             }
                   1060:             foreach my $item (@images) {
                   1061:                 if (defined($settings->{$item})) {
                   1062:                     $designs{$item} = $settings->{$item};
                   1063:                     $is_custom{$item} = 1;
                   1064:                 }
                   1065:                 if (defined($settings->{'showlogo'}{$item})) {
                   1066:                     $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
                   1067:                 }
                   1068:             }
                   1069:             foreach my $item (@logintext) {
                   1070:                 if ($settings->{$item} ne '') {
                   1071:                     $designs{'logintext'}{$item} = $settings->{$item};
                   1072:                     $is_custom{$item} = 1;
                   1073:                 }
                   1074:             }
                   1075:             if ($settings->{'font'} ne '') {
                   1076:                 $designs{'font'} = $settings->{'font'};
                   1077:                 $is_custom{'font'} = 1;
                   1078:             }
                   1079:             foreach my $item (@bgs) {
                   1080:                 if ($settings->{$item} ne '') {
                   1081:                     $designs{'bgs'}{$item} = $settings->{$item};
                   1082:                     $is_custom{$item} = 1;
                   1083:                 }
                   1084:             }
                   1085:             foreach my $item (@links) {
                   1086:                 if ($settings->{$item} ne '') {
                   1087:                     $designs{'links'}{$item} = $settings->{$item};
                   1088:                     $is_custom{$item} = 1;
                   1089:                 }
                   1090:             }
                   1091:         } else {
                   1092:             if ($designhash{$dom.'.login.font'} ne '') {
                   1093:                 $designs{'font'} = $designhash{$dom.'.login.font'};
                   1094:                 $is_custom{'font'} = 1;
                   1095:             }
                   1096:             foreach my $item (@images) {
                   1097:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1098:                     $designs{$item} = $designhash{$dom.'.login.'.$item};
                   1099:                     $is_custom{$item} = 1;
                   1100:                 }
                   1101:             }
                   1102:             foreach my $item (@bgs) {
                   1103:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1104:                     $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                   1105:                     $is_custom{$item} = 1;
                   1106:                 }
1.6       raeburn  1107:             }
1.168     raeburn  1108:             foreach my $item (@links) {
                   1109:                 if ($designhash{$dom.'.login.'.$item} ne '') {
                   1110:                     $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                   1111:                     $is_custom{$item} = 1;
                   1112:                 }
1.6       raeburn  1113:             }
                   1114:         }
1.168     raeburn  1115:         my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                   1116:                                                       logo => 'Institution Logo',
                   1117:                                                       domlogo => 'Domain Logo',
                   1118:                                                       login => 'Login box');
                   1119:         my $itemcount = 1;
                   1120:         foreach my $item (@toggles) {
                   1121:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1122:             $datatable .=  
                   1123:                 '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
                   1124:                 '</td><td>'.
                   1125:                 '<span class="LC_nobreak"><label><input type="radio" name="'.
                   1126:                 $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
                   1127:                 '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
                   1128:                 $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
                   1129:                 '</tr>';
                   1130:             $itemcount ++;
1.6       raeburn  1131:         }
1.168     raeburn  1132:         $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
                   1133:         $datatable .= '</tr></table></td></tr>';
                   1134:     } elsif ($caller eq 'help') {
                   1135:         my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
                   1136:         my $switchserver = &check_switchserver($dom,$confname);
                   1137:         my $itemcount = 1;
                   1138:         $defaulturl = '/adm/loginproblems.html';
                   1139:         $defaulttype = 'default';
                   1140:         %lt = &Apache::lonlocal::texthash (
                   1141:                      del     => 'Delete?',
                   1142:                      rep     => 'Replace:',
                   1143:                      upl     => 'Upload:',
                   1144:                      default => 'Default',
                   1145:                      custom  => 'Custom',
                   1146:                                              );
                   1147:         %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   1148:         my @currlangs;
                   1149:         if (ref($settings) eq 'HASH') {
                   1150:             if (ref($settings->{'helpurl'}) eq 'HASH') {
                   1151:                 foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
                   1152:                     next if ($settings->{'helpurl'}{$key} eq '');
                   1153:                     $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
                   1154:                     $type{$key} = 'custom';
                   1155:                     unless ($key eq 'nolang') {
                   1156:                         push(@currlangs,$key);
                   1157:                     }
                   1158:                 }
                   1159:             } elsif ($settings->{'helpurl'} ne '') {
                   1160:                 $type{'nolang'} = 'custom';
                   1161:                 $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8       raeburn  1162:             }
                   1163:         }
1.168     raeburn  1164:         foreach my $lang ('nolang',sort(@currlangs)) {
                   1165:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1166:             $datatable .= '<tr'.$css_class.'>';
                   1167:             if ($url{$lang} eq '') {
                   1168:                 $url{$lang} = $defaulturl;
                   1169:             }
                   1170:             if ($type{$lang} eq '') {
                   1171:                 $type{$lang} = $defaulttype;
                   1172:             }
                   1173:             $datatable .= '<td colspan="2"><span class="LC_nobreak">';
                   1174:             if ($lang eq 'nolang') {
                   1175:                 $datatable .= &mt('Log-in help page if no specific language file: [_1]',
                   1176:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1177:             } else {
                   1178:                 $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
                   1179:                                   $langchoices{$lang},
                   1180:                                   &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
                   1181:             }
                   1182:             $datatable .= '</span></td>'."\n".
                   1183:                           '<td class="LC_left_item">';
                   1184:             if ($type{$lang} eq 'custom') {
                   1185:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1186:                               '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
                   1187:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1188:             } else {
                   1189:                 $datatable .= $lt{'upl'};
                   1190:             }
                   1191:             $datatable .='<br />';
                   1192:             if ($switchserver) {
                   1193:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1194:             } else {
                   1195:                 $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6       raeburn  1196:             }
1.168     raeburn  1197:             $datatable .= '</td></tr>';
                   1198:             $itemcount ++;
1.6       raeburn  1199:         }
1.168     raeburn  1200:         my @addlangs;
                   1201:         foreach my $lang (sort(keys(%langchoices))) {
                   1202:             next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
                   1203:             push(@addlangs,$lang);
                   1204:         }
                   1205:         if (@addlangs > 0) {
                   1206:             my %toadd;
                   1207:             map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
                   1208:             $toadd{''} = &mt('Select');
                   1209:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   1210:             $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
                   1211:                           &mt('Add log-in help page for a specific language:').'&nbsp;'.
                   1212:                           &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
                   1213:                           '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
                   1214:             if ($switchserver) {
                   1215:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1216:             } else {
                   1217:                 $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6       raeburn  1218:             }
1.168     raeburn  1219:             $datatable .= '</td></tr>';
1.169     raeburn  1220:             $itemcount ++;
1.6       raeburn  1221:         }
1.169     raeburn  1222:         $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256     raeburn  1223:     } elsif ($caller eq 'headtag') {
                   1224:         my %domservers = &Apache::lonnet::get_servers($dom);
                   1225:         my $choice = $choices{'headtag'};
                   1226:         $css_class = ' class="LC_odd_row"';
                   1227:         $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
                   1228:                       '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
                   1229:                       '<th>'.$choices{'current'}.'</th>'.
                   1230:                       '<th>'.$choices{'action'}.'</th>'.
                   1231:                       '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
                   1232:         my (%currurls,%currexempt);
                   1233:         if (ref($settings) eq 'HASH') {
                   1234:             if (ref($settings->{'headtag'}) eq 'HASH') {
                   1235:                 foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
                   1236:                     if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
                   1237:                         $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
                   1238:                         $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
                   1239:                     }
                   1240:                 }
                   1241:             }
                   1242:         }
                   1243:         my %lt = &Apache::lonlocal::texthash(
                   1244:                                                del  => 'Delete?',
                   1245:                                                rep  => 'Replace:',
                   1246:                                                upl  => 'Upload:',
                   1247:                                                curr => 'View contents',
                   1248:                                                none => 'None',
                   1249:         );
                   1250:         my $switchserver = &check_switchserver($dom,$confname);
                   1251:         foreach my $lonhost (sort(keys(%domservers))) {
                   1252:             my $exempt = &check_exempt_addresses($currexempt{$lonhost});
                   1253:             $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
                   1254:             if ($currurls{$lonhost}) {
                   1255:                 $datatable .= '<td class="LC_right_item"><a href="'.
                   1256:                               "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
                   1257:                               'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   1258:                               '">'.$lt{'curr'}.'</a></td>'.
                   1259:                               '<td><span class="LC_nobreak"><label>'.
                   1260:                               '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
                   1261:                               $lt{'del'}.'</label>&nbsp;'.$lt{'rep'}.'</span>';
                   1262:             } else {
                   1263:                 $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
                   1264:             }
                   1265:             $datatable .='<br />';
                   1266:             if ($switchserver) {
                   1267:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1268:             } else {
                   1269:                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
                   1270:             }
                   1271:             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
                   1272:         }
                   1273:         $datatable .= '</table></td></tr>';
1.1       raeburn  1274:     }
1.6       raeburn  1275:     return $datatable;
                   1276: }
                   1277: 
                   1278: sub login_choices {
                   1279:     my %choices =
                   1280:         &Apache::lonlocal::texthash (
1.116     bisitz   1281:             coursecatalog => 'Display Course/Community Catalog link?',
1.110     raeburn  1282:             adminmail     => "Display Administrator's E-mail Address?",
1.188     raeburn  1283:             helpdesk      => 'Display "Contact Helpdesk" link',
1.110     raeburn  1284:             disallowlogin => "Login page requests redirected",
                   1285:             hostid        => "Server",
1.128     raeburn  1286:             server        => "Redirect to:",
                   1287:             serverpath    => "Path",
                   1288:             custompath    => "Custom", 
                   1289:             exempt        => "Exempt IP(s)",
1.110     raeburn  1290:             directlogin   => "No redirect",
                   1291:             newuser       => "Link to create a user account",
                   1292:             img           => "Header",
                   1293:             logo          => "Main Logo",
                   1294:             domlogo       => "Domain Logo",
                   1295:             login         => "Log-in Header", 
                   1296:             textcol       => "Text color",
                   1297:             bgcol         => "Box color",
                   1298:             bgs           => "Background colors",
                   1299:             links         => "Link colors",
                   1300:             font          => "Font color",
                   1301:             pgbg          => "Header",
                   1302:             mainbg        => "Page",
                   1303:             sidebg        => "Login box",
                   1304:             link          => "Link",
                   1305:             alink         => "Active link",
                   1306:             vlink         => "Visited link",
1.256     raeburn  1307:             headtag       => "Custom markup",
                   1308:             action        => "Action",
                   1309:             current       => "Current",
1.6       raeburn  1310:         );
                   1311:     return %choices;
                   1312: }
                   1313: 
                   1314: sub print_rolecolors {
1.30      raeburn  1315:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn  1316:     my %choices = &color_font_choices();
                   1317:     my @bgs = ('pgbg','tabbg','sidebg');
                   1318:     my @links = ('link','alink','vlink');
                   1319:     my @images = ('img');
                   1320:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel 1321:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn  1322:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1323:     my (%is_custom,%designs);
1.200     raeburn  1324:     my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6       raeburn  1325:     if (ref($settings) eq 'HASH') {
                   1326:         if (ref($settings->{$role}) eq 'HASH') {
                   1327:             if ($settings->{$role}->{'img'} ne '') {
                   1328:                 $designs{'img'} = $settings->{$role}->{'img'};
                   1329:                 $is_custom{'img'} = 1;
                   1330:             }
                   1331:             if ($settings->{$role}->{'font'} ne '') {
                   1332:                 $designs{'font'} = $settings->{$role}->{'font'};
                   1333:                 $is_custom{'font'} = 1;
                   1334:             }
1.97      tempelho 1335:             if ($settings->{$role}->{'fontmenu'} ne '') {
                   1336:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
                   1337:                 $is_custom{'fontmenu'} = 1;
                   1338:             }
1.6       raeburn  1339:             foreach my $item (@bgs) {
                   1340:                 if ($settings->{$role}->{$item} ne '') {
                   1341:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                   1342:                     $is_custom{$item} = 1;
                   1343:                 }
                   1344:             }
                   1345:             foreach my $item (@links) {
                   1346:                 if ($settings->{$role}->{$item} ne '') {
                   1347:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                   1348:                     $is_custom{$item} = 1;
                   1349:                 }
                   1350:             }
                   1351:         }
                   1352:     } else {
                   1353:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                   1354:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                   1355:             $is_custom{'img'} = 1;
                   1356:         }
1.97      tempelho 1357:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
                   1358:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
                   1359:             $is_custom{'fontmenu'} = 1; 
                   1360:         }
1.6       raeburn  1361:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                   1362:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                   1363:             $is_custom{'font'} = 1;
                   1364:         }
                   1365:         foreach my $item (@bgs) {
                   1366:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1367:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1368:                 $is_custom{$item} = 1;
                   1369:             
                   1370:             }
                   1371:         }
                   1372:         foreach my $item (@links) {
                   1373:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                   1374:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                   1375:                 $is_custom{$item} = 1;
                   1376:             }
                   1377:         }
                   1378:     }
                   1379:     my $itemcount = 1;
1.30      raeburn  1380:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn  1381:     $datatable .= '</tr></table></td></tr>';
                   1382:     return $datatable;
                   1383: }
                   1384: 
1.200     raeburn  1385: sub role_defaults {
                   1386:     my ($role,$bgs,$links,$images,$logintext) = @_;
1.202     raeburn  1387:     my %defaults;
                   1388:     unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200     raeburn  1389:         return %defaults;
                   1390:     }
                   1391:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                   1392:     if ($role eq 'login') {
                   1393:         %defaults = (
                   1394:                        font => $defaultdesign{$role.'.font'},
                   1395:                     );
                   1396:         if (ref($logintext) eq 'ARRAY') {
                   1397:             foreach my $item (@{$logintext}) {
                   1398:                 $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
                   1399:             }
                   1400:         }
                   1401:         foreach my $item (@{$images}) {
                   1402:             $defaults{'showlogo'}{$item} = 1;
                   1403:         }
                   1404:     } else {
                   1405:         %defaults = (
                   1406:                        img => $defaultdesign{$role.'.img'},
                   1407:                        font => $defaultdesign{$role.'.font'},
                   1408:                        fontmenu => $defaultdesign{$role.'.fontmenu'},
                   1409:                     );
                   1410:     }
                   1411:     foreach my $item (@{$bgs}) {
                   1412:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                   1413:     }
                   1414:     foreach my $item (@{$links}) {
                   1415:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                   1416:     }
                   1417:     foreach my $item (@{$images}) {
                   1418:         $defaults{$item} = $defaultdesign{$role.'.'.$item};
                   1419:     }
                   1420:     return %defaults;
                   1421: }
                   1422: 
1.6       raeburn  1423: sub display_color_options {
1.9       raeburn  1424:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135     bisitz   1425:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159     raeburn  1426:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6       raeburn  1427:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176     raeburn  1428:     my $datatable = '<tr'.$css_class.'>'.
1.6       raeburn  1429:         '<td>'.$choices->{'font'}.'</td>';
                   1430:     if (!$is_custom->{'font'}) {
1.30      raeburn  1431:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn  1432:     } else {
                   1433:         $datatable .= '<td>&nbsp;</td>';
                   1434:     }
1.174     foxr     1435:     my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
                   1436: 
1.8       raeburn  1437:     $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1438:                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202     raeburn  1439:                   ' value="'.$current_color.'" />&nbsp;'.
1.174     foxr     1440:                   '&nbsp;</td></tr>';
1.107     raeburn  1441:     unless ($role eq 'login') { 
                   1442:         $datatable .= '<tr'.$css_class.'>'.
                   1443:                       '<td>'.$choices->{'fontmenu'}.'</td>';
                   1444:         if (!$is_custom->{'fontmenu'}) {
                   1445:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
                   1446:         } else {
                   1447:             $datatable .= '<td>&nbsp;</td>';
                   1448:         }
1.202     raeburn  1449: 	$current_color = $designs->{'fontmenu'} ?
1.174     foxr     1450: 	    $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107     raeburn  1451:         $datatable .= '<td><span class="LC_nobreak">'.
1.174     foxr     1452:                       '<input class="colorchooser" type="text" size="10" name="'
                   1453: 		      .$role.'_fontmenu"'.
                   1454:                       ' value="'.$current_color.'" />&nbsp;'.
                   1455:                       '&nbsp;</td></tr>';
1.97      tempelho 1456:     }
1.9       raeburn  1457:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn  1458:     foreach my $img (@{$images}) {
1.18      albertel 1459: 	$itemcount ++;
1.6       raeburn  1460:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn  1461:         $datatable .= '<tr'.$css_class.'>'.
1.70      raeburn  1462:                       '<td>'.$choices->{$img};
1.41      raeburn  1463:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70      raeburn  1464:         if ($role eq 'login') {
                   1465:             if ($img eq 'login') {
                   1466:                 $login_hdr_pick =
1.135     bisitz   1467:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70      raeburn  1468:                 $logincolors =
                   1469:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201     raeburn  1470:                                        $designs,$defaults);
1.70      raeburn  1471:             } elsif ($img ne 'domlogo') {
                   1472:                 $datatable.= &logo_display_options($img,$defaults,$designs);
                   1473:             }
                   1474:         }
                   1475:         $datatable .= '</td>';
1.6       raeburn  1476:         if ($designs->{$img} ne '') {
                   1477:             $imgfile = $designs->{$img};
1.18      albertel 1478: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn  1479:         } else {
                   1480:             $imgfile = $defaults->{$img};
                   1481:         }
                   1482:         if ($imgfile) {
1.9       raeburn  1483:             my ($showfile,$fullsize);
                   1484:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn  1485:                 my $urldir = $1;
                   1486:                 my $filename = $2;
                   1487:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                   1488:                 if (@info) {
                   1489:                     my $thumbfile = 'tn-'.$filename;
                   1490:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                   1491:                     if (@thumb) {
                   1492:                         $showfile = $urldir.'/'.$thumbfile;
                   1493:                     } else {
                   1494:                         $showfile = $imgfile;
                   1495:                     }
                   1496:                 } else {
                   1497:                     $showfile = '';
                   1498:                 }
                   1499:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn  1500:                 $showfile = $imgfile;
1.6       raeburn  1501:                 my $imgdir = $1;
                   1502:                 my $filename = $2;
1.159     raeburn  1503:                 if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6       raeburn  1504:                     $showfile = "/$imgdir/tn-".$filename;
                   1505:                 } else {
1.159     raeburn  1506:                     my $input = $londocroot.$imgfile;
                   1507:                     my $output = "$londocroot/$imgdir/tn-".$filename;
1.6       raeburn  1508:                     if (!-e $output) {
1.9       raeburn  1509:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn  1510:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                   1511:                         if ($fullwidth ne '' && $fullheight ne '') {
                   1512:                             if ($fullwidth > $width && $fullheight > $height) { 
                   1513:                                 my $size = $width.'x'.$height;
                   1514:                                 system("convert -sample $size $input $output");
1.159     raeburn  1515:                                 $showfile = "/$imgdir/tn-".$filename;
1.16      raeburn  1516:                             }
                   1517:                         }
1.6       raeburn  1518:                     }
                   1519:                 }
1.16      raeburn  1520:             }
1.6       raeburn  1521:             if ($showfile) {
1.40      raeburn  1522:                 if ($showfile =~ m{^/(adm|res)/}) {
                   1523:                     if ($showfile =~ m{^/res/}) {
                   1524:                         my $local_showfile =
                   1525:                             &Apache::lonnet::filelocation('',$showfile);
                   1526:                         &Apache::lonnet::repcopy($local_showfile);
                   1527:                     }
                   1528:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                   1529:                 }
                   1530:                 if ($imgfile) {
                   1531:                     if ($imgfile  =~ m{^/(adm|res)/}) {
                   1532:                         if ($imgfile =~ m{^/res/}) {
                   1533:                             my $local_imgfile =
                   1534:                                 &Apache::lonnet::filelocation('',$imgfile);
                   1535:                             &Apache::lonnet::repcopy($local_imgfile);
                   1536:                         }
                   1537:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
                   1538:                     } else {
                   1539:                         $fullsize = $imgfile;
                   1540:                     }
                   1541:                 }
1.41      raeburn  1542:                 $datatable .= '<td>';
                   1543:                 if ($img eq 'login') {
1.135     bisitz   1544:                     $datatable .= $login_hdr_pick;
                   1545:                 } 
1.41      raeburn  1546:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
                   1547:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6       raeburn  1548:             } else {
1.201     raeburn  1549:                 $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1550:                               &mt('Upload:').'<br />';
1.6       raeburn  1551:             }
                   1552:         } else {
1.201     raeburn  1553:             $datatable .= '<td>&nbsp;</td><td class="LC_left_item">'.
                   1554:                           &mt('Upload:').'<br />';
1.6       raeburn  1555:         }
1.9       raeburn  1556:         if ($switchserver) {
                   1557:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   1558:         } else {
1.135     bisitz   1559:             if ($img ne 'login') { # suppress file selection for Log-in header
                   1560:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                   1561:             }
1.9       raeburn  1562:         }
                   1563:         $datatable .= '</td></tr>';
1.6       raeburn  1564:     }
                   1565:     $itemcount ++;
                   1566:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1567:     $datatable .= '<tr'.$css_class.'>'.
                   1568:                   '<td>'.$choices->{'bgs'}.'</td>';
                   1569:     my $bgs_def;
                   1570:     foreach my $item (@{$bgs}) {
                   1571:         if (!$is_custom->{$item}) {
1.70      raeburn  1572:             $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  1573:         }
                   1574:     }
                   1575:     if ($bgs_def) {
1.8       raeburn  1576:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn  1577:     } else {
                   1578:         $datatable .= '<td>&nbsp;</td>';
                   1579:     }
                   1580:     $datatable .= '<td class="LC_right_item">'.
                   1581:                   '<table border="0"><tr>';
1.174     foxr     1582: 
1.6       raeburn  1583:     foreach my $item (@{$bgs}) {
1.201     raeburn  1584:         $datatable .= '<td align="center">'.$choices->{$item};
1.174     foxr     1585: 	my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6       raeburn  1586:         if ($designs->{'bgs'}{$item}) {
1.174     foxr     1587:             $datatable .= '&nbsp;';
1.6       raeburn  1588:         }
1.174     foxr     1589:         $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41      raeburn  1590:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6       raeburn  1591:     }
                   1592:     $datatable .= '</tr></table></td></tr>';
                   1593:     $itemcount ++;
                   1594:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   1595:     $datatable .= '<tr'.$css_class.'>'.
                   1596:                   '<td>'.$choices->{'links'}.'</td>';
                   1597:     my $links_def;
                   1598:     foreach my $item (@{$links}) {
                   1599:         if (!$is_custom->{$item}) {
1.30      raeburn  1600:             $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  1601:         }
                   1602:     }
                   1603:     if ($links_def) {
1.8       raeburn  1604:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn  1605:     } else {
                   1606:         $datatable .= '<td>&nbsp;</td>';
                   1607:     }
                   1608:     $datatable .= '<td class="LC_right_item">'.
                   1609:                   '<table border="0"><tr>';
                   1610:     foreach my $item (@{$links}) {
1.234     raeburn  1611: 	my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.201     raeburn  1612:         $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6       raeburn  1613:         if ($designs->{'links'}{$item}) {
1.174     foxr     1614:             $datatable.='&nbsp;';
1.6       raeburn  1615:         }
1.174     foxr     1616:         $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6       raeburn  1617:                       '" /></td>';
                   1618:     }
1.30      raeburn  1619:     $$rowtotal += $itemcount;
1.3       raeburn  1620:     return $datatable;
                   1621: }
                   1622: 
1.70      raeburn  1623: sub logo_display_options {
                   1624:     my ($img,$defaults,$designs) = @_;
                   1625:     my $checkedon;
                   1626:     if (ref($defaults) eq 'HASH') {
                   1627:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
                   1628:             if ($defaults->{'showlogo'}{$img}) {
                   1629:                 $checkedon = 'checked="checked" ';     
                   1630:             }
                   1631:         } 
                   1632:     }
                   1633:     if (ref($designs) eq 'HASH') {
                   1634:         if (ref($designs->{'showlogo'}) eq 'HASH') {
                   1635:             if (defined($designs->{'showlogo'}{$img})) {
                   1636:                 if ($designs->{'showlogo'}{$img} == 0) {
                   1637:                     $checkedon = '';
                   1638:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
                   1639:                     $checkedon = 'checked="checked" ';
                   1640:                 }
                   1641:             }
                   1642:         }
                   1643:     }
                   1644:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
                   1645:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
                   1646:            &mt('show').'</label>'."\n";
                   1647: }
                   1648: 
1.41      raeburn  1649: sub login_header_options  {
1.135     bisitz   1650:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
                   1651:     my $output = '';
1.41      raeburn  1652:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135     bisitz   1653:         $output .= &mt('Text default(s):').'<br />';
1.41      raeburn  1654:         if (!$is_custom->{'textcol'}) {
                   1655:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
                   1656:                        '&nbsp;&nbsp;&nbsp;';
                   1657:         }
                   1658:         if (!$is_custom->{'bgcol'}) {
                   1659:             $output .= $choices->{'bgcol'}.':&nbsp;'.
                   1660:                        '<span id="css_'.$role.'_font" style="background-color: '.
                   1661:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
                   1662:         }
                   1663:         $output .= '<br />';
                   1664:     }
                   1665:     $output .='<br />';
                   1666:     return $output;
                   1667: }
                   1668: 
                   1669: sub login_text_colors {
1.201     raeburn  1670:     my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41      raeburn  1671:     my $color_menu = '<table border="0"><tr>';
                   1672:     foreach my $item (@{$logintext}) {
1.201     raeburn  1673:         $color_menu .= '<td align="center">'.$choices->{$item};
                   1674:         my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
                   1675:         $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
                   1676:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41      raeburn  1677:     }
                   1678:     $color_menu .= '</tr></table><br />';
                   1679:     return $color_menu;
                   1680: }
                   1681: 
                   1682: sub image_changes {
                   1683:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
                   1684:     my $output;
1.135     bisitz   1685:     if ($img eq 'login') {
                   1686:             # suppress image for Log-in header
                   1687:     } elsif (!$is_custom) {
1.70      raeburn  1688:         if ($img ne 'domlogo') {
1.41      raeburn  1689:             $output .= &mt('Default image:').'<br />';
                   1690:         } else {
                   1691:             $output .= &mt('Default in use:').'<br />';
                   1692:         }
                   1693:     }
1.135     bisitz   1694:     if ($img eq 'login') { # suppress image for Log-in header
                   1695:         $output .= '<td>'.$logincolors;
1.41      raeburn  1696:     } else {
1.135     bisitz   1697:         if ($img_import) {
                   1698:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                   1699:         }
                   1700:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                   1701:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
                   1702:         if ($is_custom) {
                   1703:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
                   1704:                        '<input type="checkbox" name="'.
                   1705:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                   1706:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
                   1707:         } else {
1.201     raeburn  1708:             $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135     bisitz   1709:         }
1.41      raeburn  1710:     }
                   1711:     return $output;
                   1712: }
                   1713: 
1.3       raeburn  1714: sub print_quotas {
1.86      raeburn  1715:     my ($dom,$settings,$rowtotal,$action) = @_;
                   1716:     my $context;
                   1717:     if ($action eq 'quotas') {
                   1718:         $context = 'tools';
                   1719:     } else {
                   1720:         $context = $action;
                   1721:     }
1.197     raeburn  1722:     my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44      raeburn  1723:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3       raeburn  1724:     my $typecount = 0;
1.101     raeburn  1725:     my ($css_class,%titles);
1.86      raeburn  1726:     if ($context eq 'requestcourses') {
1.271     raeburn  1727:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  1728:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  1729:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   1730:         %titles = &courserequest_titles();
1.163     raeburn  1731:     } elsif ($context eq 'requestauthor') {
                   1732:         @usertools = ('author');
                   1733:         @options = ('norequest','approval','automatic');
1.210     raeburn  1734:         %titles = &authorrequest_titles();
1.86      raeburn  1735:     } else {
1.162     raeburn  1736:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  1737:         %titles = &tool_titles();
1.86      raeburn  1738:     }
1.26      raeburn  1739:     if (ref($types) eq 'ARRAY') {
1.23      raeburn  1740:         foreach my $type (@{$types}) {
1.197     raeburn  1741:             my ($currdefquota,$currauthorquota);
1.163     raeburn  1742:             unless (($context eq 'requestcourses') ||
                   1743:                     ($context eq 'requestauthor')) {
1.86      raeburn  1744:                 if (ref($settings) eq 'HASH') {
                   1745:                     if (ref($settings->{defaultquota}) eq 'HASH') {
1.197     raeburn  1746:                         $currdefquota = $settings->{defaultquota}->{$type};
1.86      raeburn  1747:                     } else {
                   1748:                         $currdefquota = $settings->{$type};
                   1749:                     }
1.197     raeburn  1750:                     if (ref($settings->{authorquota}) eq 'HASH') {
                   1751:                         $currauthorquota = $settings->{authorquota}->{$type};
                   1752:                     }
1.78      raeburn  1753:                 }
1.72      raeburn  1754:             }
1.3       raeburn  1755:             if (defined($usertypes->{$type})) {
                   1756:                 $typecount ++;
                   1757:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72      raeburn  1758:                 $datatable .= '<tr'.$css_class.'>'.
1.3       raeburn  1759:                               '<td>'.$usertypes->{$type}.'</td>'.
1.72      raeburn  1760:                               '<td class="LC_left_item">';
1.101     raeburn  1761:                 if ($context eq 'requestcourses') {
                   1762:                     $datatable .= '<table><tr>';
                   1763:                 }
                   1764:                 my %cell;  
1.72      raeburn  1765:                 foreach my $item (@usertools) {
1.101     raeburn  1766:                     if ($context eq 'requestcourses') {
                   1767:                         my ($curroption,$currlimit);
                   1768:                         if (ref($settings) eq 'HASH') {
                   1769:                             if (ref($settings->{$item}) eq 'HASH') {
                   1770:                                 $curroption = $settings->{$item}->{$type};
                   1771:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
                   1772:                                     $currlimit = $1; 
                   1773:                                 }
                   1774:                             }
                   1775:                         }
                   1776:                         if (!$curroption) {
                   1777:                             $curroption = 'norequest';
                   1778:                         }
                   1779:                         $datatable .= '<th>'.$titles{$item}.'</th>';
                   1780:                         foreach my $option (@options) {
                   1781:                             my $val = $option;
                   1782:                             if ($option eq 'norequest') {
                   1783:                                 $val = 0;  
                   1784:                             }
                   1785:                             if ($option eq 'validate') {
                   1786:                                 my $canvalidate = 0;
                   1787:                                 if (ref($validations{$item}) eq 'HASH') { 
                   1788:                                     if ($validations{$item}{$type}) {
                   1789:                                         $canvalidate = 1;
                   1790:                                     }
                   1791:                                 }
                   1792:                                 next if (!$canvalidate);
                   1793:                             }
                   1794:                             my $checked = '';
                   1795:                             if ($option eq $curroption) {
                   1796:                                 $checked = ' checked="checked"';
                   1797:                             } elsif ($option eq 'autolimit') {
                   1798:                                 if ($curroption =~ /^autolimit/) {
                   1799:                                     $checked = ' checked="checked"';
                   1800:                                 }                       
                   1801:                             } 
                   1802:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
                   1803:                                   '<input type="radio" name="crsreq_'.$item.
                   1804:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127     raeburn  1805:                                   $titles{$option}.'</label>';
1.101     raeburn  1806:                             if ($option eq 'autolimit') {
1.127     raeburn  1807:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1808:                                                 $item.'_limit_'.$type.'" size="1" '.
1.103     raeburn  1809:                                                 'value="'.$currlimit.'" />';
1.101     raeburn  1810:                             }
1.127     raeburn  1811:                             $cell{$item} .= '</span> ';
1.103     raeburn  1812:                             if ($option eq 'autolimit') {
1.127     raeburn  1813:                                 $cell{$item} .= $titles{'unlimited'};
1.103     raeburn  1814:                             }
1.101     raeburn  1815:                         }
1.163     raeburn  1816:                     } elsif ($context eq 'requestauthor') {
                   1817:                         my $curroption;
                   1818:                         if (ref($settings) eq 'HASH') {
                   1819:                             $curroption = $settings->{$type};
                   1820:                         }
                   1821:                         if (!$curroption) {
                   1822:                             $curroption = 'norequest';
                   1823:                         }
                   1824:                         foreach my $option (@options) {
                   1825:                             my $val = $option;
                   1826:                             if ($option eq 'norequest') {
                   1827:                                 $val = 0;
                   1828:                             }
                   1829:                             my $checked = '';
                   1830:                             if ($option eq $curroption) {
                   1831:                                 $checked = ' checked="checked"';
                   1832:                             }
                   1833:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   1834:                                   '<input type="radio" name="authorreq_'.$type.
                   1835:                                   '" value="'.$val.'"'.$checked.' />'.
                   1836:                                   $titles{$option}.'</label></span>&nbsp; ';
                   1837:                         }
1.101     raeburn  1838:                     } else {
                   1839:                         my $checked = 'checked="checked" ';
                   1840:                         if (ref($settings) eq 'HASH') {
                   1841:                             if (ref($settings->{$item}) eq 'HASH') {
                   1842:                                 if ($settings->{$item}->{$type} == 0) {
                   1843:                                     $checked = '';
                   1844:                                 } elsif ($settings->{$item}->{$type} == 1) {
                   1845:                                     $checked =  'checked="checked" ';
                   1846:                                 }
1.78      raeburn  1847:                             }
1.72      raeburn  1848:                         }
1.101     raeburn  1849:                         $datatable .= '<span class="LC_nobreak"><label>'.
                   1850:                                       '<input type="checkbox" name="'.$context.'_'.$item.
                   1851:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                   1852:                                       '</label></span>&nbsp; ';
1.72      raeburn  1853:                     }
1.101     raeburn  1854:                 }
                   1855:                 if ($context eq 'requestcourses') {
                   1856:                     $datatable .= '</tr><tr>';
                   1857:                     foreach my $item (@usertools) {
1.106     raeburn  1858:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
1.101     raeburn  1859:                     }
                   1860:                     $datatable .= '</tr></table>';
1.72      raeburn  1861:                 }
1.86      raeburn  1862:                 $datatable .= '</td>';
1.163     raeburn  1863:                 unless (($context eq 'requestcourses') ||
                   1864:                         ($context eq 'requestauthor')) {
1.86      raeburn  1865:                     $datatable .= 
1.197     raeburn  1866:                               '<td class="LC_right_item">'.
                   1867:                               '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.3       raeburn  1868:                               '<input type="text" name="quota_'.$type.
1.72      raeburn  1869:                               '" value="'.$currdefquota.
1.197     raeburn  1870:                               '" size="5" /></span>'.('&nbsp;' x 2).
                   1871:                               '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   1872:                               '<input type="text" name="authorquota_'.$type.
                   1873:                               '" value="'.$currauthorquota.
                   1874:                               '" size="5" /></span></td>';
1.86      raeburn  1875:                 }
                   1876:                 $datatable .= '</tr>';
1.3       raeburn  1877:             }
                   1878:         }
                   1879:     }
1.163     raeburn  1880:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  1881:         $defaultquota = '20';
1.197     raeburn  1882:         $authorquota = '500';
1.86      raeburn  1883:         if (ref($settings) eq 'HASH') {
                   1884:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   1885:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
                   1886:             } elsif (defined($settings->{'default'})) {
                   1887:                 $defaultquota = $settings->{'default'};
                   1888:             }
1.197     raeburn  1889:             if (ref($settings->{'authorquota'}) eq 'HASH') {
                   1890:                 $authorquota = $settings->{'authorquota'}->{'default'};
                   1891:             }
1.3       raeburn  1892:         }
                   1893:     }
                   1894:     $typecount ++;
                   1895:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   1896:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn  1897:                   '<td>'.$othertitle.'</td>'.
1.72      raeburn  1898:                   '<td class="LC_left_item">';
1.101     raeburn  1899:     if ($context eq 'requestcourses') {
                   1900:         $datatable .= '<table><tr>';
                   1901:     }
                   1902:     my %defcell;
1.72      raeburn  1903:     foreach my $item (@usertools) {
1.101     raeburn  1904:         if ($context eq 'requestcourses') {
                   1905:             my ($curroption,$currlimit);
                   1906:             if (ref($settings) eq 'HASH') {
                   1907:                 if (ref($settings->{$item}) eq 'HASH') {
                   1908:                     $curroption = $settings->{$item}->{'default'};
                   1909:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   1910:                         $currlimit = $1;
                   1911:                     }
                   1912:                 }
                   1913:             }
                   1914:             if (!$curroption) {
                   1915:                 $curroption = 'norequest';
                   1916:             }
                   1917:             $datatable .= '<th>'.$titles{$item}.'</th>';
                   1918:             foreach my $option (@options) {
                   1919:                 my $val = $option;
                   1920:                 if ($option eq 'norequest') {
                   1921:                     $val = 0;
                   1922:                 }
                   1923:                 if ($option eq 'validate') {
                   1924:                     my $canvalidate = 0;
                   1925:                     if (ref($validations{$item}) eq 'HASH') {
                   1926:                         if ($validations{$item}{'default'}) {
                   1927:                             $canvalidate = 1;
                   1928:                         }
                   1929:                     }
                   1930:                     next if (!$canvalidate);
                   1931:                 }
                   1932:                 my $checked = '';
                   1933:                 if ($option eq $curroption) {
                   1934:                     $checked = ' checked="checked"';
                   1935:                 } elsif ($option eq 'autolimit') {
                   1936:                     if ($curroption =~ /^autolimit/) {
                   1937:                         $checked = ' checked="checked"';
                   1938:                     }
                   1939:                 }
                   1940:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
                   1941:                                   '<input type="radio" name="crsreq_'.$item.
                   1942:                                   '_default" value="'.$val.'"'.$checked.' />'.
                   1943:                                   $titles{$option}.'</label>';
                   1944:                 if ($option eq 'autolimit') {
1.127     raeburn  1945:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  1946:                                        $item.'_limit_default" size="1" '.
                   1947:                                        'value="'.$currlimit.'" />';
                   1948:                 }
1.127     raeburn  1949:                 $defcell{$item} .= '</span> ';
1.104     raeburn  1950:                 if ($option eq 'autolimit') {
1.127     raeburn  1951:                     $defcell{$item} .= $titles{'unlimited'};
1.104     raeburn  1952:                 }
1.101     raeburn  1953:             }
1.163     raeburn  1954:         } elsif ($context eq 'requestauthor') {
                   1955:             my $curroption;
                   1956:             if (ref($settings) eq 'HASH') {
1.172     raeburn  1957:                 $curroption = $settings->{'default'};
1.163     raeburn  1958:             }
                   1959:             if (!$curroption) {
                   1960:                 $curroption = 'norequest';
                   1961:             }
                   1962:             foreach my $option (@options) {
                   1963:                 my $val = $option;
                   1964:                 if ($option eq 'norequest') {
                   1965:                     $val = 0;
                   1966:                 }
                   1967:                 my $checked = '';
                   1968:                 if ($option eq $curroption) {
                   1969:                     $checked = ' checked="checked"';
                   1970:                 }
                   1971:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1972:                               '<input type="radio" name="authorreq_default"'.
                   1973:                               ' value="'.$val.'"'.$checked.' />'.
                   1974:                               $titles{$option}.'</label></span>&nbsp; ';
                   1975:             }
1.101     raeburn  1976:         } else {
                   1977:             my $checked = 'checked="checked" ';
                   1978:             if (ref($settings) eq 'HASH') {
                   1979:                 if (ref($settings->{$item}) eq 'HASH') {
                   1980:                     if ($settings->{$item}->{'default'} == 0) {
                   1981:                         $checked = '';
                   1982:                     } elsif ($settings->{$item}->{'default'} == 1) {
                   1983:                         $checked = 'checked="checked" ';
                   1984:                     }
1.78      raeburn  1985:                 }
1.72      raeburn  1986:             }
1.101     raeburn  1987:             $datatable .= '<span class="LC_nobreak"><label>'.
                   1988:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   1989:                           '" value="default" '.$checked.'/>'.$titles{$item}.
                   1990:                           '</label></span>&nbsp; ';
                   1991:         }
                   1992:     }
                   1993:     if ($context eq 'requestcourses') {
                   1994:         $datatable .= '</tr><tr>';
                   1995:         foreach my $item (@usertools) {
1.106     raeburn  1996:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72      raeburn  1997:         }
1.101     raeburn  1998:         $datatable .= '</tr></table>';
1.72      raeburn  1999:     }
1.86      raeburn  2000:     $datatable .= '</td>';
1.163     raeburn  2001:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197     raeburn  2002:         $datatable .= '<td class="LC_right_item">'.
                   2003:                       '<span class="LC_nobreak">'.&mt('Portfolio').':&nbsp;'.
1.86      raeburn  2004:                       '<input type="text" name="defaultquota" value="'.
1.197     raeburn  2005:                       $defaultquota.'" size="5" /></span>'.('&nbsp;' x2).
                   2006:                       '<span class="LC_nobreak">'.&mt('Authoring').':&nbsp;'.
                   2007:                       '<input type="text" name="authorquota" value="'.
                   2008:                       $authorquota.'" size="5" /></span></td>';
1.86      raeburn  2009:     }
                   2010:     $datatable .= '</tr>';
1.72      raeburn  2011:     $typecount ++;
                   2012:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                   2013:     $datatable .= '<tr'.$css_class.'>'.
1.197     raeburn  2014:                   '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104     raeburn  2015:     if ($context eq 'requestcourses') {
1.109     raeburn  2016:         $datatable .= &mt('(overrides affiliation, if set)').
                   2017:                       '</td>'.
                   2018:                       '<td class="LC_left_item">'.
                   2019:                       '<table><tr>';
1.101     raeburn  2020:     } else {
1.109     raeburn  2021:         $datatable .= &mt('(overrides affiliation, if checked)').
                   2022:                       '</td>'.
                   2023:                       '<td class="LC_left_item" colspan="2">'.
                   2024:                       '<br />';
1.101     raeburn  2025:     }
                   2026:     my %advcell;
1.72      raeburn  2027:     foreach my $item (@usertools) {
1.101     raeburn  2028:         if ($context eq 'requestcourses') {
                   2029:             my ($curroption,$currlimit);
                   2030:             if (ref($settings) eq 'HASH') {
                   2031:                 if (ref($settings->{$item}) eq 'HASH') {
                   2032:                     $curroption = $settings->{$item}->{'_LC_adv'};
                   2033:                     if ($curroption =~ /^autolimit=(\d*)$/) {
                   2034:                         $currlimit = $1;
                   2035:                     }
                   2036:                 }
                   2037:             }
                   2038:             $datatable .= '<th>'.$titles{$item}.'</th>';
1.104     raeburn  2039:             my $checked = '';
                   2040:             if ($curroption eq '') {
                   2041:                 $checked = ' checked="checked"';
                   2042:             }
                   2043:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2044:                                '<input type="radio" name="crsreq_'.$item.
                   2045:                                '__LC_adv" value=""'.$checked.' />'.
                   2046:                                &mt('No override set').'</label></span>&nbsp; ';
1.101     raeburn  2047:             foreach my $option (@options) {
                   2048:                 my $val = $option;
                   2049:                 if ($option eq 'norequest') {
                   2050:                     $val = 0;
                   2051:                 }
                   2052:                 if ($option eq 'validate') {
                   2053:                     my $canvalidate = 0;
                   2054:                     if (ref($validations{$item}) eq 'HASH') {
                   2055:                         if ($validations{$item}{'_LC_adv'}) {
                   2056:                             $canvalidate = 1;
                   2057:                         }
                   2058:                     }
                   2059:                     next if (!$canvalidate);
                   2060:                 }
                   2061:                 my $checked = '';
1.104     raeburn  2062:                 if ($val eq $curroption) {
1.101     raeburn  2063:                     $checked = ' checked="checked"';
                   2064:                 } elsif ($option eq 'autolimit') {
                   2065:                     if ($curroption =~ /^autolimit/) {
                   2066:                         $checked = ' checked="checked"';
                   2067:                     }
                   2068:                 }
                   2069:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
                   2070:                                   '<input type="radio" name="crsreq_'.$item.
                   2071:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
                   2072:                                   $titles{$option}.'</label>';
                   2073:                 if ($option eq 'autolimit') {
1.127     raeburn  2074:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
1.101     raeburn  2075:                                        $item.'_limit__LC_adv" size="1" '.
                   2076:                                        'value="'.$currlimit.'" />';
                   2077:                 }
1.127     raeburn  2078:                 $advcell{$item} .= '</span> ';
1.104     raeburn  2079:                 if ($option eq 'autolimit') {
1.127     raeburn  2080:                     $advcell{$item} .= $titles{'unlimited'};
1.104     raeburn  2081:                 }
1.101     raeburn  2082:             }
1.163     raeburn  2083:         } elsif ($context eq 'requestauthor') {
                   2084:             my $curroption;
                   2085:             if (ref($settings) eq 'HASH') {
                   2086:                 $curroption = $settings->{'_LC_adv'};
                   2087:             }
                   2088:             my $checked = '';
                   2089:             if ($curroption eq '') {
                   2090:                 $checked = ' checked="checked"';
                   2091:             }
                   2092:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2093:                           '<input type="radio" name="authorreq__LC_adv"'.
                   2094:                           ' value=""'.$checked.' />'.
                   2095:                           &mt('No override set').'</label></span>&nbsp; ';
                   2096:             foreach my $option (@options) {
                   2097:                 my $val = $option;
                   2098:                 if ($option eq 'norequest') {
                   2099:                     $val = 0;
                   2100:                 }
                   2101:                 my $checked = '';
                   2102:                 if ($val eq $curroption) {
                   2103:                     $checked = ' checked="checked"';
                   2104:                 }
                   2105:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.173     raeburn  2106:                               '<input type="radio" name="authorreq__LC_adv"'.
                   2107:                               ' value="'.$val.'"'.$checked.' />'.
1.163     raeburn  2108:                               $titles{$option}.'</label></span>&nbsp; ';
                   2109:             }
1.101     raeburn  2110:         } else {
                   2111:             my $checked = 'checked="checked" ';
                   2112:             if (ref($settings) eq 'HASH') {
                   2113:                 if (ref($settings->{$item}) eq 'HASH') {
                   2114:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
                   2115:                         $checked = '';
                   2116:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                   2117:                         $checked = 'checked="checked" ';
                   2118:                     }
1.79      raeburn  2119:                 }
1.72      raeburn  2120:             }
1.101     raeburn  2121:             $datatable .= '<span class="LC_nobreak"><label>'.
                   2122:                           '<input type="checkbox" name="'.$context.'_'.$item.
                   2123:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                   2124:                           '</label></span>&nbsp; ';
                   2125:         }
                   2126:     }
                   2127:     if ($context eq 'requestcourses') {
                   2128:         $datatable .= '</tr><tr>';
                   2129:         foreach my $item (@usertools) {
1.106     raeburn  2130:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72      raeburn  2131:         }
1.101     raeburn  2132:         $datatable .= '</tr></table>';
1.72      raeburn  2133:     }
1.98      raeburn  2134:     $datatable .= '</td></tr>';
1.30      raeburn  2135:     $$rowtotal += $typecount;
1.3       raeburn  2136:     return $datatable;
                   2137: }
                   2138: 
1.163     raeburn  2139: sub print_requestmail {
                   2140:     my ($dom,$action,$settings,$rowtotal) = @_;
1.208     raeburn  2141:     my ($now,$datatable,%currapp);
1.102     raeburn  2142:     $now = time;
                   2143:     if (ref($settings) eq 'HASH') {
                   2144:         if (ref($settings->{'notify'}) eq 'HASH') {
                   2145:             if ($settings->{'notify'}{'approval'} ne '') {
1.224     raeburn  2146:                 map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102     raeburn  2147:             }
                   2148:         }
                   2149:     }
1.191     raeburn  2150:     my $numinrow = 2;
1.224     raeburn  2151:     my $css_class;
                   2152:     $css_class = ($$rowtotal%2? ' class="LC_odd_row"':'');
1.163     raeburn  2153:     my $text;
                   2154:     if ($action eq 'requestcourses') {
                   2155:         $text = &mt('Receive notification of course requests requiring approval');
1.224     raeburn  2156:     } elsif ($action eq 'requestauthor') {
                   2157:         $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163     raeburn  2158:     } else {
1.224     raeburn  2159:        $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163     raeburn  2160:     }
1.224     raeburn  2161:     $datatable = '<tr'.$css_class.'>'.
1.163     raeburn  2162:                  ' <td>'.$text.'</td>'.
1.102     raeburn  2163:                  ' <td class="LC_left_item">';
1.191     raeburn  2164:     my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224     raeburn  2165:                                                  $action.'notifyapproval',%currapp);
1.191     raeburn  2166:     if ($numdc > 0) {
                   2167:         $datatable .= $table;
1.102     raeburn  2168:     } else {
                   2169:         $datatable .= &mt('There are no active Domain Coordinators');
                   2170:     }
                   2171:     $datatable .='</td></tr>';
                   2172:     return $datatable;
                   2173: }
                   2174: 
1.216     raeburn  2175: sub print_studentcode {
                   2176:     my ($settings,$rowtotal) = @_;
                   2177:     my $rownum = 0; 
1.218     raeburn  2178:     my ($output,%current);
1.271     raeburn  2179:     my @crstypes = ('official','unofficial','community','textbook','placement');
1.248     raeburn  2180:     if (ref($settings) eq 'HASH') {
                   2181:         if (ref($settings->{'uniquecode'}) eq 'HASH') {
                   2182:             foreach my $type (@crstypes) {
                   2183:                 $current{$type} = $settings->{'uniquecode'}{$type};
                   2184:             }
1.218     raeburn  2185:         }
                   2186:     }
                   2187:     $output .= '<tr>'.
                   2188:                '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
                   2189:                '<td class="LC_left_item">';
                   2190:     foreach my $type (@crstypes) {
                   2191:         my $check = ' ';
                   2192:         if ($current{$type}) {
                   2193:             $check = ' checked="checked" ';
                   2194:         }
                   2195:         $output .= '<span class="LC_nobreak"><label>'.
                   2196:                    '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
                   2197:                    &mt($type).'</label></span>'.('&nbsp;'x2).' ';
                   2198:     }
                   2199:     $output .= '</td></tr>';
                   2200:     $$rowtotal ++;
                   2201:     return $output;
1.216     raeburn  2202: }
                   2203: 
                   2204: sub print_textbookcourses {
1.242     raeburn  2205:     my ($dom,$type,$settings,$rowtotal) = @_;
1.216     raeburn  2206:     my $rownum = 0;
                   2207:     my $css_class;
                   2208:     my $itemcount = 1;
                   2209:     my $maxnum = 0;
                   2210:     my $bookshash;
                   2211:     if (ref($settings) eq 'HASH') {
1.242     raeburn  2212:         $bookshash = $settings->{$type};
1.216     raeburn  2213:     }
                   2214:     my %ordered;
                   2215:     if (ref($bookshash) eq 'HASH') {
                   2216:         foreach my $item (keys(%{$bookshash})) {
                   2217:             if (ref($bookshash->{$item}) eq 'HASH') {
                   2218:                 my $num = $bookshash->{$item}{'order'};
                   2219:                 $ordered{$num} = $item;
                   2220:             }
                   2221:         }
                   2222:     }
                   2223:     my $confname = $dom.'-domainconfig';
                   2224:     my $switchserver = &check_switchserver($dom,$confname);
1.242     raeburn  2225:     my $maxnum = scalar(keys(%ordered));
                   2226:     my $datatable;
1.216     raeburn  2227:     if (keys(%ordered)) {
                   2228:         my @items = sort { $a <=> $b } keys(%ordered);
                   2229:         for (my $i=0; $i<@items; $i++) {
                   2230:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   2231:             my $key = $ordered{$items[$i]};
                   2232:             my %coursehash=&Apache::lonnet::coursedescription($key);
                   2233:             my $coursetitle = $coursehash{'description'};
1.243     raeburn  2234:             my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216     raeburn  2235:             if (ref($bookshash->{$key}) eq 'HASH') {
                   2236:                 $subject = $bookshash->{$key}->{'subject'};
                   2237:                 $title = $bookshash->{$key}->{'title'};
1.242     raeburn  2238:                 if ($type eq 'textbooks') {
1.243     raeburn  2239:                     $publisher = $bookshash->{$key}->{'publisher'};
1.242     raeburn  2240:                     $author = $bookshash->{$key}->{'author'};
                   2241:                     $image = $bookshash->{$key}->{'image'};
                   2242:                     if ($image ne '') {
                   2243:                         my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
                   2244:                         my $imagethumb = "$path/tn-".$imagefile;
                   2245:                         $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
                   2246:                     }
1.216     raeburn  2247:                 }
                   2248:             }
1.242     raeburn  2249:             my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216     raeburn  2250:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242     raeburn  2251:                          .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216     raeburn  2252:             for (my $k=0; $k<=$maxnum; $k++) {
                   2253:                 my $vpos = $k+1;
                   2254:                 my $selstr;
                   2255:                 if ($k == $i) {
                   2256:                     $selstr = ' selected="selected" ';
                   2257:                 }
                   2258:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2259:             }
                   2260:             $datatable .= '</select>'.('&nbsp;'x2).
1.242     raeburn  2261:                 '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216     raeburn  2262:                 &mt('Delete?').'</label></span></td>'.
                   2263:                 '<td colspan="2">'.
1.242     raeburn  2264:                 '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216     raeburn  2265:                 ('&nbsp;'x2).
1.242     raeburn  2266:                 '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
                   2267:             if ($type eq 'textbooks') {
                   2268:                 $datatable .= ('&nbsp;'x2).
1.243     raeburn  2269:                               '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
                   2270:                               ('&nbsp;'x2).
1.242     raeburn  2271:                               '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
                   2272:                               ('&nbsp;'x2).
                   2273:                               '<span class="LC_nobreak">'.&mt('Thumbnail:');
                   2274:                 if ($image) {
1.267     raeburn  2275:                     $datatable .= $imgsrc.
1.242     raeburn  2276:                                   '<label><input type="checkbox" name="'.$type.'_image_del"'.
                   2277:                                   ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
                   2278:                                   '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   2279:                 }
                   2280:                 if ($switchserver) {
                   2281:                     $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2282:                 } else {
                   2283:                     $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
                   2284:                 }
1.216     raeburn  2285:             }
1.242     raeburn  2286:             $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216     raeburn  2287:                           '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   2288:                           $coursetitle.'</span></td></tr>'."\n";
                   2289:             $itemcount ++;
                   2290:         }
                   2291:     }
                   2292:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242     raeburn  2293:     my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216     raeburn  2294:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242     raeburn  2295:                   '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
                   2296:                   '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216     raeburn  2297:     for (my $k=0; $k<$maxnum+1; $k++) {
                   2298:         my $vpos = $k+1;
                   2299:         my $selstr;
                   2300:         if ($k == $maxnum) {
                   2301:             $selstr = ' selected="selected" ';
                   2302:         }
                   2303:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   2304:     }
                   2305:     $datatable .= '</select>&nbsp;'."\n".
1.242     raeburn  2306:                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".
1.216     raeburn  2307:                   '<td colspan="2">'.
1.242     raeburn  2308:                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216     raeburn  2309:                   ('&nbsp;'x2).
1.242     raeburn  2310:                   '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
                   2311:                   ('&nbsp;'x2);
                   2312:     if ($type eq 'textbooks') {
1.243     raeburn  2313:         $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
                   2314:                       ('&nbsp;'x2).
                   2315:                       '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242     raeburn  2316:                       ('&nbsp;'x2).
                   2317:                       '<span class="LC_nobreak">'.&mt('Image:').'&nbsp;';
                   2318:         if ($switchserver) {
                   2319:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   2320:         } else {
                   2321:             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
                   2322:         }
1.216     raeburn  2323:     }
                   2324:     $datatable .= '</span>'."\n".
                   2325:                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
1.242     raeburn  2326:                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   2327:                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216     raeburn  2328:                   &Apache::loncommon::selectcourse_link
1.242     raeburn  2329:                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');
1.216     raeburn  2330:                   '</span></td>'."\n".
                   2331:                   '</tr>'."\n";
                   2332:     $itemcount ++;
                   2333:     return $datatable;
                   2334: }
                   2335: 
1.217     raeburn  2336: sub textbookcourses_javascript {
1.242     raeburn  2337:     my ($settings) = @_;
                   2338:     return unless(ref($settings) eq 'HASH');
                   2339:     my (%ordered,%total,%jstext);
                   2340:     foreach my $type ('textbooks','templates') {
                   2341:         $total{$type} = 0;
                   2342:         if (ref($settings->{$type}) eq 'HASH') {
                   2343:             foreach my $item (keys(%{$settings->{$type}})) {
                   2344:                 if (ref($settings->{$type}->{$item}) eq 'HASH') {
                   2345:                     my $num = $settings->{$type}->{$item}{'order'};
                   2346:                     $ordered{$type}{$num} = $item;
                   2347:                 }
                   2348:             }
                   2349:             $total{$type} = scalar(keys(%{$settings->{$type}}));
                   2350:         }
                   2351:         my @jsarray = ();
                   2352:         foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
                   2353:             push(@jsarray,$ordered{$type}{$item});
                   2354:         }
                   2355:         $jstext{$type} = '    var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217     raeburn  2356:     }
                   2357:     return <<"ENDSCRIPT";
                   2358: <script type="text/javascript">
                   2359: // <![CDATA[
1.242     raeburn  2360: function reorderBooks(form,item,caller) {
1.217     raeburn  2361:     var changedVal;
1.242     raeburn  2362: $jstext{'textbooks'};
                   2363: $jstext{'templates'};
                   2364:     var newpos;
                   2365:     var maxh;
                   2366:     if (caller == 'textbooks') {  
                   2367:         newpos = 'textbooks_addbook_pos';
                   2368:         maxh = 1 + $total{'textbooks'};
                   2369:     } else {
                   2370:         newpos = 'templates_addbook_pos';
                   2371:         maxh = 1 + $total{'templates'};
                   2372:     }
1.217     raeburn  2373:     var current = new Array;
                   2374:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2375:     if (item == newpos) {
                   2376:         changedVal = newitemVal;
                   2377:     } else {
                   2378:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2379:         current[newitemVal] = newpos;
                   2380:     }
1.242     raeburn  2381:     if (caller == 'textbooks') {
                   2382:         for (var i=0; i<textbooks.length; i++) {
                   2383:             var elementName = 'textbooks_'+textbooks[i];
                   2384:             if (elementName != item) {
                   2385:                 if (form.elements[elementName]) {
                   2386:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2387:                     current[currVal] = elementName;
                   2388:                 }
                   2389:             }
                   2390:         }
                   2391:     }
                   2392:     if (caller == 'templates') {
                   2393:         for (var i=0; i<templates.length; i++) {
                   2394:             var elementName = 'templates_'+templates[i];
                   2395:             if (elementName != item) {
                   2396:                 if (form.elements[elementName]) {
                   2397:                     var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2398:                     current[currVal] = elementName;
                   2399:                 }
1.217     raeburn  2400:             }
                   2401:         }
                   2402:     }
                   2403:     var oldVal;
                   2404:     for (var j=0; j<maxh; j++) {
                   2405:         if (current[j] == undefined) {
                   2406:             oldVal = j;
                   2407:         }
                   2408:     }
                   2409:     if (oldVal < changedVal) {
                   2410:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2411:            var elementName = current[k];
                   2412:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2413:         }
                   2414:     } else {
                   2415:         for (var k=changedVal; k<oldVal; k++) {
                   2416:             var elementName = current[k];
                   2417:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2418:         }
                   2419:     }
                   2420:     return;
                   2421: }
                   2422: 
                   2423: // ]]>
                   2424: </script>
                   2425: 
                   2426: ENDSCRIPT
                   2427: }
                   2428: 
1.267     raeburn  2429: sub ltitools_javascript {
                   2430:     my ($settings) = @_;
                   2431:     return unless(ref($settings) eq 'HASH');
                   2432:     my (%ordered,$total,%jstext);
                   2433:     $total = 0;
                   2434:     foreach my $item (keys(%{$settings})) {
                   2435:         if (ref($settings->{$item}) eq 'HASH') {
                   2436:             my $num = $settings->{$item}{'order'};
                   2437:             $ordered{$num} = $item;
                   2438:         }
                   2439:     }
                   2440:     $total = scalar(keys(%{$settings}));
                   2441:     my @jsarray = ();
                   2442:     foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
                   2443:         push(@jsarray,$ordered{$item});
                   2444:     }
                   2445:     my $jstext = '    var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
                   2446:     return <<"ENDSCRIPT";
                   2447: <script type="text/javascript">
                   2448: // <![CDATA[
                   2449: function reorderLTI(form,item) {
                   2450:     var changedVal;
                   2451: $jstext
                   2452:     var newpos = 'ltitools_add_pos';
                   2453:     var maxh = 1 + $total;
                   2454:     var current = new Array;
                   2455:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   2456:     if (item == newpos) {
                   2457:         changedVal = newitemVal;
                   2458:     } else {
                   2459:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   2460:         current[newitemVal] = newpos;
                   2461:     }
                   2462:     for (var i=0; i<ltitools.length; i++) {
                   2463:         var elementName = 'ltitools_'+ltitools[i];
                   2464:         if (elementName != item) {
                   2465:             if (form.elements[elementName]) {
                   2466:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   2467:                 current[currVal] = elementName;
                   2468:             }
                   2469:         }
                   2470:     }
                   2471:     var oldVal;
                   2472:     for (var j=0; j<maxh; j++) {
                   2473:         if (current[j] == undefined) {
                   2474:             oldVal = j;
                   2475:         }
                   2476:     }
                   2477:     if (oldVal < changedVal) {
                   2478:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   2479:            var elementName = current[k];
                   2480:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   2481:         }
                   2482:     } else {
                   2483:         for (var k=changedVal; k<oldVal; k++) {
                   2484:             var elementName = current[k];
                   2485:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   2486:         }
                   2487:     }
                   2488:     return;
                   2489: }
                   2490: 
                   2491: // ]]>
                   2492: </script>
                   2493: 
                   2494: ENDSCRIPT
                   2495: }
                   2496: 
1.3       raeburn  2497: sub print_autoenroll {
1.30      raeburn  2498:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn  2499:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129     raeburn  2500:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3       raeburn  2501:     if (ref($settings) eq 'HASH') {
                   2502:         if (exists($settings->{'run'})) {
                   2503:             if ($settings->{'run'} eq '0') {
                   2504:                 $runoff = ' checked="checked" ';
                   2505:                 $runon = ' ';
                   2506:             } else {
                   2507:                 $runon = ' checked="checked" ';
                   2508:                 $runoff = ' ';
                   2509:             }
                   2510:         } else {
                   2511:             if ($autorun) {
                   2512:                 $runon = ' checked="checked" ';
                   2513:                 $runoff = ' ';
                   2514:             } else {
                   2515:                 $runoff = ' checked="checked" ';
                   2516:                 $runon = ' ';
                   2517:             }
                   2518:         }
1.129     raeburn  2519:         if (exists($settings->{'co-owners'})) {
                   2520:             if ($settings->{'co-owners'} eq '0') {
                   2521:                 $coownersoff = ' checked="checked" ';
                   2522:                 $coownerson = ' ';
                   2523:             } else {
                   2524:                 $coownerson = ' checked="checked" ';
                   2525:                 $coownersoff = ' ';
                   2526:             }
                   2527:         } else {
                   2528:             $coownersoff = ' checked="checked" ';
                   2529:             $coownerson = ' ';
                   2530:         }
1.3       raeburn  2531:         if (exists($settings->{'sender_domain'})) {
                   2532:             $defdom = $settings->{'sender_domain'};
                   2533:         }
1.14      raeburn  2534:     } else {
                   2535:         if ($autorun) {
                   2536:             $runon = ' checked="checked" ';
                   2537:             $runoff = ' ';
                   2538:         } else {
                   2539:             $runoff = ' checked="checked" ';
                   2540:             $runon = ' ';
                   2541:         }
1.3       raeburn  2542:     }
                   2543:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39      raeburn  2544:     my $notif_sender;
                   2545:     if (ref($settings) eq 'HASH') {
                   2546:         $notif_sender = $settings->{'sender_uname'};
                   2547:     }
1.3       raeburn  2548:     my $datatable='<tr class="LC_odd_row">'.
                   2549:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  2550:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2551:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  2552:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2553:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  2554:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2555:                   '</tr><tr>'.
                   2556:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  2557:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  2558:                   &mt('username').':&nbsp;'.
                   2559:                   '<input type="text" name="sender_uname" value="'.
1.39      raeburn  2560:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.129     raeburn  2561:                   ':&nbsp;'.$domform.'</span></td></tr>'.
                   2562:                   '<tr class="LC_odd_row">'.
                   2563:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
                   2564:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2565:                   '<input type="radio" name="autoassign_coowners"'.
                   2566:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2567:                   '<label><input type="radio" name="autoassign_coowners"'.
                   2568:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2569:                   '</tr>';
                   2570:     $$rowtotal += 3;
1.3       raeburn  2571:     return $datatable;
                   2572: }
                   2573: 
                   2574: sub print_autoupdate {
1.30      raeburn  2575:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  2576:     my $datatable;
                   2577:     if ($position eq 'top') {
                   2578:         my $updateon = ' ';
                   2579:         my $updateoff = ' checked="checked" ';
                   2580:         my $classlistson = ' ';
                   2581:         my $classlistsoff = ' checked="checked" ';
                   2582:         if (ref($settings) eq 'HASH') {
                   2583:             if ($settings->{'run'} eq '1') {
                   2584:                 $updateon = $updateoff;
                   2585:                 $updateoff = ' ';
                   2586:             }
                   2587:             if ($settings->{'classlists'} eq '1') {
                   2588:                 $classlistson = $classlistsoff;
                   2589:                 $classlistsoff = ' ';
                   2590:             }
                   2591:         }
                   2592:         my %title = (
                   2593:                    run => 'Auto-update active?',
                   2594:                    classlists => 'Update information in classlists?',
                   2595:                     );
                   2596:         $datatable = '<tr class="LC_odd_row">'. 
                   2597:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  2598:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  2599:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  2600:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2601:                   '<label><input type="radio" name="autoupdate_run"'.
                   2602:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2603:                   '</tr><tr>'.
                   2604:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  2605:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   2606:                   '<label><input type="radio" name="classlists"'.
                   2607:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2608:                   '<label><input type="radio" name="classlists"'.
                   2609:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  2610:                   '</tr>';
1.30      raeburn  2611:         $$rowtotal += 2;
1.131     raeburn  2612:     } elsif ($position eq 'middle') {
                   2613:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   2614:         my $numinrow = 3;
                   2615:         my $locknamesettings;
                   2616:         $datatable .= &insttypes_row($settings,$types,$usertypes,
                   2617:                                      $dom,$numinrow,$othertitle,
                   2618:                                     'lockablenames');
                   2619:         $$rowtotal ++;
1.3       raeburn  2620:     } else {
1.44      raeburn  2621:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132     raeburn  2622:         my @fields = ('lastname','firstname','middlename','generation',
1.20      raeburn  2623:                       'permanentemail','id');
1.33      raeburn  2624:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  2625:         my $numrows = 0;
1.26      raeburn  2626:         if (ref($types) eq 'ARRAY') {
                   2627:             if (@{$types} > 0) {
                   2628:                 $datatable = 
                   2629:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   2630:                                          \@fields,$types,\$numrows);
1.30      raeburn  2631:                     $$rowtotal += @{$types}; 
1.26      raeburn  2632:             }
1.3       raeburn  2633:         }
                   2634:         $datatable .= 
                   2635:             &usertype_update_row($settings,{'default' => $othertitle},
                   2636:                                  \%fieldtitles,\@fields,['default'],
                   2637:                                  \$numrows);
1.30      raeburn  2638:         $$rowtotal ++;     
1.3       raeburn  2639:     }
                   2640:     return $datatable;
                   2641: }
                   2642: 
1.125     raeburn  2643: sub print_autocreate {
                   2644:     my ($dom,$settings,$rowtotal) = @_;
1.191     raeburn  2645:     my (%createon,%createoff,%currhash);
1.125     raeburn  2646:     my @types = ('xml','req');
                   2647:     if (ref($settings) eq 'HASH') {
                   2648:         foreach my $item (@types) {
                   2649:             $createoff{$item} = ' checked="checked" ';
                   2650:             $createon{$item} = ' ';
                   2651:             if (exists($settings->{$item})) {
                   2652:                 if ($settings->{$item}) {
                   2653:                     $createon{$item} = ' checked="checked" ';
                   2654:                     $createoff{$item} = ' ';
                   2655:                 }
                   2656:             }
                   2657:         }
1.210     raeburn  2658:         if ($settings->{'xmldc'} ne '') {
1.191     raeburn  2659:             $currhash{$settings->{'xmldc'}} = 1;
                   2660:         }
1.125     raeburn  2661:     } else {
                   2662:         foreach my $item (@types) {
                   2663:             $createoff{$item} = ' checked="checked" ';
                   2664:             $createon{$item} = ' ';
                   2665:         }
                   2666:     }
                   2667:     $$rowtotal += 2;
1.191     raeburn  2668:     my $numinrow = 2;
1.125     raeburn  2669:     my $datatable='<tr class="LC_odd_row">'.
                   2670:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
                   2671:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2672:                   '<input type="radio" name="autocreate_xml"'.
                   2673:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2674:                   '<label><input type="radio" name="autocreate_xml"'.
1.143     raeburn  2675:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
                   2676:                   '</td></tr><tr>'.
                   2677:                   '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
                   2678:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2679:                   '<input type="radio" name="autocreate_req"'.
                   2680:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2681:                   '<label><input type="radio" name="autocreate_req"'.
                   2682:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191     raeburn  2683:     my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   2684:                                                    'autocreate_xmldc',%currhash);
1.247     raeburn  2685:     $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125     raeburn  2686:     if ($numdc > 1) {
1.247     raeburn  2687:         $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
                   2688:                       '</td><td class="LC_left_item">';
1.125     raeburn  2689:     } else {
1.247     raeburn  2690:         $datatable .= &mt('Course creation processed as:').
                   2691:                       '</td><td class="LC_right_item">';
1.125     raeburn  2692:     }
1.247     raeburn  2693:     $datatable .= $dctable.'</td></tr>';
1.191     raeburn  2694:     $$rowtotal += $rows;
1.125     raeburn  2695:     return $datatable;
                   2696: }
                   2697: 
1.23      raeburn  2698: sub print_directorysrch {
1.30      raeburn  2699:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  2700:     my $srchon = ' ';
                   2701:     my $srchoff = ' checked="checked" ';
1.25      raeburn  2702:     my ($exacton,$containson,$beginson);
1.24      raeburn  2703:     my $localon = ' ';
                   2704:     my $localoff = ' checked="checked" ';
1.23      raeburn  2705:     if (ref($settings) eq 'HASH') {
                   2706:         if ($settings->{'available'} eq '1') {
                   2707:             $srchon = $srchoff;
                   2708:             $srchoff = ' ';
                   2709:         }
1.24      raeburn  2710:         if ($settings->{'localonly'} eq '1') {
                   2711:             $localon = $localoff;
                   2712:             $localoff = ' ';
                   2713:         }
1.25      raeburn  2714:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   2715:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   2716:                 if ($type eq 'exact') {
                   2717:                     $exacton = ' checked="checked" ';
                   2718:                 } elsif ($type eq 'contains') {
                   2719:                     $containson = ' checked="checked" ';
                   2720:                 } elsif ($type eq 'begins') {
                   2721:                     $beginson = ' checked="checked" ';
                   2722:                 }
                   2723:             }
                   2724:         } else {
                   2725:             if ($settings->{'searchtypes'} eq 'exact') {
                   2726:                 $exacton = ' checked="checked" ';
                   2727:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   2728:                 $containson = ' checked="checked" ';
                   2729:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   2730:                 $exacton = ' checked="checked" ';
                   2731:                 $containson = ' checked="checked" ';
                   2732:             }
1.23      raeburn  2733:         }
                   2734:     }
                   2735:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45      raeburn  2736:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23      raeburn  2737: 
                   2738:     my $numinrow = 4;
1.26      raeburn  2739:     my $cansrchrow = 0;
1.23      raeburn  2740:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  2741:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  2742:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2743:                   '<input type="radio" name="dirsrch_available"'.
                   2744:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   2745:                   '<label><input type="radio" name="dirsrch_available"'.
                   2746:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   2747:                   '</tr><tr>'.
1.30      raeburn  2748:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  2749:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   2750:                   '<input type="radio" name="dirsrch_localonly"'.
                   2751:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   2752:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   2753:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  2754:                   '</tr>';
1.30      raeburn  2755:     $$rowtotal += 2;
1.26      raeburn  2756:     if (ref($usertypes) eq 'HASH') {
                   2757:         if (keys(%{$usertypes}) > 0) {
1.93      raeburn  2758:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
                   2759:                                          $numinrow,$othertitle,'cansearch');
1.26      raeburn  2760:             $cansrchrow = 1;
                   2761:         }
                   2762:     }
                   2763:     if ($cansrchrow) {
1.30      raeburn  2764:         $$rowtotal ++;
1.26      raeburn  2765:         $datatable .= '<tr>';
                   2766:     } else {
                   2767:         $datatable .= '<tr class="LC_odd_row">';
                   2768:     }
1.30      raeburn  2769:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   2770:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  2771:     foreach my $title (@{$titleorder}) {
                   2772:         if (defined($searchtitles->{$title})) {
                   2773:             my $check = ' ';
1.93      raeburn  2774:             if (ref($settings) eq 'HASH') {
1.39      raeburn  2775:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   2776:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   2777:                         $check = ' checked="checked" ';
                   2778:                     }
1.25      raeburn  2779:                 }
                   2780:             }
                   2781:             $datatable .= '<td class="LC_left_item">'.
                   2782:                           '<span class="LC_nobreak"><label>'.
                   2783:                           '<input type="checkbox" name="searchby" '.
                   2784:                           'value="'.$title.'"'.$check.'/>'.
                   2785:                           $searchtitles->{$title}.'</label></span></td>';
                   2786:         }
                   2787:     }
1.26      raeburn  2788:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  2789:     $$rowtotal ++;
1.26      raeburn  2790:     if ($cansrchrow) {
                   2791:         $datatable .= '<tr class="LC_odd_row">';
                   2792:     } else {
                   2793:         $datatable .= '<tr>';
                   2794:     }
1.30      raeburn  2795:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  2796:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  2797:                   '<span class="LC_nobreak"><label>'.
                   2798:                   '<input type="checkbox" name="searchtypes" '.
                   2799:                   $exacton.' value="exact" />'.&mt('Exact match').
                   2800:                   '</label>&nbsp;'.
                   2801:                   '<label><input type="checkbox" name="searchtypes" '.
                   2802:                   $beginson.' value="begins" />'.&mt('Begins with').
                   2803:                   '</label>&nbsp;'.
                   2804:                   '<label><input type="checkbox" name="searchtypes" '.
                   2805:                   $containson.' value="contains" />'.&mt('Contains').
                   2806:                   '</label></span></td></tr>';
1.30      raeburn  2807:     $$rowtotal ++;
1.25      raeburn  2808:     return $datatable;
                   2809: }
                   2810: 
1.28      raeburn  2811: sub print_contacts {
1.30      raeburn  2812:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  2813:     my $datatable;
                   2814:     my @contacts = ('adminemail','supportemail');
1.134     raeburn  2815:     my (%checked,%to,%otheremails,%bccemails);
1.102     raeburn  2816:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203     raeburn  2817:                     'requestsmail','updatesmail','idconflictsmail');
1.28      raeburn  2818:     foreach my $type (@mailings) {
                   2819:         $otheremails{$type} = '';
                   2820:     }
1.134     raeburn  2821:     $bccemails{'helpdeskmail'} = '';
1.28      raeburn  2822:     if (ref($settings) eq 'HASH') {
                   2823:         foreach my $item (@contacts) {
                   2824:             if (exists($settings->{$item})) {
                   2825:                 $to{$item} = $settings->{$item};
                   2826:             }
                   2827:         }
                   2828:         foreach my $type (@mailings) {
                   2829:             if (exists($settings->{$type})) {
                   2830:                 if (ref($settings->{$type}) eq 'HASH') {
                   2831:                     foreach my $item (@contacts) {
                   2832:                         if ($settings->{$type}{$item}) {
                   2833:                             $checked{$type}{$item} = ' checked="checked" ';
                   2834:                         }
                   2835:                     }
                   2836:                     $otheremails{$type} = $settings->{$type}{'others'};
1.134     raeburn  2837:                     if ($type eq 'helpdeskmail') {
                   2838:                         $bccemails{$type} = $settings->{$type}{'bcc'};
                   2839:                     }
1.28      raeburn  2840:                 }
1.89      raeburn  2841:             } elsif ($type eq 'lonstatusmail') {
                   2842:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2843:             }
                   2844:         }
                   2845:     } else {
                   2846:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2847:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2848:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   2849:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89      raeburn  2850:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
                   2851:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
1.102     raeburn  2852:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190     raeburn  2853:         $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203     raeburn  2854:         $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28      raeburn  2855:     }
                   2856:     my ($titles,$short_titles) = &contact_titles();
                   2857:     my $rownum = 0;
                   2858:     my $css_class;
                   2859:     foreach my $item (@contacts) {
1.69      raeburn  2860:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30      raeburn  2861:         $datatable .= '<tr'.$css_class.'>'. 
                   2862:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   2863:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  2864:                   '<input type="text" name="'.$item.'" value="'.
                   2865:                   $to{$item}.'" /></td></tr>';
1.203     raeburn  2866:         $rownum ++;
1.28      raeburn  2867:     }
                   2868:     foreach my $type (@mailings) {
1.69      raeburn  2869:         $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28      raeburn  2870:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  2871:                       '<td><span class="LC_nobreak">'.
                   2872:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  2873:                       '<td class="LC_left_item">'.
                   2874:                       '<span class="LC_nobreak">';
                   2875:         foreach my $item (@contacts) {
                   2876:             $datatable .= '<label>'.
                   2877:                           '<input type="checkbox" name="'.$type.'"'.
                   2878:                           $checked{$type}{$item}.
                   2879:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   2880:                           '</label>&nbsp;';
                   2881:         }
                   2882:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   2883:                       '<input type="text" name="'.$type.'_others" '.
1.134     raeburn  2884:                       'value="'.$otheremails{$type}.'"  />';
                   2885:         if ($type eq 'helpdeskmail') {
1.136     raeburn  2886:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
1.134     raeburn  2887:                           '<input type="text" name="'.$type.'_bcc" '.
                   2888:                           'value="'.$bccemails{$type}.'"  />';
                   2889:         }
                   2890:         $datatable .= '</td></tr>'."\n";
1.203     raeburn  2891:         $rownum ++;
1.28      raeburn  2892:     }
1.203     raeburn  2893:     my %choices;
                   2894:     $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
                   2895:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2896:                                    &mt('LON-CAPA core group - MSU'),600,500));
                   2897:     $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                   2898:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   2899:                                     &mt('LON-CAPA core group - MSU'),600,500));
                   2900:     my @toggles = ('reporterrors','reportupdates');
                   2901:     my %defaultchecked = ('reporterrors'  => 'on',
                   2902:                           'reportupdates' => 'on');
                   2903:     (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2904:                                                \%choices,$rownum);
                   2905:     $datatable .= $reports;
1.30      raeburn  2906:     $$rowtotal += $rownum;
1.28      raeburn  2907:     return $datatable;
                   2908: }
                   2909: 
1.118     jms      2910: sub print_helpsettings {
1.168     raeburn  2911:     my ($dom,$confname,$settings,$rowtotal) = @_;
                   2912:     my ($datatable,$itemcount);
1.166     raeburn  2913:     $itemcount = 1;
1.168     raeburn  2914:     my (%choices,%defaultchecked,@toggles);
                   2915:     $choices{'submitbugs'} = &mt('Display link to: [_1]?',
                   2916:                                  &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   2917:                                  &mt('LON-CAPA bug tracker'),600,500));
                   2918:     %defaultchecked = ('submitbugs' => 'on');
                   2919:     @toggles = ('submitbugs',);
1.166     raeburn  2920: 
1.168     raeburn  2921:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                   2922:                                                  \%choices,$itemcount);
1.166     raeburn  2923:     return $datatable;
1.121     raeburn  2924: }
                   2925: 
                   2926: sub radiobutton_prefs {
1.192     raeburn  2927:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.257     raeburn  2928:         $additional,$align) = @_;
1.121     raeburn  2929:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
                   2930:                    (ref($choices) eq 'HASH'));
                   2931: 
1.170     raeburn  2932:     my (%checkedon,%checkedoff,$datatable,$css_class);
1.121     raeburn  2933: 
                   2934:     foreach my $item (@{$toggles}) {
                   2935:         if ($defaultchecked->{$item} eq 'on') {
1.118     jms      2936:             $checkedon{$item} = ' checked="checked" ';
                   2937:             $checkedoff{$item} = ' ';
1.121     raeburn  2938:         } elsif ($defaultchecked->{$item} eq 'off') {
1.118     jms      2939:             $checkedoff{$item} = ' checked="checked" ';
                   2940:             $checkedon{$item} = ' ';
                   2941:         }
                   2942:     }
                   2943:     if (ref($settings) eq 'HASH') {
1.121     raeburn  2944:         foreach my $item (@{$toggles}) {
1.118     jms      2945:             if ($settings->{$item} eq '1') {
                   2946:                 $checkedon{$item} =  ' checked="checked" ';
                   2947:                 $checkedoff{$item} = ' ';
                   2948:             } elsif ($settings->{$item} eq '0') {
                   2949:                 $checkedoff{$item} =  ' checked="checked" ';
                   2950:                 $checkedon{$item} = ' ';
                   2951:             }
                   2952:         }
1.121     raeburn  2953:     }
1.192     raeburn  2954:     if ($onclick) {
                   2955:         $onclick = ' onclick="'.$onclick.'"';
                   2956:     }
1.121     raeburn  2957:     foreach my $item (@{$toggles}) {
1.118     jms      2958:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121     raeburn  2959:         $datatable .=
1.192     raeburn  2960:             '<tr'.$css_class.'><td valign="top">'.
                   2961:             '<span class="LC_nobreak">'.$choices->{$item}.
1.257     raeburn  2962:             '</span></td>';
                   2963:         if ($align eq 'left') {
                   2964:             $datatable .= '<td class="LC_left_item">';
                   2965:         } else {
                   2966:             $datatable .= '<td class="LC_right_item">';
                   2967:         }
                   2968:         $datatable .= 
                   2969:             '<span class="LC_nobreak">'.
1.118     jms      2970:             '<label><input type="radio" name="'.
1.192     raeburn  2971:             $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118     jms      2972:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
1.192     raeburn  2973:             $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
                   2974:             '</span>'.$additional.
                   2975:             '</td>'.
1.118     jms      2976:             '</tr>';
                   2977:         $itemcount ++;
1.121     raeburn  2978:     }
                   2979:     return ($datatable,$itemcount);
                   2980: }
                   2981: 
1.267     raeburn  2982: sub print_ltitools {
                   2983:     my ($dom,$settings,$rowtotal) = @_;
                   2984:     my $rownum = 0;
                   2985:     my $css_class;
                   2986:     my $itemcount = 1;
                   2987:     my $maxnum = 0;
                   2988:     my %ordered;
                   2989:     if (ref($settings) eq 'HASH') {
                   2990:         foreach my $item (keys(%{$settings})) {
                   2991:             if (ref($settings->{$item}) eq 'HASH') {
                   2992:                 my $num = $settings->{$item}{'order'};
                   2993:                 $ordered{$num} = $item;
                   2994:             }
                   2995:         }
                   2996:     }
                   2997:     my $confname = $dom.'-domainconfig';
                   2998:     my $switchserver = &check_switchserver($dom,$confname);
                   2999:     my $maxnum = scalar(keys(%ordered));
                   3000:     my $datatable = &ltitools_javascript($settings);
                   3001:     my %lt = &ltitools_names();
                   3002:     my @courseroles = ('cc','in','ta','ep','st');
                   3003:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   3004:     my @fields = ('fullname','firstname','lastname','email','user','roles');
                   3005:     if (keys(%ordered)) {
                   3006:         my @items = sort { $a <=> $b } keys(%ordered);
                   3007:         for (my $i=0; $i<@items; $i++) {
                   3008:             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3009:             my $item = $ordered{$items[$i]};
                   3010:             my ($title,$key,$secret,$url,$imgsrc,$version);
                   3011:             if (ref($settings->{$item}) eq 'HASH') {
                   3012:                 $title = $settings->{$item}->{'title'};
                   3013:                 $url = $settings->{$item}->{'url'};
                   3014:                 $key = $settings->{$item}->{'key'};
                   3015:                 $secret = $settings->{$item}->{'secret'};
                   3016:                 my $image = $settings->{$item}->{'image'};
                   3017:                 if ($image ne '') {
                   3018:                     $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
                   3019:                 }
                   3020:             }
                   3021:             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_".$item."'".');"';
                   3022:             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   3023:                          .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
                   3024:             for (my $k=0; $k<=$maxnum; $k++) {
                   3025:                 my $vpos = $k+1;
                   3026:                 my $selstr;
                   3027:                 if ($k == $i) {
                   3028:                     $selstr = ' selected="selected" ';
                   3029:                 }
                   3030:                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3031:             }
                   3032:             $datatable .= '</select>'.('&nbsp;'x2).
                   3033:                 '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
                   3034:                 &mt('Delete?').'</label></span></td>'.
                   3035:                 '<td colspan="2">'.
                   3036:                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3037:                 '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
                   3038:                 ('&nbsp;'x2).
                   3039:                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
                   3040:                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                   3041:                 ('&nbsp;'x2).
                   3042:                 '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
                   3043:                 '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3044:                 '<br /><br />'.
                   3045:                 '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_url_'.$i.'"'.
                   3046:                 ' value="'.$url.'" /></span>'.
                   3047:                 ('&nbsp;'x2).
                   3048:                 '<span class="LC_nobreak">'.$lt{'key'}.
                   3049:                 '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
                   3050:                 ('&nbsp;'x2).
                   3051:                 '<span class="LC_nobreak">'.$lt{'secret'}.':'.
                   3052:                 '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
                   3053:                 '<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>'.
                   3054:                 '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
                   3055:                 '</fieldset>'.
                   3056:                 '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3057:                 '<span class="LC_nobreak">'.&mt('Display target:');
                   3058:             my %currdisp;
                   3059:             if (ref($settings->{$item}->{'display'}) eq 'HASH') {
                   3060:                 if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
                   3061:                     $currdisp{'window'} = ' checked="checked"';
                   3062:                 } else {
                   3063:                     $currdisp{'iframe'} = ' checked="checked"';
                   3064:                 }
                   3065:                 if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
                   3066:                     $currdisp{'width'} = $1;
                   3067:                 }
                   3068:                 if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
                   3069:                      $currdisp{'height'} = $1;
                   3070:                 }
                   3071:             } else {
                   3072:                 $currdisp{'iframe'} = ' checked="checked"';
                   3073:             }
                   3074:             foreach my $disp ('iframe','window') {
                   3075:                 $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
                   3076:                               $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3077:             }
                   3078:             $datatable .= ('&nbsp;'x4);
                   3079:             foreach my $dimen ('width','height') {
                   3080:                 $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3081:                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                   3082:                               ('&nbsp;'x2);
                   3083:             }
                   3084:             $datatable .= '<br />';
                   3085:             foreach my $extra ('passback','roster') {
                   3086:                 my $checkedon = '';
                   3087:                 my $checkedoff = ' checked="checked"';
                   3088:                 if ($settings->{$item}->{$extra}) {
                   3089:                     $checkedon = $checkedoff;
                   3090:                     $checkedoff = '';
                   3091:                 }
                   3092:                 $datatable .= $lt{$extra}.'&nbsp;'.
                   3093:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="1"'.$checkedon.' />'.
                   3094:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   3095:                               '<label><input type="radio" name="ltitools_'.$extra.'_'.$i.'" value="0"'.$checkedoff.' />'.
                   3096:                               &mt('No').'</label>'.('&nbsp;'x4);
                   3097:             }
                   3098:             $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;';
                   3099:             if ($imgsrc) {
                   3100:                 $datatable .= $imgsrc.
                   3101:                               '<label><input type="checkbox" name="ltitools_image_del"'.
                   3102:                               ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
                   3103:                               '<span class="LC_nobreak">&nbsp;'.&mt('Replace:').'&nbsp;';
                   3104:             } else {
                   3105:                 $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3106:             }
                   3107:             if ($switchserver) {
                   3108:                 $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3109:             } else {
                   3110:                 $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
                   3111:             }
                   3112:             $datatable .= '</span></fieldset>';
                   3113:             my (%checkedfields,%rolemaps);
                   3114:             if (ref($settings->{$item}) eq 'HASH') {
                   3115:                 if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
                   3116:                     %checkedfields = %{$settings->{$item}->{'fields'}};
                   3117:                 }
                   3118:                 if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
                   3119:                     %rolemaps = %{$settings->{$item}->{'roles'}};
                   3120:                     $checkedfields{'roles'} = 1;
                   3121:                 }
                   3122:             }
                   3123:             $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3124:                           '<span class="LC_nobreak">';
                   3125:             foreach my $field (@fields) {
                   3126:                 my $checked;
                   3127:                 if ($checkedfields{$field}) {
                   3128:                     $checked = ' checked="checked"';
                   3129:                 }
                   3130:                 $datatable .= '<label>'.
                   3131:                               '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$checked.' />'.
                   3132:                               $lt{$field}.'</label>'.('&nbsp;' x2);
                   3133:             }
                   3134:             $datatable .= '</span></fieldset>'.
                   3135:                           '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3136:             foreach my $role (@courseroles) {
                   3137:                 my ($selected,$selectnone);
                   3138:                 if (!$rolemaps{$role}) {
                   3139:                     $selectnone = ' selected="selected"';
                   3140:                 }
                   3141:                 $datatable .= '<td align="center">'. 
                   3142:                               &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3143:                               '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
                   3144:                               '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
                   3145:                 foreach my $ltirole (@ltiroles) {
                   3146:                     unless ($selectnone) {
                   3147:                         if ($rolemaps{$role} eq $ltirole) {
                   3148:                             $selected = ' selected="selected"';
                   3149:                         } else {
                   3150:                             $selected = '';
                   3151:                         }
                   3152:                     }
                   3153:                     $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
                   3154:                 }
                   3155:                 $datatable .= '</select></td>';
                   3156:             }
                   3157:             $datatable .= '</tr></table></fieldset>'.
                   3158:                           '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3159:                           '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
                   3160:             if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
                   3161:                 my %custom = %{$settings->{$item}->{'custom'}};
                   3162:                 if (keys(%custom) > 0) {
                   3163:                     foreach my $key (sort(keys(%custom))) {
                   3164:                         $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3165:                                       '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
                   3166:                                       $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
                   3167:                                       '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
                   3168:                                       ' value="'.$custom{$key}.'" /></td></tr>';
                   3169:                     }
                   3170:                 }
                   3171:             }
                   3172:             $datatable .= '<tr><td><span class="LC_nobreak">'.
                   3173:                           '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
                   3174:                           &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
                   3175:                           '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
                   3176:             $datatable .= '</table></fieldset></td></tr>'."\n";
                   3177:             $itemcount ++;
                   3178:         }
                   3179:     }
                   3180:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3181:     my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'ltitools_add_pos'".');"';
                   3182:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
                   3183:                   '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
                   3184:                   '<select name="ltitools_add_pos"'.$chgstr.'>';
                   3185:     for (my $k=0; $k<$maxnum+1; $k++) {
                   3186:         my $vpos = $k+1;
                   3187:         my $selstr;
                   3188:         if ($k == $maxnum) {
                   3189:             $selstr = ' selected="selected" ';
                   3190:         }
                   3191:         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   3192:     }
                   3193:     $datatable .= '</select>&nbsp;'."\n".
                   3194:                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".
                   3195:                   '<td colspan="2">'.
                   3196:                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   3197:                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="30" name="ltitools_add_title" value="" /></span> '."\n".
                   3198:                   ('&nbsp;'x2).
                   3199:                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
                   3200:                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   3201:                   ('&nbsp;'x2).
                   3202:                   '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
                   3203:                   '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
                   3204:                   '<br />'.
                   3205:                   '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="30" name="ltitools_add_url" value="" /></span> '."\n".
                   3206:                   ('&nbsp;'x2).
                   3207:                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
                   3208:                   ('&nbsp;'x2).
                   3209:                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
                   3210:                   '<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".
                   3211:                   '</fieldset>'.
                   3212:                   '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
                   3213:                   '<span class="LC_nobreak">'.&mt('Display target:');
                   3214:     my %defaultdisp;
                   3215:     $defaultdisp{'iframe'} = ' checked="checked"';
                   3216:     foreach my $disp ('iframe','window') {
                   3217:         $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
                   3218:                       $lt{$disp}.'</label>'.('&nbsp;'x2);
                   3219:     }
                   3220:     $datatable .= ('&nbsp;'x4);
                   3221:     foreach my $dimen ('width','height') {
                   3222:         $datatable .= '<label>'.$lt{$dimen}.'&nbsp;'.
                   3223:                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                   3224:                       ('&nbsp;'x2);
                   3225:     }
                   3226:     $datatable .= '<br />';
                   3227:     foreach my $extra ('passback','roster') {
                   3228:         $datatable .= $lt{$extra}.'&nbsp;'.
                   3229:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="1" />'.
                   3230:                       &mt('Yes').'</label>'.('&nbsp;'x2).
                   3231:                       '<label><input type="radio" name="ltitools_add_'.$extra.'" value="0" checked="checked" />'.
                   3232:                       &mt('No').'</label>'.('&nbsp;'x4);
                   3233:     }
                   3234:     $datatable .= '<br /><br /><span class="LC_nobreak">'.$lt{'icon'}.':&nbsp;'.
                   3235:                   '('.&mt('if larger than 21x21 pixels, image will be scaled').')&nbsp;';
                   3236:     if ($switchserver) {
                   3237:         $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   3238:     } else {
                   3239:         $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
                   3240:     }
                   3241:     $datatable .= '</span></fieldset>'.
                   3242:                   '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
                   3243:                   '<span class="LC_nobreak">';
                   3244:     foreach my $field (@fields) {
                   3245:         $datatable .= '<label>'.
                   3246:                       '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'" />'.
                   3247:                       $lt{$field}.'</label>'.('&nbsp;' x2);
                   3248:     }
                   3249:     $datatable .= '</span></fieldset>'.
                   3250:                   '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
                   3251:     foreach my $role (@courseroles) {
                   3252:         my ($checked,$checkednone);
                   3253:         $datatable .= '<td align="center">'.
                   3254:                       &Apache::lonnet::plaintext($role,'Course').'<br />'.
                   3255:                       '<select name="ltitools_add_roles_'.$role.'">'.
                   3256:                       '<option value="" selected="selected">'.&mt('Select').'</option>';
                   3257:         foreach my $ltirole (@ltiroles) {
                   3258:             $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
                   3259:         }
                   3260:         $datatable .= '</select></td>';
                   3261:     }
                   3262:     $datatable .= '</tr></table></fieldset>'.
                   3263:                   '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
                   3264:                   '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
                   3265:                   '<tr><td><span class="LC_nobreak">'.
                   3266:                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   3267:                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   3268:                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   3269:                   '</table></fieldset></td></tr>'."\n".
                   3270:                   '</td>'."\n".
                   3271:                   '</tr>'."\n";
                   3272:     $itemcount ++;
                   3273:     return $datatable;
                   3274: }
                   3275: 
                   3276: sub ltitools_names {
                   3277:     my %lt = &Apache::lonlocal::texthash(
                   3278:                                           'title'     => 'Title',
                   3279:                                           'version'   => 'Version',
                   3280:                                           'msgtype'   => 'Message Type',
                   3281:                                           'url'       => 'URL',
                   3282:                                           'key'       => 'Key',
                   3283:                                           'secret'    => 'Secret',
                   3284:                                           'icon'      => 'Icon',   
                   3285:                                           'user'      => 'Username:domain',
                   3286:                                           'fullname'  => 'Full Name',
                   3287:                                           'firstname' => 'First Name',
                   3288:                                           'lastname'  => 'Last Name',
                   3289:                                           'email'     => 'E-mail',
                   3290:                                           'roles'     => 'Role',
                   3291:                                           'window'    => 'Window/Tab',
                   3292:                                           'iframe'    => 'iFrame',
                   3293:                                           'height'    => 'Height',
                   3294:                                           'width'     => 'Width',
                   3295:                                           'passback'  => 'Tool can return grades:',
                   3296:                                           'roster'    => 'Tool can retrieve roster:',
                   3297:                                         );
                   3298:     return %lt;
                   3299: }
                   3300: 
1.121     raeburn  3301: sub print_coursedefaults {
1.139     raeburn  3302:     my ($position,$dom,$settings,$rowtotal) = @_;
1.192     raeburn  3303:     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121     raeburn  3304:     my $itemcount = 1;
1.192     raeburn  3305:     my %choices =  &Apache::lonlocal::texthash (
                   3306:         canuse_pdfforms      => 'Course/Community users can create/upload PDF forms',
1.198     raeburn  3307:         uploadquota          => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192     raeburn  3308:         anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
                   3309:         coursecredits        => 'Credits can be specified for courses',
1.257     raeburn  3310:         uselcmath            => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
                   3311:         usejsme              => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
                   3312:         postsubmit           => 'Disable submit button/keypress following student submission',
1.264     raeburn  3313:         canclone             => "People who may clone a course (besides course's owner and coordinators)",     
1.192     raeburn  3314:     );
1.198     raeburn  3315:     my %staticdefaults = (
                   3316:                            anonsurvey_threshold => 10,
                   3317:                            uploadquota          => 500,
1.257     raeburn  3318:                            postsubmit           => 60,
1.198     raeburn  3319:                          );
1.139     raeburn  3320:     if ($position eq 'top') {
1.257     raeburn  3321:         %defaultchecked = (
                   3322:                             'canuse_pdfforms' => 'off',
                   3323:                             'uselcmath'       => 'on',
                   3324:                             'usejsme'         => 'on',
1.264     raeburn  3325:                             'canclone'        => 'none', 
1.257     raeburn  3326:                           );
                   3327:         @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.139     raeburn  3328:         ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257     raeburn  3329:                                                      \%choices,$itemcount);
1.264     raeburn  3330:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3331:         $datatable .=
                   3332:             '<tr'.$css_class.'><td valign="top">'.
                   3333:             '<span class="LC_nobreak">'.$choices{'canclone'}.
                   3334:             '</span></td><td class="LC_left_item">';
                   3335:         my $currcanclone = 'none';
                   3336:         my $onclick;
                   3337:         my @cloneoptions = ('none','domain');
                   3338:         my %clonetitles = (
                   3339:                              none     => 'No additional course requesters',
                   3340:                              domain   => "Any course requester in course's domain",
                   3341:                              instcode => 'Course requests for official courses ...',
                   3342:                           );
                   3343:         my (%codedefaults,@code_order,@posscodes);
                   3344:         if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   3345:                                                     \@code_order) eq 'ok') {
                   3346:             if (@code_order > 0) {
                   3347:                 push(@cloneoptions,'instcode');
                   3348:                 $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
                   3349:             }
                   3350:         }
                   3351:         if (ref($settings) eq 'HASH') {
                   3352:             if ($settings->{'canclone'}) {
                   3353:                 if (ref($settings->{'canclone'}) eq 'HASH') {
                   3354:                     if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
                   3355:                         if (@code_order > 0) {
                   3356:                             $currcanclone = 'instcode';
                   3357:                             @posscodes = @{$settings->{'canclone'}{'instcode'}};
                   3358:                         }
                   3359:                     }
                   3360:                 } elsif ($settings->{'canclone'} eq 'domain') {
                   3361:                     $currcanclone = $settings->{'canclone'};
                   3362:                 }
                   3363:             }
                   3364:         } 
                   3365:         foreach my $option (@cloneoptions) {
                   3366:             my ($checked,$additional);
                   3367:             if ($currcanclone eq $option) {
                   3368:                 $checked = ' checked="checked"';
                   3369:             }
                   3370:             if ($option eq 'instcode') {
                   3371:                 if (@code_order) {
                   3372:                     my $show = 'none';
                   3373:                     if ($checked) {
                   3374:                         $show = 'block';
                   3375:                     }
                   3376:                     $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
                   3377:                                   &mt('Institutional codes for new and cloned course have identical:').
                   3378:                                   '<br />';
                   3379:                     foreach my $item (@code_order) {
                   3380:                         my $codechk;
                   3381:                         if ($checked) {
                   3382:                             if (grep(/^\Q$item\E$/,@posscodes)) {
                   3383:                                 $codechk = ' checked="checked"';
                   3384:                             }
                   3385:                         }
                   3386:                         $additional .= '<label>'.
                   3387:                                        '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
                   3388:                                        $item.'</label>';
                   3389:                     }
                   3390:                     $additional .= ('&nbsp;'x2).'('.&mt('check as many as needed').')</div>';
                   3391:                 }
                   3392:             }
                   3393:             $datatable .=
                   3394:                 '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
                   3395:                 ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
                   3396:                 '</label>&nbsp;'.$additional.'</span><br />';
                   3397:         }
                   3398:         $datatable .= '</td>'.
                   3399:                       '</tr>';
                   3400:         $itemcount ++;
1.139     raeburn  3401:     } else {
                   3402:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.257     raeburn  3403:         my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout);
1.192     raeburn  3404:         my $currusecredits = 0;
1.257     raeburn  3405:         my $postsubmitclient = 1;
1.271     raeburn  3406:         my @types = ('official','unofficial','community','textbook','placement');
1.139     raeburn  3407:         if (ref($settings) eq 'HASH') {
                   3408:             $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198     raeburn  3409:             if (ref($settings->{'uploadquota'}) eq 'HASH') {
                   3410:                 foreach my $type (keys(%{$settings->{'uploadquota'}})) {
                   3411:                     $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
                   3412:                 }
                   3413:             }
1.192     raeburn  3414:             if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257     raeburn  3415:                 foreach my $type (@types) {
                   3416:                     next if ($type eq 'community');
                   3417:                     $defcredits{$type} = $settings->{'coursecredits'}->{$type};
                   3418:                     if ($defcredits{$type} ne '') {
                   3419:                         $currusecredits = 1;
                   3420:                     }
                   3421:                 }
                   3422:             }
                   3423:             if (ref($settings->{'postsubmit'}) eq 'HASH') {
                   3424:                 if ($settings->{'postsubmit'}->{'client'} eq 'off') {
                   3425:                     $postsubmitclient = 0;
                   3426:                     foreach my $type (@types) {
                   3427:                         $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3428:                     }
                   3429:                 } else {
                   3430:                     foreach my $type (@types) {
                   3431:                         if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
                   3432:                             if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
                   3433:                                 $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type}; 
                   3434:                             } else {
                   3435:                                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3436:                             }
                   3437:                         } else {
                   3438:                             $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3439:                         }
                   3440:                     }
                   3441:                 }
                   3442:             } else {
                   3443:                 foreach my $type (@types) {
                   3444:                     $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192     raeburn  3445:                 }
                   3446:             }
1.258     raeburn  3447:         } else {
                   3448:             foreach my $type (@types) {
                   3449:                 $deftimeout{$type} = $staticdefaults{'postsubmit'};
                   3450:             }
1.139     raeburn  3451:         }
                   3452:         if (!$currdefresponder) {
1.198     raeburn  3453:             $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139     raeburn  3454:         } elsif ($currdefresponder < 1) {
                   3455:             $currdefresponder = 1;
                   3456:         }
1.198     raeburn  3457:         foreach my $type (@types) {
                   3458:             if ($curruploadquota{$type} eq '') {
                   3459:                 $curruploadquota{$type} = $staticdefaults{'uploadquota'};
                   3460:             }
                   3461:         }
1.139     raeburn  3462:         $datatable .=
1.192     raeburn  3463:                 '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3464:                 $choices{'anonsurvey_threshold'}.
1.139     raeburn  3465:                 '</span></td>'.
                   3466:                 '<td class="LC_right_item"><span class="LC_nobreak">'.
                   3467:                 '<input type="text" name="anonsurvey_threshold"'.
                   3468:                 ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230     raeburn  3469:                 '</td></tr>'."\n";
                   3470:         $itemcount ++;
                   3471:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3472:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3473:                       $choices{'uploadquota'}.
                   3474:                       '</span></td>'.
                   3475:                       '<td align="right" class="LC_right_item">'.
                   3476:                       '<table><tr>';
1.198     raeburn  3477:         foreach my $type (@types) {
                   3478:             $datatable .= '<td align="center">'.&mt($type).'<br />'.
                   3479:                            '<input type="text" name="uploadquota_'.$type.'"'.
                   3480:                            ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
                   3481:         }
                   3482:         $datatable .= '</tr></table></td></tr>'."\n";
1.230     raeburn  3483:         $itemcount ++;
1.236     raeburn  3484:         my $onclick = "toggleDisplay(this.form,'credits');";
1.210     raeburn  3485:         my $display = 'none';
1.192     raeburn  3486:         if ($currusecredits) {
                   3487:             $display = 'block';
                   3488:         }
                   3489:         my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257     raeburn  3490:                          '<i>'.&mt('Default credits').'</i><br /><table><tr>';
                   3491:         foreach my $type (@types) {
                   3492:             next if ($type eq 'community');
                   3493:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3494:                            '<input type="text" name="'.$type.'_credits"'.
1.258     raeburn  3495:                            ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257     raeburn  3496:         }
                   3497:         $additional .= '</tr></table></div>'."\n";
1.192     raeburn  3498:         %defaultchecked = ('coursecredits' => 'off');
                   3499:         @toggles = ('coursecredits');
                   3500:         my $current = {
                   3501:                         'coursecredits' => $currusecredits,
                   3502:                       };
                   3503:         (my $table,$itemcount) =
                   3504:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257     raeburn  3505:                                \%choices,$itemcount,$onclick,$additional,'left');
                   3506:         $datatable .= $table;
                   3507:         $onclick = "toggleDisplay(this.form,'studentsubmission');";
                   3508:         my $display = 'none';
                   3509:         if ($postsubmitclient) {
                   3510:             $display = 'block';
                   3511:         }
                   3512:         $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259     raeburn  3513:                       &mt('Number of seconds submit is disabled').'<br />'.
                   3514:                       '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
                   3515:                       '<table><tr>';
1.257     raeburn  3516:         foreach my $type (@types) {
                   3517:             $additional .= '<td align="center">'.&mt($type).'<br />'.
                   3518:                            '<input type="text" name="'.$type.'_timeout" value="'.
                   3519:                            $deftimeout{$type}.'" size="5" /></td>';
                   3520:         }
                   3521:         $additional .= '</tr></table></div>'."\n";
                   3522:         %defaultchecked = ('postsubmit' => 'on');
                   3523:         @toggles = ('postsubmit');
                   3524:         my $current = {
                   3525:                         'postsubmit' => $postsubmitclient,
                   3526:                       };
                   3527:         ($table,$itemcount) =
                   3528:             &radiobutton_prefs($current,\@toggles,\%defaultchecked,
                   3529:                                \%choices,$itemcount,$onclick,$additional,'left');
1.192     raeburn  3530:         $datatable .= $table;
1.139     raeburn  3531:     }
1.192     raeburn  3532:     $$rowtotal += $itemcount;
1.121     raeburn  3533:     return $datatable;
1.118     jms      3534: }
                   3535: 
1.231     raeburn  3536: sub print_selfenrollment {
                   3537:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3538:     my ($css_class,$datatable);
                   3539:     my $itemcount = 1;
1.271     raeburn  3540:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  3541:     if (($position eq 'top') || ($position eq 'middle')) {
1.232     raeburn  3542:         my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
                   3543:         my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231     raeburn  3544:         my @rows;
                   3545:         my $key;
                   3546:         if ($position eq 'top') {
                   3547:             $key = 'admin'; 
                   3548:             if (ref($rowsref) eq 'ARRAY') {
                   3549:                 @rows = @{$rowsref};
                   3550:             }
                   3551:         } elsif ($position eq 'middle') {
                   3552:             $key = 'default';
                   3553:             @rows = ('types','registered','approval','limit');
                   3554:         }
                   3555:         foreach my $row (@rows) {
                   3556:             if (defined($titlesref->{$row})) {
                   3557:                 $itemcount ++;
                   3558:                 $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   3559:                 $datatable .= '<tr'.$css_class.'>'.
                   3560:                               '<td>'.$titlesref->{$row}.'</td>'.
                   3561:                               '<td class="LC_left_item">'.
                   3562:                               '<table><tr>';
                   3563:                 my (%current,%currentcap);
                   3564:                 if (ref($settings) eq 'HASH') {
                   3565:                     if (ref($settings->{$key}) eq 'HASH') {
                   3566:                         foreach my $type (@types) {
                   3567:                             if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3568:                                 $current{$type} = $settings->{$key}->{$type}->{$row};
                   3569:                             }
                   3570:                             if (($row eq 'limit') && ($key eq 'default')) {
                   3571:                                 if (ref($settings->{$key}->{$type}) eq 'HASH') {
                   3572:                                     $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
                   3573:                                 }
                   3574:                             }
                   3575:                         }
                   3576:                     }
                   3577:                 }
                   3578:                 my %roles = (
                   3579:                              '0' => &Apache::lonnet::plaintext('dc'),
                   3580:                             ); 
                   3581:             
                   3582:                 foreach my $type (@types) {
                   3583:                     unless (($row eq 'registered') && ($key eq 'default')) {
                   3584:                         $datatable .= '<th>'.&mt($type).'</th>';
                   3585:                     }
                   3586:                 }
                   3587:                 unless (($row eq 'registered') && ($key eq 'default')) {
                   3588:                     $datatable .= '</tr><tr>';
                   3589:                 }
                   3590:                 foreach my $type (@types) {
                   3591:                     if ($type eq 'community') {
                   3592:                         $roles{'1'} = &mt('Community personnel');
                   3593:                     } else {
                   3594:                         $roles{'1'} = &mt('Course personnel');
                   3595:                     }
                   3596:                     $datatable .= '<td style="vertical-align: top">';
                   3597:                     if ($position eq 'top') {
                   3598:                         my %checked;
                   3599:                         if ($current{$type} eq '0') {
                   3600:                             $checked{'0'} = ' checked="checked"';
                   3601:                         } else {
                   3602:                             $checked{'1'} = ' checked="checked"';
                   3603:                         }
                   3604:                         foreach my $role ('1','0') {
                   3605:                             $datatable .= '<span class="LC_nobreak"><label>'.
                   3606:                                           '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
                   3607:                                           'value="'.$role.'"'.$checked{$role}.' />'.
                   3608:                                           $roles{$role}.'</label></span> ';
                   3609:                         }
                   3610:                     } else {
                   3611:                         if ($row eq 'types') {
                   3612:                             my %checked;
                   3613:                             if ($current{$type} =~ /^(all|dom)$/) {
                   3614:                                 $checked{$1} = ' checked="checked"';
                   3615:                             } else {
                   3616:                                 $checked{''} = ' checked="checked"';
                   3617:                             }
                   3618:                             foreach my $val ('','dom','all') {
                   3619:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3620:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3621:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3622:                             }
                   3623:                         } elsif ($row eq 'registered') {
                   3624:                             my %checked;
                   3625:                             if ($current{$type} eq '1') {
                   3626:                                 $checked{'1'} = ' checked="checked"';
                   3627:                             } else {
                   3628:                                 $checked{'0'} = ' checked="checked"';
                   3629:                             }
                   3630:                             foreach my $val ('0','1') {
                   3631:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3632:                                               '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3633:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3634:                             }
                   3635:                         } elsif ($row eq 'approval') {
                   3636:                             my %checked;
                   3637:                             if ($current{$type} =~ /^([12])$/) {
                   3638:                                 $checked{$1} = ' checked="checked"';
                   3639:                             } else {
                   3640:                                 $checked{'0'} = ' checked="checked"';
                   3641:                             }
                   3642:                             for my $val (0..2) {
                   3643:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3644:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3645:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3646:                             }
                   3647:                         } elsif ($row eq 'limit') {
                   3648:                             my %checked;
                   3649:                             if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
                   3650:                                 $checked{$1} = ' checked="checked"';
                   3651:                             } else {
                   3652:                                 $checked{'none'} = ' checked="checked"';
                   3653:                             }
                   3654:                             my $cap;
                   3655:                             if ($currentcap{$type} =~ /^\d+$/) {
                   3656:                                 $cap = $currentcap{$type};
                   3657:                             }
                   3658:                             foreach my $val ('none','allstudents','selfenrolled') {
                   3659:                                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3660:                                               '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
                   3661:                                               'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
                   3662:                             }
                   3663:                             $datatable .= '<br />'.
                   3664:                                           '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
                   3665:                                           '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
                   3666:                                           '</span>'; 
                   3667:                         }
                   3668:                     }
                   3669:                     $datatable .= '</td>';
                   3670:                 }
                   3671:                 $datatable .= '</tr>';
                   3672:             }
                   3673:             $datatable .= '</table></td></tr>';
                   3674:         }
                   3675:     } elsif ($position eq 'bottom') {
1.235     raeburn  3676:         $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
                   3677:     }
                   3678:     $$rowtotal += $itemcount;
                   3679:     return $datatable;
                   3680: }
                   3681: 
                   3682: sub print_validation_rows {
                   3683:     my ($caller,$dom,$settings,$rowtotal) = @_;
                   3684:     my ($itemsref,$namesref,$fieldsref);
                   3685:     if ($caller eq 'selfenroll') { 
                   3686:         ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
                   3687:     } elsif ($caller eq 'requestcourses') {
                   3688:         ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
                   3689:     }
                   3690:     my %currvalidation;
                   3691:     if (ref($settings) eq 'HASH') {
                   3692:         if (ref($settings->{'validation'}) eq 'HASH') {
                   3693:             %currvalidation = %{$settings->{'validation'}};
1.231     raeburn  3694:         }
1.235     raeburn  3695:     }
                   3696:     my $datatable;
                   3697:     my $itemcount = 0;
                   3698:     foreach my $item (@{$itemsref}) {
                   3699:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3700:         $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
                   3701:                       $namesref->{$item}.
                   3702:                       '</span></td>'.
                   3703:                       '<td class="LC_left_item">';
                   3704:         if (($item eq 'url') || ($item eq 'button')) {
                   3705:             $datatable .= '<span class="LC_nobreak">'.
                   3706:                           '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
                   3707:                           ' value="'.$currvalidation{$item}.'" size="50" /></span>';
                   3708:         } elsif ($item eq 'fields') {
                   3709:             my @currfields;
                   3710:             if (ref($currvalidation{$item}) eq 'ARRAY') {
                   3711:                 @currfields = @{$currvalidation{$item}};
                   3712:             }
                   3713:             foreach my $field (@{$fieldsref}) {
                   3714:                 my $check = '';
                   3715:                 if (grep(/^\Q$field\E$/,@currfields)) {
                   3716:                     $check = ' checked="checked"';
                   3717:                 }
                   3718:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   3719:                               '<input type="checkbox" name="'.$caller.'_validation_fields"'.
                   3720:                               ' value="'.$field.'"'.$check.' />'.$field.
                   3721:                               '</label></span> ';
                   3722:             }
                   3723:         } elsif ($item eq 'markup') {
                   3724:             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.
                   3725:                            $currvalidation{$item}.
1.231     raeburn  3726:                               '</textarea>';
1.235     raeburn  3727:         }
                   3728:         $datatable .= '</td></tr>'."\n";
                   3729:         if (ref($rowtotal)) {
1.231     raeburn  3730:             $itemcount ++;
                   3731:         }
                   3732:     }
1.235     raeburn  3733:     if ($caller eq 'requestcourses') {
                   3734:         my %currhash;
1.248     raeburn  3735:         if (ref($settings) eq 'HASH') {
                   3736:             if (ref($settings->{'validation'}) eq 'HASH') {
                   3737:                 if ($settings->{'validation'}{'dc'} ne '') {
                   3738:                     $currhash{$settings->{'validation'}{'dc'}} = 1;
                   3739:                 }
1.235     raeburn  3740:             }
                   3741:         }
                   3742:         my $numinrow = 2;
                   3743:         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                   3744:                                                        'validationdc',%currhash);
1.247     raeburn  3745:         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3746:         $datatable .= '</td></tr><tr'.$css_class.'><td>';
1.235     raeburn  3747:         if ($numdc > 1) {
1.247     raeburn  3748:             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235     raeburn  3749:         } else {
1.247     raeburn  3750:             $datatable .=  &mt('Course creation processed as: ');
1.235     raeburn  3751:         }
1.247     raeburn  3752:         $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235     raeburn  3753:         $itemcount ++;
                   3754:     }
                   3755:     if (ref($rowtotal)) {
                   3756:         $$rowtotal += $itemcount;
                   3757:     }
1.231     raeburn  3758:     return $datatable;
                   3759: }
                   3760: 
1.137     raeburn  3761: sub print_usersessions {
                   3762:     my ($position,$dom,$settings,$rowtotal) = @_;
                   3763:     my ($css_class,$datatable,%checked,%choices);
1.140     raeburn  3764:     my (%by_ip,%by_location,@intdoms);
                   3765:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145     raeburn  3766: 
                   3767:     my @alldoms = &Apache::lonnet::all_domains();
1.152     raeburn  3768:     my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149     raeburn  3769:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152     raeburn  3770:     my %altids = &id_for_thisdom(%servers);
1.145     raeburn  3771:     my $itemcount = 1;
                   3772:     if ($position eq 'top') {
1.152     raeburn  3773:         if (keys(%serverhomes) > 1) {
1.145     raeburn  3774:             my %spareid = &current_offloads_to($dom,$settings,\%servers);
1.261     raeburn  3775:             my $curroffloadnow;
                   3776:             if (ref($settings) eq 'HASH') {
                   3777:                 if (ref($settings->{'offloadnow'}) eq 'HASH') {
                   3778:                     $curroffloadnow = $settings->{'offloadnow'};
                   3779:                 }
                   3780:             }
                   3781:             $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$curroffloadnow,$rowtotal);
1.145     raeburn  3782:         } else {
1.140     raeburn  3783:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  3784:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140     raeburn  3785:         }
1.137     raeburn  3786:     } else {
1.145     raeburn  3787:         if (keys(%by_location) == 0) {
                   3788:             $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150     raeburn  3789:                           &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145     raeburn  3790:         } else {
                   3791:             my %lt = &usersession_titles();
                   3792:             my $numinrow = 5;
                   3793:             my $prefix;
                   3794:             my @types;
                   3795:             if ($position eq 'bottom') {
                   3796:                 $prefix = 'remote';
                   3797:                 @types = ('version','excludedomain','includedomain');
                   3798:             } else {
                   3799:                 $prefix = 'hosted';
                   3800:                 @types = ('excludedomain','includedomain');
                   3801:             }
                   3802:             my (%current,%checkedon,%checkedoff);
                   3803:             my @lcversions = &Apache::lonnet::all_loncaparevs();
                   3804:             my @locations = sort(keys(%by_location));
                   3805:             foreach my $type (@types) {
                   3806:                 $checkedon{$type} = '';
                   3807:                 $checkedoff{$type} = ' checked="checked"';
                   3808:             }
                   3809:             if (ref($settings) eq 'HASH') {
                   3810:                 if (ref($settings->{$prefix}) eq 'HASH') {
                   3811:                     foreach my $key (keys(%{$settings->{$prefix}})) {
                   3812:                         $current{$key} = $settings->{$prefix}{$key};
                   3813:                         if ($key eq 'version') {
                   3814:                             if ($current{$key} ne '') {
                   3815:                                 $checkedon{$key} = ' checked="checked"';
                   3816:                                 $checkedoff{$key} = '';
                   3817:                             }
                   3818:                         } elsif (ref($current{$key}) eq 'ARRAY') {
                   3819:                             $checkedon{$key} = ' checked="checked"';
                   3820:                             $checkedoff{$key} = '';
                   3821:                         }
1.137     raeburn  3822:                     }
                   3823:                 }
                   3824:             }
1.145     raeburn  3825:             foreach my $type (@types) {
                   3826:                 next if ($type ne 'version' && !@locations);
                   3827:                 $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   3828:                 $datatable .= '<tr'.$css_class.'>
                   3829:                                <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
                   3830:                                <span class="LC_nobreak">&nbsp;
                   3831:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
                   3832:                                <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
                   3833:                 if ($type eq 'version') {
                   3834:                     my $selector = '<select name="'.$prefix.'_version">';
                   3835:                     foreach my $version (@lcversions) {
                   3836:                         my $selected = '';
                   3837:                         if ($current{'version'} eq $version) {
                   3838:                             $selected = ' selected="selected"';
                   3839:                         }
                   3840:                         $selector .= ' <option value="'.$version.'"'.
                   3841:                                      $selected.'>'.$version.'</option>';
                   3842:                     }
                   3843:                     $selector .= '</select> ';
                   3844:                     $datatable .= &mt('remote server must be version: [_1] or later',$selector);
                   3845:                 } else {
                   3846:                     $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
                   3847:                                  'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
                   3848:                                  ' />'.('&nbsp;'x2).
                   3849:                                  '<input type="button" value="'.&mt('uncheck all').'" '.
                   3850:                                  'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
                   3851:                                  "\n".
                   3852:                                  '</div><div><table>';
                   3853:                     my $rem;
                   3854:                     for (my $i=0; $i<@locations; $i++) {
                   3855:                         my ($showloc,$value,$checkedtype);
                   3856:                         if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
                   3857:                             my $ip = $by_location{$locations[$i]}->[0];
                   3858:                             if (ref($by_ip{$ip}) eq 'ARRAY') {
                   3859:                                  $value = join(':',@{$by_ip{$ip}});
                   3860:                                 $showloc = join(', ',@{$by_ip{$ip}});
                   3861:                                 if (ref($current{$type}) eq 'ARRAY') {
                   3862:                                     foreach my $loc (@{$by_ip{$ip}}) {  
                   3863:                                         if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
                   3864:                                             $checkedtype = ' checked="checked"';
                   3865:                                             last;
                   3866:                                         }
                   3867:                                     }
1.138     raeburn  3868:                                 }
                   3869:                             }
                   3870:                         }
1.145     raeburn  3871:                         $rem = $i%($numinrow);
                   3872:                         if ($rem == 0) {
                   3873:                             if ($i > 0) {
                   3874:                                 $datatable .= '</tr>';
                   3875:                             }
                   3876:                             $datatable .= '<tr>';
                   3877:                         }
                   3878:                         $datatable .= '<td class="LC_left_item">'.
                   3879:                                       '<span class="LC_nobreak"><label>'.
                   3880:                                       '<input type="checkbox" name="'.$prefix.'_'.$type.
                   3881:                                       '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
                   3882:                                       '</label></span></td>';
1.137     raeburn  3883:                     }
1.145     raeburn  3884:                     $rem = @locations%($numinrow);
                   3885:                     my $colsleft = $numinrow - $rem;
                   3886:                     if ($colsleft > 1 ) {
                   3887:                         $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   3888:                                       '&nbsp;</td>';
                   3889:                     } elsif ($colsleft == 1) {
                   3890:                         $datatable .= '<td class="LC_left_item">&nbsp;</td>';
1.137     raeburn  3891:                     }
1.145     raeburn  3892:                     $datatable .= '</tr></table>';
1.137     raeburn  3893:                 }
1.145     raeburn  3894:                 $datatable .= '</td></tr>';
                   3895:                 $itemcount ++;
1.137     raeburn  3896:             }
                   3897:         }
                   3898:     }
                   3899:     $$rowtotal += $itemcount;
                   3900:     return $datatable;
                   3901: }
                   3902: 
1.138     raeburn  3903: sub build_location_hashes {
                   3904:     my ($intdoms,$by_ip,$by_location) = @_;
                   3905:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
                   3906:                   (ref($by_location) eq 'HASH')); 
                   3907:     my %iphost = &Apache::lonnet::get_iphost();
                   3908:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
                   3909:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
                   3910:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
                   3911:         foreach my $id (@{$iphost{$primary_ip}}) {
                   3912:             my $intdom = &Apache::lonnet::internet_dom($id);
                   3913:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
                   3914:                 push(@{$intdoms},$intdom);
                   3915:             }
                   3916:         }
                   3917:     }
                   3918:     foreach my $ip (keys(%iphost)) {
                   3919:         if (ref($iphost{$ip}) eq 'ARRAY') {
                   3920:             foreach my $id (@{$iphost{$ip}}) {
                   3921:                 my $location = &Apache::lonnet::internet_dom($id);
                   3922:                 if ($location) {
                   3923:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
                   3924:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   3925:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
                   3926:                             push(@{$by_ip->{$ip}},$location);
                   3927:                         }
                   3928:                     } else {
                   3929:                         $by_ip->{$ip} = [$location];
                   3930:                     }
                   3931:                 }
                   3932:             }
                   3933:         }
                   3934:     }
                   3935:     foreach my $ip (sort(keys(%{$by_ip}))) {
                   3936:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
                   3937:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
                   3938:             my $first = $by_ip->{$ip}->[0];
                   3939:             if (ref($by_location->{$first}) eq 'ARRAY') {
                   3940:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
                   3941:                     push(@{$by_location->{$first}},$ip);
                   3942:                 }
                   3943:             } else {
                   3944:                 $by_location->{$first} = [$ip];
                   3945:             }
                   3946:         }
                   3947:     }
                   3948:     return;
                   3949: }
                   3950: 
1.145     raeburn  3951: sub current_offloads_to {
                   3952:     my ($dom,$settings,$servers) = @_;
                   3953:     my (%spareid,%otherdomconfigs);
1.152     raeburn  3954:     if (ref($servers) eq 'HASH') {
1.145     raeburn  3955:         foreach my $lonhost (sort(keys(%{$servers}))) {
                   3956:             my $gotspares;
1.152     raeburn  3957:             if (ref($settings) eq 'HASH') {
                   3958:                 if (ref($settings->{'spares'}) eq 'HASH') {
                   3959:                     if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
                   3960:                         $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
                   3961:                         $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
                   3962:                         $gotspares = 1;
                   3963:                     }
1.145     raeburn  3964:                 }
                   3965:             }
                   3966:             unless ($gotspares) {
                   3967:                 my $gotspares;
                   3968:                 my $serverhomeID =
                   3969:                     &Apache::lonnet::get_server_homeID($servers->{$lonhost});
                   3970:                 my $serverhomedom =
                   3971:                     &Apache::lonnet::host_domain($serverhomeID);
                   3972:                 if ($serverhomedom ne $dom) {
                   3973:                     if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
                   3974:                         if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   3975:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   3976:                                 $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   3977:                                 $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   3978:                                 $gotspares = 1;
                   3979:                             }
                   3980:                         }
                   3981:                     } else {
                   3982:                         $otherdomconfigs{$serverhomedom} =
                   3983:                             &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
                   3984:                         if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
                   3985:                             if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
                   3986:                                 if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
                   3987:                                     if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
                   3988:                                         $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
                   3989:                                         $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
                   3990:                                         $gotspares = 1;
                   3991:                                     }
                   3992:                                 }
                   3993:                             }
                   3994:                         }
                   3995:                     }
                   3996:                 }
                   3997:             }
                   3998:             unless ($gotspares) {
                   3999:                 if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4000:                     $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4001:                     $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4002:                } else {
                   4003:                     my $server_hostname = &Apache::lonnet::hostname($lonhost);
                   4004:                     my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
                   4005:                     if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
                   4006:                         $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
                   4007:                         $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
                   4008:                     } else {
1.150     raeburn  4009:                         my %what = (
                   4010:                              spareid => 1,
                   4011:                         );
                   4012:                         my ($result,$returnhash) = 
                   4013:                             &Apache::lonnet::get_remote_globals($lonhost,\%what);
                   4014:                         if ($result eq 'ok') { 
                   4015:                             if (ref($returnhash) eq 'HASH') {
                   4016:                                 if (ref($returnhash->{'spareid'}) eq 'HASH') {
                   4017:                                     $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
                   4018:                                     $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
                   4019:                                 }
                   4020:                             }
1.145     raeburn  4021:                         }
                   4022:                     }
                   4023:                 }
                   4024:             }
                   4025:         }
                   4026:     }
                   4027:     return %spareid;
                   4028: }
                   4029: 
                   4030: sub spares_row {
1.261     raeburn  4031:     my ($dom,$servers,$spareid,$serverhomes,$altids,$curroffloadnow,$rowtotal) = @_;
1.145     raeburn  4032:     my $css_class;
                   4033:     my $numinrow = 4;
                   4034:     my $itemcount = 1;
                   4035:     my $datatable;
1.152     raeburn  4036:     my %typetitles = &sparestype_titles();
                   4037:     if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145     raeburn  4038:         foreach my $server (sort(keys(%{$servers}))) {
1.152     raeburn  4039:             my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
                   4040:             my ($othercontrol,$serverdom);
                   4041:             if ($serverhome ne $server) {
                   4042:                 $serverdom = &Apache::lonnet::host_domain($serverhome);
                   4043:                 $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4044:             } else {
                   4045:                 $serverdom = &Apache::lonnet::host_domain($server);
                   4046:                 if ($serverdom ne $dom) {
                   4047:                     $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
                   4048:                 }
                   4049:             }
                   4050:             next unless (ref($spareid->{$server}) eq 'HASH');
1.261     raeburn  4051:             my $checkednow;
                   4052:             if (ref($curroffloadnow) eq 'HASH') {
                   4053:                 if ($curroffloadnow->{$server}) {
                   4054:                     $checkednow = ' checked="checked"';
                   4055:                 }
                   4056:             }
1.145     raeburn  4057:             $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
                   4058:             $datatable .= '<tr'.$css_class.'>
                   4059:                            <td rowspan="2">
1.183     bisitz   4060:                             <span class="LC_nobreak">'.
                   4061:                           &mt('[_1] when busy, offloads to:'
1.261     raeburn  4062:                               ,'<b>'.$server.'</b>').'</span><br />'.
                   4063:                           '<span class="LC_nobreak">'."\n". 
                   4064:                           '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
                   4065:                           '&nbsp;'.&mt('Switch active users on next access').'</label></span>'.
1.183     bisitz   4066:                           "\n";
1.145     raeburn  4067:             my (%current,%canselect);
1.152     raeburn  4068:             my @choices = 
                   4069:                 &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
                   4070:             foreach my $type ('primary','default') {
                   4071:                 if (ref($spareid->{$server}) eq 'HASH') {
1.145     raeburn  4072:                     if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
                   4073:                         my @spares = @{$spareid->{$server}{$type}};
                   4074:                         if (@spares > 0) {
1.152     raeburn  4075:                             if ($othercontrol) {
                   4076:                                 $current{$type} = join(', ',@spares);
                   4077:                             } else {
                   4078:                                 $current{$type} .= '<table>';
                   4079:                                 my $numspares = scalar(@spares);
                   4080:                                 for (my $i=0;  $i<@spares; $i++) {
                   4081:                                     my $rem = $i%($numinrow);
                   4082:                                     if ($rem == 0) {
                   4083:                                         if ($i > 0) {
                   4084:                                             $current{$type} .= '</tr>';
                   4085:                                         }
                   4086:                                         $current{$type} .= '<tr>';
1.145     raeburn  4087:                                     }
1.152     raeburn  4088:                                     $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;'.
                   4089:                                                        $spareid->{$server}{$type}[$i].
                   4090:                                                        '</label></td>'."\n";
                   4091:                                 }
                   4092:                                 my $rem = @spares%($numinrow);
                   4093:                                 my $colsleft = $numinrow - $rem;
                   4094:                                 if ($colsleft > 1 ) {
                   4095:                                     $current{$type} .= '<td colspan="'.$colsleft.
                   4096:                                                        '" class="LC_left_item">'.
                   4097:                                                        '&nbsp;</td>';
                   4098:                                 } elsif ($colsleft == 1) {
                   4099:                                     $current{$type} .= '<td class="LC_left_item">&nbsp;</td>'."\n";
1.145     raeburn  4100:                                 }
1.152     raeburn  4101:                                 $current{$type} .= '</tr></table>';
1.150     raeburn  4102:                             }
1.145     raeburn  4103:                         }
                   4104:                     }
                   4105:                     if ($current{$type} eq '') {
                   4106:                         $current{$type} = &mt('None specified');
                   4107:                     }
1.152     raeburn  4108:                     if ($othercontrol) {
                   4109:                         if ($type eq 'primary') {
                   4110:                             $canselect{$type} = $othercontrol;
                   4111:                         }
                   4112:                     } else {
                   4113:                         $canselect{$type} = 
                   4114:                             &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').'&nbsp;'.
                   4115:                             '<select name="newspare_'.$type.'_'.$server.'" '.
                   4116:                             'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
                   4117:                             '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
                   4118:                         if (@choices > 0) {
                   4119:                             foreach my $lonhost (@choices) {
                   4120:                                 $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
                   4121:                             }
                   4122:                         }
                   4123:                         $canselect{$type} .= '</select>'."\n";
                   4124:                     }
                   4125:                 } else {
                   4126:                     $current{$type} = &mt('Could not be determined');
                   4127:                     if ($type eq 'primary') {
                   4128:                         $canselect{$type} =  $othercontrol;
                   4129:                     }
1.145     raeburn  4130:                 }
1.152     raeburn  4131:                 if ($type eq 'default') {
                   4132:                     $datatable .= '<tr'.$css_class.'>';
                   4133:                 }
                   4134:                 $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
                   4135:                               '<td>'.$current{$type}.'</td>'."\n".
                   4136:                               '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145     raeburn  4137:             }
                   4138:             $itemcount ++;
                   4139:         }
                   4140:     }
                   4141:     $$rowtotal += $itemcount;
                   4142:     return $datatable;
                   4143: }
                   4144: 
1.152     raeburn  4145: sub possible_newspares {
                   4146:     my ($server,$currspares,$serverhomes,$altids) = @_;
                   4147:     my $serverhostname = &Apache::lonnet::hostname($server);
                   4148:     my %excluded;
                   4149:     if ($serverhostname ne '') {
                   4150:         %excluded = (
                   4151:                        $serverhostname => 1,
                   4152:                     );
                   4153:     }
                   4154:     if (ref($currspares) eq 'HASH') {
                   4155:         foreach my $type (keys(%{$currspares})) {
                   4156:             if (ref($currspares->{$type}) eq 'ARRAY') {
                   4157:                 if (@{$currspares->{$type}} > 0) {
                   4158:                     foreach my $curr (@{$currspares->{$type}}) {
                   4159:                         my $hostname = &Apache::lonnet::hostname($curr);
                   4160:                         $excluded{$hostname} = 1;
                   4161:                     }
                   4162:                 }
                   4163:             }
                   4164:         }
                   4165:     }
                   4166:     my @choices;
                   4167:     if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
                   4168:         if (keys(%{$serverhomes}) > 1) {
                   4169:             foreach my $name (sort(keys(%{$serverhomes}))) {
                   4170:                 unless ($excluded{$name}) {
                   4171:                     if (exists($altids->{$serverhomes->{$name}})) {
                   4172:                         push(@choices,$altids->{$serverhomes->{$name}});
                   4173:                     } else {
                   4174:                         push(@choices,$serverhomes->{$name});
1.145     raeburn  4175:                     }
                   4176:                 }
                   4177:             }
                   4178:         }
                   4179:     }
1.152     raeburn  4180:     return sort(@choices);
1.145     raeburn  4181: }
                   4182: 
1.150     raeburn  4183: sub print_loadbalancing {
                   4184:     my ($dom,$settings,$rowtotal) = @_;
                   4185:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   4186:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   4187:     my $numinrow = 1;
                   4188:     my $datatable;
                   4189:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171     raeburn  4190:     my (%currbalancer,%currtargets,%currrules,%existing);
                   4191:     if (ref($settings) eq 'HASH') {
                   4192:         %existing = %{$settings};
                   4193:     }
                   4194:     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
                   4195:         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   4196:                                   \%currtargets,\%currrules);
1.150     raeburn  4197:     } else {
                   4198:         return;
                   4199:     }
                   4200:     my ($othertitle,$usertypes,$types) =
                   4201:         &Apache::loncommon::sorted_inst_types($dom);
1.209     raeburn  4202:     my $rownum = 8;
1.150     raeburn  4203:     if (ref($types) eq 'ARRAY') {
                   4204:         $rownum += scalar(@{$types});
                   4205:     }
1.171     raeburn  4206:     my @css_class = ('LC_odd_row','LC_even_row');
                   4207:     my $balnum = 0;
                   4208:     my $islast;
                   4209:     my (@toshow,$disabledtext);
                   4210:     if (keys(%currbalancer) > 0) {
                   4211:         @toshow = sort(keys(%currbalancer));
                   4212:         if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
                   4213:             push(@toshow,'');
                   4214:         }
                   4215:     } else {
                   4216:         @toshow = ('');
                   4217:         $disabledtext = &mt('No existing load balancer');
                   4218:     }
                   4219:     foreach my $lonhost (@toshow) {
                   4220:         if ($balnum == scalar(@toshow)-1) {
                   4221:             $islast = 1;
                   4222:         } else {
                   4223:             $islast = 0;
                   4224:         }
                   4225:         my $cssidx = $balnum%2;
                   4226:         my $targets_div_style = 'display: none';
                   4227:         my $disabled_div_style = 'display: block';
                   4228:         my $homedom_div_style = 'display: none';
                   4229:         $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
                   4230:                       '<td rowspan="'.$rownum.'" valign="top">'.
                   4231:                       '<p>';
                   4232:         if ($lonhost eq '') {
1.210     raeburn  4233:             $datatable .= '<span class="LC_nobreak">';
1.171     raeburn  4234:             if (keys(%currbalancer) > 0) {
                   4235:                 $datatable .= &mt('Add balancer:');
                   4236:             } else {
                   4237:                 $datatable .= &mt('Enable balancer:');
                   4238:             }
                   4239:             $datatable .= '&nbsp;'.
                   4240:                           '<select name="loadbalancing_lonhost_'.$balnum.'"'.
                   4241:                           ' id="loadbalancing_lonhost_'.$balnum.'"'.
                   4242:                           ' onchange="toggleTargets('."'$balnum'".');">'."\n".
                   4243:                           '<option value="" selected="selected">'.&mt('None').
                   4244:                           '</option>'."\n";
                   4245:             foreach my $server (sort(keys(%servers))) {
                   4246:                 next if ($currbalancer{$server});
                   4247:                 $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
                   4248:             }
1.210     raeburn  4249:             $datatable .=
1.171     raeburn  4250:                 '</select>'."\n".
                   4251:                 '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" />&nbsp;</span>'."\n";
                   4252:         } else {
                   4253:             $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
                   4254:                           '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" />&nbsp;'.
                   4255:                            &mt('Stop balancing').'</label>'.
                   4256:                            '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
                   4257:             $targets_div_style = 'display: block';
                   4258:             $disabled_div_style = 'display: none';
                   4259:             if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
                   4260:                 $homedom_div_style = 'display: block';
                   4261:             }
                   4262:         }
                   4263:         $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
                   4264:                   '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
                   4265:                   $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
                   4266:                   '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
                   4267:         my ($numspares,@spares) = &count_servers($lonhost,%servers);
                   4268:         my @sparestypes = ('primary','default');
                   4269:         my %typetitles = &sparestype_titles();
                   4270:         foreach my $sparetype (@sparestypes) {
                   4271:             my $targettable;
                   4272:             for (my $i=0; $i<$numspares; $i++) {
                   4273:                 my $checked;
                   4274:                 if (ref($currtargets{$lonhost}) eq 'HASH') {
                   4275:                     if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
                   4276:                         if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
                   4277:                             $checked = ' checked="checked"';
                   4278:                         }
                   4279:                     }
                   4280:                 }
                   4281:                 my ($chkboxval,$disabled);
                   4282:                 if (($lonhost ne '') && (exists($servers{$lonhost}))) {
                   4283:                     $chkboxval = $spares[$i];
                   4284:                 }
                   4285:                 if (exists($currbalancer{$spares[$i]})) {
                   4286:                     $disabled = ' disabled="disabled"';
                   4287:                 }
1.210     raeburn  4288:                 $targettable .=
1.253     raeburn  4289:                     '<td><span class="LC_nobreak"><label>'.
                   4290:                     '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171     raeburn  4291:                     $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'">&nbsp;'.$chkboxval.
1.253     raeburn  4292:                     '</span></label></span></td>';
1.171     raeburn  4293:                 my $rem = $i%($numinrow);
                   4294:                 if ($rem == 0) {
                   4295:                     if (($i > 0) && ($i < $numspares-1)) {
                   4296:                         $targettable .= '</tr>';
                   4297:                     }
                   4298:                     if ($i < $numspares-1) {
                   4299:                         $targettable .= '<tr>';
1.150     raeburn  4300:                     }
                   4301:                 }
                   4302:             }
1.171     raeburn  4303:             if ($targettable ne '') {
                   4304:                 my $rem = $numspares%($numinrow);
                   4305:                 my $colsleft = $numinrow - $rem;
                   4306:                 if ($colsleft > 1 ) {
                   4307:                     $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4308:                                     '&nbsp;</td>';
                   4309:                 } elsif ($colsleft == 1) {
                   4310:                     $targettable .= '<td class="LC_left_item">&nbsp;</td>';
                   4311:                 }
                   4312:                 $datatable .=  '<i>'.$typetitles{$sparetype}.'</i><br />'.
                   4313:                                '<table><tr>'.$targettable.'</tr></table><br />';
                   4314:             }
                   4315:         }
                   4316:         $datatable .= '</div></td></tr>'.
                   4317:                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                   4318:                                            $othertitle,$usertypes,$types,\%servers,
                   4319:                                            \%currbalancer,$lonhost,
                   4320:                                            $targets_div_style,$homedom_div_style,
                   4321:                                            $css_class[$cssidx],$balnum,$islast);
                   4322:         $$rowtotal += $rownum;
                   4323:         $balnum ++;
                   4324:     }
                   4325:     $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
                   4326:     return $datatable;
                   4327: }
                   4328: 
                   4329: sub get_loadbalancers_config {
                   4330:     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
                   4331:     return unless ((ref($servers) eq 'HASH') &&
                   4332:                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                   4333:                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
                   4334:     if (keys(%{$existing}) > 0) {
                   4335:         my $oldlonhost;
                   4336:         foreach my $key (sort(keys(%{$existing}))) {
                   4337:             if ($key eq 'lonhost') {
                   4338:                 $oldlonhost = $existing->{'lonhost'};
                   4339:                 $currbalancer->{$oldlonhost} = 1;
                   4340:             } elsif ($key eq 'targets') {
                   4341:                 if ($oldlonhost) {
                   4342:                     $currtargets->{$oldlonhost} = $existing->{'targets'};
                   4343:                 }
                   4344:             } elsif ($key eq 'rules') {
                   4345:                 if ($oldlonhost) {
                   4346:                     $currrules->{$oldlonhost} = $existing->{'rules'};
                   4347:                 }
                   4348:             } elsif (ref($existing->{$key}) eq 'HASH') {
                   4349:                 $currbalancer->{$key} = 1;
                   4350:                 $currtargets->{$key} = $existing->{$key}{'targets'};
                   4351:                 $currrules->{$key} = $existing->{$key}{'rules'};
1.150     raeburn  4352:             }
                   4353:         }
1.171     raeburn  4354:     } else {
                   4355:         my ($balancerref,$targetsref) =
                   4356:                 &Apache::lonnet::get_lonbalancer_config($servers);
                   4357:         if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
                   4358:             foreach my $server (sort(keys(%{$balancerref}))) {
                   4359:                 $currbalancer->{$server} = 1;
                   4360:                 $currtargets->{$server} = $targetsref->{$server};
1.150     raeburn  4361:             }
                   4362:         }
                   4363:     }
1.171     raeburn  4364:     return;
1.150     raeburn  4365: }
                   4366: 
                   4367: sub loadbalancing_rules {
                   4368:     my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171     raeburn  4369:         $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
                   4370:         $css_class,$balnum,$islast) = @_;
1.150     raeburn  4371:     my $output;
1.171     raeburn  4372:     my $num = 0;
1.210     raeburn  4373:     my ($alltypes,$othertypes,$titles) =
1.150     raeburn  4374:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   4375:     if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH'))  {
                   4376:         foreach my $type (@{$alltypes}) {
1.171     raeburn  4377:             $num ++;
1.150     raeburn  4378:             my $current;
                   4379:             if (ref($currrules) eq 'HASH') {
                   4380:                 $current = $currrules->{$type};
                   4381:             }
1.253     raeburn  4382:             if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171     raeburn  4383:                 if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150     raeburn  4384:                     $current = '';
                   4385:                 }
                   4386:             }
                   4387:             $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171     raeburn  4388:                                              $servers,$currbalancer,$lonhost,$dom,
                   4389:                                              $targets_div_style,$homedom_div_style,
                   4390:                                              $css_class,$balnum,$num,$islast);
1.150     raeburn  4391:         }
                   4392:     }
                   4393:     return $output;
                   4394: }
                   4395: 
                   4396: sub loadbalancing_titles {
                   4397:     my ($dom,$intdom,$usertypes,$types) = @_;
                   4398:     my %othertypes = (
                   4399:            '_LC_adv'         => &mt('Advanced users from [_1]',$dom),
                   4400:            '_LC_author'      => &mt('Users from [_1] with author role',$dom),
                   4401:            '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
                   4402:            '_LC_external'    => &mt('Users not from [_1]',$intdom),
1.209     raeburn  4403:            '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
                   4404:            '_LC_ipchange'    => &mt('Non-SSO users with IP mismatch'),
1.150     raeburn  4405:                      );
1.209     raeburn  4406:     my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150     raeburn  4407:     if (ref($types) eq 'ARRAY') {
                   4408:         unshift(@alltypes,@{$types},'default');
                   4409:     }
                   4410:     my %titles;
                   4411:     foreach my $type (@alltypes) {
                   4412:         if ($type =~ /^_LC_/) {
                   4413:             $titles{$type} = $othertypes{$type};
                   4414:         } elsif ($type eq 'default') {
                   4415:             $titles{$type} = &mt('All users from [_1]',$dom);
                   4416:             if (ref($types) eq 'ARRAY') {
                   4417:                 if (@{$types} > 0) {
                   4418:                     $titles{$type} = &mt('Other users from [_1]',$dom);
                   4419:                 }
                   4420:             }
                   4421:         } elsif (ref($usertypes) eq 'HASH') {
                   4422:             $titles{$type} = $usertypes->{$type};
                   4423:         }
                   4424:     }
                   4425:     return (\@alltypes,\%othertypes,\%titles);
                   4426: }
                   4427: 
                   4428: sub loadbalance_rule_row {
1.171     raeburn  4429:     my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
                   4430:         $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209     raeburn  4431:     my @rulenames;
1.150     raeburn  4432:     my %ruletitles = &offloadtype_text();
1.209     raeburn  4433:     if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254     raeburn  4434:         @rulenames = ('balancer','offloadedto','specific');
1.150     raeburn  4435:     } else {
1.209     raeburn  4436:         @rulenames = ('default','homeserver');
                   4437:         if ($type eq '_LC_external') {
                   4438:             push(@rulenames,'externalbalancer');
                   4439:         } else {
                   4440:             push(@rulenames,'specific');
                   4441:         }
                   4442:         push(@rulenames,'none');
1.150     raeburn  4443:     }
                   4444:     my $style = $targets_div_style;
1.253     raeburn  4445:     if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150     raeburn  4446:         $style = $homedom_div_style;
                   4447:     }
1.171     raeburn  4448:     my $space;
                   4449:     if ($islast && $num == 1) {
                   4450:         $space = '<div display="inline-block">&nbsp;</div>';
                   4451:     }
1.210     raeburn  4452:     my $output =
1.171     raeburn  4453:         '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
                   4454:         '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
                   4455:         '<td valaign="top">'.$space.
                   4456:         '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150     raeburn  4457:     for (my $i=0; $i<@rulenames; $i++) {
                   4458:         my $rule = $rulenames[$i];
                   4459:         my ($checked,$extra);
                   4460:         if ($rulenames[$i] eq 'default') {
                   4461:             $rule = '';
                   4462:         }
                   4463:         if ($rulenames[$i] eq 'specific') {
                   4464:             if (ref($servers) eq 'HASH') {
                   4465:                 my $default;
                   4466:                 if (($current ne '') && (exists($servers->{$current}))) {
                   4467:                     $checked = ' checked="checked"';
                   4468:                 }
                   4469:                 unless ($checked) {
                   4470:                     $default = ' selected="selected"';
                   4471:                 }
1.210     raeburn  4472:                 $extra =
1.171     raeburn  4473:                     ':&nbsp;<select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4474:                     '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
                   4475:                     '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
                   4476:                     '<option value=""'.$default.'></option>'."\n";
                   4477:                 foreach my $server (sort(keys(%{$servers}))) {
                   4478:                     if (ref($currbalancer) eq 'HASH') {
                   4479:                         next if (exists($currbalancer->{$server}));
                   4480:                     }
1.150     raeburn  4481:                     my $selected;
1.171     raeburn  4482:                     if ($server eq $current) {
1.150     raeburn  4483:                         $selected = ' selected="selected"';
                   4484:                     }
1.171     raeburn  4485:                     $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150     raeburn  4486:                 }
                   4487:                 $extra .= '</select>';
                   4488:             }
                   4489:         } elsif ($rule eq $current) {
                   4490:             $checked = ' checked="checked"';
                   4491:         }
                   4492:         $output .= '<span class="LC_nobreak"><label>'.
1.171     raeburn  4493:                    '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
                   4494:                    '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
                   4495:                    $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254     raeburn  4496:                    ')"'.$checked.' />&nbsp;';
                   4497:         if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
                   4498:             $output .= $ruletitles{'particular'};
                   4499:         } else {
                   4500:             $output .= $ruletitles{$rulenames[$i]};
                   4501:         }
                   4502:         $output .= '</label>'.$extra.'</span><br />'."\n";
1.150     raeburn  4503:     }
                   4504:     $output .= '</div></td></tr>'."\n";
                   4505:     return $output;
                   4506: }
                   4507: 
                   4508: sub offloadtype_text {
                   4509:     my %ruletitles = &Apache::lonlocal::texthash (
                   4510:            'default'          => 'Offloads to default destinations',
                   4511:            'homeserver'       => "Offloads to user's home server",
                   4512:            'externalbalancer' => "Offloads to Load Balancer in user's domain",
                   4513:            'specific'         => 'Offloads to specific server',
1.161     raeburn  4514:            'none'             => 'No offload',
1.209     raeburn  4515:            'balancer'         => 'Session hosted on Load Balancer, after re-authentication',
                   4516:            'offloadedto'      => 'Session hosted on offload server, after re-authentication',
1.254     raeburn  4517:            'particular'       => 'Session hosted (after re-auth) on server:',
1.150     raeburn  4518:     );
                   4519:     return %ruletitles;
                   4520: }
                   4521: 
                   4522: sub sparestype_titles {
                   4523:     my %typestitles = &Apache::lonlocal::texthash (
                   4524:                           'primary' => 'primary',
                   4525:                           'default' => 'default',
                   4526:                       );
                   4527:     return %typestitles;
                   4528: }
                   4529: 
1.28      raeburn  4530: sub contact_titles {
                   4531:     my %titles = &Apache::lonlocal::texthash (
                   4532:                    'supportemail' => 'Support E-mail address',
1.69      raeburn  4533:                    'adminemail'   => 'Default Server Admin E-mail address',
1.28      raeburn  4534:                    'errormail'    => 'Error reports to be e-mailed to',
                   4535:                    'packagesmail' => 'Package update alerts to be e-mailed to',
1.89      raeburn  4536:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
                   4537:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102     raeburn  4538:                    'requestsmail' => 'E-mail from course requests requiring approval',
1.190     raeburn  4539:                    'updatesmail'  => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203     raeburn  4540:                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28      raeburn  4541:                  );
                   4542:     my %short_titles = &Apache::lonlocal::texthash (
                   4543:                            adminemail   => 'Admin E-mail address',
                   4544:                            supportemail => 'Support E-mail',
                   4545:                        );   
                   4546:     return (\%titles,\%short_titles);
                   4547: }
                   4548: 
1.72      raeburn  4549: sub tool_titles {
                   4550:     my %titles = &Apache::lonlocal::texthash (
1.162     raeburn  4551:                      aboutme    => 'Personal web page',
1.86      raeburn  4552:                      blog       => 'Blog',
1.162     raeburn  4553:                      webdav     => 'WebDAV',
1.86      raeburn  4554:                      portfolio  => 'Portfolio',
1.88      bisitz   4555:                      official   => 'Official courses (with institutional codes)',
                   4556:                      unofficial => 'Unofficial courses',
1.98      raeburn  4557:                      community  => 'Communities',
1.216     raeburn  4558:                      textbook   => 'Textbook courses',
1.271     raeburn  4559:                      placement  => 'Placement tests',
1.86      raeburn  4560:                  );
1.72      raeburn  4561:     return %titles;
                   4562: }
                   4563: 
1.101     raeburn  4564: sub courserequest_titles {
                   4565:     my %titles = &Apache::lonlocal::texthash (
                   4566:                                    official   => 'Official',
                   4567:                                    unofficial => 'Unofficial',
                   4568:                                    community  => 'Communities',
1.216     raeburn  4569:                                    textbook   => 'Textbook',
1.271     raeburn  4570:                                    placement  => 'Placement tests',
1.101     raeburn  4571:                                    norequest  => 'Not allowed',
1.104     raeburn  4572:                                    approval   => 'Approval by Dom. Coord.',
1.101     raeburn  4573:                                    validate   => 'With validation',
                   4574:                                    autolimit  => 'Numerical limit',
1.103     raeburn  4575:                                    unlimited  => '(blank for unlimited)',
1.101     raeburn  4576:                  );
                   4577:     return %titles;
                   4578: }
                   4579: 
1.163     raeburn  4580: sub authorrequest_titles {
                   4581:     my %titles = &Apache::lonlocal::texthash (
                   4582:                                    norequest  => 'Not allowed',
                   4583:                                    approval   => 'Approval by Dom. Coord.',
                   4584:                                    automatic  => 'Automatic approval',
                   4585:                  );
                   4586:     return %titles;
1.210     raeburn  4587: }
1.163     raeburn  4588: 
1.101     raeburn  4589: sub courserequest_conditions {
                   4590:     my %conditions = &Apache::lonlocal::texthash (
1.104     raeburn  4591:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
1.193     bisitz   4592:        validate   => '(Processing of request subject to institutional validation).',
1.101     raeburn  4593:                  );
                   4594:     return %conditions;
                   4595: }
                   4596: 
                   4597: 
1.27      raeburn  4598: sub print_usercreation {
1.30      raeburn  4599:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  4600:     my $numinrow = 4;
1.28      raeburn  4601:     my $datatable;
                   4602:     if ($position eq 'top') {
1.30      raeburn  4603:         $$rowtotal ++;
1.34      raeburn  4604:         my $rowcount = 0;
1.32      raeburn  4605:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  4606:         if (ref($rules) eq 'HASH') {
                   4607:             if (keys(%{$rules}) > 0) {
1.32      raeburn  4608:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   4609:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  4610:                 $$rowtotal ++;
1.32      raeburn  4611:                 $rowcount ++;
                   4612:             }
                   4613:         }
                   4614:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   4615:         if (ref($idrules) eq 'HASH') {
                   4616:             if (keys(%{$idrules}) > 0) {
                   4617:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   4618:                                                 $idruleorder,$numinrow,$rowcount);
                   4619:                 $$rowtotal ++;
                   4620:                 $rowcount ++;
1.28      raeburn  4621:             }
                   4622:         }
1.39      raeburn  4623:         if ($rowcount == 0) {
                   4624:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
                   4625:             $$rowtotal ++;
                   4626:             $rowcount ++;
                   4627:         }
1.34      raeburn  4628:     } elsif ($position eq 'middle') {
1.224     raeburn  4629:         my @creators = ('author','course','requestcrs');
1.37      raeburn  4630:         my ($rules,$ruleorder) =
                   4631:             &Apache::lonnet::inst_userrules($dom,'username');
1.34      raeburn  4632:         my %lt = &usercreation_types();
                   4633:         my %checked;
                   4634:         if (ref($settings) eq 'HASH') {
                   4635:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   4636:                 foreach my $item (@creators) {
                   4637:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   4638:                 }
                   4639:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   4640:                 foreach my $item (@creators) {
                   4641:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   4642:                         $checked{$item} = 'none';
                   4643:                     }
                   4644:                 }
                   4645:             }
                   4646:         }
                   4647:         my $rownum = 0;
                   4648:         foreach my $item (@creators) {
                   4649:             $rownum ++;
1.224     raeburn  4650:             if ($checked{$item} eq '') {
                   4651:                 $checked{$item} = 'any';
1.34      raeburn  4652:             }
                   4653:             my $css_class;
                   4654:             if ($rownum%2) {
                   4655:                 $css_class = '';
                   4656:             } else {
                   4657:                 $css_class = ' class="LC_odd_row" ';
                   4658:             }
                   4659:             $datatable .= '<tr'.$css_class.'>'.
                   4660:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   4661:                          '</span></td><td align="right">';
1.224     raeburn  4662:             my @options = ('any');
                   4663:             if (ref($rules) eq 'HASH') {
                   4664:                 if (keys(%{$rules}) > 0) {
                   4665:                     push(@options,('official','unofficial'));
1.37      raeburn  4666:                 }
                   4667:             }
1.224     raeburn  4668:             push(@options,'none');
1.37      raeburn  4669:             foreach my $option (@options) {
1.50      raeburn  4670:                 my $type = 'radio';
1.34      raeburn  4671:                 my $check = ' ';
1.224     raeburn  4672:                 if ($checked{$item} eq $option) {
                   4673:                     $check = ' checked="checked" ';
1.34      raeburn  4674:                 } 
                   4675:                 $datatable .= '<span class="LC_nobreak"><label>'.
1.50      raeburn  4676:                               '<input type="'.$type.'" name="can_createuser_'.
1.34      raeburn  4677:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   4678:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   4679:             }
                   4680:             $datatable .= '</td></tr>';
                   4681:         }
1.28      raeburn  4682:     } else {
                   4683:         my @contexts = ('author','course','domain');
                   4684:         my @authtypes = ('int','krb4','krb5','loc');
                   4685:         my %checked;
                   4686:         if (ref($settings) eq 'HASH') {
                   4687:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   4688:                 foreach my $item (@contexts) {
                   4689:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   4690:                         foreach my $auth (@authtypes) {
                   4691:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   4692:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   4693:                             }
                   4694:                         }
                   4695:                     }
                   4696:                 }
1.27      raeburn  4697:             }
1.35      raeburn  4698:         } else {
                   4699:             foreach my $item (@contexts) {
1.36      raeburn  4700:                 foreach my $auth (@authtypes) {
1.35      raeburn  4701:                     $checked{$item}{$auth} = ' checked="checked" ';
                   4702:                 }
                   4703:             }
1.27      raeburn  4704:         }
1.28      raeburn  4705:         my %title = &context_names();
                   4706:         my %authname = &authtype_names();
                   4707:         my $rownum = 0;
                   4708:         my $css_class; 
                   4709:         foreach my $item (@contexts) {
                   4710:             if ($rownum%2) {
                   4711:                 $css_class = '';
                   4712:             } else {
                   4713:                 $css_class = ' class="LC_odd_row" ';
                   4714:             }
1.30      raeburn  4715:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  4716:                             '<td>'.$title{$item}.
                   4717:                             '</td><td class="LC_left_item">'.
                   4718:                             '<span class="LC_nobreak">';
                   4719:             foreach my $auth (@authtypes) {
                   4720:                 $datatable .= '<label>'. 
                   4721:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   4722:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   4723:                               $authname{$auth}.'</label>&nbsp;';
                   4724:             }
                   4725:             $datatable .= '</span></td></tr>';
                   4726:             $rownum ++;
1.27      raeburn  4727:         }
1.30      raeburn  4728:         $$rowtotal += $rownum;
1.27      raeburn  4729:     }
                   4730:     return $datatable;
                   4731: }
                   4732: 
1.224     raeburn  4733: sub print_selfcreation {
                   4734:     my ($position,$dom,$settings,$rowtotal) = @_;
1.236     raeburn  4735:     my (@selfcreate,$createsettings,$processing,$datatable);
1.224     raeburn  4736:     if (ref($settings) eq 'HASH') {
                   4737:         if (ref($settings->{'cancreate'}) eq 'HASH') {
                   4738:             $createsettings = $settings->{'cancreate'};
1.236     raeburn  4739:             if (ref($createsettings) eq 'HASH') {
                   4740:                 if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
                   4741:                     @selfcreate = @{$createsettings->{'selfcreate'}};
                   4742:                 } elsif ($createsettings->{'selfcreate'} ne '') {
                   4743:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                   4744:                         @selfcreate = ('email','login','sso');
                   4745:                     } elsif ($createsettings->{'selfcreate'} ne 'none') {
                   4746:                         @selfcreate = ($createsettings->{'selfcreate'});
                   4747:                     }
                   4748:                 }
                   4749:                 if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
                   4750:                     $processing = $createsettings->{'selfcreateprocessing'};
1.224     raeburn  4751:                 }
                   4752:             }
                   4753:         }
                   4754:     }
                   4755:     my %radiohash;
                   4756:     my $numinrow = 4;
                   4757:     map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
                   4758:     if ($position eq 'top') {
                   4759:         my %choices = &Apache::lonlocal::texthash (
                   4760:                                                       cancreate_login      => 'Institutional Login',
                   4761:                                                       cancreate_sso        => 'Institutional Single Sign On',
                   4762:                                                   );
                   4763:         my @toggles = sort(keys(%choices));
                   4764:         my %defaultchecked = (
                   4765:                                'cancreate_login' => 'off',
                   4766:                                'cancreate_sso'   => 'off',
                   4767:                              );
1.228     raeburn  4768:         my ($onclick,$itemcount);
1.224     raeburn  4769:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
                   4770:                                                      \%choices,$itemcount,$onclick);
1.228     raeburn  4771:         $$rowtotal += $itemcount;
                   4772:         
1.224     raeburn  4773:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4774: 
                   4775:         if (ref($usertypes) eq 'HASH') {
                   4776:             if (keys(%{$usertypes}) > 0) {
                   4777:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
                   4778:                                              $dom,$numinrow,$othertitle,
1.228     raeburn  4779:                                              'statustocreate',$$rowtotal);
1.224     raeburn  4780:                 $$rowtotal ++;
                   4781:             }
                   4782:         }
1.240     raeburn  4783:         my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
                   4784:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   4785:         $fieldtitles{'inststatus'} = &mt('Institutional status');
                   4786:         my $rem;
                   4787:         my $numperrow = 2;
                   4788:         my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
                   4789:         $datatable .= '<tr'.$css_class.'>'.
1.241     raeburn  4790:                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240     raeburn  4791:                      '<td class="LC_left_item">'."\n".
                   4792:                      '<table><tr><td>'."\n";
                   4793:         for (my $i=0; $i<@fields; $i++) {
                   4794:             $rem = $i%($numperrow);
                   4795:             if ($rem == 0) {
                   4796:                 if ($i > 0) {
                   4797:                     $datatable .= '</tr>';
                   4798:                 }
                   4799:                 $datatable .= '<tr>';
                   4800:             }
                   4801:             my $currval;
1.248     raeburn  4802:             if (ref($createsettings) eq 'HASH') {
                   4803:                 if (ref($createsettings->{'shibenv'}) eq 'HASH') {
                   4804:                     $currval = $createsettings->{'shibenv'}{$fields[$i]};
                   4805:                 }
1.240     raeburn  4806:             }
                   4807:             $datatable .= '<td class="LC_left_item">'.
                   4808:                           '<span class="LC_nobreak">'.
                   4809:                           '<input type="text" name="shibenv_'.$fields[$i].'" '.
                   4810:                           'value="'.$currval.'" size="10" />&nbsp;'.
                   4811:                           $fieldtitles{$fields[$i]}.'</span></td>';
                   4812:         }
                   4813:         my $colsleft = $numperrow - $rem;
                   4814:         if ($colsleft > 1 ) {
                   4815:             $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   4816:                          '&nbsp;</td>';
                   4817:         } elsif ($colsleft == 1) {
                   4818:             $datatable .= '<td class="LC_left_item">&nbsp;</td>';
                   4819:         }
                   4820:         $datatable .= '</tr></table></td></tr>';
                   4821:         $$rowtotal ++;
1.224     raeburn  4822:     } elsif ($position eq 'middle') {
                   4823:         my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
                   4824:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   4825:         $usertypes->{'default'} = $othertitle;
                   4826:         if (ref($types) eq 'ARRAY') {
                   4827:             push(@{$types},'default');
                   4828:             $usertypes->{'default'} = $othertitle;
                   4829:             foreach my $status (@{$types}) {
                   4830:                 $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
1.228     raeburn  4831:                                                        $numinrow,$$rowtotal,$usertypes);
1.240     raeburn  4832:                 $$rowtotal ++;
1.224     raeburn  4833:             }
                   4834:         }
                   4835:     } else {
1.236     raeburn  4836:         my %choices = &Apache::lonlocal::texthash (
                   4837:                                                       cancreate_email => 'E-mail address as username',
                   4838:                                                   );
                   4839:         my @toggles = sort(keys(%choices));
                   4840:         my %defaultchecked = (
                   4841:                                'cancreate_email' => 'off',
                   4842:                              );
                   4843:         my $itemcount = 0;
                   4844:         my $display = 'none';
                   4845:         if (grep(/^\Qemail\E$/,@selfcreate)) {
                   4846:             $display = 'block';
                   4847:         }
                   4848:         my $onclick = "toggleDisplay(this.form,'emailoptions');";
                   4849:         my $additional = '<div id="emailoptions" style="display: '.$display.'">';
                   4850:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   4851:         my $usertypes = {};
                   4852:         my $order = [];
                   4853:         if ((ref($domdefaults{'inststatustypes'}) eq 'HASH') && (ref($domdefaults{'inststatusguest'}) eq 'ARRAY')) {
                   4854:             $usertypes = $domdefaults{'inststatustypes'};
                   4855:             $order = $domdefaults{'inststatusguest'};
                   4856:         }
                   4857:         if (ref($order) eq 'ARRAY') {
                   4858:             push(@{$order},'default');
                   4859:             if (@{$order} > 1) {
                   4860:                 $usertypes->{'default'} = &mt('Other users');
                   4861:                 $additional .= '<table><tr>';
                   4862:                 foreach my $status (@{$order}) {
                   4863:                     $additional .= '<th>'.$usertypes->{$status}.'</th>';
                   4864:                 }
                   4865:                 $additional .= '</tr><tr>';
                   4866:                 foreach my $status (@{$order}) {
                   4867:                     $additional .= '<td>'.&email_as_username($rowtotal,$processing,$status).'</td>';
1.224     raeburn  4868:                 }
1.236     raeburn  4869:                 $additional .= '</tr></table>';
1.224     raeburn  4870:             } else {
1.236     raeburn  4871:                 $usertypes->{'default'} = &mt('All users');
                   4872:                 $additional .= &email_as_username($rowtotal,$processing);
1.224     raeburn  4873:             }
                   4874:         }
1.236     raeburn  4875:         $additional .= '</div>'."\n";
                   4876: 
                   4877:         ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
1.240     raeburn  4878:                                                      \%choices,$$rowtotal,$onclick,$additional);
                   4879:         $$rowtotal ++;
1.236     raeburn  4880:         $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal);
1.228     raeburn  4881:         $$rowtotal ++;
1.224     raeburn  4882:         my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228     raeburn  4883:         $numinrow = 1;
1.236     raeburn  4884:         if (ref($order) eq 'ARRAY') {
                   4885:             foreach my $status (@{$order}) {
1.228     raeburn  4886:                 $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
                   4887:                                                        $numinrow,$$rowtotal,$usertypes,$infofields,$infotitles);
                   4888:                 $$rowtotal ++;
                   4889:             }
                   4890:         }
1.224     raeburn  4891:         my ($emailrules,$emailruleorder) =
                   4892:             &Apache::lonnet::inst_userrules($dom,'email');
                   4893:         if (ref($emailrules) eq 'HASH') {
                   4894:             if (keys(%{$emailrules}) > 0) {
                   4895:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
1.228     raeburn  4896:                                                 $emailruleorder,$numinrow,$$rowtotal);
1.224     raeburn  4897:                 $$rowtotal ++;
                   4898:             }
                   4899:         }
1.228     raeburn  4900:         $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal);
1.224     raeburn  4901:     }
                   4902:     return $datatable;
                   4903: }
                   4904: 
1.236     raeburn  4905: sub email_as_username {
                   4906:     my ($rowtotal,$processing,$type) = @_;
                   4907:     my %choices =
                   4908:         &Apache::lonlocal::texthash (
                   4909:                                       automatic => 'Automatic approval',
                   4910:                                       approval  => 'Queued for approval',
                   4911:                                     );
                   4912:     my $output;
                   4913:     foreach my $option ('automatic','approval') {
                   4914:         my $checked;
                   4915:         if (ref($processing) eq 'HASH') {
                   4916:             if ($type eq '') {   
                   4917:                 if (!exists($processing->{'default'})) {
                   4918:                     if ($option eq 'automatic') {
                   4919:                         $checked = ' checked="checked"';
                   4920:                     }
                   4921:                 } else {
                   4922:                     if ($processing->{'default'} eq $option) {
                   4923:                         $checked = ' checked="checked"';
                   4924:                     }
                   4925:                 }
                   4926:             } else {
                   4927:                 if (!exists($processing->{$type})) {
                   4928:                     if ($option eq 'automatic') {
                   4929:                         $checked = ' checked="checked"';
                   4930:                     }
                   4931:                 } else {
                   4932:                     if ($processing->{$type} eq $option) {
                   4933:                         $checked = ' checked="checked"';
                   4934:                     }
                   4935:                 }
                   4936:             }
                   4937:         } elsif ($option eq 'automatic') {
                   4938:             $checked = ' checked="checked"'; 
                   4939:         }
                   4940:         my $name = 'cancreate_emailprocess';
                   4941:         if (($type ne '') && ($type ne 'default')) {
                   4942:             $name .= '_'.$type;
                   4943:         }
                   4944:         $output .= '<span class="LC_nobreak"><label>'.
                   4945:                    '<input type="radio" name="'.$name.'"'.
                   4946:                    $checked.' value="'.$option.'" />'.
                   4947:                    $choices{$option}.'</label></span>';
                   4948:         if ($type eq '') {
                   4949:             $output .= '&nbsp;';
                   4950:         } else {
                   4951:             $output .= '<br />';
                   4952:         }
                   4953:     }
                   4954:     $$rowtotal ++;
                   4955:     return $output;
                   4956: }
                   4957: 
1.165     raeburn  4958: sub captcha_choice {
1.169     raeburn  4959:     my ($context,$settings,$itemcount) = @_;
1.269     raeburn  4960:     my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
                   4961:         $vertext,$currver);
1.165     raeburn  4962:     my %lt = &captcha_phrases();
                   4963:     $keyentry = 'hidden';
                   4964:     if ($context eq 'cancreate') {
1.224     raeburn  4965:         $rowname = &mt('CAPTCHA validation');
1.169     raeburn  4966:     } elsif ($context eq 'login') {
                   4967:         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
1.165     raeburn  4968:     }
                   4969:     if (ref($settings) eq 'HASH') {
                   4970:         if ($settings->{'captcha'}) {
                   4971:             $checked{$settings->{'captcha'}} = ' checked="checked"';
                   4972:         } else {
                   4973:             $checked{'original'} = ' checked="checked"';
                   4974:         }
                   4975:         if ($settings->{'captcha'} eq 'recaptcha') {
                   4976:             $pubtext = $lt{'pub'};
                   4977:             $privtext = $lt{'priv'};
                   4978:             $keyentry = 'text';
1.269     raeburn  4979:             $vertext = $lt{'ver'};
                   4980:             $currver = $settings->{'recaptchaversion'};
                   4981:             if ($currver ne '2') {
                   4982:                 $currver = 1;
                   4983:             }
1.165     raeburn  4984:         }
                   4985:         if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
                   4986:             $currpub = $settings->{'recaptchakeys'}{'public'};
                   4987:             $currpriv = $settings->{'recaptchakeys'}{'private'};
                   4988:         }
                   4989:     } else {
                   4990:         $checked{'original'} = ' checked="checked"';
                   4991:     }
1.169     raeburn  4992:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   4993:     my $output = '<tr'.$css_class.'>'.
                   4994:                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165     raeburn  4995:                  '<table><tr><td>'."\n";
                   4996:     foreach my $option ('original','recaptcha','notused') {
                   4997:         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
                   4998:                    $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
                   4999:                    $lt{$option}.'</label></span>';
                   5000:         unless ($option eq 'notused') {
                   5001:             $output .= ('&nbsp;'x2)."\n";
                   5002:         }
                   5003:     }
                   5004: #
                   5005: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
                   5006: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210     raeburn  5007: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165     raeburn  5008: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210     raeburn  5009: #
1.165     raeburn  5010:     $output .= '</td></tr>'."\n".
                   5011:                '<tr><td>'."\n".
                   5012:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span>&nbsp;'."\n".
                   5013:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
                   5014:                $currpub.'" size="40" /></span><br />'."\n".
                   5015:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span>&nbsp;'."\n".
                   5016:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269     raeburn  5017:                $currpriv.'" size="40" /></span><br />'.
                   5018:                '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span>&nbsp;'."\n".
                   5019:                '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
                   5020:                $currver.'" size="3" /></span><br />'.
                   5021:                '</td></tr></table>'."\n".
1.165     raeburn  5022:                '</td></tr>';
                   5023:     return $output;
                   5024: }
                   5025: 
1.32      raeburn  5026: sub user_formats_row {
                   5027:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   5028:     my $output;
                   5029:     my %text = (
                   5030:                    'username' => 'new usernames',
                   5031:                    'id'       => 'IDs',
1.45      raeburn  5032:                    'email'    => 'self-created accounts (e-mail)',
1.32      raeburn  5033:                );
                   5034:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   5035:     $output = '<tr '.$css_class.'>'.
1.63      raeburn  5036:               '<td><span class="LC_nobreak">';
                   5037:     if ($type eq 'email') {
                   5038:         $output .= &mt("Formats disallowed for $text{$type}: ");
                   5039:     } else {
                   5040:         $output .= &mt("Format rules to check for $text{$type}: ");
                   5041:     }
                   5042:     $output .= '</span></td>'.
                   5043:                '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  5044:     my $rem;
                   5045:     if (ref($ruleorder) eq 'ARRAY') {
                   5046:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   5047:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   5048:                 my $rem = $i%($numinrow);
                   5049:                 if ($rem == 0) {
                   5050:                     if ($i > 0) {
                   5051:                         $output .= '</tr>';
                   5052:                     }
                   5053:                     $output .= '<tr>';
                   5054:                 }
                   5055:                 my $check = ' ';
1.39      raeburn  5056:                 if (ref($settings) eq 'HASH') {
                   5057:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   5058:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
                   5059:                             $check = ' checked="checked" ';
                   5060:                         }
1.27      raeburn  5061:                     }
                   5062:                 }
                   5063:                 $output .= '<td class="LC_left_item">'.
                   5064:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  5065:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  5066:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   5067:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   5068:             }
                   5069:         }
                   5070:         $rem = @{$ruleorder}%($numinrow);
                   5071:     }
                   5072:     my $colsleft = $numinrow - $rem;
                   5073:     if ($colsleft > 1 ) {
                   5074:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   5075:                    '&nbsp;</td>';
                   5076:     } elsif ($colsleft == 1) {
                   5077:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   5078:     }
                   5079:     $output .= '</tr></table></td></tr>';
                   5080:     return $output;
                   5081: }
                   5082: 
1.34      raeburn  5083: sub usercreation_types {
                   5084:     my %lt = &Apache::lonlocal::texthash (
                   5085:                     author     => 'When adding a co-author',
                   5086:                     course     => 'When adding a user to a course',
1.100     raeburn  5087:                     requestcrs => 'When requesting a course',
1.34      raeburn  5088:                     any        => 'Any',
                   5089:                     official   => 'Institutional only ',
                   5090:                     unofficial => 'Non-institutional only',
                   5091:                     none       => 'None',
                   5092:     );
                   5093:     return %lt;
1.48      raeburn  5094: }
1.34      raeburn  5095: 
1.224     raeburn  5096: sub selfcreation_types {
                   5097:     my %lt = &Apache::lonlocal::texthash (
                   5098:                     selfcreate => 'User creates own account',
                   5099:                     any        => 'Any',
                   5100:                     official   => 'Institutional only ',
                   5101:                     unofficial => 'Non-institutional only',
                   5102:                     email      => 'E-mail address',
                   5103:                     login      => 'Institutional Login',
                   5104:                     sso        => 'SSO',
                   5105:              );
                   5106: }
                   5107: 
1.28      raeburn  5108: sub authtype_names {
                   5109:     my %lt = &Apache::lonlocal::texthash(
                   5110:                       int    => 'Internal',
                   5111:                       krb4   => 'Kerberos 4',
                   5112:                       krb5   => 'Kerberos 5',
                   5113:                       loc    => 'Local',
                   5114:                   );
                   5115:     return %lt;
                   5116: }
                   5117: 
                   5118: sub context_names {
                   5119:     my %context_title = &Apache::lonlocal::texthash(
                   5120:        author => 'Creating users when an Author',
                   5121:        course => 'Creating users when in a course',
                   5122:        domain => 'Creating users when a Domain Coordinator',
                   5123:     );
                   5124:     return %context_title;
                   5125: }
                   5126: 
1.33      raeburn  5127: sub print_usermodification {
                   5128:     my ($position,$dom,$settings,$rowtotal) = @_;
                   5129:     my $numinrow = 4;
                   5130:     my ($context,$datatable,$rowcount);
                   5131:     if ($position eq 'top') {
                   5132:         $rowcount = 0;
                   5133:         $context = 'author'; 
                   5134:         foreach my $role ('ca','aa') {
                   5135:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5136:                                                    $numinrow,$rowcount);
                   5137:             $$rowtotal ++;
                   5138:             $rowcount ++;
                   5139:         }
1.230     raeburn  5140:     } elsif ($position eq 'bottom') {
1.33      raeburn  5141:         $context = 'course';
                   5142:         $rowcount = 0;
                   5143:         foreach my $role ('st','ep','ta','in','cr') {
                   5144:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   5145:                                                    $numinrow,$rowcount);
                   5146:             $$rowtotal ++;
                   5147:             $rowcount ++;
                   5148:         }
                   5149:     }
                   5150:     return $datatable;
                   5151: }
                   5152: 
1.43      raeburn  5153: sub print_defaults {
1.236     raeburn  5154:     my ($position,$dom,$settings,$rowtotal) = @_;
1.43      raeburn  5155:     my $rownum = 0;
                   5156:     my ($datatable,$css_class);
1.236     raeburn  5157:     if ($position eq 'top') {
                   5158:         my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                   5159:                      'datelocale_def','portal_def');
                   5160:         my %defaults;
                   5161:         if (ref($settings) eq 'HASH') {
                   5162:             %defaults = %{$settings};
1.43      raeburn  5163:         } else {
1.236     raeburn  5164:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   5165:             foreach my $item (@items) {
                   5166:                 $defaults{$item} = $domdefaults{$item};
                   5167:             }
1.43      raeburn  5168:         }
1.236     raeburn  5169:         my $titles = &defaults_titles($dom);
                   5170:         foreach my $item (@items) {
                   5171:             if ($rownum%2) {
                   5172:                 $css_class = '';
                   5173:             } else {
                   5174:                 $css_class = ' class="LC_odd_row" ';
                   5175:             }
                   5176:             $datatable .= '<tr'.$css_class.'>'.
                   5177:                           '<td><span class="LC_nobreak">'.$titles->{$item}.
                   5178:                           '</span></td><td class="LC_right_item" colspan="3">';
                   5179:             if ($item eq 'auth_def') {
                   5180:                 my @authtypes = ('internal','krb4','krb5','localauth');
                   5181:                 my %shortauth = (
                   5182:                                  internal => 'int',
                   5183:                                  krb4 => 'krb4',
                   5184:                                  krb5 => 'krb5',
                   5185:                                  localauth  => 'loc'
                   5186:                                 );
                   5187:                 my %authnames = &authtype_names();
                   5188:                 foreach my $auth (@authtypes) {
                   5189:                     my $checked = ' ';
                   5190:                     if ($defaults{$item} eq $auth) {
                   5191:                         $checked = ' checked="checked" ';
                   5192:                     }
                   5193:                     $datatable .= '<label><input type="radio" name="'.$item.
                   5194:                                   '" value="'.$auth.'"'.$checked.'/>'.
                   5195:                                   $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
                   5196:                 }
                   5197:             } elsif ($item eq 'timezone_def') {
                   5198:                 my $includeempty = 1;
                   5199:                 $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
                   5200:             } elsif ($item eq 'datelocale_def') {
                   5201:                 my $includeempty = 1;
                   5202:                 $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
                   5203:             } elsif ($item eq 'lang_def') {
1.263     raeburn  5204:                 my $includeempty = 1;
                   5205:                 $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.236     raeburn  5206:             } else {
                   5207:                 my $size;
                   5208:                 if ($item eq 'portal_def') {
                   5209:                     $size = ' size="25"';
                   5210:                 }
                   5211:                 $datatable .= '<input type="text" name="'.$item.'" value="'.
                   5212:                               $defaults{$item}.'"'.$size.' />';
1.43      raeburn  5213:             }
1.236     raeburn  5214:             $datatable .= '</td></tr>';
                   5215:             $rownum ++;
                   5216:         }
                   5217:     } else {
                   5218:         my (%defaults);
                   5219:         if (ref($settings) eq 'HASH') {
                   5220:             if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH') &&
                   5221:                 (ref($settings->{'inststatusguest'}) eq 'ARRAY')) {
                   5222:                 my $maxnum = @{$settings->{'inststatusorder'}};
                   5223:                 for (my $i=0; $i<$maxnum; $i++) {
                   5224:                     $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5225:                     my $item = $settings->{'inststatusorder'}->[$i];
                   5226:                     my $title = $settings->{'inststatustypes'}->{$item};
                   5227:                     my $guestok;
                   5228:                     if (grep(/^\Q$item\E$/,@{$settings->{'inststatusguest'}})) {
                   5229:                         $guestok = 1;
                   5230:                     }
                   5231:                     my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
                   5232:                     $datatable .= '<tr'.$css_class.'>'.
                   5233:                                   '<td><span class="LC_nobreak">'.
                   5234:                                   '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
                   5235:                     for (my $k=0; $k<=$maxnum; $k++) {
                   5236:                         my $vpos = $k+1;
                   5237:                         my $selstr;
                   5238:                         if ($k == $i) {
                   5239:                             $selstr = ' selected="selected" ';
                   5240:                         }
                   5241:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5242:                     }
                   5243:                     my ($checkedon,$checkedoff);
                   5244:                     $checkedoff = ' checked="checked"';
                   5245:                     if ($guestok) {
                   5246:                         $checkedon = $checkedoff;
                   5247:                         $checkedoff = ''; 
                   5248:                     }
                   5249:                     $datatable .= '</select>&nbsp;'.&mt('Internal ID:').'&nbsp;<b>'.$item.'</b>&nbsp;'.
                   5250:                                   '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
                   5251:                                   &mt('delete').'</span></td>'.
                   5252:                                   '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed:').
                   5253:                                   '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
                   5254:                                   '</span></td>'.
                   5255:                                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5256:                                   '<label><input type="radio" value="1" name="inststatus_guest_'.$item.'"'.$checkedon.' />'.
                   5257:                                   &mt('Yes').'</label>'.('&nbsp;'x2).
                   5258:                                   '<label><input type="radio" value="0" name="inststatus_guest_'.$item.'"'.$checkedoff.' />'.
                   5259:                                   &mt('No').'</label></span></td></tr>';
                   5260:                 }
                   5261:                 $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5262:                 my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
                   5263:                 $datatable .= '<tr '.$css_class.'>'.
                   5264:                               '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
                   5265:                 for (my $k=0; $k<=$maxnum; $k++) {
                   5266:                     my $vpos = $k+1;
                   5267:                     my $selstr;
                   5268:                     if ($k == $maxnum) {
                   5269:                         $selstr = ' selected="selected" ';
                   5270:                     }
                   5271:                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5272:                 }
                   5273:                 $datatable .= '</select>&nbsp;'.&mt('Internal ID:').
1.263     raeburn  5274:                               '<input type="text" size="10" name="addinststatus" value="" />'.
1.236     raeburn  5275:                               '&nbsp;'.&mt('(new)').
                   5276:                               '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
                   5277:                               &mt('Name displayed:').
                   5278:                               '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
                   5279:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5280:                               '<label><input type="radio" value="1" name="addinststatus_guest" />'.
                   5281:                               &mt('Yes').'</label>'.('&nbsp;'x2).
                   5282:                               '<label><input type="radio" value="0" name="addinststatus_guest" />'.
                   5283:                               &mt('No').'</label></span></td></tr>';
                   5284:                               '</tr>'."\n";
                   5285:                 $rownum ++;
1.141     raeburn  5286:             }
1.43      raeburn  5287:         }
                   5288:     }
                   5289:     $$rowtotal += $rownum;
                   5290:     return $datatable;
                   5291: }
                   5292: 
1.168     raeburn  5293: sub get_languages_hash {
                   5294:     my %langchoices;
                   5295:     foreach my $id (&Apache::loncommon::languageids()) {
                   5296:         my $code = &Apache::loncommon::supportedlanguagecode($id);
                   5297:         if ($code ne '') {
                   5298:             $langchoices{$code} =  &Apache::loncommon::plainlanguagedescription($id);
                   5299:         }
                   5300:     }
                   5301:     return %langchoices;
                   5302: }
                   5303: 
1.43      raeburn  5304: sub defaults_titles {
1.141     raeburn  5305:     my ($dom) = @_;
1.43      raeburn  5306:     my %titles = &Apache::lonlocal::texthash (
                   5307:                    'auth_def'      => 'Default authentication type',
                   5308:                    'auth_arg_def'  => 'Default authentication argument',
                   5309:                    'lang_def'      => 'Default language',
1.54      raeburn  5310:                    'timezone_def'  => 'Default timezone',
1.68      raeburn  5311:                    'datelocale_def' => 'Default locale for dates',
1.141     raeburn  5312:                    'portal_def'     => 'Portal/Default URL',
1.43      raeburn  5313:                  );
1.141     raeburn  5314:     if ($dom) {
                   5315:         my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
                   5316:         my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
                   5317:         my $protocol = $Apache::lonnet::protocol{$uprimary_id};
                   5318:         $protocol = 'http' if ($protocol ne 'https');
                   5319:         if ($uint_dom) {
                   5320:             $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
                   5321:                                          $uint_dom);
                   5322:         }
                   5323:     }
1.43      raeburn  5324:     return (\%titles);
                   5325: }
                   5326: 
1.46      raeburn  5327: sub print_scantronformat {
                   5328:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
                   5329:     my $itemcount = 1;
1.60      raeburn  5330:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
                   5331:         %confhash);
1.46      raeburn  5332:     my $switchserver = &check_switchserver($dom,$confname);
                   5333:     my %lt = &Apache::lonlocal::texthash (
1.95      www      5334:                 default => 'Default bubblesheet format file error',
                   5335:                 custom  => 'Custom bubblesheet format file error',
1.46      raeburn  5336:              );
                   5337:     my %scantronfiles = (
                   5338:         default => 'default.tab',
                   5339:         custom => 'custom.tab',
                   5340:     );
                   5341:     foreach my $key (keys(%scantronfiles)) {
                   5342:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
                   5343:                               .$scantronfiles{$key};
                   5344:     }
                   5345:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
                   5346:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
                   5347:         if (!$switchserver) {
                   5348:             my $servadm = $r->dir_config('lonAdmEMail');
                   5349:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
                   5350:             if ($configuserok eq 'ok') {
                   5351:                 if ($author_ok eq 'ok') {
                   5352:                     my %legacyfile = (
                   5353:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
                   5354:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
                   5355:                     );
                   5356:                     my %md5chk;
                   5357:                     foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5358:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                   5359:                         chomp($md5chk{$type});
1.46      raeburn  5360:                     }
                   5361:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
                   5362:                         foreach my $type (keys(%legacyfile)) {
1.60      raeburn  5363:                             ($scantronurls{$type},my $error) = 
1.46      raeburn  5364:                                 &legacy_scantronformat($r,$dom,$confname,
                   5365:                                                  $type,$legacyfile{$type},
                   5366:                                                  $scantronurls{$type},
                   5367:                                                  $scantronfiles{$type});
1.60      raeburn  5368:                             if ($error ne '') {
                   5369:                                 $error{$type} = $error;
                   5370:                             }
                   5371:                         }
                   5372:                         if (keys(%error) == 0) {
                   5373:                             $is_custom = 1;
                   5374:                             $confhash{'scantron'}{'scantronformat'} = 
                   5375:                                 $scantronurls{'custom'};
                   5376:                             my $putresult = 
                   5377:                                 &Apache::lonnet::put_dom('configuration',
                   5378:                                                          \%confhash,$dom);
                   5379:                             if ($putresult ne 'ok') {
                   5380:                                 $error{'custom'} = 
                   5381:                                     '<span class="LC_error">'.
                   5382:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5383:                             }
1.46      raeburn  5384:                         }
                   5385:                     } else {
1.60      raeburn  5386:                         ($scantronurls{'default'},my $error) =
1.46      raeburn  5387:                             &legacy_scantronformat($r,$dom,$confname,
                   5388:                                           'default',$legacyfile{'default'},
                   5389:                                           $scantronurls{'default'},
                   5390:                                           $scantronfiles{'default'});
1.60      raeburn  5391:                         if ($error eq '') {
                   5392:                             $confhash{'scantron'}{'scantronformat'} = ''; 
                   5393:                             my $putresult =
                   5394:                                 &Apache::lonnet::put_dom('configuration',
                   5395:                                                          \%confhash,$dom);
                   5396:                             if ($putresult ne 'ok') {
                   5397:                                 $error{'default'} =
                   5398:                                     '<span class="LC_error">'.
                   5399:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                   5400:                             }
                   5401:                         } else {
                   5402:                             $error{'default'} = $error;
                   5403:                         }
1.46      raeburn  5404:                     }
                   5405:                 }
                   5406:             }
                   5407:         } else {
1.95      www      5408:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46      raeburn  5409:         }
                   5410:     }
                   5411:     if (ref($settings) eq 'HASH') {
                   5412:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
                   5413:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
                   5414:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
                   5415:                 $scantronurl = '';
                   5416:             } else {
                   5417:                 $scantronurl = $settings->{'scantronformat'};
                   5418:             }
                   5419:             $is_custom = 1;
                   5420:         } else {
                   5421:             $scantronurl = $scantronurls{'default'};
                   5422:         }
                   5423:     } else {
1.60      raeburn  5424:         if ($is_custom) {
                   5425:             $scantronurl = $scantronurls{'custom'};
                   5426:         } else {
                   5427:             $scantronurl = $scantronurls{'default'};
                   5428:         }
1.46      raeburn  5429:     }
                   5430:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5431:     $datatable .= '<tr'.$css_class.'>';
                   5432:     if (!$is_custom) {
1.65      raeburn  5433:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                   5434:                       '<span class="LC_nobreak">';
1.46      raeburn  5435:         if ($scantronurl) {
1.199     raeburn  5436:             $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
                   5437:                                                          undef,undef,undef,undef,'background-color:#ffffff');
1.46      raeburn  5438:         } else {
                   5439:             $datatable = &mt('File unavailable for display');
                   5440:         }
1.65      raeburn  5441:         $datatable .= '</span></td>';
1.60      raeburn  5442:         if (keys(%error) == 0) { 
                   5443:             $datatable .= '<td valign="bottom">';
                   5444:             if (!$switchserver) {
                   5445:                 $datatable .= &mt('Upload:').'<br />';
                   5446:             }
                   5447:         } else {
                   5448:             my $errorstr;
                   5449:             foreach my $key (sort(keys(%error))) {
                   5450:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5451:             }
                   5452:             $datatable .= '<td>'.$errorstr;
                   5453:         }
1.46      raeburn  5454:     } else {
                   5455:         if (keys(%error) > 0) {
                   5456:             my $errorstr;
                   5457:             foreach my $key (sort(keys(%error))) {
                   5458:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
                   5459:             } 
1.60      raeburn  5460:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
1.46      raeburn  5461:         } elsif ($scantronurl) {
1.199     raeburn  5462:             my $link =  &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
                   5463:                                                        undef,undef,undef,undef,'background-color:#ffffff');
1.65      raeburn  5464:             $datatable .= '<td><span class="LC_nobreak">'.
1.199     raeburn  5465:                           $link.
                   5466:                           '<label><input type="checkbox" name="scantronformat_del"'.
                   5467:                           ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65      raeburn  5468:                           '<td><span class="LC_nobreak">&nbsp;'.
                   5469:                           &mt('Replace:').'</span><br />';
1.46      raeburn  5470:         }
                   5471:     }
                   5472:     if (keys(%error) == 0) {
                   5473:         if ($switchserver) {
                   5474:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                   5475:         } else {
1.65      raeburn  5476:             $datatable .='<span class="LC_nobreak">&nbsp;'.
                   5477:                          '<input type="file" name="scantronformat" /></span>';
1.46      raeburn  5478:         }
                   5479:     }
                   5480:     $datatable .= '</td></tr>';
                   5481:     $$rowtotal ++;
                   5482:     return $datatable;
                   5483: }
                   5484: 
                   5485: sub legacy_scantronformat {
                   5486:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
                   5487:     my ($url,$error);
                   5488:     my @statinfo = &Apache::lonnet::stat_file($newurl);
                   5489:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
                   5490:         (my $result,$url) =
                   5491:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
                   5492:                          '','',$newfile);
                   5493:         if ($result ne 'ok') {
1.130     raeburn  5494:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46      raeburn  5495:         }
                   5496:     }
                   5497:     return ($url,$error);
                   5498: }
1.43      raeburn  5499: 
1.49      raeburn  5500: sub print_coursecategories {
1.57      raeburn  5501:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
                   5502:     my $datatable;
                   5503:     if ($position eq 'top') {
1.238     raeburn  5504:         my (%checked);
                   5505:         my @catitems = ('unauth','auth');
                   5506:         my @cattypes = ('std','domonly','codesrch','none');
                   5507:         $checked{'unauth'} = 'std';
                   5508:         $checked{'auth'} = 'std';
                   5509:         if (ref($settings) eq 'HASH') {
                   5510:             foreach my $type (@cattypes) {
                   5511:                 if ($type eq $settings->{'unauth'}) {
                   5512:                     $checked{'unauth'} = $type;
                   5513:                 }
                   5514:                 if ($type eq $settings->{'auth'}) {
                   5515:                     $checked{'auth'} = $type;
                   5516:                 }
                   5517:             }
                   5518:         }
                   5519:         my %lt = &Apache::lonlocal::texthash (
                   5520:                                                unauth   => 'Catalog type for unauthenticated users',
                   5521:                                                auth     => 'Catalog type for authenticated users',
                   5522:                                                none     => 'No catalog',
                   5523:                                                std      => 'Standard catalog',
                   5524:                                                domonly  => 'Domain-only catalog',
                   5525:                                                codesrch => "Code search form",
                   5526:                                              );
                   5527:        my $itemcount = 0;
                   5528:        foreach my $item (@catitems) {
                   5529:            my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
                   5530:            $datatable .= '<tr '.$css_class.'>'.
                   5531:                          '<td>'.$lt{$item}.'</td>'.
                   5532:                          '<td class="LC_right_item"><span class="LC_nobreak">';
                   5533:            foreach my $type (@cattypes) {
                   5534:                my $ischecked;
                   5535:                if ($checked{$item} eq $type) {
                   5536:                    $ischecked=' checked="checked"';
                   5537:                }
                   5538:                $datatable .= '<label>'.
                   5539:                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                   5540:                              ' />'.$lt{$type}.'</label>&nbsp;';
                   5541:            }
                   5542:            $datatable .= '</td></tr>';
                   5543:            $itemcount ++;
                   5544:         }
                   5545:         $$rowtotal += $itemcount;
                   5546:     } elsif ($position eq 'middle') {
1.57      raeburn  5547:         my $toggle_cats_crs = ' ';
                   5548:         my $toggle_cats_dom = ' checked="checked" ';
                   5549:         my $can_cat_crs = ' ';
                   5550:         my $can_cat_dom = ' checked="checked" ';
1.120     raeburn  5551:         my $toggle_catscomm_comm = ' ';
                   5552:         my $toggle_catscomm_dom = ' checked="checked" ';
                   5553:         my $can_catcomm_comm = ' ';
                   5554:         my $can_catcomm_dom = ' checked="checked" ';
1.272   ! raeburn  5555:         my $toggle_catsplace_place = ' ';
        !          5556:         my $toggle_catsplace_dom = ' checked="checked" ';
        !          5557:         my $can_catplace_place = ' ';
        !          5558:         my $can_catplace_dom = ' checked="checked" ';
1.120     raeburn  5559: 
1.57      raeburn  5560:         if (ref($settings) eq 'HASH') {
                   5561:             if ($settings->{'togglecats'} eq 'crs') {
                   5562:                 $toggle_cats_crs = $toggle_cats_dom;
                   5563:                 $toggle_cats_dom = ' ';
                   5564:             }
                   5565:             if ($settings->{'categorize'} eq 'crs') {
                   5566:                 $can_cat_crs = $can_cat_dom;
                   5567:                 $can_cat_dom = ' ';
                   5568:             }
1.120     raeburn  5569:             if ($settings->{'togglecatscomm'} eq 'comm') {
                   5570:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
                   5571:                 $toggle_catscomm_dom = ' ';
                   5572:             }
                   5573:             if ($settings->{'categorizecomm'} eq 'comm') {
                   5574:                 $can_catcomm_comm = $can_catcomm_dom;
                   5575:                 $can_catcomm_dom = ' ';
                   5576:             }
1.272   ! raeburn  5577:             if ($settings->{'togglecatsplace'} eq 'place') {
        !          5578:                 $toggle_catsplace_place = $toggle_catsplace_dom;
        !          5579:                 $toggle_catsplace_dom = ' ';
        !          5580:             }
        !          5581:             if ($settings->{'categorizeplace'} eq 'place') {
        !          5582:                 $can_catplace_place = $can_catplace_dom;
        !          5583:                 $can_catplace_dom = ' ';
        !          5584:             }
1.57      raeburn  5585:         }
                   5586:         my %title = &Apache::lonlocal::texthash (
1.272   ! raeburn  5587:                      togglecats      => 'Show/Hide a course in catalog',
        !          5588:                      togglecatscomm  => 'Show/Hide a community in catalog',
        !          5589:                      togglecatsplace => 'Show/Hide a placement test in catalog',
        !          5590:                      categorize      => 'Assign a category to a course',
        !          5591:                      categorizecomm  => 'Assign a category to a community',
        !          5592:                      categorizeplace => 'Assign a category to a placement test',
1.57      raeburn  5593:                     );
                   5594:         my %level = &Apache::lonlocal::texthash (
1.272   ! raeburn  5595:                      dom   => 'Set in Domain',
        !          5596:                      crs   => 'Set in Course',
        !          5597:                      comm  => 'Set in Community',
        !          5598:                      place => 'Set in Placement Test',
1.57      raeburn  5599:                     );
                   5600:         $datatable = '<tr class="LC_odd_row">'.
                   5601:                   '<td>'.$title{'togglecats'}.'</td>'.
                   5602:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   5603:                   '<input type="radio" name="togglecats"'.
                   5604:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5605:                   '<label><input type="radio" name="togglecats"'.
                   5606:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                   5607:                   '</tr><tr>'.
                   5608:                   '<td>'.$title{'categorize'}.'</td>'.
                   5609:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5610:                   '<label><input type="radio" name="categorize"'.
                   5611:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5612:                   '<label><input type="radio" name="categorize"'.
                   5613:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120     raeburn  5614:                   '</tr><tr class="LC_odd_row">'.
                   5615:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
                   5616:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   5617:                   '<input type="radio" name="togglecatscomm"'.
                   5618:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5619:                   '<label><input type="radio" name="togglecatscomm"'.
                   5620:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   5621:                   '</tr><tr>'.
                   5622:                   '<td>'.$title{'categorizecomm'}.'</td>'.
                   5623:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   5624:                   '<label><input type="radio" name="categorizecomm"'.
                   5625:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   5626:                   '<label><input type="radio" name="categorizecomm"'.
                   5627:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.272   ! raeburn  5628:                   '</tr><tr>'.
        !          5629:                   '<td>'.$title{'togglecatsplace'}.'</td>'.
        !          5630:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
        !          5631:                   '<input type="radio" name="togglecatsplace"'.
        !          5632:                   $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
        !          5633:                   '<label><input type="radio" name="togglecatscomm"'.
        !          5634:                   $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
        !          5635:                   '</tr><tr>'.
        !          5636:                   '<td>'.$title{'categorizeplace'}.'</td>'.
        !          5637:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
        !          5638:                   '<label><input type="radio" name="categorizeplace"'.
        !          5639:                   $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
        !          5640:                   '<label><input type="radio" name="categorizeplace"'.
        !          5641:                   $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57      raeburn  5642:                   '</tr>';
1.272   ! raeburn  5643:         $$rowtotal += 6;
1.57      raeburn  5644:     } else {
                   5645:         my $css_class;
                   5646:         my $itemcount = 1;
                   5647:         my $cathash; 
                   5648:         if (ref($settings) eq 'HASH') {
                   5649:             $cathash = $settings->{'cats'};
                   5650:         }
                   5651:         if (ref($cathash) eq 'HASH') {
                   5652:             my (@cats,@trails,%allitems,%idx,@jsarray);
                   5653:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                   5654:                                                    \%allitems,\%idx,\@jsarray);
                   5655:             my $maxdepth = scalar(@cats);
                   5656:             my $colattrib = '';
                   5657:             if ($maxdepth > 2) {
                   5658:                 $colattrib = ' colspan="2" ';
                   5659:             }
                   5660:             my @path;
                   5661:             if (@cats > 0) {
                   5662:                 if (ref($cats[0]) eq 'ARRAY') {
                   5663:                     my $numtop = @{$cats[0]};
                   5664:                     my $maxnum = $numtop;
1.120     raeburn  5665:                     my %default_names = (
                   5666:                           instcode    => &mt('Official courses'),
                   5667:                           communities => &mt('Communities'),
1.272   ! raeburn  5668:                           placement   => &mt('Placement Tests'),
1.120     raeburn  5669:                     );
                   5670: 
                   5671:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
                   5672:                         ($cathash->{'instcode::0'} eq '') ||
                   5673:                         (!grep(/^communities$/,@{$cats[0]})) || 
1.272   ! raeburn  5674:                         ($cathash->{'communities::0'} eq '') ||
        !          5675:                         (!grep(/^placement$/,@{$cats[0]})) ||
        !          5676:                         ($cathash->{'placement::0'} eq '')) {
1.57      raeburn  5677:                         $maxnum ++;
                   5678:                     }
                   5679:                     my $lastidx;
                   5680:                     for (my $i=0; $i<$numtop; $i++) {
                   5681:                         my $parent = $cats[0][$i];
                   5682:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5683:                         my $item = &escape($parent).'::0';
                   5684:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                   5685:                         $lastidx = $idx{$item};
                   5686:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   5687:                                       .'<select name="'.$item.'"'.$chgstr.'>';
                   5688:                         for (my $k=0; $k<=$maxnum; $k++) {
                   5689:                             my $vpos = $k+1;
                   5690:                             my $selstr;
                   5691:                             if ($k == $i) {
                   5692:                                 $selstr = ' selected="selected" ';
                   5693:                             }
                   5694:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5695:                         }
1.214     raeburn  5696:                         $datatable .= '</select></span></td><td>';
1.272   ! raeburn  5697:                         if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120     raeburn  5698:                             $datatable .=  '<span class="LC_nobreak">'
                   5699:                                            .$default_names{$parent}.'</span>';
                   5700:                             if ($parent eq 'instcode') {
                   5701:                                 $datatable .= '<br /><span class="LC_nobreak">('
                   5702:                                               .&mt('with institutional codes')
                   5703:                                               .')</span></td><td'.$colattrib.'>';
                   5704:                             } else {
                   5705:                                 $datatable .= '<table><tr><td>';
                   5706:                             }
                   5707:                             $datatable .= '<span class="LC_nobreak">'
                   5708:                                           .'<label><input type="radio" name="'
                   5709:                                           .$parent.'" value="1" checked="checked" />'
                   5710:                                           .&mt('Display').'</label>';
                   5711:                             if ($parent eq 'instcode') {
                   5712:                                 $datatable .= '&nbsp;';
                   5713:                             } else {
                   5714:                                 $datatable .= '</span></td></tr><tr><td>'
                   5715:                                               .'<span class="LC_nobreak">';
                   5716:                             }
                   5717:                             $datatable .= '<label><input type="radio" name="'
                   5718:                                           .$parent.'" value="0" />'
                   5719:                                           .&mt('Do not display').'</label></span>';
1.272   ! raeburn  5720:                             if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120     raeburn  5721:                                 $datatable .= '</td></tr></table>';
                   5722:                             }
                   5723:                             $datatable .= '</td>';
1.57      raeburn  5724:                         } else {
                   5725:                             $datatable .= $parent
1.214     raeburn  5726:                                           .'&nbsp;<span class="LC_nobreak"><label>'
                   5727:                                           .'<input type="checkbox" name="deletecategory" '
1.57      raeburn  5728:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                   5729:                         }
                   5730:                         my $depth = 1;
                   5731:                         push(@path,$parent);
                   5732:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                   5733:                         pop(@path);
                   5734:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   5735:                         $itemcount ++;
                   5736:                     }
1.48      raeburn  5737:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57      raeburn  5738:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                   5739:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48      raeburn  5740:                     for (my $k=0; $k<=$maxnum; $k++) {
                   5741:                         my $vpos = $k+1;
                   5742:                         my $selstr;
1.57      raeburn  5743:                         if ($k == $numtop) {
1.48      raeburn  5744:                             $selstr = ' selected="selected" ';
                   5745:                         }
                   5746:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                   5747:                     }
1.59      bisitz   5748:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
1.57      raeburn  5749:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                   5750:                                   .'</tr>'."\n";
1.48      raeburn  5751:                     $itemcount ++;
1.272   ! raeburn  5752:                     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  5753:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
                   5754:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   5755:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
                   5756:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                   5757:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
                   5758:                             for (my $k=0; $k<=$maxnum; $k++) {
                   5759:                                 my $vpos = $k+1;
                   5760:                                 my $selstr;
                   5761:                                 if ($k == $maxnum) {
                   5762:                                     $selstr = ' selected="selected" ';
                   5763:                                 }
                   5764:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57      raeburn  5765:                             }
1.120     raeburn  5766:                             $datatable .= '</select></span></td>'.
                   5767:                                           '<td><span class="LC_nobreak">'.
                   5768:                                           $default_names{$default}.'</span>';
                   5769:                             if ($default eq 'instcode') {
                   5770:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
                   5771:                                               .&mt('with institutional codes').')</span>';
                   5772:                             }
                   5773:                             $datatable .= '</td>'
                   5774:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
                   5775:                                           .&mt('Display').'</label>&nbsp;'
                   5776:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
                   5777:                                           .&mt('Do not display').'</label></span></td></tr>';
1.48      raeburn  5778:                         }
                   5779:                     }
                   5780:                 }
1.57      raeburn  5781:             } else {
                   5782:                 $datatable .= &initialize_categories($itemcount);
1.48      raeburn  5783:             }
                   5784:         } else {
1.238     raeburn  5785:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'
1.57      raeburn  5786:                           .&initialize_categories($itemcount);
1.48      raeburn  5787:         }
1.57      raeburn  5788:         $$rowtotal += $itemcount;
1.48      raeburn  5789:     }
                   5790:     return $datatable;
                   5791: }
                   5792: 
1.69      raeburn  5793: sub print_serverstatuses {
                   5794:     my ($dom,$settings,$rowtotal) = @_;
                   5795:     my $datatable;
                   5796:     my @pages = &serverstatus_pages();
                   5797:     my (%namedaccess,%machineaccess);
                   5798:     foreach my $type (@pages) {
                   5799:         $namedaccess{$type} = '';
                   5800:         $machineaccess{$type}= '';
                   5801:     }
                   5802:     if (ref($settings) eq 'HASH') {
                   5803:         foreach my $type (@pages) {
                   5804:             if (exists($settings->{$type})) {
                   5805:                 if (ref($settings->{$type}) eq 'HASH') {
                   5806:                     foreach my $key (keys(%{$settings->{$type}})) {
                   5807:                         if ($key eq 'namedusers') {
                   5808:                             $namedaccess{$type} = $settings->{$type}->{$key};
                   5809:                         } elsif ($key eq 'machines') {
                   5810:                             $machineaccess{$type} = $settings->{$type}->{$key};
                   5811:                         }
                   5812:                     }
                   5813:                 }
                   5814:             }
                   5815:         }
                   5816:     }
1.81      raeburn  5817:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  5818:     my $rownum = 0;
                   5819:     my $css_class;
                   5820:     foreach my $type (@pages) {
                   5821:         $rownum ++;
                   5822:         $css_class = $rownum%2?' class="LC_odd_row"':'';
                   5823:         $datatable .= '<tr'.$css_class.'>'.
                   5824:                       '<td><span class="LC_nobreak">'.
                   5825:                       $titles->{$type}.'</span></td>'.
                   5826:                       '<td class="LC_left_item">'.
                   5827:                       '<input type="text" name="'.$type.'_namedusers" '.
                   5828:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                   5829:                       '<td class="LC_right_item">'.
                   5830:                       '<span class="LC_nobreak">'.
                   5831:                       '<input type="text" name="'.$type.'_machines" '.
                   5832:                       'value="'.$machineaccess{$type}.'" size="10" />'.
                   5833:                       '</td></tr>'."\n";
                   5834:     }
                   5835:     $$rowtotal += $rownum;
                   5836:     return $datatable;
                   5837: }
                   5838: 
                   5839: sub serverstatus_pages {
                   5840:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189     raeburn  5841:             'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.221     raeburn  5842:             'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.262     raeburn  5843:             'uniquecodes','diskusage','coursecatalog');
1.69      raeburn  5844: }
                   5845: 
1.236     raeburn  5846: sub defaults_javascript {
                   5847:     my ($settings) = @_;
1.248     raeburn  5848:     return unless (ref($settings) eq 'HASH'); 
1.236     raeburn  5849:     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
                   5850:         my $maxnum = scalar(@{$settings->{'inststatusorder'}});
                   5851:         if ($maxnum eq '') {
                   5852:             $maxnum = 0;
                   5853:         }
                   5854:         $maxnum ++;
1.249     raeburn  5855:         my $jstext = '    var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';  
1.236     raeburn  5856:         return <<"ENDSCRIPT";
                   5857: <script type="text/javascript">
                   5858: // <![CDATA[
                   5859: function reorderTypes(form,caller) {
                   5860:     var changedVal;
                   5861: $jstext 
                   5862:     var newpos = 'addinststatus_pos';
                   5863:     var current = new Array;
                   5864:     var maxh = $maxnum;
                   5865:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   5866:     var oldVal;
                   5867:     if (caller == newpos) {
                   5868:         changedVal = newitemVal;
                   5869:     } else {
                   5870:         var curritem = 'inststatus_pos_'+caller;
                   5871:         changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
                   5872:         current[newitemVal] = newpos;
                   5873:     }
                   5874:     for (var i=0; i<inststatuses.length; i++) {
                   5875:         if (inststatuses[i] != caller) {
                   5876:             var elementName = 'inststatus_pos_'+inststatuses[i];
                   5877:             if (form.elements[elementName]) {
                   5878:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   5879:                 current[currVal] = elementName;
                   5880:             }
                   5881:         }
                   5882:     }
                   5883:     for (var j=0; j<maxh; j++) {
                   5884:         if (current[j] == undefined) {
                   5885:             oldVal = j;
                   5886:         }
                   5887:     }
                   5888:     if (oldVal < changedVal) {
                   5889:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   5890:            var elementName = current[k];
                   5891:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   5892:         }
                   5893:     } else {
                   5894:         for (var k=changedVal; k<oldVal; k++) {
                   5895:             var elementName = current[k];
                   5896:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   5897:         }
                   5898:     }
                   5899:     return;
                   5900: }
                   5901: 
                   5902: // ]]>
                   5903: </script>
                   5904: 
                   5905: ENDSCRIPT
                   5906:     }
                   5907: }
                   5908: 
1.49      raeburn  5909: sub coursecategories_javascript {
                   5910:     my ($settings) = @_;
1.57      raeburn  5911:     my ($output,$jstext,$cathash);
1.49      raeburn  5912:     if (ref($settings) eq 'HASH') {
1.57      raeburn  5913:         $cathash = $settings->{'cats'};
                   5914:     }
                   5915:     if (ref($cathash) eq 'HASH') {
1.49      raeburn  5916:         my (@cats,@jsarray,%idx);
1.57      raeburn  5917:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49      raeburn  5918:         if (@jsarray > 0) {
                   5919:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
                   5920:             for (my $i=0; $i<@jsarray; $i++) {
                   5921:                 if (ref($jsarray[$i]) eq 'ARRAY') {
                   5922:                     my $catstr = join('","',@{$jsarray[$i]});
                   5923:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   5924:                 }
                   5925:             }
                   5926:         }
                   5927:     } else {
                   5928:         $jstext  = '    var categories = Array(1);'."\n".
                   5929:                    '    categories[0] = Array("instcode_pos");'."\n"; 
                   5930:     }
1.237     bisitz   5931:     my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
                   5932:     my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272   ! raeburn  5933:     my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265     damieng  5934:     my $choose_again = "\n".&mt('Please use a different name for the new top level category.'); 
                   5935:     &js_escape(\$instcode_reserved);
                   5936:     &js_escape(\$communities_reserved);
1.272   ! raeburn  5937:     &js_escape(\$placement_reserved);
1.265     damieng  5938:     &js_escape(\$choose_again);
1.49      raeburn  5939:     $output = <<"ENDSCRIPT";
                   5940: <script type="text/javascript">
1.109     raeburn  5941: // <![CDATA[
1.49      raeburn  5942: function reorderCats(form,parent,item,idx) {
                   5943:     var changedVal;
                   5944: $jstext
                   5945:     var newpos = 'addcategory_pos';
                   5946:     if (parent == '') {
                   5947:         var has_instcode = 0;
                   5948:         var maxtop = categories[idx].length;
                   5949:         for (var j=0; j<maxtop; j++) {
                   5950:             if (categories[idx][j] == 'instcode::0') {
                   5951:                 has_instcode == 1;
                   5952:             }
                   5953:         }
                   5954:         if (has_instcode == 0) {
                   5955:             categories[idx][maxtop] = 'instcode_pos';
                   5956:         }
                   5957:     } else {
                   5958:         newpos += '_'+parent;
                   5959:     }
                   5960:     var maxh = 1 + categories[idx].length;
                   5961:     var current = new Array;
                   5962:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
                   5963:     if (item == newpos) {
                   5964:         changedVal = newitemVal;
                   5965:     } else {
                   5966:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
                   5967:         current[newitemVal] = newpos;
                   5968:     }
                   5969:     for (var i=0; i<categories[idx].length; i++) {
                   5970:         var elementName = categories[idx][i];
                   5971:         if (elementName != item) {
                   5972:             if (form.elements[elementName]) {
                   5973:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   5974:                 current[currVal] = elementName;
                   5975:             }
                   5976:         }
                   5977:     }
                   5978:     var oldVal;
                   5979:     for (var j=0; j<maxh; j++) {
                   5980:         if (current[j] == undefined) {
                   5981:             oldVal = j;
                   5982:         }
                   5983:     }
                   5984:     if (oldVal < changedVal) {
                   5985:         for (var k=oldVal+1; k<=changedVal ; k++) {
                   5986:            var elementName = current[k];
                   5987:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
                   5988:         }
                   5989:     } else {
                   5990:         for (var k=changedVal; k<oldVal; k++) {
                   5991:             var elementName = current[k];
                   5992:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
                   5993:         }
                   5994:     }
                   5995:     return;
                   5996: }
1.120     raeburn  5997: 
                   5998: function categoryCheck(form) {
                   5999:     if (form.elements['addcategory_name'].value == 'instcode') {
                   6000:         alert('$instcode_reserved\\n$choose_again');
                   6001:         return false;
                   6002:     }
                   6003:     if (form.elements['addcategory_name'].value == 'communities') {
                   6004:         alert('$communities_reserved\\n$choose_again');
                   6005:         return false;
                   6006:     }
1.272   ! raeburn  6007:     if (form.elements['addcategory_name'].value == 'placement') {
        !          6008:         alert('$placement_reserved\\n$choose_again');
        !          6009:         return false;
        !          6010:     }
1.120     raeburn  6011:     return true;
                   6012: }
                   6013: 
1.109     raeburn  6014: // ]]>
1.49      raeburn  6015: </script>
                   6016: 
                   6017: ENDSCRIPT
                   6018:     return $output;
                   6019: }
                   6020: 
1.48      raeburn  6021: sub initialize_categories {
                   6022:     my ($itemcount) = @_;
1.120     raeburn  6023:     my ($datatable,$css_class,$chgstr);
                   6024:     my %default_names = (
                   6025:                       instcode    => 'Official courses (with institutional codes)',
                   6026:                       communities => 'Communities',
1.272   ! raeburn  6027:                       placement   => 'Placement Tests',
1.120     raeburn  6028:                         );
                   6029:     my $select0 = ' selected="selected"';
                   6030:     my $select1 = '';
1.272   ! raeburn  6031:     foreach my $default ('instcode','communities','placement') {
1.120     raeburn  6032:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   6033:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
1.272   ! raeburn  6034:         if (($default eq 'communities') || ($default eq 'placement')) {
1.120     raeburn  6035:             $select1 = $select0;
                   6036:             $select0 = '';
                   6037:         }
                   6038:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   6039:                      .'<select name="'.$default.'_pos">'
                   6040:                      .'<option value="0"'.$select0.'>1</option>'
                   6041:                      .'<option value="1"'.$select1.'>2</option>'
                   6042:                      .'<option value="2">3</option></select>&nbsp;'
                   6043:                      .$default_names{$default}
                   6044:                      .'</span></td><td><span class="LC_nobreak">'
                   6045:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
                   6046:                      .&mt('Display').'</label>&nbsp;<label>'
                   6047:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48      raeburn  6048:                  .'</label></span></td></tr>';
1.120     raeburn  6049:         $itemcount ++;
                   6050:     }
1.48      raeburn  6051:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49      raeburn  6052:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48      raeburn  6053:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120     raeburn  6054:                   .'<select name="addcategory_pos"'.$chgstr.'>'
                   6055:                   .'<option value="0">1</option>'
                   6056:                   .'<option value="1">2</option>'
                   6057:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
1.48      raeburn  6058:                   .&mt('Add category').'</td><td>'.&mt('Name:')
                   6059:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
                   6060:     return $datatable;
                   6061: }
                   6062: 
                   6063: sub build_category_rows {
1.49      raeburn  6064:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
                   6065:     my ($text,$name,$item,$chgstr);
1.48      raeburn  6066:     if (ref($cats) eq 'ARRAY') {
                   6067:         my $maxdepth = scalar(@{$cats});
                   6068:         if (ref($cats->[$depth]) eq 'HASH') {
                   6069:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   6070:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   6071:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204     raeburn  6072:                 $text .= '<td><table class="LC_data_table">';
1.49      raeburn  6073:                 my ($idxnum,$parent_name,$parent_item);
                   6074:                 my $higher = $depth - 1;
                   6075:                 if ($higher == 0) {
                   6076:                     $parent_name = &escape($parent).'::'.$higher;
                   6077:                 } else {
                   6078:                     if (ref($path) eq 'ARRAY') {
                   6079:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6080:                     }
                   6081:                 }
                   6082:                 $parent_item = 'addcategory_pos_'.$parent_name;
1.48      raeburn  6083:                 for (my $j=0; $j<=$numchildren; $j++) {
1.49      raeburn  6084:                     if ($j < $numchildren) {
1.48      raeburn  6085:                         $name = $cats->[$depth]{$parent}[$j];
                   6086:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49      raeburn  6087:                         $idxnum = $idx->{$item};
                   6088:                     } else {
                   6089:                         $name = $parent_name;
                   6090:                         $item = $parent_item;
1.48      raeburn  6091:                     }
1.49      raeburn  6092:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                   6093:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48      raeburn  6094:                     for (my $i=0; $i<=$numchildren; $i++) {
                   6095:                         my $vpos = $i+1;
                   6096:                         my $selstr;
                   6097:                         if ($j == $i) {
                   6098:                             $selstr = ' selected="selected" ';
                   6099:                         }
                   6100:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
                   6101:                     }
                   6102:                     $text .= '</select>&nbsp;';
                   6103:                     if ($j < $numchildren) {
                   6104:                         my $deeper = $depth+1;
                   6105:                         $text .= $name.'&nbsp;'
                   6106:                                  .'<label><input type="checkbox" name="deletecategory" value="'
                   6107:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                   6108:                         if(ref($path) eq 'ARRAY') {
                   6109:                             push(@{$path},$name);
1.49      raeburn  6110:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48      raeburn  6111:                             pop(@{$path});
                   6112:                         }
                   6113:                     } else {
1.59      bisitz   6114:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
1.48      raeburn  6115:                         if ($j == $numchildren) {
                   6116:                             $text .= $name;
                   6117:                         } else {
                   6118:                             $text .= $item;
                   6119:                         }
                   6120:                         $text .= '" value="" />';
                   6121:                     }
                   6122:                     $text .= '</td></tr>';
                   6123:                 }
                   6124:                 $text .= '</table></td>';
                   6125:             } else {
                   6126:                 my $higher = $depth-1;
                   6127:                 if ($higher == 0) {
                   6128:                     $name = &escape($parent).'::'.$higher;
                   6129:                 } else {
                   6130:                     if (ref($path) eq 'ARRAY') {
                   6131:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                   6132:                     }
                   6133:                 }
                   6134:                 my $colspan;
                   6135:                 if ($parent ne 'instcode') {
                   6136:                     $colspan = $maxdepth - $depth - 1;
                   6137:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
                   6138:                 }
                   6139:             }
                   6140:         }
                   6141:     }
                   6142:     return $text;
                   6143: }
                   6144: 
1.33      raeburn  6145: sub modifiable_userdata_row {
1.228     raeburn  6146:     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref) = @_;
                   6147:     my ($role,$rolename,$statustype);
                   6148:     $role = $item;
1.224     raeburn  6149:     if ($context eq 'cancreate') {
1.228     raeburn  6150:         if ($item =~ /^emailusername_(.+)$/) {
                   6151:             $statustype = $1;
                   6152:             $role = 'emailusername';
                   6153:             if (ref($usertypes) eq 'HASH') {
                   6154:                 if ($usertypes->{$statustype}) {
                   6155:                     $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
                   6156:                 } else {
                   6157:                     $rolename = &mt('Data provided by user');
                   6158:                 }
                   6159:             }
1.224     raeburn  6160:         }
                   6161:     } elsif ($context eq 'selfcreate') {
1.63      raeburn  6162:         if (ref($usertypes) eq 'HASH') {
                   6163:             $rolename = $usertypes->{$role};
                   6164:         } else {
                   6165:             $rolename = $role;
                   6166:         }
1.33      raeburn  6167:     } else {
1.63      raeburn  6168:         if ($role eq 'cr') {
                   6169:             $rolename = &mt('Custom role');
                   6170:         } else {
                   6171:             $rolename = &Apache::lonnet::plaintext($role);
                   6172:         }
1.33      raeburn  6173:     }
1.224     raeburn  6174:     my (@fields,%fieldtitles);
                   6175:     if (ref($fieldsref) eq 'ARRAY') {
                   6176:         @fields = @{$fieldsref};
                   6177:     } else {
                   6178:         @fields = ('lastname','firstname','middlename','generation',
                   6179:                    'permanentemail','id');
                   6180:     }
                   6181:     if ((ref($titlesref) eq 'HASH')) {
                   6182:         %fieldtitles = %{$titlesref};
                   6183:     } else {
                   6184:         %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   6185:     }
1.33      raeburn  6186:     my $output;
                   6187:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   6188:     $output = '<tr '.$css_class.'>'.
                   6189:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   6190:               '<td class="LC_left_item" colspan="2"><table>';
                   6191:     my $rem;
                   6192:     my %checks;
                   6193:     if (ref($settings) eq 'HASH') {
                   6194:         if (ref($settings->{$context}) eq 'HASH') {
                   6195:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.228     raeburn  6196:                 my $hashref = $settings->{$context}->{$role};
                   6197:                 if ($role eq 'emailusername') {
                   6198:                     if ($statustype) {
                   6199:                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                   6200:                             $hashref = $settings->{$context}->{$role}->{$statustype};
                   6201:                             if (ref($hashref) eq 'HASH') { 
                   6202:                                 foreach my $field (@fields) {
                   6203:                                     if ($hashref->{$field}) {
                   6204:                                         $checks{$field} = $hashref->{$field};
                   6205:                                     }
                   6206:                                 }
                   6207:                             }
                   6208:                         }
                   6209:                     }
                   6210:                 } else {
                   6211:                     if (ref($hashref) eq 'HASH') {
                   6212:                         foreach my $field (@fields) {
                   6213:                             if ($hashref->{$field}) {
                   6214:                                 $checks{$field} = ' checked="checked" ';
                   6215:                             }
                   6216:                         }
1.33      raeburn  6217:                     }
                   6218:                 }
                   6219:             }
                   6220:         }
                   6221:     }
1.228     raeburn  6222:      
1.33      raeburn  6223:     for (my $i=0; $i<@fields; $i++) {
                   6224:         my $rem = $i%($numinrow);
                   6225:         if ($rem == 0) {
                   6226:             if ($i > 0) {
                   6227:                 $output .= '</tr>';
                   6228:             }
                   6229:             $output .= '<tr>';
                   6230:         }
                   6231:         my $check = ' ';
1.228     raeburn  6232:         unless ($role eq 'emailusername') {
                   6233:             if (exists($checks{$fields[$i]})) {
                   6234:                 $check = $checks{$fields[$i]}
                   6235:             } else {
                   6236:                 if ($role eq 'st') {
                   6237:                     if (ref($settings) ne 'HASH') {
                   6238:                         $check = ' checked="checked" '; 
                   6239:                     }
1.33      raeburn  6240:                 }
                   6241:             }
                   6242:         }
                   6243:         $output .= '<td class="LC_left_item">'.
1.228     raeburn  6244:                    '<span class="LC_nobreak">';
                   6245:         if ($role eq 'emailusername') {
                   6246:             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                   6247:                 $checks{$fields[$i]} = 'omit';
                   6248:             }
                   6249:             foreach my $option ('required','optional','omit') {
                   6250:                 my $checked='';
                   6251:                 if ($checks{$fields[$i]} eq $option) {
                   6252:                     $checked='checked="checked" ';
                   6253:                 }
                   6254:                 $output .= '<label>'.
                   6255:                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                   6256:                            &mt($option).'</label>'.('&nbsp;' x2);
                   6257:             }
                   6258:             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
                   6259:         } else {
                   6260:             $output .= '<label>'.
                   6261:                        '<input type="checkbox" name="canmodify_'.$role.'" '.
                   6262:                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   6263:                        '</label>';
                   6264:         }
                   6265:         $output .= '</span></td>';
1.33      raeburn  6266:         $rem = @fields%($numinrow);
                   6267:     }
                   6268:     my $colsleft = $numinrow - $rem;
                   6269:     if ($colsleft > 1 ) {
                   6270:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   6271:                    '&nbsp;</td>';
                   6272:     } elsif ($colsleft == 1) {
                   6273:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   6274:     }
                   6275:     $output .= '</tr></table></td></tr>';
                   6276:     return $output;
                   6277: }
1.28      raeburn  6278: 
1.93      raeburn  6279: sub insttypes_row {
1.224     raeburn  6280:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rownum) = @_;
1.93      raeburn  6281:     my %lt = &Apache::lonlocal::texthash (
                   6282:                       cansearch => 'Users allowed to search',
                   6283:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131     raeburn  6284:                       lockablenames => 'User preference to lock name',
1.93      raeburn  6285:              );
                   6286:     my $showdom;
                   6287:     if ($context eq 'cansearch') {
                   6288:         $showdom = ' ('.$dom.')';
                   6289:     }
1.165     raeburn  6290:     my $class = 'LC_left_item';
                   6291:     if ($context eq 'statustocreate') {
                   6292:         $class = 'LC_right_item';
                   6293:     }
1.224     raeburn  6294:     my $css_class = ' class="LC_odd_row"';
                   6295:     if ($rownum ne '') { 
                   6296:         $css_class = ($rownum%2? ' class="LC_odd_row"':'');
                   6297:     }
                   6298:     my $output = '<tr'.$css_class.'>'.
                   6299:                  '<td>'.$lt{$context}.$showdom.
                   6300:                  '</td><td class="'.$class.'" colspan="2"><table>';
1.26      raeburn  6301:     my $rem;
                   6302:     if (ref($types) eq 'ARRAY') {
                   6303:         for (my $i=0; $i<@{$types}; $i++) {
                   6304:             if (defined($usertypes->{$types->[$i]})) {
                   6305:                 my $rem = $i%($numinrow);
                   6306:                 if ($rem == 0) {
                   6307:                     if ($i > 0) {
                   6308:                         $output .= '</tr>';
                   6309:                     }
                   6310:                     $output .= '<tr>';
1.23      raeburn  6311:                 }
1.26      raeburn  6312:                 my $check = ' ';
1.99      raeburn  6313:                 if (ref($settings) eq 'HASH') {
                   6314:                     if (ref($settings->{$context}) eq 'ARRAY') {
                   6315:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
                   6316:                             $check = ' checked="checked" ';
                   6317:                         }
                   6318:                     } elsif ($context eq 'statustocreate') {
1.26      raeburn  6319:                         $check = ' checked="checked" ';
                   6320:                     }
1.23      raeburn  6321:                 }
1.26      raeburn  6322:                 $output .= '<td class="LC_left_item">'.
                   6323:                            '<span class="LC_nobreak"><label>'.
1.93      raeburn  6324:                            '<input type="checkbox" name="'.$context.'" '.
1.26      raeburn  6325:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   6326:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  6327:             }
                   6328:         }
1.26      raeburn  6329:         $rem = @{$types}%($numinrow);
1.23      raeburn  6330:     }
                   6331:     my $colsleft = $numinrow - $rem;
1.131     raeburn  6332:     if (($rem == 0) && (@{$types} > 0)) {
                   6333:         $output .= '<tr>';
                   6334:     }
1.23      raeburn  6335:     if ($colsleft > 1) {
1.25      raeburn  6336:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  6337:     } else {
1.25      raeburn  6338:         $output .= '<td class="LC_left_item">';
1.23      raeburn  6339:     }
                   6340:     my $defcheck = ' ';
1.99      raeburn  6341:     if (ref($settings) eq 'HASH') {  
                   6342:         if (ref($settings->{$context}) eq 'ARRAY') {
                   6343:             if (grep(/^default$/,@{$settings->{$context}})) {
                   6344:                 $defcheck = ' checked="checked" ';
                   6345:             }
                   6346:         } elsif ($context eq 'statustocreate') {
1.26      raeburn  6347:             $defcheck = ' checked="checked" ';
                   6348:         }
1.23      raeburn  6349:     }
1.25      raeburn  6350:     $output .= '<span class="LC_nobreak"><label>'.
1.93      raeburn  6351:                '<input type="checkbox" name="'.$context.'" '.
1.25      raeburn  6352:                'value="default"'.$defcheck.'/>'.
                   6353:                $othertitle.'</label></span></td>'.
                   6354:                '</tr></table></td></tr>';
                   6355:     return $output;
1.23      raeburn  6356: }
                   6357: 
                   6358: sub sorted_searchtitles {
                   6359:     my %searchtitles = &Apache::lonlocal::texthash(
                   6360:                          'uname' => 'username',
                   6361:                          'lastname' => 'last name',
                   6362:                          'lastfirst' => 'last name, first name',
                   6363:                      );
                   6364:     my @titleorder = ('uname','lastname','lastfirst');
                   6365:     return (\%searchtitles,\@titleorder);
                   6366: }
                   6367: 
1.25      raeburn  6368: sub sorted_searchtypes {
                   6369:     my %srchtypes_desc = (
                   6370:                            exact    => 'is exact match',
                   6371:                            contains => 'contains ..',
                   6372:                            begins   => 'begins with ..',
                   6373:                          );
                   6374:     my @srchtypeorder = ('exact','begins','contains');
                   6375:     return (\%srchtypes_desc,\@srchtypeorder);
                   6376: }
                   6377: 
1.3       raeburn  6378: sub usertype_update_row {
                   6379:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   6380:     my $datatable;
                   6381:     my $numinrow = 4;
                   6382:     foreach my $type (@{$types}) {
                   6383:         if (defined($usertypes->{$type})) {
                   6384:             $$rownums ++;
                   6385:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   6386:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   6387:                           '</td><td class="LC_left_item"><table>';
                   6388:             for (my $i=0; $i<@{$fields}; $i++) {
                   6389:                 my $rem = $i%($numinrow);
                   6390:                 if ($rem == 0) {
                   6391:                     if ($i > 0) {
                   6392:                         $datatable .= '</tr>';
                   6393:                     }
                   6394:                     $datatable .= '<tr>';
                   6395:                 }
                   6396:                 my $check = ' ';
1.39      raeburn  6397:                 if (ref($settings) eq 'HASH') {
                   6398:                     if (ref($settings->{'fields'}) eq 'HASH') {
                   6399:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   6400:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   6401:                                 $check = ' checked="checked" ';
                   6402:                             }
1.3       raeburn  6403:                         }
                   6404:                     }
                   6405:                 }
                   6406: 
                   6407:                 if ($i == @{$fields}-1) {
                   6408:                     my $colsleft = $numinrow - $rem;
                   6409:                     if ($colsleft > 1) {
                   6410:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   6411:                     } else {
                   6412:                         $datatable .= '<td>';
                   6413:                     }
                   6414:                 } else {
                   6415:                     $datatable .= '<td>';
                   6416:                 }
1.8       raeburn  6417:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   6418:                               '<input type="checkbox" name="updateable_'.$type.
                   6419:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   6420:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  6421:             }
                   6422:             $datatable .= '</tr></table></td></tr>';
                   6423:         }
                   6424:     }
                   6425:     return $datatable;
1.1       raeburn  6426: }
                   6427: 
                   6428: sub modify_login {
1.205     raeburn  6429:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168     raeburn  6430:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
                   6431:         %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
                   6432:     %title = ( coursecatalog => 'Display course catalog',
                   6433:                adminmail => 'Display administrator E-mail address',
1.188     raeburn  6434:                helpdesk  => 'Display "Contact Helpdesk" link',
1.168     raeburn  6435:                newuser => 'Link for visitors to create a user account',
                   6436:                loginheader => 'Log-in box header');
                   6437:     @offon = ('off','on');
1.112     raeburn  6438:     if (ref($domconfig{login}) eq 'HASH') {
                   6439:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
                   6440:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
                   6441:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
                   6442:             }
                   6443:         }
                   6444:     }
1.9       raeburn  6445:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   6446:                                            \%domconfig,\%loginhash);
1.188     raeburn  6447:     my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  6448:     foreach my $item (@toggles) {
                   6449:         $loginhash{login}{$item} = $env{'form.'.$item};
                   6450:     }
1.41      raeburn  6451:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6       raeburn  6452:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   6453:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   6454:                                          \%loginhash);
                   6455:     }
1.110     raeburn  6456: 
1.149     raeburn  6457:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256     raeburn  6458:     my %domservers = &Apache::lonnet::get_servers($dom);
1.128     raeburn  6459:     my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110     raeburn  6460:     if (keys(%servers) > 1) {
                   6461:         foreach my $lonhost (keys(%servers)) {
1.128     raeburn  6462:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
                   6463:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
                   6464:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
                   6465:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
                   6466:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
                   6467:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6468:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6469:                         $changes{'loginvia'}{$lonhost} = 1;
                   6470:                     } else {
                   6471:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
                   6472:                         $changes{'loginvia'}{$lonhost} = 1;
                   6473:                     }
                   6474:                 } else {
                   6475:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6476:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
                   6477:                         $changes{'loginvia'}{$lonhost} = 1;
                   6478:                     }
                   6479:                 }
                   6480:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
                   6481:                     foreach my $item (@loginvia_attribs) {
                   6482:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
                   6483:                     }
                   6484:                 } else {
                   6485:                     foreach my $item (@loginvia_attribs) {
                   6486:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6487:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6488:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
                   6489:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6490:                                 $new = '/';
                   6491:                             }
                   6492:                         }
                   6493:                         if (($item eq 'custompath') && 
                   6494:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6495:                             $new = '';
                   6496:                         }
                   6497:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
                   6498:                             $changes{'loginvia'}{$lonhost} = 1;
                   6499:                         }
                   6500:                         if ($item eq 'exempt') {
1.256     raeburn  6501:                             $new = &check_exempt_addresses($new);
1.128     raeburn  6502:                         }
                   6503:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6504:                     }
                   6505:                 }
1.112     raeburn  6506:             } else {
1.128     raeburn  6507:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
                   6508:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112     raeburn  6509:                     $changes{'loginvia'}{$lonhost} = 1;
1.128     raeburn  6510:                     foreach my $item (@loginvia_attribs) {
                   6511:                         my $new = $env{'form.'.$lonhost.'_'.$item};
                   6512:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
                   6513:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
                   6514:                                 $new = '/';
                   6515:                             }
                   6516:                         }
                   6517:                         if (($item eq 'custompath') && 
                   6518:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
                   6519:                             $new = '';
                   6520:                         }
                   6521:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
                   6522:                     }
1.110     raeburn  6523:                 }
                   6524:             }
                   6525:         }
                   6526:     }
1.119     raeburn  6527: 
1.168     raeburn  6528:     my $servadm = $r->dir_config('lonAdmEMail');
                   6529:     my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
                   6530:     if (ref($domconfig{'login'}) eq 'HASH') {
                   6531:         if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
                   6532:             foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
                   6533:                 if ($lang eq 'nolang') {
                   6534:                     push(@currlangs,$lang);
                   6535:                 } elsif (defined($langchoices{$lang})) {
                   6536:                     push(@currlangs,$lang);
                   6537:                 } else {
                   6538:                     next;
                   6539:                 }
                   6540:             }
                   6541:         }
                   6542:     }
                   6543:     my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
                   6544:     if (@currlangs > 0) {
                   6545:         foreach my $lang (@currlangs) {
                   6546:             if (grep(/^\Q$lang\E$/,@delurls)) {
                   6547:                 $changes{'helpurl'}{$lang} = 1;
                   6548:             } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
                   6549:                 $changes{'helpurl'}{$lang} = 1;
                   6550:                 $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
                   6551:                 push(@newlangs,$lang);
                   6552:             } else {
                   6553:                 $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   6554:             }
                   6555:         }
                   6556:     }
                   6557:     unless (grep(/^nolang$/,@currlangs)) {
                   6558:         if ($env{'form.loginhelpurl_nolang.filename'}) {
                   6559:             $changes{'helpurl'}{'nolang'} = 1;
                   6560:             $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
                   6561:             push(@newlangs,'nolang');
                   6562:         }
                   6563:     }
                   6564:     if ($env{'form.loginhelpurl_add_lang'}) {
                   6565:         if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
                   6566:             ($env{'form.loginhelpurl_add_file.filename'})) {
                   6567:             $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
                   6568:             $addedfile = $env{'form.loginhelpurl_add_lang'};
                   6569:         }
                   6570:     }
                   6571:     if ((@newlangs > 0) || ($addedfile)) {
                   6572:         my $error;
                   6573:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   6574:         if ($configuserok eq 'ok') {
                   6575:             if ($switchserver) {
                   6576:                 $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
                   6577:             } elsif ($author_ok eq 'ok') {
                   6578:                 my @allnew = @newlangs;
                   6579:                 if ($addedfile ne '') {
                   6580:                     push(@allnew,$addedfile);
                   6581:                 }
                   6582:                 foreach my $lang (@allnew) {
                   6583:                     my $formelem = 'loginhelpurl_'.$lang;
                   6584:                     if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
                   6585:                         $formelem = 'loginhelpurl_add_file';
                   6586:                     }
                   6587:                     (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   6588:                                                                "help/$lang",'','',$newfile{$lang});
                   6589:                     if ($result eq 'ok') {
                   6590:                         $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
                   6591:                         $changes{'helpurl'}{$lang} = 1;
                   6592:                     } else {
                   6593:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
                   6594:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210     raeburn  6595:                         if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168     raeburn  6596:                             (!grep(/^\Q$lang\E$/,@delurls))) {
                   6597:                             $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
                   6598:                         }
                   6599:                     }
                   6600:                 }
                   6601:             } else {
                   6602:                 $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);
                   6603:             }
                   6604:         } else {
                   6605:             $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);
                   6606:         }
                   6607:         if ($error) {
                   6608:             &Apache::lonnet::logthis($error);
                   6609:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6610:         }
                   6611:     }
1.256     raeburn  6612: 
                   6613:     my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
                   6614:     if (ref($domconfig{'login'}) eq 'HASH') {
                   6615:         if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
                   6616:             foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
                   6617:                 if ($domservers{$lonhost}) {
                   6618:                     if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   6619:                         $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268     raeburn  6620:                         $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256     raeburn  6621:                     }
                   6622:                 }
                   6623:             }
                   6624:         }
                   6625:     }
                   6626:     my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
                   6627:     foreach my $lonhost (sort(keys(%domservers))) {
                   6628:         if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   6629:             $changes{'headtag'}{$lonhost} = 1;
                   6630:         } else {
                   6631:             if ($env{'form.loginheadtagexempt_'.$lonhost}) {
                   6632:                 $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
                   6633:             }
                   6634:             if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
                   6635:                 push(@newhosts,$lonhost);
                   6636:             } elsif ($currheadtagurls{$lonhost}) {
                   6637:                 $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
                   6638:                 if ($currexempt{$lonhost}) {
                   6639:                     if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) { 
                   6640:                         $changes{'headtag'}{$lonhost} = 1;
                   6641:                     }
                   6642:                 } elsif ($possexempt{$lonhost}) {
                   6643:                     $changes{'headtag'}{$lonhost} = 1;
                   6644:                 }
                   6645:                 if ($possexempt{$lonhost}) {
                   6646:                     $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   6647:                 }
                   6648:             }
                   6649:         }
                   6650:     }
                   6651:     if (@newhosts) {
                   6652:         my $error;
                   6653:         my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   6654:         if ($configuserok eq 'ok') {
                   6655:             if ($switchserver) {
                   6656:                 $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
                   6657:             } elsif ($author_ok eq 'ok') {
                   6658:                 foreach my $lonhost (@newhosts) {
                   6659:                     my $formelem = 'loginheadtag_'.$lonhost;
                   6660:                     (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
                   6661:                                                                           "login/headtag/$lonhost",'','',
                   6662:                                                                           $env{'form.loginheadtag_'.$lonhost.'.filename'});
                   6663:                     if ($result eq 'ok') {
                   6664:                         $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
                   6665:                         $changes{'headtag'}{$lonhost} = 1;
                   6666:                         if ($possexempt{$lonhost}) {
                   6667:                             $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
                   6668:                         }
                   6669:                     } else {
                   6670:                         my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
                   6671:                                            $newheadtagurls{$lonhost},$result);
                   6672:                         $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
                   6673:                         if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
                   6674:                             (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
                   6675:                             $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
                   6676:                         }
                   6677:                     }
                   6678:                 }
                   6679:             } else {
                   6680:                 $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);
                   6681:             }
                   6682:         } else {
                   6683:             $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);
                   6684:         }
                   6685:         if ($error) {
                   6686:             &Apache::lonnet::logthis($error);
                   6687:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   6688:         }
                   6689:     }
1.169     raeburn  6690:     &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168     raeburn  6691: 
                   6692:     my $defaulthelpfile = '/adm/loginproblems.html';
                   6693:     my $defaulttext = &mt('Default in use');
                   6694: 
1.1       raeburn  6695:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   6696:                                              $dom);
                   6697:     if ($putresult eq 'ok') {
1.188     raeburn  6698:         my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42      raeburn  6699:         my %defaultchecked = (
                   6700:                     'coursecatalog' => 'on',
1.188     raeburn  6701:                     'helpdesk'      => 'on',
1.42      raeburn  6702:                     'adminmail'     => 'off',
1.43      raeburn  6703:                     'newuser'       => 'off',
1.42      raeburn  6704:         );
1.55      raeburn  6705:         if (ref($domconfig{'login'}) eq 'HASH') {
                   6706:             foreach my $item (@toggles) {
                   6707:                 if ($defaultchecked{$item} eq 'on') { 
                   6708:                     if (($domconfig{'login'}{$item} eq '0') &&
                   6709:                         ($env{'form.'.$item} eq '1')) {
                   6710:                         $changes{$item} = 1;
                   6711:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   6712:                               $domconfig{'login'}{$item} eq '1') &&
                   6713:                              ($env{'form.'.$item} eq '0')) {
                   6714:                         $changes{$item} = 1;
                   6715:                     }
                   6716:                 } elsif ($defaultchecked{$item} eq 'off') {
                   6717:                     if (($domconfig{'login'}{$item} eq '1') &&
                   6718:                         ($env{'form.'.$item} eq '0')) {
                   6719:                         $changes{$item} = 1;
                   6720:                     } elsif (($domconfig{'login'}{$item} eq '' ||
                   6721:                               $domconfig{'login'}{$item} eq '0') &&
                   6722:                              ($env{'form.'.$item} eq '1')) {
                   6723:                         $changes{$item} = 1;
                   6724:                     }
1.42      raeburn  6725:                 }
                   6726:             }
1.41      raeburn  6727:         }
1.6       raeburn  6728:         if (keys(%changes) > 0 || $colchgtext) {
1.41      raeburn  6729:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  6730:             if (ref($lastactref) eq 'HASH') {
                   6731:                 $lastactref->{'domainconfig'} = 1;
                   6732:             }
1.1       raeburn  6733:             $resulttext = &mt('Changes made:').'<ul>';
                   6734:             foreach my $item (sort(keys(%changes))) {
1.135     bisitz   6735:                 if ($item eq 'loginvia') {
1.112     raeburn  6736:                     if (ref($changes{$item}) eq 'HASH') {
                   6737:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
                   6738:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128     raeburn  6739:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
                   6740:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
                   6741:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
                   6742:                                     $protocol = 'http' if ($protocol ne 'https');
                   6743:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
                   6744: 
                   6745:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
                   6746:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
                   6747:                                     } else {
                   6748:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
                   6749:                                     }
                   6750:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
                   6751:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
                   6752:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
                   6753:                                     }
                   6754:                                     $resulttext .= '</li>';
                   6755:                                 } else {
                   6756:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
                   6757:                                 }
1.112     raeburn  6758:                             } else {
1.128     raeburn  6759:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112     raeburn  6760:                             }
                   6761:                         }
1.128     raeburn  6762:                         $resulttext .= '</ul></li>';
1.112     raeburn  6763:                     }
1.168     raeburn  6764:                 } elsif ($item eq 'helpurl') {
                   6765:                     if (ref($changes{$item}) eq 'HASH') {
                   6766:                         foreach my $lang (sort(keys(%{$changes{$item}}))) {
                   6767:                             if (grep(/^\Q$lang\E$/,@delurls)) {
                   6768:                                 my ($chg,$link);
                   6769:                                 $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
                   6770:                                 if ($lang eq 'nolang') {
                   6771:                                     $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
                   6772:                                 } else {
                   6773:                                     $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
                   6774:                                 }
                   6775:                                 $resulttext .= '<li>'.$chg.'</li>';
                   6776:                             } else {
                   6777:                                 my $chg;
                   6778:                                 if ($lang eq 'nolang') {
                   6779:                                     $chg = &mt('custom log-in help file for no preferred language');
                   6780:                                 } else {
                   6781:                                     $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
                   6782:                                 }
                   6783:                                 $resulttext .= '<li>'.&Apache::loncommon::modal_link(
                   6784:                                                       $loginhash{'login'}{'helpurl'}{$lang}.
                   6785:                                                       '?inhibitmenu=yes',$chg,600,500).
                   6786:                                                '</li>';
                   6787:                             }
                   6788:                         }
                   6789:                     }
1.256     raeburn  6790:                 } elsif ($item eq 'headtag') {
                   6791:                     if (ref($changes{$item}) eq 'HASH') {
                   6792:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
                   6793:                             if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
                   6794:                                 $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
                   6795:                             } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
                   6796:                                 $resulttext .= '<li><a href="'.
                   6797:                                                "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
                   6798:                                                'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
                   6799:                                                '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
                   6800:                                 if ($possexempt{$lonhost}) {
                   6801:                                     $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
                   6802:                                 } else {
                   6803:                                     $resulttext .= &mt('included for any client IP');
                   6804:                                 }
                   6805:                                 $resulttext .= '</li>';
                   6806:                             }
                   6807:                         }
                   6808:                     }
1.169     raeburn  6809:                 } elsif ($item eq 'captcha') {
                   6810:                     if (ref($loginhash{'login'}) eq 'HASH') {
1.210     raeburn  6811:                         my $chgtxt;
1.169     raeburn  6812:                         if ($loginhash{'login'}{$item} eq 'notused') {
                   6813:                             $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
                   6814:                         } else {
                   6815:                             my %captchas = &captcha_phrases();
                   6816:                             if ($captchas{$loginhash{'login'}{$item}}) {
                   6817:                                 $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
                   6818:                             } else {
                   6819:                                 $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
                   6820:                             }
                   6821:                         }
                   6822:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   6823:                     }
                   6824:                 } elsif ($item eq 'recaptchakeys') {
                   6825:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   6826:                         my ($privkey,$pubkey);
                   6827:                         if (ref($loginhash{'login'}{$item}) eq 'HASH') {
                   6828:                             $pubkey = $loginhash{'login'}{$item}{'public'};
                   6829:                             $privkey = $loginhash{'login'}{$item}{'private'};
                   6830:                         }
                   6831:                         my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
                   6832:                         if (!$pubkey) {
                   6833:                             $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
                   6834:                         } else {
                   6835:                             $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   6836:                         }
                   6837:                         if (!$privkey) {
                   6838:                             $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
                   6839:                         } else {
1.251     raeburn  6840:                             $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169     raeburn  6841:                         }
                   6842:                         $chgtxt .= '</ul>';
                   6843:                         $resulttext .= '<li>'.$chgtxt.'</li>';
                   6844:                     }
1.269     raeburn  6845:                 } elsif ($item eq 'recaptchaversion') {
                   6846:                     if (ref($loginhash{'login'}) eq 'HASH') {
                   6847:                         if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270     raeburn  6848:                             $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269     raeburn  6849:                                            '</li>';
                   6850:                         }
                   6851:                     }
1.41      raeburn  6852:                 } else {
                   6853:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   6854:                 }
1.1       raeburn  6855:             }
1.6       raeburn  6856:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  6857:         } else {
                   6858:             $resulttext = &mt('No changes made to log-in page settings');
                   6859:         }
                   6860:     } else {
1.11      albertel 6861:         $resulttext = '<span class="LC_error">'.
                   6862: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  6863:     }
1.6       raeburn  6864:     if ($errors) {
1.9       raeburn  6865:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  6866:                        $errors.'</ul>';
                   6867:     }
                   6868:     return $resulttext;
                   6869: }
                   6870: 
1.256     raeburn  6871: 
                   6872: sub check_exempt_addresses {
                   6873:     my ($iplist) = @_;
                   6874:     $iplist =~ s/^\s+//;
                   6875:     $iplist =~ s/\s+$//;
                   6876:     my @poss_ips = split(/\s*[,:]\s*/,$iplist);
                   6877:     my (@okips,$new);
                   6878:     foreach my $ip (@poss_ips) {
                   6879:         if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
                   6880:             if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
                   6881:                 push(@okips,$ip);
                   6882:             }
                   6883:         }
                   6884:     }
                   6885:     if (@okips > 0) {
                   6886:         $new = join(',',@okips);
                   6887:     } else {
                   6888:         $new = '';
                   6889:     }
                   6890:     return $new;
                   6891: }
                   6892: 
1.6       raeburn  6893: sub color_font_choices {
                   6894:     my %choices =
                   6895:         &Apache::lonlocal::texthash (
                   6896:             img => "Header",
                   6897:             bgs => "Background colors",
                   6898:             links => "Link colors",
1.55      raeburn  6899:             images => "Images",
1.6       raeburn  6900:             font => "Font color",
1.201     raeburn  6901:             fontmenu => "Font menu",
1.76      raeburn  6902:             pgbg => "Page",
1.6       raeburn  6903:             tabbg => "Header",
                   6904:             sidebg => "Border",
                   6905:             link => "Link",
                   6906:             alink => "Active link",
                   6907:             vlink => "Visited link",
                   6908:         );
                   6909:     return %choices;
                   6910: }
                   6911: 
                   6912: sub modify_rolecolors {
1.205     raeburn  6913:     my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6       raeburn  6914:     my ($resulttext,%rolehash);
                   6915:     $rolehash{'rolecolors'} = {};
1.55      raeburn  6916:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
                   6917:         if ($domconfig{'rolecolors'} eq '') {
                   6918:             $domconfig{'rolecolors'} = {};
                   6919:         }
                   6920:     }
1.9       raeburn  6921:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  6922:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   6923:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   6924:                                              $dom);
                   6925:     if ($putresult eq 'ok') {
                   6926:         if (keys(%changes) > 0) {
1.41      raeburn  6927:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  6928:             if (ref($lastactref) eq 'HASH') {
                   6929:                 $lastactref->{'domainconfig'} = 1;
                   6930:             }
1.6       raeburn  6931:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   6932:                                              $rolehash{'rolecolors'});
                   6933:         } else {
                   6934:             $resulttext = &mt('No changes made to default color schemes');
                   6935:         }
                   6936:     } else {
1.11      albertel 6937:         $resulttext = '<span class="LC_error">'.
                   6938: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  6939:     }
                   6940:     if ($errors) {
                   6941:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   6942:                        $errors.'</ul>';
                   6943:     }
                   6944:     return $resulttext;
                   6945: }
                   6946: 
                   6947: sub modify_colors {
1.9       raeburn  6948:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  6949:     my (%changes,%choices);
1.51      raeburn  6950:     my @bgs;
1.6       raeburn  6951:     my @links = ('link','alink','vlink');
1.41      raeburn  6952:     my @logintext;
1.6       raeburn  6953:     my @images;
                   6954:     my $servadm = $r->dir_config('lonAdmEMail');
                   6955:     my $errors;
1.200     raeburn  6956:     my %defaults;
1.6       raeburn  6957:     foreach my $role (@{$roles}) {
                   6958:         if ($role eq 'login') {
1.12      raeburn  6959:             %choices = &login_choices();
1.41      raeburn  6960:             @logintext = ('textcol','bgcol');
1.12      raeburn  6961:         } else {
                   6962:             %choices = &color_font_choices();
                   6963:         }
                   6964:         if ($role eq 'login') {
1.41      raeburn  6965:             @images = ('img','logo','domlogo','login');
1.51      raeburn  6966:             @bgs = ('pgbg','mainbg','sidebg');
1.6       raeburn  6967:         } else {
                   6968:             @images = ('img');
1.200     raeburn  6969:             @bgs = ('pgbg','tabbg','sidebg');
                   6970:         }
                   6971:         my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
                   6972:         unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
                   6973:             $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   6974:         }
                   6975:         if ($role eq 'login') {
                   6976:             foreach my $item (@logintext) {
1.234     raeburn  6977:                 $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   6978:                 if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   6979:                     $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   6980:                 }
                   6981:                 unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200     raeburn  6982:                     $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   6983:                 }
                   6984:             }
                   6985:         } else {
1.234     raeburn  6986:             $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
                   6987:             if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
                   6988:                 $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
                   6989:             }
                   6990:             unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200     raeburn  6991:                 $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
                   6992:             }
1.6       raeburn  6993:         }
1.200     raeburn  6994:         foreach my $item (@bgs) {
1.234     raeburn  6995:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   6996:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   6997:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   6998:             }
                   6999:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200     raeburn  7000:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7001:             }
                   7002:         }
                   7003:         foreach my $item (@links) {
1.234     raeburn  7004:             $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
                   7005:             if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
                   7006:                 $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
                   7007:             }
                   7008:             unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200     raeburn  7009:                 $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   7010:             }
1.6       raeburn  7011:         }
1.46      raeburn  7012:         my ($configuserok,$author_ok,$switchserver) = 
                   7013:             &config_check($dom,$confname,$servadm);
1.9       raeburn  7014:         my ($width,$height) = &thumb_dimensions();
1.40      raeburn  7015:         if (ref($domconfig->{$role}) ne 'HASH') {
                   7016:             $domconfig->{$role} = {};
                   7017:         }
1.8       raeburn  7018:         foreach my $img (@images) {
1.70      raeburn  7019:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   7020:                 if (defined($env{'form.login_showlogo_'.$img})) {
                   7021:                     $confhash->{$role}{'showlogo'}{$img} = 1;
                   7022:                 } else { 
                   7023:                     $confhash->{$role}{'showlogo'}{$img} = 0;
                   7024:                 }
                   7025:             } 
1.18      albertel 7026: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   7027: 		 && !defined($domconfig->{$role}{$img})
                   7028: 		 && !$env{'form.'.$role.'_del_'.$img}
                   7029: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   7030: 		# import the old configured image from the .tab setting
                   7031: 		# if they haven't provided a new one 
                   7032: 		$domconfig->{$role}{$img} = 
                   7033: 		    $env{'form.'.$role.'_import_'.$img};
                   7034: 	    }
1.6       raeburn  7035:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  7036:                 my $error;
1.6       raeburn  7037:                 if ($configuserok eq 'ok') {
1.9       raeburn  7038:                     if ($switchserver) {
1.12      raeburn  7039:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  7040:                     } else {
                   7041:                         if ($author_ok eq 'ok') {
                   7042:                             my ($result,$logourl) = 
                   7043:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   7044:                                            $dom,$confname,$img,$width,$height);
                   7045:                             if ($result eq 'ok') {
                   7046:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  7047:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7048:                             } else {
1.12      raeburn  7049:                                 $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  7050:                             }
                   7051:                         } else {
1.46      raeburn  7052:                             $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  7053:                         }
                   7054:                     }
                   7055:                 } else {
1.46      raeburn  7056:                     $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  7057:                 }
                   7058:                 if ($error) {
1.8       raeburn  7059:                     &Apache::lonnet::logthis($error);
1.11      albertel 7060:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  7061:                 }
                   7062:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  7063:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   7064:                     my $error;
                   7065:                     if ($configuserok eq 'ok') {
                   7066: # is confname an author?
                   7067:                         if ($switchserver eq '') {
                   7068:                             if ($author_ok eq 'ok') {
                   7069:                                 my ($result,$logourl) = 
                   7070:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   7071:                                             $dom,$confname,$img,$width,$height);
                   7072:                                 if ($result eq 'ok') {
                   7073:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 7074: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  7075:                                 }
                   7076:                             }
                   7077:                         }
                   7078:                     }
1.6       raeburn  7079:                 }
                   7080:             }
                   7081:         }
                   7082:         if (ref($domconfig) eq 'HASH') {
                   7083:             if (ref($domconfig->{$role}) eq 'HASH') {
                   7084:                 foreach my $img (@images) {
                   7085:                     if ($domconfig->{$role}{$img} ne '') {
                   7086:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7087:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7088:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7089:                         } else {
1.9       raeburn  7090:                             if ($confhash->{$role}{$img} eq '') {
                   7091:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   7092:                             }
1.6       raeburn  7093:                         }
                   7094:                     } else {
                   7095:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   7096:                             $confhash->{$role}{$img} = '';
1.12      raeburn  7097:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  7098:                         } 
                   7099:                     }
1.70      raeburn  7100:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                   7101:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                   7102:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
                   7103:                                 $domconfig->{$role}{'showlogo'}{$img}) {
                   7104:                                 $changes{$role}{'showlogo'}{$img} = 1; 
                   7105:                             }
                   7106:                         } else {
                   7107:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7108:                                 $changes{$role}{'showlogo'}{$img} = 1;
                   7109:                             }
                   7110:                         }
                   7111:                     }
                   7112:                 }
1.6       raeburn  7113:                 if ($domconfig->{$role}{'font'} ne '') {
                   7114:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   7115:                         $changes{$role}{'font'} = 1;
                   7116:                     }
                   7117:                 } else {
                   7118:                     if ($confhash->{$role}{'font'}) {
                   7119:                         $changes{$role}{'font'} = 1;
                   7120:                     }
                   7121:                 }
1.107     raeburn  7122:                 if ($role ne 'login') {
                   7123:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
                   7124:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
                   7125:                             $changes{$role}{'fontmenu'} = 1;
                   7126:                         }
                   7127:                     } else {
                   7128:                         if ($confhash->{$role}{'fontmenu'}) {
                   7129:                             $changes{$role}{'fontmenu'} = 1;
                   7130:                         }
1.97      tempelho 7131:                     }
                   7132:                 }
1.6       raeburn  7133:                 foreach my $item (@bgs) {
                   7134:                     if ($domconfig->{$role}{$item} ne '') {
                   7135:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7136:                             $changes{$role}{'bgs'}{$item} = 1;
                   7137:                         } 
                   7138:                     } else {
                   7139:                         if ($confhash->{$role}{$item}) {
                   7140:                             $changes{$role}{'bgs'}{$item} = 1;
                   7141:                         }
                   7142:                     }
                   7143:                 }
                   7144:                 foreach my $item (@links) {
                   7145:                     if ($domconfig->{$role}{$item} ne '') {
                   7146:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7147:                             $changes{$role}{'links'}{$item} = 1;
                   7148:                         }
                   7149:                     } else {
                   7150:                         if ($confhash->{$role}{$item}) {
                   7151:                             $changes{$role}{'links'}{$item} = 1;
                   7152:                         }
                   7153:                     }
                   7154:                 }
1.41      raeburn  7155:                 foreach my $item (@logintext) {
                   7156:                     if ($domconfig->{$role}{$item} ne '') {
                   7157:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   7158:                             $changes{$role}{'logintext'}{$item} = 1;
                   7159:                         }
                   7160:                     } else {
                   7161:                         if ($confhash->{$role}{$item}) {
                   7162:                             $changes{$role}{'logintext'}{$item} = 1;
                   7163:                         }
                   7164:                     }
                   7165:                 }
1.6       raeburn  7166:             } else {
                   7167:                 &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7168:                                         \@logintext,$confhash,\%changes); 
1.6       raeburn  7169:             }
                   7170:         } else {
                   7171:             &default_change_checker($role,\@images,\@links,\@bgs,
1.41      raeburn  7172:                                     \@logintext,$confhash,\%changes); 
1.6       raeburn  7173:         }
                   7174:     }
                   7175:     return ($errors,%changes);
                   7176: }
                   7177: 
1.46      raeburn  7178: sub config_check {
                   7179:     my ($dom,$confname,$servadm) = @_;
                   7180:     my ($configuserok,$author_ok,$switchserver,%currroles);
                   7181:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   7182:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   7183:                                                    $confname,$servadm);
                   7184:     if ($configuserok eq 'ok') {
                   7185:         $switchserver = &check_switchserver($dom,$confname);
                   7186:         if ($switchserver eq '') {
                   7187:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   7188:         }
                   7189:     }
                   7190:     return ($configuserok,$author_ok,$switchserver);
                   7191: }
                   7192: 
1.6       raeburn  7193: sub default_change_checker {
1.41      raeburn  7194:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6       raeburn  7195:     foreach my $item (@{$links}) {
                   7196:         if ($confhash->{$role}{$item}) {
                   7197:             $changes->{$role}{'links'}{$item} = 1;
                   7198:         }
                   7199:     }
                   7200:     foreach my $item (@{$bgs}) {
                   7201:         if ($confhash->{$role}{$item}) {
                   7202:             $changes->{$role}{'bgs'}{$item} = 1;
                   7203:         }
                   7204:     }
1.41      raeburn  7205:     foreach my $item (@{$logintext}) {
                   7206:         if ($confhash->{$role}{$item}) {
                   7207:             $changes->{$role}{'logintext'}{$item} = 1;
                   7208:         }
                   7209:     }
1.6       raeburn  7210:     foreach my $img (@{$images}) {
                   7211:         if ($env{'form.'.$role.'_del_'.$img}) {
                   7212:             $confhash->{$role}{$img} = '';
1.12      raeburn  7213:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  7214:         }
1.70      raeburn  7215:         if ($role eq 'login') {
                   7216:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   7217:                 $changes->{$role}{'showlogo'}{$img} = 1;
                   7218:             }
                   7219:         }
1.6       raeburn  7220:     }
                   7221:     if ($confhash->{$role}{'font'}) {
                   7222:         $changes->{$role}{'font'} = 1;
                   7223:     }
1.48      raeburn  7224: }
1.6       raeburn  7225: 
                   7226: sub display_colorchgs {
                   7227:     my ($dom,$changes,$roles,$confhash) = @_;
                   7228:     my (%choices,$resulttext);
                   7229:     if (!grep(/^login$/,@{$roles})) {
                   7230:         $resulttext = &mt('Changes made:').'<br />';
                   7231:     }
                   7232:     foreach my $role (@{$roles}) {
                   7233:         if ($role eq 'login') {
                   7234:             %choices = &login_choices();
                   7235:         } else {
                   7236:             %choices = &color_font_choices();
                   7237:         }
                   7238:         if (ref($changes->{$role}) eq 'HASH') {
                   7239:             if ($role ne 'login') {
                   7240:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   7241:             }
                   7242:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   7243:                 if ($role ne 'login') {
                   7244:                     $resulttext .= '<ul>';
                   7245:                 }
                   7246:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   7247:                     if ($role ne 'login') {
                   7248:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   7249:                     }
                   7250:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70      raeburn  7251:                         if (($role eq 'login') && ($key eq 'showlogo')) {
                   7252:                             if ($confhash->{$role}{$key}{$item}) {
                   7253:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                   7254:                             } else {
                   7255:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                   7256:                             }
                   7257:                         } elsif ($confhash->{$role}{$item} eq '') {
1.6       raeburn  7258:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   7259:                         } else {
1.12      raeburn  7260:                             my $newitem = $confhash->{$role}{$item};
                   7261:                             if ($key eq 'images') {
                   7262:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   7263:                             }
                   7264:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  7265:                         }
                   7266:                     }
                   7267:                     if ($role ne 'login') {
                   7268:                         $resulttext .= '</ul></li>';
                   7269:                     }
                   7270:                 } else {
                   7271:                     if ($confhash->{$role}{$key} eq '') {
                   7272:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   7273:                     } else {
                   7274:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   7275:                     }
                   7276:                 }
                   7277:                 if ($role ne 'login') {
                   7278:                     $resulttext .= '</ul>';
                   7279:                 }
                   7280:             }
                   7281:         }
                   7282:     }
1.3       raeburn  7283:     return $resulttext;
1.1       raeburn  7284: }
                   7285: 
1.9       raeburn  7286: sub thumb_dimensions {
                   7287:     return ('200','50');
                   7288: }
                   7289: 
1.16      raeburn  7290: sub check_dimensions {
                   7291:     my ($inputfile) = @_;
                   7292:     my ($fullwidth,$fullheight);
                   7293:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   7294:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   7295:             my $imageinfo = <PIPE>;
                   7296:             if (!close(PIPE)) {
                   7297:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   7298:             }
                   7299:             chomp($imageinfo);
                   7300:             my ($fullsize) = 
1.21      raeburn  7301:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  7302:             if ($fullsize) {
                   7303:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   7304:             }
                   7305:         }
                   7306:     }
                   7307:     return ($fullwidth,$fullheight);
                   7308: }
                   7309: 
1.9       raeburn  7310: sub check_configuser {
                   7311:     my ($uhome,$dom,$confname,$servadm) = @_;
                   7312:     my ($configuserok,%currroles);
                   7313:     if ($uhome eq 'no_host') {
                   7314:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   7315:         my $configpass = &LONCAPA::Enrollment::create_password();
                   7316:         $configuserok = 
                   7317:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   7318:                              $configpass,'','','','','',undef,$servadm);
                   7319:     } else {
                   7320:         $configuserok = 'ok';
                   7321:         %currroles = 
                   7322:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   7323:     }
                   7324:     return ($configuserok,%currroles);
                   7325: }
                   7326: 
                   7327: sub check_authorstatus {
                   7328:     my ($dom,$confname,%currroles) = @_;
                   7329:     my $author_ok;
1.40      raeburn  7330:     if (!$currroles{':'.$dom.':au'}) {
1.9       raeburn  7331:         my $start = time;
                   7332:         my $end = 0;
                   7333:         $author_ok = 
                   7334:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47      raeburn  7335:                                         'au',$end,$start,'','','domconfig');
1.9       raeburn  7336:     } else {
                   7337:         $author_ok = 'ok';
                   7338:     }
                   7339:     return $author_ok;
                   7340: }
                   7341: 
                   7342: sub publishlogo {
1.46      raeburn  7343:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.267     raeburn  7344:     my ($output,$fname,$logourl,$madethumb);
1.9       raeburn  7345:     if ($action eq 'upload') {
                   7346:         $fname=$env{'form.'.$formname.'.filename'};
                   7347:         chop($env{'form.'.$formname});
                   7348:     } else {
                   7349:         ($fname) = ($formname =~ /([^\/]+)$/);
                   7350:     }
1.46      raeburn  7351:     if ($savefileas ne '') {
                   7352:         $fname = $savefileas;
                   7353:     }
1.9       raeburn  7354:     $fname=&Apache::lonnet::clean_filename($fname);
                   7355: # See if there is anything left
                   7356:     unless ($fname) { return ('error: no uploaded file'); }
                   7357:     $fname="$subdir/$fname";
1.210     raeburn  7358:     my $docroot=$r->dir_config('lonDocRoot');
1.164     raeburn  7359:     my $filepath="$docroot/priv";
                   7360:     my $relpath = "$dom/$confname";
1.9       raeburn  7361:     my ($fnamepath,$file,$fetchthumb);
                   7362:     $file=$fname;
                   7363:     if ($fname=~m|/|) {
                   7364:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   7365:     }
1.164     raeburn  7366:     my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9       raeburn  7367:     my $count;
1.164     raeburn  7368:     for ($count=5;$count<=$#parts;$count++) {
1.9       raeburn  7369:         $filepath.="/$parts[$count]";
                   7370:         if ((-e $filepath)!=1) {
                   7371:             mkdir($filepath,02770);
                   7372:         }
                   7373:     }
                   7374:     # Check for bad extension and disallow upload
                   7375:     if ($file=~/\.(\w+)$/ &&
                   7376:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7377:         $output = 
1.207     bisitz   7378:             &mt('Invalid file extension ([_1]) - reserved for internal use.',$1); 
1.9       raeburn  7379:     } elsif ($file=~/\.(\w+)$/ &&
                   7380:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   7381:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7382:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195     bisitz   7383:         $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  7384:     } elsif (-d "$filepath/$file") {
1.195     bisitz   7385:         $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9       raeburn  7386:     } else {
                   7387:         my $source = $filepath.'/'.$file;
                   7388:         my $logfile;
                   7389:         if (!open($logfile,">>$source".'.log')) {
1.196     raeburn  7390:             return (&mt('No write permission to Authoring Space'));
1.9       raeburn  7391:         }
                   7392:         print $logfile
                   7393: "\n================= Publish ".localtime()." ================\n".
                   7394: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   7395: # Save the file
                   7396:         if (!open(FH,'>'.$source)) {
                   7397:             &Apache::lonnet::logthis('Failed to create '.$source);
                   7398:             return (&mt('Failed to create file'));
                   7399:         }
                   7400:         if ($action eq 'upload') {
                   7401:             if (!print FH ($env{'form.'.$formname})) {
                   7402:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   7403:                 return (&mt('Failed to write file'));
                   7404:             }
                   7405:         } else {
                   7406:             my $original = &Apache::lonnet::filelocation('',$formname);
                   7407:             if(!copy($original,$source)) {
                   7408:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   7409:                 return (&mt('Failed to write file'));
                   7410:             }
                   7411:         }
                   7412:         close(FH);
                   7413:         chmod(0660, $source); # Permissions to rw-rw---.
                   7414: 
                   7415:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   7416:         my $copyfile=$targetdir.'/'.$file;
                   7417: 
                   7418:         my @parts=split(/\//,$targetdir);
                   7419:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   7420:         for (my $count=5;$count<=$#parts;$count++) {
                   7421:             $path.="/$parts[$count]";
                   7422:             if (!-e $path) {
                   7423:                 print $logfile "\nCreating directory ".$path;
                   7424:                 mkdir($path,02770);
                   7425:             }
                   7426:         }
                   7427:         my $versionresult;
                   7428:         if (-e $copyfile) {
                   7429:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   7430:         } else {
                   7431:             $versionresult = 'ok';
                   7432:         }
                   7433:         if ($versionresult eq 'ok') {
                   7434:             if (copy($source,$copyfile)) {
                   7435:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   7436:                 $output = 'ok';
                   7437:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155     raeburn  7438:                 push(@{$modified_urls},[$copyfile,$source]);
                   7439:                 my $metaoutput = 
                   7440:                     &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   7441:                 unless ($registered_cleanup) {
                   7442:                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7443:                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7444:                     $registered_cleanup=1;
                   7445:                 }
1.9       raeburn  7446:             } else {
                   7447:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   7448:                 $output = &mt('Failed to copy file to RES space').", $!";
                   7449:             }
                   7450:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   7451:                 my $inputfile = $filepath.'/'.$file;
                   7452:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  7453:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   7454:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   7455:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   7456:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   7457:                         system("convert -sample $thumbsize $inputfile $outfile");
                   7458:                         chmod(0660, $filepath.'/tn-'.$file);
                   7459:                         if (-e $outfile) {
                   7460:                             my $copyfile=$targetdir.'/tn-'.$file;
                   7461:                             if (copy($outfile,$copyfile)) {
                   7462:                                 print $logfile "\nCopied source to ".$copyfile."\n";
1.155     raeburn  7463:                                 my $thumb_metaoutput = 
                   7464:                                     &write_metadata($dom,$confname,$formname,
                   7465:                                                     $targetdir,'tn-'.$file,$logfile);
                   7466:                                 push(@{$modified_urls},[$copyfile,$outfile]);
                   7467:                                 unless ($registered_cleanup) {
                   7468:                                     my $handlers = $r->get_handlers('PerlCleanupHandler');
                   7469:                                     $r->set_handlers('PerlCleanupHandler' => [\&notifysubscribed,@{$handlers}]);
                   7470:                                     $registered_cleanup=1;
                   7471:                                 }
1.267     raeburn  7472:                                 $madethumb = 1;
1.16      raeburn  7473:                             } else {
                   7474:                                 print $logfile "\nUnable to write ".$copyfile.
                   7475:                                                ':'.$!."\n";
                   7476:                             }
                   7477:                         }
1.9       raeburn  7478:                     }
                   7479:                 }
                   7480:             }
                   7481:         } else {
                   7482:             $output = $versionresult;
                   7483:         }
                   7484:     }
1.267     raeburn  7485:     return ($output,$logourl,$madethumb);
1.9       raeburn  7486: }
                   7487: 
                   7488: sub logo_versioning {
                   7489:     my ($targetdir,$file,$logfile) = @_;
                   7490:     my $target = $targetdir.'/'.$file;
                   7491:     my ($maxversion,$fn,$extn,$output);
                   7492:     $maxversion = 0;
                   7493:     if ($file =~ /^(.+)\.(\w+)$/) {
                   7494:         $fn=$1;
                   7495:         $extn=$2;
                   7496:     }
                   7497:     opendir(DIR,$targetdir);
                   7498:     while (my $filename=readdir(DIR)) {
                   7499:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   7500:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   7501:         }
                   7502:     }
                   7503:     $maxversion++;
                   7504:     print $logfile "\nCreating old version ".$maxversion."\n";
                   7505:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   7506:     if (copy($target,$copyfile)) {
                   7507:         print $logfile "Copied old target to ".$copyfile."\n";
                   7508:         $copyfile=$copyfile.'.meta';
                   7509:         if (copy($target.'.meta',$copyfile)) {
                   7510:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   7511:             $output = 'ok';
                   7512:         } else {
                   7513:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   7514:             $output = &mt('Failed to copy old meta').", $!, ";
                   7515:         }
                   7516:     } else {
                   7517:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   7518:         $output = &mt('Failed to copy old target').", $!, ";
                   7519:     }
                   7520:     return $output;
                   7521: }
                   7522: 
                   7523: sub write_metadata {
                   7524:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   7525:     my (%metadatafields,%metadatakeys,$output);
                   7526:     $metadatafields{'title'}=$formname;
                   7527:     $metadatafields{'creationdate'}=time;
                   7528:     $metadatafields{'lastrevisiondate'}=time;
                   7529:     $metadatafields{'copyright'}='public';
                   7530:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   7531:                                          $env{'user.domain'};
                   7532:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   7533:     $metadatafields{'domain'}=$dom;
                   7534:     {
                   7535:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   7536:         my $mfh;
1.155     raeburn  7537:         if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184     raeburn  7538:             foreach (sort(keys(%metadatafields))) {
1.155     raeburn  7539:                 unless ($_=~/\./) {
                   7540:                     my $unikey=$_;
                   7541:                     $unikey=~/^([A-Za-z]+)/;
                   7542:                     my $tag=$1;
                   7543:                     $tag=~tr/A-Z/a-z/;
                   7544:                     print $mfh "\n\<$tag";
                   7545:                     foreach (split(/\,/,$metadatakeys{$unikey})) {
                   7546:                         my $value=$metadatafields{$unikey.'.'.$_};
                   7547:                         $value=~s/\"/\'\'/g;
                   7548:                         print $mfh ' '.$_.'="'.$value.'"';
                   7549:                     }
                   7550:                     print $mfh '>'.
                   7551:                         &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   7552:                             .'</'.$tag.'>';
                   7553:                 }
                   7554:             }
                   7555:             $output = 'ok';
                   7556:             print $logfile "\nWrote metadata";
                   7557:             close($mfh);
                   7558:         } else {
                   7559:             print $logfile "\nFailed to open metadata file";
1.9       raeburn  7560:             $output = &mt('Could not write metadata');
                   7561:         }
                   7562:     }
1.155     raeburn  7563:     return $output;
                   7564: }
                   7565: 
                   7566: sub notifysubscribed {
                   7567:     foreach my $targetsource (@{$modified_urls}){
                   7568:         next unless (ref($targetsource) eq 'ARRAY');
                   7569:         my ($target,$source)=@{$targetsource};
                   7570:         if ($source ne '') {
                   7571:             if (open(my $logfh,'>>'.$source.'.log')) {
                   7572:                 print $logfh "\nCleanup phase: Notifications\n";
                   7573:                 my @subscribed=&subscribed_hosts($target);
                   7574:                 foreach my $subhost (@subscribed) {
                   7575:                     print $logfh "\nNotifying host ".$subhost.':';
                   7576:                     my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
                   7577:                     print $logfh $reply;
                   7578:                 }
                   7579:                 my @subscribedmeta=&subscribed_hosts("$target.meta");
                   7580:                 foreach my $subhost (@subscribedmeta) {
                   7581:                     print $logfh "\nNotifying host for metadata only ".$subhost.':';
                   7582:                     my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
                   7583:                                                         $subhost);
                   7584:                     print $logfh $reply;
                   7585:                 }
                   7586:                 print $logfh "\n============ Done ============\n";
1.160     raeburn  7587:                 close($logfh);
1.155     raeburn  7588:             }
                   7589:         }
                   7590:     }
                   7591:     return OK;
                   7592: }
                   7593: 
                   7594: sub subscribed_hosts {
                   7595:     my ($target) = @_;
                   7596:     my @subscribed;
                   7597:     if (open(my $fh,"<$target.subscription")) {
                   7598:         while (my $subline=<$fh>) {
                   7599:             if ($subline =~ /^($match_lonid):/) {
                   7600:                 my $host = $1;
                   7601:                 if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
                   7602:                     unless (grep(/^\Q$host\E$/,@subscribed)) {
                   7603:                         push(@subscribed,$host);
                   7604:                     }
                   7605:                 }
                   7606:             }
                   7607:         }
                   7608:     }
                   7609:     return @subscribed;
1.9       raeburn  7610: }
                   7611: 
                   7612: sub check_switchserver {
                   7613:     my ($dom,$confname) = @_;
                   7614:     my ($allowed,$switchserver);
                   7615:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   7616:     if ($home eq 'no_host') {
                   7617:         $home = &Apache::lonnet::domain($dom,'primary');
                   7618:     }
                   7619:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 7620:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   7621:     if (!$allowed) {
1.180     raeburn  7622: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&amp;role=dc./'.$dom.'/&amp;destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9       raeburn  7623:     }
                   7624:     return $switchserver;
                   7625: }
                   7626: 
1.1       raeburn  7627: sub modify_quotas {
1.216     raeburn  7628:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101     raeburn  7629:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216     raeburn  7630:         %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235     raeburn  7631:         $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
                   7632:         $validationfieldsref);
1.86      raeburn  7633:     if ($action eq 'quotas') {
                   7634:         $context = 'tools'; 
1.163     raeburn  7635:     } else {
1.86      raeburn  7636:         $context = $action;
                   7637:     }
                   7638:     if ($context eq 'requestcourses') {
1.271     raeburn  7639:         @usertools = ('official','unofficial','community','textbook','placement');
1.106     raeburn  7640:         @options =('norequest','approval','validate','autolimit');
1.101     raeburn  7641:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
                   7642:         %titles = &courserequest_titles();
                   7643:         $toolregexp = join('|',@usertools);
                   7644:         %conditions = &courserequest_conditions();
1.216     raeburn  7645:         $confname = $dom.'-domainconfig';
                   7646:         my $servadm = $r->dir_config('lonAdmEMail');
                   7647:         ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235     raeburn  7648:         ($validationitemsref,$validationnamesref,$validationfieldsref) = 
                   7649:             &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163     raeburn  7650:     } elsif ($context eq 'requestauthor') {
                   7651:         @usertools = ('author');
                   7652:         %titles = &authorrequest_titles();
1.86      raeburn  7653:     } else {
1.162     raeburn  7654:         @usertools = ('aboutme','blog','webdav','portfolio');
1.101     raeburn  7655:         %titles = &tool_titles();
1.86      raeburn  7656:     }
1.212     raeburn  7657:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44      raeburn  7658:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  7659:     foreach my $key (keys(%env)) {
1.101     raeburn  7660:         if ($context eq 'requestcourses') {
                   7661:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
                   7662:                 my $item = $1;
                   7663:                 my $type = $2;
                   7664:                 if ($type =~ /^limit_(.+)/) {
                   7665:                     $limithash{$item}{$1} = $env{$key};
                   7666:                 } else {
                   7667:                     $confhash{$item}{$type} = $env{$key};
                   7668:                 }
                   7669:             }
1.163     raeburn  7670:         } elsif ($context eq 'requestauthor') {
                   7671:             if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
                   7672:                 $confhash{$1} = $env{$key};
                   7673:             }
1.101     raeburn  7674:         } else {
1.86      raeburn  7675:             if ($key =~ /^form\.quota_(.+)$/) {
                   7676:                 $confhash{'defaultquota'}{$1} = $env{$key};
1.197     raeburn  7677:             } elsif ($key =~ /^form\.authorquota_(.+)$/) {
                   7678:                 $confhash{'authorquota'}{$1} = $env{$key};
                   7679:             } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101     raeburn  7680:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
                   7681:             }
1.72      raeburn  7682:         }
                   7683:     }
1.163     raeburn  7684:     if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224     raeburn  7685:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102     raeburn  7686:         @approvalnotify = sort(@approvalnotify);
                   7687:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.271     raeburn  7688:         my @crstypes = ('official','unofficial','community','textbook','placement');
1.218     raeburn  7689:         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
                   7690:         foreach my $type (@hasuniquecode) {
                   7691:             if (grep(/^\Q$type\E$/,@crstypes)) {
                   7692:                 $confhash{'uniquecode'}{$type} = 1;
                   7693:             }
1.216     raeburn  7694:         }
1.242     raeburn  7695:         my (%newbook,%allpos);
1.216     raeburn  7696:         if ($context eq 'requestcourses') {
1.242     raeburn  7697:             foreach my $type ('textbooks','templates') {
                   7698:                 @{$allpos{$type}} = (); 
                   7699:                 my $invalid;
                   7700:                 if ($type eq 'textbooks') {
                   7701:                     $invalid = &mt('Invalid LON-CAPA course for textbook');
                   7702:                 } else {
                   7703:                     $invalid = &mt('Invalid LON-CAPA course for template');
                   7704:                 }
                   7705:                 if ($env{'form.'.$type.'_addbook'}) {
                   7706:                     if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
                   7707:                         ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
                   7708:                         if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
                   7709:                                                         $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
                   7710:                             $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
                   7711:                         } else {
                   7712:                             $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
                   7713:                             my $position = $env{'form.'.$type.'_addbook_pos'};
                   7714:                             $position =~ s/\D+//g;
                   7715:                             if ($position ne '') {
                   7716:                                 $allpos{$type}[$position] = $newbook{$type};
                   7717:                             }
1.216     raeburn  7718:                         }
1.242     raeburn  7719:                     } else {
                   7720:                         $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216     raeburn  7721:                     }
                   7722:                 }
1.242     raeburn  7723:             } 
1.216     raeburn  7724:         }
1.102     raeburn  7725:         if (ref($domconfig{$action}) eq 'HASH') {
                   7726:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
                   7727:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
                   7728:                     $changes{'notify'}{'approval'} = 1;
                   7729:                 }
                   7730:             } else {
1.144     raeburn  7731:                 if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  7732:                     $changes{'notify'}{'approval'} = 1;
                   7733:                 }
                   7734:             }
1.218     raeburn  7735:             if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
                   7736:                 if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   7737:                     foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
                   7738:                         unless ($confhash{'uniquecode'}{$crstype}) {
                   7739:                             $changes{'uniquecode'} = 1;
                   7740:                         }
                   7741:                     }
                   7742:                     unless ($changes{'uniquecode'}) {
                   7743:                         foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
                   7744:                             unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
                   7745:                                 $changes{'uniquecode'} = 1;
                   7746:                             }
                   7747:                         }
                   7748:                     }
                   7749:                } else {
                   7750:                    $changes{'uniquecode'} = 1;
                   7751:                }
                   7752:             } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
                   7753:                 $changes{'uniquecode'} = 1;
1.216     raeburn  7754:             }
                   7755:             if ($context eq 'requestcourses') {
1.242     raeburn  7756:                 foreach my $type ('textbooks','templates') {
                   7757:                     if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   7758:                         my %deletions;
                   7759:                         my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
                   7760:                         if (@todelete) {
                   7761:                             map { $deletions{$_} = 1; } @todelete;
                   7762:                         }
                   7763:                         my %imgdeletions;
                   7764:                         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
                   7765:                         if (@todeleteimages) {
                   7766:                             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   7767:                         }
                   7768:                         my $maxnum = $env{'form.'.$type.'_maxnum'};
                   7769:                         for (my $i=0; $i<=$maxnum; $i++) {
                   7770:                             my $itemid = $env{'form.'.$type.'_id_'.$i};
                   7771:                             my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/); 
                   7772:                             if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
                   7773:                                 if ($deletions{$key}) {
                   7774:                                     if ($domconfig{$action}{$type}{$key}{'image'}) {
                   7775:                                         #FIXME need to obsolete item in RES space
                   7776:                                     }
                   7777:                                     next;
                   7778:                                 } else {
                   7779:                                     my $newpos = $env{'form.'.$itemid};
                   7780:                                     $newpos =~ s/\D+//g;
1.243     raeburn  7781:                                     foreach my $item ('subject','title','publisher','author') {
                   7782:                                         next if ((($item eq 'author') || ($item eq 'publisher')) && 
                   7783:                                                  ($type eq 'templates'));
1.242     raeburn  7784:                                         $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
                   7785:                                         if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
                   7786:                                             $changes{$type}{$key} = 1;
                   7787:                                         }
                   7788:                                     }
                   7789:                                     $allpos{$type}[$newpos] = $key;
                   7790:                                 }
                   7791:                                 if ($imgdeletions{$key}) {
                   7792:                                     $changes{$type}{$key} = 1;
1.216     raeburn  7793:                                     #FIXME need to obsolete item in RES space
1.242     raeburn  7794:                                 } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
                   7795:                                     my ($cdom,$cnum) = split(/_/,$key);
                   7796:                                     my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
                   7797:                                                                                   $cdom,$cnum,$type,$configuserok,
                   7798:                                                                                   $switchserver,$author_ok);
                   7799:                                     if ($imgurl) {
                   7800:                                         $confhash{$type}{$key}{'image'} = $imgurl;
                   7801:                                         $changes{$type}{$key} = 1; 
1.216     raeburn  7802:                                     }
1.242     raeburn  7803:                                     if ($error) {
                   7804:                                         &Apache::lonnet::logthis($error);
                   7805:                                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7806:                                     } 
                   7807:                                 } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
                   7808:                                     $confhash{$type}{$key}{'image'} = 
                   7809:                                         $domconfig{$action}{$type}{$key}{'image'};
1.216     raeburn  7810:                                 }
                   7811:                             }
                   7812:                         }
                   7813:                     }
                   7814:                 }
                   7815:             }
1.102     raeburn  7816:         } else {
1.144     raeburn  7817:             if ($confhash{'notify'}{'approval'}) {
1.102     raeburn  7818:                 $changes{'notify'}{'approval'} = 1;
                   7819:             }
1.218     raeburn  7820:             if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216     raeburn  7821:                 $changes{'uniquecode'} = 1;
                   7822:             }
                   7823:         }
                   7824:         if ($context eq 'requestcourses') {
1.242     raeburn  7825:             foreach my $type ('textbooks','templates') {
                   7826:                 if ($newbook{$type}) {
                   7827:                     $changes{$type}{$newbook{$type}} = 1;
1.243     raeburn  7828:                     foreach my $item ('subject','title','publisher','author') {
                   7829:                         next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   7830:                                  ($type eq 'template'));
1.242     raeburn  7831:                         $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
                   7832:                         if ($env{'form.'.$type.'_addbook_'.$item}) {
                   7833:                             $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
                   7834:                         }
                   7835:                     }
                   7836:                     if ($type eq 'textbooks') {
                   7837:                         if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
                   7838:                             my ($cdom,$cnum) = split(/_/,$newbook{$type});
                   7839:                             my ($imageurl,$error) =
                   7840:                                 &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
                   7841:                                                         $configuserok,$switchserver,$author_ok);
                   7842:                             if ($imageurl) {
                   7843:                                 $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
                   7844:                             }
                   7845:                             if ($error) {
                   7846:                                 &Apache::lonnet::logthis($error);
                   7847:                                 $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   7848:                             }
                   7849:                         }
1.216     raeburn  7850:                     }
                   7851:                 }
1.242     raeburn  7852:                 if (@{$allpos{$type}} > 0) {
                   7853:                     my $idx = 0;
                   7854:                     foreach my $item (@{$allpos{$type}}) {
                   7855:                         if ($item ne '') {
                   7856:                             $confhash{$type}{$item}{'order'} = $idx;
                   7857:                             if (ref($domconfig{$action}) eq 'HASH') {
                   7858:                                 if (ref($domconfig{$action}{$type}) eq 'HASH') {
                   7859:                                     if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
                   7860:                                         if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
                   7861:                                             $changes{$type}{$item} = 1;
                   7862:                                         }
1.216     raeburn  7863:                                     }
                   7864:                                 }
                   7865:                             }
1.242     raeburn  7866:                             $idx ++;
1.216     raeburn  7867:                         }
                   7868:                     }
                   7869:                 }
                   7870:             }
1.235     raeburn  7871:             if (ref($validationitemsref) eq 'ARRAY') {
                   7872:                 foreach my $item (@{$validationitemsref}) {
                   7873:                     if ($item eq 'fields') {
                   7874:                         my @changed;
                   7875:                         @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
                   7876:                         if (@{$confhash{'validation'}{$item}} > 0) {
                   7877:                             @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
                   7878:                         }
1.266     raeburn  7879:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   7880:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   7881:                                 if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
                   7882:                                     @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
                   7883:                                                                                   $domconfig{'requestcourses'}{'validation'}{$item});
                   7884:                                 } else {
                   7885:                                     @changed = @{$confhash{'validation'}{$item}};
                   7886:                                 }
1.235     raeburn  7887:                             } else {
                   7888:                                 @changed = @{$confhash{'validation'}{$item}};
                   7889:                             }
                   7890:                         } else {
                   7891:                             @changed = @{$confhash{'validation'}{$item}};
                   7892:                         }
                   7893:                         if (@changed) {
                   7894:                             if ($confhash{'validation'}{$item}) {
                   7895:                                 $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
                   7896:                             } else {
                   7897:                                 $changes{'validation'}{$item} = &mt('None');
                   7898:                             }
                   7899:                         }
                   7900:                     } else {
                   7901:                         $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
                   7902:                         if ($item eq 'markup') {
                   7903:                             if ($env{'form.requestcourses_validation_'.$item}) {
                   7904:                                 $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   7905:                             }
                   7906:                         }
1.266     raeburn  7907:                         if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   7908:                             if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   7909:                                 if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
                   7910:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   7911:                                 }
                   7912:                             } else {
                   7913:                                 if ($confhash{'validation'}{$item} ne '') {
                   7914:                                     $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   7915:                                 }
1.235     raeburn  7916:                             }
                   7917:                         } else {
                   7918:                             if ($confhash{'validation'}{$item} ne '') {
                   7919:                                 $changes{'validation'}{$item} = $confhash{'validation'}{$item};
                   7920:                             }
                   7921:                         }
                   7922:                     }
                   7923:                 }
                   7924:             }
                   7925:             if ($env{'form.validationdc'}) {
                   7926:                 my $newval = $env{'form.validationdc'};
                   7927:                 my %domcoords = &get_active_dcs($dom);
                   7928:                 if (exists($domcoords{$newval})) {
                   7929:                     $confhash{'validation'}{'dc'} = $newval;
                   7930:                 }
                   7931:             }
                   7932:             if (ref($confhash{'validation'}) eq 'HASH') {
1.266     raeburn  7933:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   7934:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   7935:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   7936:                             unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   7937:                                 if ($confhash{'validation'}{'dc'} eq '') {
                   7938:                                     $changes{'validation'}{'dc'} = &mt('None');
                   7939:                                 } else {
                   7940:                                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   7941:                                 }
1.235     raeburn  7942:                             }
1.266     raeburn  7943:                         } elsif ($confhash{'validation'}{'dc'} ne '') {
                   7944:                             $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235     raeburn  7945:                         }
                   7946:                     } elsif ($confhash{'validation'}{'dc'} ne '') {
                   7947:                         $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
                   7948:                     }
                   7949:                 } elsif ($confhash{'validation'}{'dc'} ne '') {
                   7950:                     $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.266     raeburn  7951:                 }  
                   7952:             } else {
                   7953:                 if (ref($domconfig{'requestcourses'}) eq 'HASH') {
                   7954:                     if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
                   7955:                         if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
                   7956:                             $changes{'validation'}{'dc'} = &mt('None');
                   7957:                         }
                   7958:                     }
1.235     raeburn  7959:                 }
                   7960:             }
1.102     raeburn  7961:         }
                   7962:     } else {
1.86      raeburn  7963:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197     raeburn  7964:         $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86      raeburn  7965:     }
1.72      raeburn  7966:     foreach my $item (@usertools) {
                   7967:         foreach my $type (@{$types},'default','_LC_adv') {
1.104     raeburn  7968:             my $unset; 
1.101     raeburn  7969:             if ($context eq 'requestcourses') {
1.104     raeburn  7970:                 $unset = '0';
                   7971:                 if ($type eq '_LC_adv') {
                   7972:                     $unset = '';
                   7973:                 }
1.101     raeburn  7974:                 if ($confhash{$item}{$type} eq 'autolimit') {
                   7975:                     $confhash{$item}{$type} .= '=';
                   7976:                     unless ($limithash{$item}{$type} =~ /\D/) {
                   7977:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
                   7978:                     }
                   7979:                 }
1.163     raeburn  7980:             } elsif ($context eq 'requestauthor') {
                   7981:                 $unset = '0';
                   7982:                 if ($type eq '_LC_adv') {
                   7983:                     $unset = '';
                   7984:                 }
1.72      raeburn  7985:             } else {
1.101     raeburn  7986:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   7987:                     $confhash{$item}{$type} = 1;
                   7988:                 } else {
                   7989:                     $confhash{$item}{$type} = 0;
                   7990:                 }
1.72      raeburn  7991:             }
1.86      raeburn  7992:             if (ref($domconfig{$action}) eq 'HASH') {
1.163     raeburn  7993:                 if ($action eq 'requestauthor') {
                   7994:                     if ($domconfig{$action}{$type} ne $confhash{$type}) {
                   7995:                         $changes{$type} = 1;
                   7996:                     }
                   7997:                 } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86      raeburn  7998:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                   7999:                         $changes{$item}{$type} = 1;
                   8000:                     }
                   8001:                 } else {
                   8002:                     if ($context eq 'requestcourses') {
1.104     raeburn  8003:                         if ($confhash{$item}{$type} ne $unset) {
1.86      raeburn  8004:                             $changes{$item}{$type} = 1;
                   8005:                         }
                   8006:                     } else {
                   8007:                         if (!$confhash{$item}{$type}) {
                   8008:                             $changes{$item}{$type} = 1;
                   8009:                         }
                   8010:                     }
                   8011:                 }
                   8012:             } else {
                   8013:                 if ($context eq 'requestcourses') {
1.104     raeburn  8014:                     if ($confhash{$item}{$type} ne $unset) {
1.72      raeburn  8015:                         $changes{$item}{$type} = 1;
                   8016:                     }
1.163     raeburn  8017:                 } elsif ($context eq 'requestauthor') {
                   8018:                     if ($confhash{$type} ne $unset) {
                   8019:                         $changes{$type} = 1;
                   8020:                     }
1.72      raeburn  8021:                 } else {
                   8022:                     if (!$confhash{$item}{$type}) {
                   8023:                         $changes{$item}{$type} = 1;
                   8024:                     }
                   8025:                 }
                   8026:             }
1.1       raeburn  8027:         }
                   8028:     }
1.163     raeburn  8029:     unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86      raeburn  8030:         if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8031:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8032:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                   8033:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8034:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                   8035:                             $changes{'defaultquota'}{$key} = 1;
                   8036:                         }
                   8037:                     } else {
                   8038:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72      raeburn  8039:                     }
                   8040:                 }
1.86      raeburn  8041:             } else {
                   8042:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   8043:                     if (exists($confhash{'defaultquota'}{$key})) {
                   8044:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                   8045:                             $changes{'defaultquota'}{$key} = 1;
                   8046:                         }
                   8047:                     } else {
                   8048:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72      raeburn  8049:                     }
1.1       raeburn  8050:                 }
                   8051:             }
1.197     raeburn  8052:             if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8053:                 foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
                   8054:                     if (exists($confhash{'authorquota'}{$key})) {
                   8055:                         if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
                   8056:                             $changes{'authorquota'}{$key} = 1;
                   8057:                         }
                   8058:                     } else {
                   8059:                         $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
                   8060:                     }
                   8061:                 }
                   8062:             }
1.1       raeburn  8063:         }
1.86      raeburn  8064:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
                   8065:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   8066:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8067:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8068:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                   8069:                             $changes{'defaultquota'}{$key} = 1;
                   8070:                         }
                   8071:                     } else {
                   8072:                         if (!exists($domconfig{'quotas'}{$key})) {
                   8073:                             $changes{'defaultquota'}{$key} = 1;
                   8074:                         }
1.72      raeburn  8075:                     }
                   8076:                 } else {
1.86      raeburn  8077:                     $changes{'defaultquota'}{$key} = 1;
1.55      raeburn  8078:                 }
1.1       raeburn  8079:             }
                   8080:         }
1.197     raeburn  8081:         if (ref($confhash{'authorquota'}) eq 'HASH') {
                   8082:             foreach my $key (keys(%{$confhash{'authorquota'}})) {
                   8083:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
                   8084:                     if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
                   8085:                         if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
                   8086:                             $changes{'authorquota'}{$key} = 1;
                   8087:                         }
                   8088:                     } else {
                   8089:                         $changes{'authorquota'}{$key} = 1;
                   8090:                     }
                   8091:                 } else {
                   8092:                     $changes{'authorquota'}{$key} = 1;
                   8093:                 }
                   8094:             }
                   8095:         }
1.1       raeburn  8096:     }
1.72      raeburn  8097: 
1.163     raeburn  8098:     if ($context eq 'requestauthor') {
                   8099:         $domdefaults{'requestauthor'} = \%confhash;
                   8100:     } else {
                   8101:         foreach my $key (keys(%confhash)) {
1.242     raeburn  8102:             unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216     raeburn  8103:                 $domdefaults{$key} = $confhash{$key};
                   8104:             }
1.163     raeburn  8105:         }
1.72      raeburn  8106:     }
1.163     raeburn  8107: 
1.1       raeburn  8108:     my %quotahash = (
1.86      raeburn  8109:                       $action => { %confhash }
1.1       raeburn  8110:                     );
                   8111:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   8112:                                              $dom);
                   8113:     if ($putresult eq 'ok') {
                   8114:         if (keys(%changes) > 0) {
1.72      raeburn  8115:             my $cachetime = 24*60*60;
                   8116:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  8117:             if (ref($lastactref) eq 'HASH') {
                   8118:                 $lastactref->{'domdefaults'} = 1;
                   8119:             }
1.1       raeburn  8120:             $resulttext = &mt('Changes made:').'<ul>';
1.210     raeburn  8121:             unless (($context eq 'requestcourses') ||
1.163     raeburn  8122:                     ($context eq 'requestauthor')) {
1.86      raeburn  8123:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
                   8124:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                   8125:                     foreach my $type (@{$types},'default') {
                   8126:                         if (defined($changes{'defaultquota'}{$type})) {
                   8127:                             my $typetitle = $usertypes->{$type};
                   8128:                             if ($type eq 'default') {
                   8129:                                 $typetitle = $othertitle;
                   8130:                             }
1.213     raeburn  8131:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72      raeburn  8132:                         }
                   8133:                     }
1.86      raeburn  8134:                     $resulttext .= '</ul></li>';
1.72      raeburn  8135:                 }
1.197     raeburn  8136:                 if (ref($changes{'authorquota'}) eq 'HASH') {
1.223     bisitz   8137:                     $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197     raeburn  8138:                     foreach my $type (@{$types},'default') {
                   8139:                         if (defined($changes{'authorquota'}{$type})) {
                   8140:                             my $typetitle = $usertypes->{$type};
                   8141:                             if ($type eq 'default') {
                   8142:                                 $typetitle = $othertitle;
                   8143:                             }
1.213     raeburn  8144:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197     raeburn  8145:                         }
                   8146:                     }
                   8147:                     $resulttext .= '</ul></li>';
                   8148:                 }
1.72      raeburn  8149:             }
1.80      raeburn  8150:             my %newenv;
1.72      raeburn  8151:             foreach my $item (@usertools) {
1.163     raeburn  8152:                 my (%haschgs,%inconf);
                   8153:                 if ($context eq 'requestauthor') {
                   8154:                     %haschgs = %changes;
1.210     raeburn  8155:                     %inconf = %confhash;
1.163     raeburn  8156:                 } else {
                   8157:                     if (ref($changes{$item}) eq 'HASH') {
                   8158:                         %haschgs = %{$changes{$item}};
                   8159:                     }
                   8160:                     if (ref($confhash{$item}) eq 'HASH') {
                   8161:                         %inconf = %{$confhash{$item}};
                   8162:                     }
                   8163:                 }
                   8164:                 if (keys(%haschgs) > 0) {
1.80      raeburn  8165:                     my $newacc = 
                   8166:                         &Apache::lonnet::usertools_access($env{'user.name'},
                   8167:                                                           $env{'user.domain'},
1.86      raeburn  8168:                                                           $item,'reload',$context);
1.210     raeburn  8169:                     if (($context eq 'requestcourses') ||
1.163     raeburn  8170:                         ($context eq 'requestauthor')) {
1.108     raeburn  8171:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
                   8172:                             $newenv{'environment.canrequest.'.$item} = $newacc;
1.86      raeburn  8173:                         }
                   8174:                     } else {
                   8175:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                   8176:                             $newenv{'environment.availabletools.'.$item} = $newacc;
                   8177:                         }
1.80      raeburn  8178:                     }
1.163     raeburn  8179:                     unless ($context eq 'requestauthor') {
                   8180:                         $resulttext .= '<li>'.$titles{$item}.'<ul>';
                   8181:                     }
1.72      raeburn  8182:                     foreach my $type (@{$types},'default','_LC_adv') {
1.163     raeburn  8183:                         if ($haschgs{$type}) {
1.72      raeburn  8184:                             my $typetitle = $usertypes->{$type};
                   8185:                             if ($type eq 'default') {
                   8186:                                 $typetitle = $othertitle;
                   8187:                             } elsif ($type eq '_LC_adv') {
                   8188:                                 $typetitle = 'LON-CAPA Advanced Users'; 
                   8189:                             }
1.163     raeburn  8190:                             if ($inconf{$type}) {
1.101     raeburn  8191:                                 if ($context eq 'requestcourses') {
                   8192:                                     my $cond;
1.163     raeburn  8193:                                     if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101     raeburn  8194:                                         if ($1 eq '') {
                   8195:                                             $cond = &mt('(Automatic processing of any request).');
                   8196:                                         } else {
                   8197:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
                   8198:                                         }
                   8199:                                     } else { 
1.163     raeburn  8200:                                         $cond = $conditions{$inconf{$type}};
1.101     raeburn  8201:                                     }
                   8202:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172     raeburn  8203:                                 } elsif ($context eq 'requestauthor') {
                   8204:                                     $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
                   8205:                                                              $titles{$inconf{$type}},$typetitle);
                   8206: 
1.101     raeburn  8207:                                 } else {
                   8208:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                   8209:                                 }
1.72      raeburn  8210:                             } else {
1.104     raeburn  8211:                                 if ($type eq '_LC_adv') {
1.163     raeburn  8212:                                     if ($inconf{$type} eq '0') {
1.104     raeburn  8213:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8214:                                     } else { 
                   8215:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
                   8216:                                     }
                   8217:                                 } else {
                   8218:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                   8219:                                 }
1.72      raeburn  8220:                             }
                   8221:                         }
1.26      raeburn  8222:                     }
1.163     raeburn  8223:                     unless ($context eq 'requestauthor') {
                   8224:                         $resulttext .= '</ul></li>';
                   8225:                     }
1.26      raeburn  8226:                 }
1.1       raeburn  8227:             }
1.163     raeburn  8228:             if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102     raeburn  8229:                 if (ref($changes{'notify'}) eq 'HASH') {
                   8230:                     if ($changes{'notify'}{'approval'}) {
                   8231:                         if (ref($confhash{'notify'}) eq 'HASH') {
                   8232:                             if ($confhash{'notify'}{'approval'}) {
                   8233:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
                   8234:                             } else {
1.163     raeburn  8235:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102     raeburn  8236:                             }
                   8237:                         }
                   8238:                     }
                   8239:                 }
                   8240:             }
1.216     raeburn  8241:             if ($action eq 'requestcourses') {
                   8242:                 my @offon = ('off','on');
                   8243:                 if ($changes{'uniquecode'}) {
1.218     raeburn  8244:                     if (ref($confhash{'uniquecode'}) eq 'HASH') {
                   8245:                         my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
                   8246:                         $resulttext .= '<li>'.
                   8247:                                        &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
                   8248:                                        '</li>';
                   8249:                     } else {
                   8250:                         $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
                   8251:                                        '</li>';
                   8252:                     }
1.216     raeburn  8253:                 }
1.242     raeburn  8254:                 foreach my $type ('textbooks','templates') {
                   8255:                     if (ref($changes{$type}) eq 'HASH') {
                   8256:                         $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
                   8257:                         foreach my $key (sort(keys(%{$changes{$type}}))) {
                   8258:                             my %coursehash = &Apache::lonnet::coursedescription($key);
                   8259:                             my $coursetitle = $coursehash{'description'};
                   8260:                             my $position = $confhash{$type}{$key}{'order'} + 1;
                   8261:                             $resulttext .= '<li>';
1.243     raeburn  8262:                             foreach my $item ('subject','title','publisher','author') {
                   8263:                                 next if ((($item eq 'author') || ($item eq 'publisher')) &&
                   8264:                                          ($type eq 'templates'));
1.242     raeburn  8265:                                 my $name = $item.':';
                   8266:                                 $name =~ s/^(\w)/\U$1/;
                   8267:                                 $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
                   8268:                             }
                   8269:                             $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
                   8270:                             if ($type eq 'textbooks') {
                   8271:                                 if ($confhash{$type}{$key}{'image'}) {
                   8272:                                     $resulttext .= ' '.&mt('Image: [_1]',
                   8273:                                                    '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
                   8274:                                                    ' alt="Textbook cover" />').'<br />';
                   8275:                                 }
                   8276:                             }
                   8277:                             $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216     raeburn  8278:                         }
1.242     raeburn  8279:                         $resulttext .= '</ul></li>';
1.216     raeburn  8280:                     }
                   8281:                 }
1.235     raeburn  8282:                 if (ref($changes{'validation'}) eq 'HASH') {
                   8283:                     if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
                   8284:                         $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
                   8285:                         foreach my $item (@{$validationitemsref}) {
                   8286:                             if (exists($changes{'validation'}{$item})) {
                   8287:                                 if ($item eq 'markup') {
                   8288:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8289:                                                               '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
                   8290:                                 } else {
                   8291:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
                   8292:                                                               '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
                   8293:                                 }
                   8294:                             }
                   8295:                         }
                   8296:                         if (exists($changes{'validation'}{'dc'})) {
                   8297:                             $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
                   8298:                                                      '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
                   8299:                         }
                   8300:                     }
                   8301:                 }
1.216     raeburn  8302:             }
1.1       raeburn  8303:             $resulttext .= '</ul>';
1.80      raeburn  8304:             if (keys(%newenv)) {
                   8305:                 &Apache::lonnet::appenv(\%newenv);
                   8306:             }
1.1       raeburn  8307:         } else {
1.86      raeburn  8308:             if ($context eq 'requestcourses') {
                   8309:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163     raeburn  8310:             } elsif ($context eq 'requestauthor') {
                   8311:                 $resulttext = &mt('No changes made to rights to request author space.');
1.86      raeburn  8312:             } else {
1.90      weissno  8313:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86      raeburn  8314:             }
1.1       raeburn  8315:         }
                   8316:     } else {
1.11      albertel 8317:         $resulttext = '<span class="LC_error">'.
                   8318: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8319:     }
1.216     raeburn  8320:     if ($errors) {
                   8321:         $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
                   8322:                        '<ul>'.$errors.'</ul></p>';
                   8323:     }
1.3       raeburn  8324:     return $resulttext;
1.1       raeburn  8325: }
                   8326: 
1.216     raeburn  8327: sub process_textbook_image {
1.242     raeburn  8328:     my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216     raeburn  8329:     my $filename = $env{'form.'.$caller.'.filename'};
                   8330:     my ($error,$url);
                   8331:     my ($width,$height) = (50,50);
                   8332:     if ($configuserok eq 'ok') {
                   8333:         if ($switchserver) {
                   8334:             $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
                   8335:                          $switchserver);
                   8336:         } elsif ($author_ok eq 'ok') {
                   8337:             my ($result,$imageurl) =
                   8338:                 &publishlogo($r,'upload',$caller,$dom,$confname,
1.242     raeburn  8339:                              "$type/$dom/$cnum/cover",$width,$height);
1.216     raeburn  8340:             if ($result eq 'ok') {
                   8341:                 $url = $imageurl;
                   8342:             } else {
                   8343:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   8344:             }
                   8345:         } else {
                   8346:             $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);
                   8347:         }
                   8348:     } else {
                   8349:         $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);
                   8350:     }
                   8351:     return ($url,$error);
                   8352: }
                   8353: 
1.267     raeburn  8354: sub modify_ltitools {
                   8355:     my ($r,$dom,$action,$lastactref,%domconfig) = @_;
                   8356:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   8357:     my ($newid,@allpos,%changes,%confhash,$errors,$resulttext);
                   8358:     my $confname = $dom.'-domainconfig';
                   8359:     my $servadm = $r->dir_config('lonAdmEMail');
                   8360:     my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
                   8361:     my (%posslti,%possfield);
                   8362:     my @courseroles = ('cc','in','ta','ep','st');
                   8363:     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
                   8364:     map { $posslti{$_} = 1; } @ltiroles;
                   8365:     my @allfields = ('fullname','firstname','lastname','email','user','roles');
                   8366:     map { $possfield{$_} = 1; } @allfields;
                   8367:     my %lt = &ltitools_names(); 
                   8368:     if ($env{'form.ltitools_add'}) {
                   8369:         my $title = $env{'form.ltitools_add_title'};
                   8370:         $title =~ s/(`)/'/g;
                   8371:         ($newid,my $error) = &get_ltitools_id($dom,$title);
                   8372:         if ($newid) {
                   8373:             my $position = $env{'form.ltitools_add_pos'};
                   8374:             $position =~ s/\D+//g;
                   8375:             if ($position ne '') {
                   8376:                 $allpos[$position] = $newid;
                   8377:             }
                   8378:             $changes{$newid} = 1;
                   8379:             foreach my $item ('title','url','key','secret') {
                   8380:                 $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
                   8381:                 if ($env{'form.ltitools_add_'.$item}) {
                   8382:                     $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
                   8383:                 }
                   8384:             }
                   8385:             if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
                   8386:                 $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
                   8387:             }
                   8388:             if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
                   8389:                 $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
                   8390:             }
                   8391:             foreach my $item ('width','height') {
                   8392:                 $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
                   8393:                 $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
                   8394:                 if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
                   8395:                     $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
                   8396:                 }
                   8397:             }
                   8398:             if ($env{'form.ltitools_add_target'} eq 'window') {
                   8399:                 $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
                   8400:             } else {
                   8401:                 $confhash{$newid}{'display'}{'target'} = 'iframe';
                   8402:             }
                   8403:             foreach my $item ('passback','roster') {
                   8404:                 if ($env{'form.ltitools_add_'.$item}) {
                   8405:                     $confhash{$newid}{$item} = 1;
                   8406:                 }
                   8407:             }
                   8408:             if ($env{'form.ltitools_add_image.filename'} ne '') {
                   8409:                 my ($imageurl,$error) =
                   8410:                     &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$dom,
                   8411:                                             $configuserok,$switchserver,$author_ok);
                   8412:                 if ($imageurl) {
                   8413:                     $confhash{$newid}{'image'} = $imageurl;
                   8414:                 }
                   8415:                 if ($error) {
                   8416:                     &Apache::lonnet::logthis($error);
                   8417:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8418:                 }
                   8419:             }
                   8420:             my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
                   8421:             foreach my $field (@fields) {
                   8422:                 if ($possfield{$field}) {
                   8423:                     if ($field eq 'roles') {
                   8424:                         foreach my $role (@courseroles) {
                   8425:                             my $choice = $env{'form.ltitools_add_roles_'.$role};
                   8426:                             if (($choice ne '') && ($posslti{$choice})) {
                   8427:                                 $confhash{$newid}{'roles'}{$role} = $choice;
                   8428:                                 if ($role eq 'cc') {
                   8429:                                     $confhash{$newid}{'roles'}{'co'} = $choice; 
                   8430:                                 }
                   8431:                             }
                   8432:                         }
                   8433:                     } else {
                   8434:                         $confhash{$newid}{'fields'}{$field} = 1;
                   8435:                     }
                   8436:                 }
                   8437:             }
                   8438:             if ($env{'form.ltitools_add_custom'}) {
                   8439:                 my $name = $env{'form.ltitools_add_custom_name'};
                   8440:                 my $value = $env{'form.ltitools_add_custom_value'};
                   8441:                 $value =~ s/(`)/'/g;
                   8442:                 $name =~ s/(`)/'/g;
                   8443:                 $confhash{$newid}{'custom'}{$name} = $value;
                   8444:             }
                   8445:         } else {
                   8446:             my $error = &mt('Failed to acquire unique ID for new external tool');   
                   8447:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8448:         }
                   8449:     }
                   8450:     if (ref($domconfig{$action}) eq 'HASH') {
                   8451:         my %deletions;
                   8452:         my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
                   8453:         if (@todelete) {
                   8454:             map { $deletions{$_} = 1; } @todelete;
                   8455:         }
                   8456:         my %customadds;
                   8457:         my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
                   8458:         if (@newcustom) {
                   8459:             map { $customadds{$_} = 1; } @newcustom;
                   8460:         } 
                   8461:         my %imgdeletions;
                   8462:         my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
                   8463:         if (@todeleteimages) {
                   8464:             map { $imgdeletions{$_} = 1; } @todeleteimages;
                   8465:         }
                   8466:         my $maxnum = $env{'form.ltitools_maxnum'};
                   8467:         for (my $i=0; $i<=$maxnum; $i++) {
                   8468:             my $itemid = $env{'form.ltitools_id_'.$i};
                   8469:             if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   8470:                 if ($deletions{$itemid}) {
                   8471:                     if ($domconfig{$action}{$itemid}{'image'}) {
                   8472:                         #FIXME need to obsolete item in RES space
                   8473:                     }
                   8474:                     $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
                   8475:                     next;
                   8476:                 } else {
                   8477:                     my $newpos = $env{'form.ltitools_'.$itemid};
                   8478:                     $newpos =~ s/\D+//g;
                   8479:                     foreach my $item ('title','url','key','secret') {
                   8480:                         $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
                   8481:                         if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
                   8482:                             $changes{$itemid} = 1;
                   8483:                         }
                   8484:                     }
                   8485:                     if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
                   8486:                         $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
                   8487:                     }
                   8488:                     if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
                   8489:                         $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
                   8490:                     }
                   8491:                     foreach my $size ('width','height') {
                   8492:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
                   8493:                         $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
                   8494:                         if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
                   8495:                             $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
                   8496:                             if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   8497:                                 if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
                   8498:                                     $changes{$itemid} = 1;
                   8499:                                 }
                   8500:                             } else {
                   8501:                                 $changes{$itemid} = 1;
                   8502:                             }
                   8503:                         }
                   8504:                     }
                   8505:                     if ($env{'form.ltitools_target_'.$i} eq 'window') {
                   8506:                         $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
                   8507:                     } else {
                   8508:                         $confhash{$itemid}{'display'}{'target'} = 'iframe';
                   8509:                     }
                   8510:                     if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
                   8511:                         if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
                   8512:                             $changes{$itemid} = 1;
                   8513:                         }
                   8514:                     } else {
                   8515:                         $changes{$itemid} = 1;
                   8516:                     }
                   8517:                     foreach my $extra ('passback','roster') {
                   8518:                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                   8519:                             $confhash{$itemid}{$extra} = 1;
                   8520:                         }
                   8521:                         if ($domconfig{$action}{$itemid}{$extra} ne $confhash{$itemid}{$extra}) {
                   8522:                             $changes{$itemid} = 1;
                   8523:                         }
                   8524:                     }
                   8525:                     my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
                   8526:                     foreach my $field (@fields) {
                   8527:                         if ($possfield{$field}) {
                   8528:                             if ($field eq 'roles') {
                   8529:                                 foreach my $role (@courseroles) {
                   8530:                                     my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
                   8531:                                     if (($choice ne '') && ($posslti{$choice})) {
                   8532:                                         $confhash{$itemid}{'roles'}{$role} = $choice;
                   8533:                                         if ($role eq 'cc') {
                   8534:                                             $confhash{$itemid}{'roles'}{'co'} = $choice;
                   8535:                                         }
                   8536:                                     }
                   8537:                                     if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
                   8538:                                         if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
                   8539:                                             $changes{$itemid} = 1;
                   8540:                                         }
                   8541:                                     } elsif ($confhash{$itemid}{'roles'}{$role}) {
                   8542:                                         $changes{$itemid} = 1;
                   8543:                                     }
                   8544:                                 }
                   8545:                             } else {
                   8546:                                 $confhash{$itemid}{'fields'}{$field} = 1;
                   8547:                                 if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
                   8548:                                     if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
                   8549:                                         $changes{$itemid} = 1;
                   8550:                                     }
                   8551:                                 } else {
                   8552:                                     $changes{$itemid} = 1;
                   8553:                                 }
                   8554:                             }
                   8555:                         }
                   8556:                     }
                   8557:                     $allpos[$newpos] = $itemid;
                   8558:                 }
                   8559:                 if ($imgdeletions{$itemid}) {
                   8560:                     $changes{$itemid} = 1;
                   8561:                     #FIXME need to obsolete item in RES space
                   8562:                 } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
                   8563:                     my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
                   8564:                                                                  $itemid,$configuserok,$switchserver,
                   8565:                                                                  $author_ok);
                   8566:                     if ($imgurl) {
                   8567:                         $confhash{$itemid}{'image'} = $imgurl;
                   8568:                         $changes{$itemid} = 1;
                   8569:                     }
                   8570:                     if ($error) {
                   8571:                         &Apache::lonnet::logthis($error);
                   8572:                         $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   8573:                     }
                   8574:                 } elsif ($domconfig{$action}{$itemid}{'image'}) {
                   8575:                     $confhash{$itemid}{'image'} =
                   8576:                        $domconfig{$action}{$itemid}{'image'};
                   8577:                 }
                   8578:                 if ($customadds{$i}) {
                   8579:                     my $name = $env{'form.ltitools_custom_name_'.$i};
                   8580:                     $name =~ s/(`)/'/g;
                   8581:                     $name =~ s/^\s+//;
                   8582:                     $name =~ s/\s+$//;
                   8583:                     my $value = $env{'form.ltitools_custom_value_'.$i};
                   8584:                     $value =~ s/(`)/'/g;
                   8585:                     $value =~ s/^\s+//;
                   8586:                     $value =~ s/\s+$//;
                   8587:                     if ($name ne '') {
                   8588:                         $confhash{$itemid}{'custom'}{$name} = $value;
                   8589:                         $changes{$itemid} = 1;
                   8590:                     }
                   8591:                 }
                   8592:                 my %customdels;
                   8593:                 my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i); 
                   8594:                 if (@customdeletions) {
                   8595:                     $changes{$itemid} = 1;
                   8596:                 }
                   8597:                 map { $customdels{$_} = 1; } @customdeletions;
                   8598:                 if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
                   8599:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
                   8600:                         unless ($customdels{$key}) {
                   8601:                             if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
                   8602:                                 $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i}; 
                   8603:                             }
                   8604:                             if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
                   8605:                                 $changes{$itemid} = 1;
                   8606:                             }
                   8607:                         }
                   8608:                     }
                   8609:                 }
                   8610:                 unless ($changes{$itemid}) {
                   8611:                     foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
                   8612:                         if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
                   8613:                             if (ref($confhash{$itemid}{$key}) eq 'HASH') {
                   8614:                                 foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
                   8615:                                     unless (exists($confhash{$itemid}{$key}{$innerkey})) {
                   8616:                                         $changes{$itemid} = 1;
                   8617:                                         last;
                   8618:                                     }
                   8619:                                 }
                   8620:                             } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
                   8621:                                 $changes{$itemid} = 1;
                   8622:                             }
                   8623:                         }
                   8624:                         last if ($changes{$itemid});
                   8625:                     }
                   8626:                 }
                   8627:             }
                   8628:         }
                   8629:     }
                   8630:     if (@allpos > 0) {
                   8631:         my $idx = 0;
                   8632:         foreach my $itemid (@allpos) {
                   8633:             if ($itemid ne '') {
                   8634:                 $confhash{$itemid}{'order'} = $idx;
                   8635:                 if (ref($domconfig{$action}) eq 'HASH') {
                   8636:                     if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
                   8637:                         if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
                   8638:                             $changes{$itemid} = 1;
                   8639:                         }
                   8640:                     }
                   8641:                 }
                   8642:                 $idx ++;
                   8643:             }
                   8644:         }
                   8645:     }
                   8646:     my %ltitoolshash = (
                   8647:                           $action => { %confhash }
                   8648:                        );
                   8649:     my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
                   8650:                                              $dom);
                   8651:     if ($putresult eq 'ok') {
                   8652:         if (keys(%changes) > 0) {
                   8653:             my $cachetime = 24*60*60;
                   8654:             &Apache::lonnet::do_cache_new('ltitools',$dom,\%confhash,$cachetime);
                   8655:             if (ref($lastactref) eq 'HASH') {
                   8656:                 $lastactref->{'ltitools'} = 1;
                   8657:             }
                   8658:             $resulttext = &mt('Changes made:').'<ul>';
                   8659:             my %bynum;
                   8660:             foreach my $itemid (sort(keys(%changes))) {
                   8661:                 my $position = $confhash{$itemid}{'order'};
                   8662:                 $bynum{$position} = $itemid;
                   8663:             }
                   8664:             foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
                   8665:                 my $itemid = $bynum{$pos}; 
                   8666:                 if (ref($confhash{$itemid}) ne 'HASH') {
                   8667:                     $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
                   8668:                 } else {
                   8669:                     $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
                   8670:                     if ($confhash{$itemid}{'image'}) {
                   8671:                         $resulttext .= '&nbsp;'.
                   8672:                                        '<img src="'.$confhash{$itemid}{'image'}.'"'.
                   8673:                                        ' alt="'.&mt('Tool Provider icon').'" />';
                   8674:                     }
                   8675:                     $resulttext .= '</li><ul>';
                   8676:                     my $position = $pos + 1;
                   8677:                     $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
                   8678:                     foreach my $item ('version','msgtype','url','key') {
                   8679:                         if ($confhash{$itemid}{$item} ne '') {
                   8680:                             $resulttext .= '<li>'.$lt{$item}.':&nbsp;'.$confhash{$itemid}{$item}.'</li>';
                   8681:                         }
                   8682:                     }
                   8683:                     if ($confhash{$itemid}{'secret'} ne '') {
                   8684:                         $resulttext .= '<li>'.$lt{'secret'}.':&nbsp;';
                   8685:                         my $num = length($confhash{$itemid}{'secret'});
                   8686:                         $resulttext .= ('*'x$num).'</li>';
                   8687:                     }
                   8688:                     foreach my $item ('passback','roster') {
                   8689:                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';
                   8690:                         if ($confhash{$itemid}{$item}) {
                   8691:                             $resulttext .= &mt('Yes');
                   8692:                         } else {
                   8693:                             $resulttext .= &mt('No');
                   8694:                         }
                   8695:                         $resulttext .= '</li>';
                   8696:                     }
                   8697:                     if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
                   8698:                         my $displaylist;
                   8699:                         if ($confhash{$itemid}{'display'}{'target'}) {
                   8700:                             $displaylist = &mt('Display target').':&nbsp;'.
                   8701:                                            $confhash{$itemid}{'display'}{'target'}.',';
                   8702:                         }
                   8703:                         foreach my $size ('width','height') { 
                   8704:                             if ($confhash{$itemid}{'display'}{$size}) {
                   8705:                                 $displaylist .= ('&nbsp;'x2).$lt{$size}.':&nbsp;'.
                   8706:                                                 $confhash{$itemid}{'display'}{$size}.',';
                   8707:                             }
                   8708:                         }
                   8709:                         if ($displaylist) {
                   8710:                             $displaylist =~ s/,$//;
                   8711:                             $resulttext .= '<li>'.$displaylist.'</li>';
                   8712:                         }
                   8713:                     } 
                   8714:                     if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
                   8715:                         my $fieldlist;
                   8716:                         foreach my $field (@allfields) {
                   8717:                             if ($confhash{$itemid}{'fields'}{$field}) {
                   8718:                                 $fieldlist .= ('&nbsp;'x2).$lt{$field}.',';
                   8719:                             }
                   8720:                         }
                   8721:                         if ($fieldlist) {
                   8722:                             $fieldlist =~ s/,$//;
                   8723:                             $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
                   8724:                         }
                   8725:                     }
                   8726:                     if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
                   8727:                         my $rolemaps;
                   8728:                         foreach my $role (@courseroles) {
                   8729:                             if ($confhash{$itemid}{'roles'}{$role}) {
                   8730:                                 $rolemaps .= ('&nbsp;'x2).&Apache::lonnet::plaintext($role,'Course').'='.
                   8731:                                              $confhash{$itemid}{'roles'}{$role}.',';
                   8732:                             }
                   8733:                         }
                   8734:                         if ($rolemaps) {
                   8735:                             $rolemaps =~ s/,$//; 
                   8736:                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                   8737:                         }
                   8738:                     }
                   8739:                     if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
                   8740:                         my $customlist;
                   8741:                         if (keys(%{$confhash{$itemid}{'custom'}})) {
                   8742:                             foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
                   8743:                                 $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.('&nbsp;'x2);
                   8744:                             } 
                   8745:                         }
                   8746:                         if ($customlist) {
                   8747:                             $resulttext .= '<li>'.&mt('Custom items').':'.$customlist.'</li>';
                   8748:                         }
                   8749:                     } 
                   8750:                     $resulttext .= '</ul></li>';
                   8751:                 }
                   8752:             }
                   8753:             $resulttext .= '</ul>';
                   8754:         } else {
                   8755:             $resulttext = &mt('No changes made.');
                   8756:         }
                   8757:     } else {
                   8758:         $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
                   8759:     }
                   8760:     if ($errors) {
                   8761:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   8762:                        $errors.'</ul>';
                   8763:     }
                   8764:     return $resulttext;
                   8765: }
                   8766: 
                   8767: sub process_ltitools_image {
                   8768:     my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
                   8769:     my $filename = $env{'form.'.$caller.'.filename'};
                   8770:     my ($error,$url);
                   8771:     my ($width,$height) = (21,21);
                   8772:     if ($configuserok eq 'ok') {
                   8773:         if ($switchserver) {
                   8774:             $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
                   8775:                          $switchserver);
                   8776:         } elsif ($author_ok eq 'ok') {
                   8777:             my ($result,$imageurl,$madethumb) =
                   8778:                 &publishlogo($r,'upload',$caller,$dom,$confname,
                   8779:                              "ltitools/$itemid/icon",$width,$height);
                   8780:             if ($result eq 'ok') {
                   8781:                 if ($madethumb) {
                   8782:                     my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
                   8783:                     my $imagethumb = "$path/tn-".$imagefile;
                   8784:                     $url = $imagethumb;
                   8785:                 } else {
                   8786:                     $url = $imageurl;
                   8787:                 }
                   8788:             } else {
                   8789:                 $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
                   8790:             }
                   8791:         } else {
                   8792:             $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);
                   8793:         }
                   8794:     } else {
                   8795:         $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);
                   8796:     }
                   8797:     return ($url,$error);
                   8798: }
                   8799: 
                   8800: sub get_ltitools_id {
                   8801:     my ($cdom,$title) = @_;
                   8802:     # get lock on ltitools db
                   8803:     my $lockhash = {
                   8804:                       lock => $env{'user.name'}.
                   8805:                               ':'.$env{'user.domain'},
                   8806:                    };
                   8807:     my $tries = 0;
                   8808:     my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   8809:     my ($id,$error);
                   8810:  
                   8811:     while (($gotlock ne 'ok') && ($tries<10)) {
                   8812:         $tries ++;
                   8813:         sleep (0.1);
                   8814:         $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
                   8815:     }
                   8816:     if ($gotlock eq 'ok') {
                   8817:         my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
                   8818:         if ($currids{'lock'}) {
                   8819:             delete($currids{'lock'});
                   8820:             if (keys(%currids)) {
                   8821:                 my @curr = sort { $a <=> $b } keys(%currids);
                   8822:                 if ($curr[-1] =~ /^\d+$/) {
                   8823:                     $id = 1 + $curr[-1];
                   8824:                 }
                   8825:             } else {
                   8826:                 $id = 1;
                   8827:             }
                   8828:             if ($id) {
                   8829:                 unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
                   8830:                     $error = 'nostore';
                   8831:                 }
                   8832:             } else {
                   8833:                 $error = 'nonumber';
                   8834:             }
                   8835:         }
                   8836:         my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
                   8837:     } else {
                   8838:         $error = 'nolock';
                   8839:     }
                   8840:     return ($id,$error);
                   8841: }
                   8842: 
1.3       raeburn  8843: sub modify_autoenroll {
1.205     raeburn  8844:     my ($dom,$lastactref,%domconfig) = @_;
1.1       raeburn  8845:     my ($resulttext,%changes);
                   8846:     my %currautoenroll;
                   8847:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   8848:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   8849:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   8850:         }
                   8851:     }
                   8852:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   8853:     my %title = ( run => 'Auto-enrollment active',
1.129     raeburn  8854:                   sender => 'Sender for notification messages',
                   8855:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1       raeburn  8856:     my @offon = ('off','on');
1.17      raeburn  8857:     my $sender_uname = $env{'form.sender_uname'};
                   8858:     my $sender_domain = $env{'form.sender_domain'};
                   8859:     if ($sender_domain eq '') {
                   8860:         $sender_uname = '';
                   8861:     } elsif ($sender_uname eq '') {
                   8862:         $sender_domain = '';
                   8863:     }
1.129     raeburn  8864:     my $coowners = $env{'form.autoassign_coowners'};
1.1       raeburn  8865:     my %autoenrollhash =  (
1.129     raeburn  8866:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
                   8867:                                        'sender_uname' => $sender_uname,
                   8868:                                        'sender_domain' => $sender_domain,
                   8869:                                        'co-owners' => $coowners,
1.1       raeburn  8870:                                 }
                   8871:                      );
1.4       raeburn  8872:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   8873:                                              $dom);
1.1       raeburn  8874:     if ($putresult eq 'ok') {
                   8875:         if (exists($currautoenroll{'run'})) {
                   8876:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   8877:                  $changes{'run'} = 1;
                   8878:              }
                   8879:         } elsif ($autorun) {
                   8880:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  8881:                  $changes{'run'} = 1;
1.1       raeburn  8882:             }
                   8883:         }
1.17      raeburn  8884:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  8885:             $changes{'sender'} = 1;
                   8886:         }
1.17      raeburn  8887:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  8888:             $changes{'sender'} = 1;
                   8889:         }
1.129     raeburn  8890:         if ($currautoenroll{'co-owners'} ne '') {
                   8891:             if ($currautoenroll{'co-owners'} ne $coowners) {
                   8892:                 $changes{'coowners'} = 1;
                   8893:             }
                   8894:         } elsif ($coowners) {
                   8895:             $changes{'coowners'} = 1;
                   8896:         }      
1.1       raeburn  8897:         if (keys(%changes) > 0) {
                   8898:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  8899:             if ($changes{'run'}) {
1.1       raeburn  8900:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   8901:             }
                   8902:             if ($changes{'sender'}) {
1.17      raeburn  8903:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   8904:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   8905:                 } else {
                   8906:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   8907:                 }
1.1       raeburn  8908:             }
1.129     raeburn  8909:             if ($changes{'coowners'}) {
                   8910:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
                   8911:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  8912:                 if (ref($lastactref) eq 'HASH') {
                   8913:                     $lastactref->{'domainconfig'} = 1;
                   8914:                 }
1.129     raeburn  8915:             }
1.1       raeburn  8916:             $resulttext .= '</ul>';
                   8917:         } else {
                   8918:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   8919:         }
                   8920:     } else {
1.11      albertel 8921:         $resulttext = '<span class="LC_error">'.
                   8922: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  8923:     }
1.3       raeburn  8924:     return $resulttext;
1.1       raeburn  8925: }
                   8926: 
                   8927: sub modify_autoupdate {
1.3       raeburn  8928:     my ($dom,%domconfig) = @_;
1.1       raeburn  8929:     my ($resulttext,%currautoupdate,%fields,%changes);
                   8930:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   8931:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   8932:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   8933:         }
                   8934:     }
                   8935:     my @offon = ('off','on');
                   8936:     my %title = &Apache::lonlocal::texthash (
                   8937:                    run => 'Auto-update:',
                   8938:                    classlists => 'Updates to user information in classlists?'
                   8939:                 );
1.44      raeburn  8940:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1       raeburn  8941:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8942:                         id => 'Student/Employee ID',
1.20      raeburn  8943:                         permanentemail => 'E-mail address',
1.1       raeburn  8944:                         lastname => 'Last Name',
                   8945:                         firstname => 'First Name',
                   8946:                         middlename => 'Middle Name',
1.132     raeburn  8947:                         generation => 'Generation',
1.1       raeburn  8948:                       );
1.142     raeburn  8949:     $othertitle = &mt('All users');
1.1       raeburn  8950:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  8951:         $othertitle = &mt('Other users');
1.1       raeburn  8952:     }
                   8953:     foreach my $key (keys(%env)) {
                   8954:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132     raeburn  8955:             my ($usertype,$item) = ($1,$2);
                   8956:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
                   8957:                 if ($usertype eq 'default') {   
                   8958:                     push(@{$fields{$1}},$2);
                   8959:                 } elsif (ref($types) eq 'ARRAY') {
                   8960:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
                   8961:                         push(@{$fields{$1}},$2);
                   8962:                     }
                   8963:                 }
                   8964:             }
1.1       raeburn  8965:         }
                   8966:     }
1.131     raeburn  8967:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
                   8968:     @lockablenames = sort(@lockablenames);
                   8969:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
                   8970:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   8971:         if (@changed) {
                   8972:             $changes{'lockablenames'} = 1;
                   8973:         }
                   8974:     } else {
                   8975:         if (@lockablenames) {
                   8976:             $changes{'lockablenames'} = 1;
                   8977:         }
                   8978:     }
1.1       raeburn  8979:     my %updatehash = (
                   8980:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   8981:                                       classlists => $env{'form.classlists'},
                   8982:                                       fields => {%fields},
1.131     raeburn  8983:                                       lockablenames => \@lockablenames,
1.1       raeburn  8984:                                     }
                   8985:                      );
                   8986:     foreach my $key (keys(%currautoupdate)) {
                   8987:         if (($key eq 'run') || ($key eq 'classlists')) {
                   8988:             if (exists($updatehash{autoupdate}{$key})) {
                   8989:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   8990:                     $changes{$key} = 1;
                   8991:                 }
                   8992:             }
                   8993:         } elsif ($key eq 'fields') {
                   8994:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  8995:                 foreach my $item (@{$types},'default') {
1.1       raeburn  8996:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   8997:                         my $change = 0;
                   8998:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   8999:                             if (!exists($fields{$item})) {
                   9000:                                 $change = 1;
1.132     raeburn  9001:                                 last;
1.1       raeburn  9002:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  9003:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  9004:                                     $change = 1;
1.132     raeburn  9005:                                     last;
1.1       raeburn  9006:                                 }
                   9007:                             }
                   9008:                         }
                   9009:                         if ($change) {
                   9010:                             push(@{$changes{$key}},$item);
                   9011:                         }
1.26      raeburn  9012:                     } 
1.1       raeburn  9013:                 }
                   9014:             }
1.131     raeburn  9015:         } elsif ($key eq 'lockablenames') {
                   9016:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
                   9017:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
                   9018:                 if (@changed) {
                   9019:                     $changes{'lockablenames'} = 1;
                   9020:                 }
                   9021:             } else {
                   9022:                 if (@lockablenames) {
                   9023:                     $changes{'lockablenames'} = 1;
                   9024:                 }
                   9025:             }
                   9026:         }
                   9027:     }
                   9028:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
                   9029:         if (@lockablenames) {
                   9030:             $changes{'lockablenames'} = 1;
1.1       raeburn  9031:         }
                   9032:     }
1.26      raeburn  9033:     foreach my $item (@{$types},'default') {
                   9034:         if (defined($fields{$item})) {
                   9035:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132     raeburn  9036:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
                   9037:                     my $change = 0;
                   9038:                     if (ref($fields{$item}) eq 'ARRAY') {
                   9039:                         foreach my $type (@{$fields{$item}}) {
                   9040:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
                   9041:                                 $change = 1;
                   9042:                                 last;
                   9043:                             }
                   9044:                         }
                   9045:                     }
                   9046:                     if ($change) {
                   9047:                         push(@{$changes{'fields'}},$item);
                   9048:                     }
                   9049:                 } else {
1.26      raeburn  9050:                     push(@{$changes{'fields'}},$item);
                   9051:                 }
                   9052:             } else {
                   9053:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  9054:             }
                   9055:         }
                   9056:     }
                   9057:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   9058:                                              $dom);
                   9059:     if ($putresult eq 'ok') {
                   9060:         if (keys(%changes) > 0) {
                   9061:             $resulttext = &mt('Changes made:').'<ul>';
                   9062:             foreach my $key (sort(keys(%changes))) {
1.131     raeburn  9063:                 if ($key eq 'lockablenames') {
                   9064:                     $resulttext .= '<li>';
                   9065:                     if (@lockablenames) {
                   9066:                         $usertypes->{'default'} = $othertitle;
                   9067:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
                   9068:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
                   9069:                     } else {
                   9070:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
                   9071:                     }
                   9072:                     $resulttext .= '</li>';
                   9073:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1       raeburn  9074:                     foreach my $item (@{$changes{$key}}) {
                   9075:                         my @newvalues;
                   9076:                         foreach my $type (@{$fields{$item}}) {
                   9077:                             push(@newvalues,$fieldtitles{$type});
                   9078:                         }
1.3       raeburn  9079:                         my $newvaluestr;
                   9080:                         if (@newvalues > 0) {
                   9081:                             $newvaluestr = join(', ',@newvalues);
                   9082:                         } else {
                   9083:                             $newvaluestr = &mt('none');
1.6       raeburn  9084:                         }
1.1       raeburn  9085:                         if ($item eq 'default') {
1.26      raeburn  9086:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  9087:                         } else {
1.26      raeburn  9088:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  9089:                         }
                   9090:                     }
                   9091:                 } else {
                   9092:                     my $newvalue;
                   9093:                     if ($key eq 'run') {
                   9094:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   9095:                     } else {
                   9096:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  9097:                     }
1.1       raeburn  9098:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   9099:                 }
                   9100:             }
                   9101:             $resulttext .= '</ul>';
                   9102:         } else {
1.3       raeburn  9103:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  9104:         }
                   9105:     } else {
1.11      albertel 9106:         $resulttext = '<span class="LC_error">'.
                   9107: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  9108:     }
1.3       raeburn  9109:     return $resulttext;
1.1       raeburn  9110: }
                   9111: 
1.125     raeburn  9112: sub modify_autocreate {
                   9113:     my ($dom,%domconfig) = @_;
                   9114:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
                   9115:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
                   9116:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
                   9117:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
                   9118:         }
                   9119:     }
                   9120:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
                   9121:                  req => 'Auto-creation of validated requests for official courses',
                   9122:                  xmldc => 'Identity of course creator of courses from XML files',
                   9123:                );
                   9124:     my @types = ('xml','req');
                   9125:     foreach my $item (@types) {
                   9126:         $newvals{$item} = $env{'form.autocreate_'.$item};
                   9127:         $newvals{$item} =~ s/\D//g;
                   9128:         $newvals{$item} = 0 if ($newvals{$item} eq '');
                   9129:     }
                   9130:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
                   9131:     my %domcoords = &get_active_dcs($dom);
                   9132:     unless (exists($domcoords{$newvals{'xmldc'}})) {
                   9133:         $newvals{'xmldc'} = '';
                   9134:     } 
                   9135:     %autocreatehash =  (
                   9136:                         autocreate => { xml => $newvals{'xml'},
                   9137:                                         req => $newvals{'req'},
                   9138:                                       }
                   9139:                        );
                   9140:     if ($newvals{'xmldc'} ne '') {
                   9141:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
                   9142:     }
                   9143:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
                   9144:                                              $dom);
                   9145:     if ($putresult eq 'ok') {
                   9146:         my @items = @types;
                   9147:         if ($newvals{'xml'}) {
                   9148:             push(@items,'xmldc');
                   9149:         }
                   9150:         foreach my $item (@items) {
                   9151:             if (exists($currautocreate{$item})) {
                   9152:                 if ($currautocreate{$item} ne $newvals{$item}) {
                   9153:                     $changes{$item} = 1;
                   9154:                 }
                   9155:             } elsif ($newvals{$item}) {
                   9156:                 $changes{$item} = 1;
                   9157:             }
                   9158:         }
                   9159:         if (keys(%changes) > 0) {
                   9160:             my @offon = ('off','on'); 
                   9161:             $resulttext = &mt('Changes made:').'<ul>';
                   9162:             foreach my $item (@types) {
                   9163:                 if ($changes{$item}) {
                   9164:                     my $newtxt = $offon[$newvals{$item}];
1.178     raeburn  9165:                     $resulttext .= '<li>'.
                   9166:                                    &mt("$title{$item} set to [_1]$newtxt [_2]",
                   9167:                                        '<b>','</b>').
                   9168:                                    '</li>';
1.125     raeburn  9169:                 }
                   9170:             }
                   9171:             if ($changes{'xmldc'}) {
                   9172:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
                   9173:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178     raeburn  9174:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>'; 
1.125     raeburn  9175:             }
                   9176:             $resulttext .= '</ul>';
                   9177:         } else {
                   9178:             $resulttext = &mt('No changes made to auto-creation settings');
                   9179:         }
                   9180:     } else {
                   9181:         $resulttext = '<span class="LC_error">'.
                   9182:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9183:     }
                   9184:     return $resulttext;
                   9185: }
                   9186: 
1.23      raeburn  9187: sub modify_directorysrch {
                   9188:     my ($dom,%domconfig) = @_;
                   9189:     my ($resulttext,%changes);
                   9190:     my %currdirsrch;
                   9191:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   9192:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   9193:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   9194:         }
                   9195:     }
                   9196:     my %title = ( available => 'Directory search available',
1.24      raeburn  9197:                   localonly => 'Other domains can search',
1.23      raeburn  9198:                   searchby => 'Search types',
                   9199:                   searchtypes => 'Search latitude');
                   9200:     my @offon = ('off','on');
1.24      raeburn  9201:     my @otherdoms = ('Yes','No');
1.23      raeburn  9202: 
1.25      raeburn  9203:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  9204:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   9205:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   9206: 
1.44      raeburn  9207:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26      raeburn  9208:     if (keys(%{$usertypes}) == 0) {
                   9209:         @cansearch = ('default');
                   9210:     } else {
                   9211:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   9212:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   9213:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   9214:                     push(@{$changes{'cansearch'}},$type);
                   9215:                 }
1.23      raeburn  9216:             }
1.26      raeburn  9217:             foreach my $type (@cansearch) {
                   9218:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   9219:                     push(@{$changes{'cansearch'}},$type);
                   9220:                 }
1.23      raeburn  9221:             }
1.26      raeburn  9222:         } else {
                   9223:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  9224:         }
                   9225:     }
                   9226: 
                   9227:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   9228:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   9229:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   9230:                 push(@{$changes{'searchby'}},$by);
                   9231:             }
                   9232:         }
                   9233:         foreach my $by (@searchby) {
                   9234:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   9235:                 push(@{$changes{'searchby'}},$by);
                   9236:             }
                   9237:         }
                   9238:     } else {
                   9239:         push(@{$changes{'searchby'}},@searchby);
                   9240:     }
1.25      raeburn  9241: 
                   9242:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   9243:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   9244:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   9245:                 push(@{$changes{'searchtypes'}},$type);
                   9246:             }
                   9247:         }
                   9248:         foreach my $type (@searchtypes) {
                   9249:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   9250:                 push(@{$changes{'searchtypes'}},$type);
                   9251:             }
                   9252:         }
                   9253:     } else {
                   9254:         if (exists($currdirsrch{'searchtypes'})) {
                   9255:             foreach my $type (@searchtypes) {  
                   9256:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   9257:                     push(@{$changes{'searchtypes'}},$type);
                   9258:                 }
                   9259:             }
                   9260:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   9261:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   9262:             }   
                   9263:         } else {
                   9264:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   9265:         }
                   9266:     }
                   9267: 
1.23      raeburn  9268:     my %dirsrch_hash =  (
                   9269:             directorysrch => { available => $env{'form.dirsrch_available'},
                   9270:                                cansearch => \@cansearch,
1.24      raeburn  9271:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  9272:                                searchby => \@searchby,
1.25      raeburn  9273:                                searchtypes => \@searchtypes,
1.23      raeburn  9274:                              }
                   9275:             );
                   9276:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   9277:                                              $dom);
                   9278:     if ($putresult eq 'ok') {
                   9279:         if (exists($currdirsrch{'available'})) {
                   9280:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   9281:                  $changes{'available'} = 1;
                   9282:              }
                   9283:         } else {
                   9284:             if ($env{'form.dirsrch_available'} eq '1') {
                   9285:                 $changes{'available'} = 1;
                   9286:             }
                   9287:         }
1.24      raeburn  9288:         if (exists($currdirsrch{'localonly'})) {
                   9289:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   9290:                  $changes{'localonly'} = 1;
                   9291:              }
                   9292:         } else {
                   9293:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   9294:                 $changes{'localonly'} = 1;
                   9295:             }
                   9296:         }
1.23      raeburn  9297:         if (keys(%changes) > 0) {
                   9298:             $resulttext = &mt('Changes made:').'<ul>';
                   9299:             if ($changes{'available'}) {
                   9300:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   9301:             }
1.24      raeburn  9302:             if ($changes{'localonly'}) {
                   9303:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   9304:             }
                   9305: 
1.23      raeburn  9306:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   9307:                 my $chgtext;
1.26      raeburn  9308:                 if (ref($usertypes) eq 'HASH') {
                   9309:                     if (keys(%{$usertypes}) > 0) {
                   9310:                         foreach my $type (@{$types}) {
                   9311:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   9312:                                 $chgtext .= $usertypes->{$type}.'; ';
                   9313:                             }
                   9314:                         }
                   9315:                         if (grep(/^default$/,@cansearch)) {
                   9316:                             $chgtext .= $othertitle;
                   9317:                         } else {
                   9318:                             $chgtext =~ s/\; $//;
                   9319:                         }
1.210     raeburn  9320:                         $resulttext .=
1.178     raeburn  9321:                             '<li>'.
                   9322:                             &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
                   9323:                                 '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
                   9324:                             '</li>';
1.23      raeburn  9325:                     }
                   9326:                 }
                   9327:             }
                   9328:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   9329:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   9330:                 my $chgtext;
                   9331:                 foreach my $type (@{$titleorder}) {
                   9332:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   9333:                         if (defined($searchtitles->{$type})) {
                   9334:                             $chgtext .= $searchtitles->{$type}.'; ';
                   9335:                         }
                   9336:                     }
                   9337:                 }
                   9338:                 $chgtext =~ s/\; $//;
                   9339:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   9340:             }
1.25      raeburn  9341:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   9342:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   9343:                 my $chgtext;
                   9344:                 foreach my $type (@{$srchtypeorder}) {
                   9345:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   9346:                         if (defined($srchtypes_desc->{$type})) {
                   9347:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   9348:                         }
                   9349:                     }
                   9350:                 }
                   9351:                 $chgtext =~ s/\; $//;
1.178     raeburn  9352:                 $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23      raeburn  9353:             }
                   9354:             $resulttext .= '</ul>';
                   9355:         } else {
                   9356:             $resulttext = &mt('No changes made to institution directory search settings');
                   9357:         }
                   9358:     } else {
                   9359:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  9360:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   9361:     }
                   9362:     return $resulttext;
                   9363: }
                   9364: 
1.28      raeburn  9365: sub modify_contacts {
1.205     raeburn  9366:     my ($dom,$lastactref,%domconfig) = @_;
1.28      raeburn  9367:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   9368:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   9369:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   9370:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   9371:         }
                   9372:     }
1.134     raeburn  9373:     my (%others,%to,%bcc);
1.28      raeburn  9374:     my @contacts = ('supportemail','adminemail');
1.102     raeburn  9375:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203     raeburn  9376:                     'requestsmail','updatesmail','idconflictsmail');
                   9377:     my @toggles = ('reporterrors','reportupdates');
1.28      raeburn  9378:     foreach my $type (@mailings) {
                   9379:         @{$newsetting{$type}} = 
                   9380:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   9381:         foreach my $item (@contacts) {
                   9382:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   9383:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   9384:             } else {
                   9385:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   9386:             }
                   9387:         }  
                   9388:         $others{$type} = $env{'form.'.$type.'_others'};
                   9389:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134     raeburn  9390:         if ($type eq 'helpdeskmail') {
                   9391:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
                   9392:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
                   9393:         }
1.28      raeburn  9394:     }
                   9395:     foreach my $item (@contacts) {
                   9396:         $to{$item} = $env{'form.'.$item};
                   9397:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   9398:     }
1.203     raeburn  9399:     foreach my $item (@toggles) {
                   9400:         if ($env{'form.'.$item} =~ /^(0|1)$/) {
                   9401:             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
                   9402:         }
                   9403:     }
1.28      raeburn  9404:     if (keys(%currsetting) > 0) {
                   9405:         foreach my $item (@contacts) {
                   9406:             if ($to{$item} ne $currsetting{$item}) {
                   9407:                 $changes{$item} = 1;
                   9408:             }
                   9409:         }
                   9410:         foreach my $type (@mailings) {
                   9411:             foreach my $item (@contacts) {
                   9412:                 if (ref($currsetting{$type}) eq 'HASH') {
                   9413:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   9414:                         push(@{$changes{$type}},$item);
                   9415:                     }
                   9416:                 } else {
                   9417:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   9418:                 }
                   9419:             }
                   9420:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   9421:                 push(@{$changes{$type}},'others');
                   9422:             }
1.134     raeburn  9423:             if ($type eq 'helpdeskmail') {   
                   9424:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
                   9425:                     push(@{$changes{$type}},'bcc'); 
                   9426:                 }
                   9427:             }
1.28      raeburn  9428:         }
                   9429:     } else {
                   9430:         my %default;
                   9431:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   9432:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   9433:         $default{'errormail'} = 'adminemail';
                   9434:         $default{'packagesmail'} = 'adminemail';
                   9435:         $default{'helpdeskmail'} = 'supportemail';
1.89      raeburn  9436:         $default{'lonstatusmail'} = 'adminemail';
1.102     raeburn  9437:         $default{'requestsmail'} = 'adminemail';
1.190     raeburn  9438:         $default{'updatesmail'} = 'adminemail';
1.28      raeburn  9439:         foreach my $item (@contacts) {
                   9440:            if ($to{$item} ne $default{$item}) {
                   9441:               $changes{$item} = 1;
1.203     raeburn  9442:            }
1.28      raeburn  9443:         }
                   9444:         foreach my $type (@mailings) {
                   9445:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   9446:                
                   9447:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   9448:             }
                   9449:             if ($others{$type} ne '') {
                   9450:                 push(@{$changes{$type}},'others');
1.134     raeburn  9451:             }
                   9452:             if ($type eq 'helpdeskmail') {
                   9453:                 if ($bcc{$type} ne '') {
                   9454:                     push(@{$changes{$type}},'bcc');
                   9455:                 }
                   9456:             }
1.28      raeburn  9457:         }
                   9458:     }
1.203     raeburn  9459:     foreach my $item (@toggles) {
                   9460:         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
                   9461:             $changes{$item} = 1;
                   9462:         } elsif ((!$env{'form.'.$item}) &&
                   9463:                  (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
                   9464:             $changes{$item} = 1;
                   9465:         }
                   9466:     }
1.28      raeburn  9467:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   9468:                                              $dom);
                   9469:     if ($putresult eq 'ok') {
                   9470:         if (keys(%changes) > 0) {
1.205     raeburn  9471:             &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  9472:             if (ref($lastactref) eq 'HASH') {
                   9473:                 $lastactref->{'domainconfig'} = 1;
                   9474:             }
1.28      raeburn  9475:             my ($titles,$short_titles)  = &contact_titles();
                   9476:             $resulttext = &mt('Changes made:').'<ul>';
                   9477:             foreach my $item (@contacts) {
                   9478:                 if ($changes{$item}) {
                   9479:                     $resulttext .= '<li>'.$titles->{$item}.
                   9480:                                     &mt(' set to: ').
                   9481:                                     '<span class="LC_cusr_emph">'.
                   9482:                                     $to{$item}.'</span></li>';
                   9483:                 }
                   9484:             }
                   9485:             foreach my $type (@mailings) {
                   9486:                 if (ref($changes{$type}) eq 'ARRAY') {
                   9487:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   9488:                     my @text;
                   9489:                     foreach my $item (@{$newsetting{$type}}) {
                   9490:                         push(@text,$short_titles->{$item});
                   9491:                     }
                   9492:                     if ($others{$type} ne '') {
                   9493:                         push(@text,$others{$type});
                   9494:                     }
                   9495:                     $resulttext .= '<span class="LC_cusr_emph">'.
1.134     raeburn  9496:                                    join(', ',@text).'</span>';
                   9497:                     if ($type eq 'helpdeskmail') {
                   9498:                         if ($bcc{$type} ne '') {
                   9499:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
                   9500:                         }
                   9501:                     }
                   9502:                     $resulttext .= '</li>';
1.28      raeburn  9503:                 }
                   9504:             }
1.203     raeburn  9505:             my @offon = ('off','on');
                   9506:             if ($changes{'reporterrors'}) {
                   9507:                 $resulttext .= '<li>'.
                   9508:                                &mt('E-mail error reports to [_1] set to "'.
                   9509:                                    $offon[$env{'form.reporterrors'}].'".',
                   9510:                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   9511:                                        &mt('LON-CAPA core group - MSU'),600,500)).
                   9512:                                '</li>';
                   9513:             }
                   9514:             if ($changes{'reportupdates'}) {
                   9515:                 $resulttext .= '<li>'.
                   9516:                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                   9517:                                     $offon[$env{'form.reportupdates'}].'".',
                   9518:                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                   9519:                                         &mt('LON-CAPA core group - MSU'),600,500)).
                   9520:                                 '</li>';
                   9521:             }
1.28      raeburn  9522:             $resulttext .= '</ul>';
                   9523:         } else {
1.34      raeburn  9524:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  9525:         }
                   9526:     } else {
                   9527:         $resulttext = '<span class="LC_error">'.
                   9528:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   9529:     }
                   9530:     return $resulttext;
                   9531: }
                   9532: 
                   9533: sub modify_usercreation {
1.27      raeburn  9534:     my ($dom,%domconfig) = @_;
1.224     raeburn  9535:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43      raeburn  9536:     my $warningmsg;
1.27      raeburn  9537:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9538:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224     raeburn  9539:             if ($key eq 'cancreate') {
                   9540:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   9541:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   9542:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.269     raeburn  9543:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
                   9544:                             ($item eq 'recaptchaversion')) {
1.224     raeburn  9545:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9546:                         } else {
                   9547:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9548:                         }
                   9549:                     }
                   9550:                 }
                   9551:             } elsif ($key eq 'email_rule') {
                   9552:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   9553:             } else {
                   9554:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   9555:             }
1.27      raeburn  9556:         }
                   9557:     }
                   9558:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  9559:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224     raeburn  9560:     my @contexts = ('author','course','requestcrs');
1.34      raeburn  9561:     foreach my $item(@contexts) {
1.224     raeburn  9562:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93      raeburn  9563:     }
1.34      raeburn  9564:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   9565:         foreach my $item (@contexts) {
1.224     raeburn  9566:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   9567:                 push(@{$changes{'cancreate'}},$item);
1.50      raeburn  9568:             }
1.27      raeburn  9569:         }
1.34      raeburn  9570:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   9571:         foreach my $item (@contexts) {
1.43      raeburn  9572:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34      raeburn  9573:                 if ($cancreate{$item} ne 'any') {
                   9574:                     push(@{$changes{'cancreate'}},$item);
                   9575:                 }
                   9576:             } else {
                   9577:                 if ($cancreate{$item} ne 'none') {
                   9578:                     push(@{$changes{'cancreate'}},$item);
                   9579:                 }
1.27      raeburn  9580:             }
                   9581:         }
                   9582:     } else {
1.43      raeburn  9583:         foreach my $item (@contexts)  {
1.34      raeburn  9584:             push(@{$changes{'cancreate'}},$item);
                   9585:         }
1.27      raeburn  9586:     }
1.34      raeburn  9587: 
1.27      raeburn  9588:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   9589:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   9590:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   9591:                 push(@{$changes{'username_rule'}},$type);
                   9592:             }
                   9593:         }
                   9594:         foreach my $type (@username_rule) {
                   9595:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   9596:                 push(@{$changes{'username_rule'}},$type);
                   9597:             }
                   9598:         }
                   9599:     } else {
                   9600:         push(@{$changes{'username_rule'}},@username_rule);
                   9601:     }
                   9602: 
1.32      raeburn  9603:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   9604:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   9605:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   9606:                 push(@{$changes{'id_rule'}},$type);
                   9607:             }
                   9608:         }
                   9609:         foreach my $type (@id_rule) {
                   9610:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   9611:                 push(@{$changes{'id_rule'}},$type);
                   9612:             }
                   9613:         }
                   9614:     } else {
                   9615:         push(@{$changes{'id_rule'}},@id_rule);
                   9616:     }
                   9617: 
1.43      raeburn  9618:     my @authen_contexts = ('author','course','domain');
1.28      raeburn  9619:     my @authtypes = ('int','krb4','krb5','loc');
                   9620:     my %authhash;
1.43      raeburn  9621:     foreach my $item (@authen_contexts) {
1.28      raeburn  9622:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   9623:         foreach my $auth (@authtypes) {
                   9624:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   9625:                 $authhash{$item}{$auth} = 1;
                   9626:             } else {
                   9627:                 $authhash{$item}{$auth} = 0;
                   9628:             }
                   9629:         }
                   9630:     }
                   9631:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43      raeburn  9632:         foreach my $item (@authen_contexts) {
1.28      raeburn  9633:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   9634:                 foreach my $auth (@authtypes) {
                   9635:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   9636:                         push(@{$changes{'authtypes'}},$item);
                   9637:                         last;
                   9638:                     }
                   9639:                 }
                   9640:             }
                   9641:         }
                   9642:     } else {
1.43      raeburn  9643:         foreach my $item (@authen_contexts) {
1.28      raeburn  9644:             push(@{$changes{'authtypes'}},$item);
                   9645:         }
                   9646:     }
                   9647: 
1.224     raeburn  9648:     $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'}; 
                   9649:     $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
                   9650:     $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
                   9651:     $save_usercreate{'id_rule'} = \@id_rule;
                   9652:     $save_usercreate{'username_rule'} = \@username_rule,
                   9653:     $save_usercreate{'authtypes'} = \%authhash;
                   9654: 
1.27      raeburn  9655:     my %usercreation_hash =  (
1.224     raeburn  9656:         usercreation     => \%save_usercreate,
                   9657:     );
1.27      raeburn  9658: 
                   9659:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   9660:                                              $dom);
1.50      raeburn  9661: 
1.224     raeburn  9662:     if ($putresult eq 'ok') {
                   9663:         if (keys(%changes) > 0) {
                   9664:             $resulttext = &mt('Changes made:').'<ul>';
                   9665:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   9666:                 my %lt = &usercreation_types();
                   9667:                 foreach my $type (@{$changes{'cancreate'}}) {
                   9668:                     my $chgtext = $lt{$type}.', ';
                   9669:                     if ($cancreate{$type} eq 'none') {
                   9670:                         $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   9671:                     } elsif ($cancreate{$type} eq 'any') {
                   9672:                         $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
                   9673:                     } elsif ($cancreate{$type} eq 'official') {
                   9674:                         $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
                   9675:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   9676:                         $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
                   9677:                     }
                   9678:                     $resulttext .= '<li>'.$chgtext.'</li>';
                   9679:                 }
                   9680:             }
                   9681:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
                   9682:                 my ($rules,$ruleorder) = 
                   9683:                     &Apache::lonnet::inst_userrules($dom,'username');
                   9684:                 my $chgtext = '<ul>';
                   9685:                 foreach my $type (@username_rule) {
                   9686:                     if (ref($rules->{$type}) eq 'HASH') {
                   9687:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   9688:                     }
                   9689:                 }
                   9690:                 $chgtext .= '</ul>';
                   9691:                 if (@username_rule > 0) {
                   9692:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   9693:                 } else {
                   9694:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
                   9695:                 }
                   9696:             }
                   9697:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   9698:                 my ($idrules,$idruleorder) = 
                   9699:                     &Apache::lonnet::inst_userrules($dom,'id');
                   9700:                 my $chgtext = '<ul>';
                   9701:                 foreach my $type (@id_rule) {
                   9702:                     if (ref($idrules->{$type}) eq 'HASH') {
                   9703:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   9704:                     }
                   9705:                 }
                   9706:                 $chgtext .= '</ul>';
                   9707:                 if (@id_rule > 0) {
                   9708:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   9709:                 } else {
                   9710:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   9711:                 }
                   9712:             }
                   9713:             my %authname = &authtype_names();
                   9714:             my %context_title = &context_names();
                   9715:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   9716:                 my $chgtext = '<ul>';
                   9717:                 foreach my $type (@{$changes{'authtypes'}}) {
                   9718:                     my @allowed;
                   9719:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   9720:                     foreach my $auth (@authtypes) {
                   9721:                         if ($authhash{$type}{$auth}) {
                   9722:                             push(@allowed,$authname{$auth});
                   9723:                         }
                   9724:                     }
                   9725:                     if (@allowed > 0) {
                   9726:                         $chgtext .= join(', ',@allowed).'</li>';
                   9727:                     } else {
                   9728:                         $chgtext .= &mt('none').'</li>';
                   9729:                     }
                   9730:                 }
                   9731:                 $chgtext .= '</ul>';
                   9732:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   9733:                 $resulttext .= '</li>';
                   9734:             }
                   9735:             $resulttext .= '</ul>';
                   9736:         } else {
                   9737:             $resulttext = &mt('No changes made to user creation settings');
                   9738:         }
                   9739:     } else {
                   9740:         $resulttext = '<span class="LC_error">'.
                   9741:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   9742:     }
                   9743:     if ($warningmsg ne '') {
                   9744:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   9745:     }
                   9746:     return $resulttext;
                   9747: }
                   9748: 
                   9749: sub modify_selfcreation {
                   9750:     my ($dom,%domconfig) = @_;
                   9751:     my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%changes,%cancreate);
                   9752:     my (%save_usercreate,%save_usermodify);
1.228     raeburn  9753:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   9754:     if (ref($types) eq 'ARRAY') {
                   9755:         $usertypes->{'default'} = $othertitle;
                   9756:         push(@{$types},'default');
                   9757:     }
1.224     raeburn  9758: #
                   9759: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
                   9760: #
                   9761:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9762:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   9763:             if ($key eq 'cancreate') {
                   9764:                 if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
                   9765:                     foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
                   9766:                         if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
                   9767:                             ($item eq 'captcha') || ($item eq 'recaptchakeys') || 
1.269     raeburn  9768:                             ($item eq 'recaptchaversion') ||
1.236     raeburn  9769:                             ($item eq 'emailusername') || ($item eq 'notify') ||
1.240     raeburn  9770:                             ($item eq 'selfcreateprocessing') || ($item eq 'shibenv')) {
1.224     raeburn  9771:                             $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9772:                         } else {
                   9773:                             $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
                   9774:                         }
                   9775:                     }
                   9776:                 }
                   9777:             } elsif ($key eq 'email_rule') {
                   9778:                 $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   9779:             } else {
                   9780:                 $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
                   9781:             }
                   9782:         }
                   9783:     }
                   9784: #
                   9785: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
                   9786: #
                   9787:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   9788:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   9789:             if ($key eq 'selfcreate') {
                   9790:                 $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   9791:             } else {
                   9792:                 $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
                   9793:             }
                   9794:         }
                   9795:     }
                   9796: 
                   9797:     my @contexts = ('selfcreate');
                   9798:     @{$cancreate{'selfcreate'}} = ();
                   9799:     %{$cancreate{'emailusername'}} = ();
                   9800:     @{$cancreate{'statustocreate'}} = ();
1.236     raeburn  9801:     %{$cancreate{'selfcreateprocessing'}} = ();
1.240     raeburn  9802:     %{$cancreate{'shibenv'}} = ();
1.50      raeburn  9803:     my %selfcreatetypes = (
                   9804:                              sso   => 'users authenticated by institutional single sign on',
                   9805:                              login => 'users authenticated by institutional log-in',
1.236     raeburn  9806:                              email => 'users who provide a valid e-mail address for use as username',
1.50      raeburn  9807:                           );
1.224     raeburn  9808: #
                   9809: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
                   9810: # is permitted.
                   9811: #
1.236     raeburn  9812: 
                   9813:     my @statuses;
                   9814:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   9815:         if (ref($domconfig{'inststatus'}{'inststatusguest'}) eq 'ARRAY') {
                   9816:             @statuses = @{$domconfig{'inststatus'}{'inststatusguest'}};
                   9817:         }
                   9818:     }
                   9819:     push(@statuses,'default');
                   9820: 
1.228     raeburn  9821:     foreach my $item ('login','sso','email') {
1.224     raeburn  9822:         if ($item eq 'email') {
1.236     raeburn  9823:             if ($env{'form.cancreate_email'}) {
1.224     raeburn  9824:                 push(@{$cancreate{'selfcreate'}},'email');
1.236     raeburn  9825:                 push(@contexts,'selfcreateprocessing');
                   9826:                 foreach my $type (@statuses) {
                   9827:                     if ($type eq 'default') {
                   9828:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess'};
                   9829:                     } else { 
                   9830:                         $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
                   9831:                     }
                   9832:                 }
1.224     raeburn  9833:             }
                   9834:         } else {
                   9835:             if ($env{'form.cancreate_'.$item}) {
                   9836:                 push(@{$cancreate{'selfcreate'}},$item);
                   9837:             }
                   9838:         }
                   9839:     }
                   9840:     my (@email_rule,%userinfo,%savecaptcha);
                   9841:     my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
                   9842: #
1.228     raeburn  9843: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
                   9844: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224     raeburn  9845: #
1.236     raeburn  9846: 
1.244     raeburn  9847:     if ($env{'form.cancreate_email'}) {
1.228     raeburn  9848:         push(@contexts,'emailusername');
                   9849:         if (ref($types) eq 'ARRAY') {
                   9850:             foreach my $type (@{$types}) {
                   9851:                 if (ref($infofields) eq 'ARRAY') {
                   9852:                     foreach my $field (@{$infofields}) {
                   9853:                         if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
                   9854:                             $cancreate{'emailusername'}{$type}{$field} = $1;
                   9855:                         }
                   9856:                     }
1.224     raeburn  9857:                 }
                   9858:             }
                   9859:         }
                   9860: #
                   9861: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
                   9862: # queued requests for self-creation of account using e-mail address as username
                   9863: #
                   9864: 
                   9865:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
                   9866:         @approvalnotify = sort(@approvalnotify);
                   9867:         $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
                   9868:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   9869:             if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
                   9870:                 if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
                   9871:                     push(@{$changes{'cancreate'}},'notify');
                   9872:                 }
                   9873:             } else {
                   9874:                 if ($cancreate{'notify'}{'approval'}) {
                   9875:                     push(@{$changes{'cancreate'}},'notify');
                   9876:                 }
                   9877:             }
                   9878:         } elsif ($cancreate{'notify'}{'approval'}) {
                   9879:             push(@{$changes{'cancreate'}},'notify');
                   9880:         }
                   9881: 
                   9882: #
                   9883: # Retrieve rules (if any) governing types of e-mail address which may be used as a username
                   9884: #
                   9885:         @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
                   9886:         &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
                   9887:         if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
                   9888:             if (@{$curr_usercreation{'email_rule'}} > 0) {
                   9889:                 foreach my $type (@{$curr_usercreation{'email_rule'}}) {
                   9890:                     if (!grep(/^\Q$type\E$/,@email_rule)) {
                   9891:                         push(@{$changes{'email_rule'}},$type);
                   9892:                     }
                   9893:                 }
                   9894:             }
                   9895:             if (@email_rule > 0) {
                   9896:                 foreach my $type (@email_rule) {
                   9897:                     if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
                   9898:                         push(@{$changes{'email_rule'}},$type);
                   9899:                     }
                   9900:                 }
                   9901:             }
                   9902:         } elsif (@email_rule > 0) {
                   9903:             push(@{$changes{'email_rule'}},@email_rule);
                   9904:         }
                   9905:     }
                   9906: #  
1.236     raeburn  9907: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224     raeburn  9908: # institutional log-in.
                   9909: #
                   9910:     if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
                   9911:         my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   9912:         if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || 
                   9913:                ($domdefaults{'auth_def'} eq 'localauth'))) {
                   9914:             $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.').' '.
                   9915:                           &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.');
                   9916:         }
                   9917:     }
                   9918:     my @fields = ('lastname','firstname','middlename','generation',
                   9919:                   'permanentemail','id');
1.240     raeburn  9920:     my @shibfields = (@fields,'inststatus');
1.224     raeburn  9921:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   9922: #
                   9923: # Where usernames may created for institutional log-in and/or institutional single sign on:
                   9924: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
                   9925: # may self-create accounts 
                   9926: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
                   9927: # which the user may supply, if institutional data is unavailable.
                   9928: #
                   9929:     if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
                   9930:         if (ref($types) eq 'ARRAY') {
1.228     raeburn  9931:             if (@{$types} > 1) {
1.224     raeburn  9932:                 @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
                   9933:                 push(@contexts,'statustocreate');
                   9934:             } else {
                   9935:                 undef($cancreate{'statustocreate'});
                   9936:             } 
                   9937:             foreach my $type (@{$types}) {
                   9938:                 my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
                   9939:                 foreach my $field (@fields) {
                   9940:                     if (grep(/^\Q$field\E$/,@modifiable)) {
                   9941:                         $save_usermodify{'selfcreate'}{$type}{$field} = 1;
                   9942:                     } else {
                   9943:                         $save_usermodify{'selfcreate'}{$type}{$field} = 0;
                   9944:                     }
                   9945:                 }
                   9946:             }
                   9947:             if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
                   9948:                 foreach my $type (@{$types}) {
                   9949:                     if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
                   9950:                         foreach my $field (@fields) {
                   9951:                             if ($save_usermodify{'selfcreate'}{$type}{$field} ne
                   9952:                                 $curr_usermodify{'selfcreate'}{$type}{$field}) {
                   9953:                                 push(@{$changes{'selfcreate'}},$type);
                   9954:                                 last;
                   9955:                             }
                   9956:                         }
                   9957:                     }
                   9958:                 }
                   9959:             } else {
                   9960:                 foreach my $type (@{$types}) {
                   9961:                     push(@{$changes{'selfcreate'}},$type);
                   9962:                 }
                   9963:             }
                   9964:         }
1.240     raeburn  9965:         foreach my $field (@shibfields) {
                   9966:             if ($env{'form.shibenv_'.$field} ne '') {
                   9967:                 $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
                   9968:             }
                   9969:         }
                   9970:         if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   9971:             if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
                   9972:                 foreach my $field (@shibfields) {
                   9973:                     if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
                   9974:                         push(@{$changes{'cancreate'}},'shibenv');
                   9975:                     }
                   9976:                 }
                   9977:             } else {
                   9978:                 foreach my $field (@shibfields) {
                   9979:                     if ($env{'form.shibenv_'.$field}) {
                   9980:                         push(@{$changes{'cancreate'}},'shibenv');
                   9981:                         last;
                   9982:                     }
                   9983:                 }
                   9984:             }
                   9985:         }
1.224     raeburn  9986:     }
                   9987:     foreach my $item (@contexts) {
                   9988:         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                   9989:             foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                   9990:                 if (ref($cancreate{$item}) eq 'ARRAY') {
                   9991:                     if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                   9992:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   9993:                             push(@{$changes{'cancreate'}},$item);
                   9994:                         }
                   9995:                     }
                   9996:                 }
                   9997:             }
                   9998:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   9999:                 foreach my $type (@{$cancreate{$item}}) {
                   10000:                     if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                   10001:                         if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10002:                             push(@{$changes{'cancreate'}},$item);
                   10003:                         }
                   10004:                     }
                   10005:                 }
                   10006:             }
                   10007:         } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
                   10008:             if (ref($cancreate{$item}) eq 'HASH') {
                   10009:                 foreach my $curr (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
1.228     raeburn  10010:                     if (ref($curr_usercreation{'cancreate'}{$item}{$curr}) eq 'HASH') {
                   10011:                         foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$curr}})) {
                   10012:                             unless ($curr_usercreation{'cancreate'}{$item}{$curr}{$field} eq $cancreate{$item}{$curr}{$field}) {
                   10013:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10014:                                     push(@{$changes{'cancreate'}},$item);
                   10015:                                 }
                   10016:                             }
                   10017:                         }
1.236     raeburn  10018:                     } elsif ($item eq 'selfcreateprocessing') {
                   10019:                         if ($cancreate{$item}{$curr} ne $curr_usercreation{'cancreate'}{$item}{$curr}) {
                   10020:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10021:                                 push(@{$changes{'cancreate'}},$item);
                   10022:                             }
                   10023:                         }
1.228     raeburn  10024:                     } else {
                   10025:                         if (!$cancreate{$item}{$curr}) {
                   10026:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10027:                                 push(@{$changes{'cancreate'}},$item);
                   10028:                             }
1.224     raeburn  10029:                         }
                   10030:                     }
                   10031:                 }
                   10032:                 foreach my $field (keys(%{$cancreate{$item}})) {
1.228     raeburn  10033:                     if (ref($cancreate{$item}{$field}) eq 'HASH') {
                   10034:                         foreach my $inner (keys(%{$cancreate{$item}{$field}})) {
                   10035:                             if (ref($curr_usercreation{'cancreate'}{$item}{$field}) eq 'HASH') {
                   10036:                                 unless ($curr_usercreation{'cancreate'}{$item}{$field}{$inner} eq $cancreate{$item}{$field}{$inner}) {
                   10037:                                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10038:                                         push(@{$changes{'cancreate'}},$item);
                   10039:                                     }
                   10040:                                 }
                   10041:                             } else {
                   10042:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10043:                                     push(@{$changes{'cancreate'}},$item);
                   10044:                                 }
                   10045:                             }
                   10046:                         }
1.236     raeburn  10047:                     } elsif ($item eq 'selfcreateprocessing') {
                   10048:                         if ($cancreate{$item}{$field} ne $curr_usercreation{'cancreate'}{$item}{$field}) {
                   10049:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10050:                                 push(@{$changes{'cancreate'}},$item);
                   10051:                             }
                   10052:                         }
1.228     raeburn  10053:                     } else {
                   10054:                         if (!$curr_usercreation{'cancreate'}{$item}{$field}) {
                   10055:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10056:                                 push(@{$changes{'cancreate'}},$item);
                   10057:                             }
1.224     raeburn  10058:                         }
                   10059:                     }
                   10060:                 }
                   10061:             }
                   10062:         } elsif ($curr_usercreation{'cancreate'}{$item}) {
                   10063:             if (ref($cancreate{$item}) eq 'ARRAY') {
                   10064:                 if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
                   10065:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10066:                         push(@{$changes{'cancreate'}},$item);
                   10067:                     }
                   10068:                 }
                   10069:             } elsif (ref($cancreate{$item}) eq 'HASH') {
                   10070:                 if (!$cancreate{$item}{$curr_usercreation{'cancreate'}{$item}}) {
                   10071:                     if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10072:                         push(@{$changes{'cancreate'}},$item);
                   10073:                     }
                   10074:                 }
                   10075:             }
                   10076:         } elsif ($item eq 'emailusername') {
1.228     raeburn  10077:             if (ref($cancreate{$item}) eq 'HASH') {
                   10078:                 foreach my $type (keys(%{$cancreate{$item}})) {
                   10079:                     if (ref($cancreate{$item}{$type}) eq 'HASH') {
                   10080:                         foreach my $field (keys(%{$cancreate{$item}{$type}})) {
                   10081:                             if ($cancreate{$item}{$type}{$field}) {
                   10082:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                   10083:                                     push(@{$changes{'cancreate'}},$item);
                   10084:                                 }
                   10085:                                 last;
                   10086:                             }
                   10087:                         }
                   10088:                     }
                   10089:                 }
1.224     raeburn  10090:             }
                   10091:         }
                   10092:     }
                   10093: #
                   10094: # Populate %save_usercreate hash with updates to self-creation configuration.
                   10095: #
                   10096:     $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
                   10097:     $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269     raeburn  10098:     $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224     raeburn  10099:     $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
                   10100:     if (ref($cancreate{'notify'}) eq 'HASH') {
                   10101:         $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
                   10102:     }
1.236     raeburn  10103:     if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
                   10104:         $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
                   10105:     }
1.224     raeburn  10106:     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10107:         $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
                   10108:     }
1.240     raeburn  10109:     if (ref($cancreate{'shibenv'}) eq 'HASH') {
                   10110:         $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
                   10111:     }
1.224     raeburn  10112:     $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
                   10113:     $save_usercreate{'emailrule'} = \@email_rule;
                   10114: 
                   10115:     my %userconfig_hash = (
                   10116:             usercreation     => \%save_usercreate,
                   10117:             usermodification => \%save_usermodify,
                   10118:     );
                   10119:     my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
                   10120:                                              $dom);
                   10121: #
                   10122: # Accumulate details of changes to domain cofiguration for self-creation of usernames in $resulttext
                   10123: #
1.27      raeburn  10124:     if ($putresult eq 'ok') {
                   10125:         if (keys(%changes) > 0) {
                   10126:             $resulttext = &mt('Changes made:').'<ul>';
                   10127:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224     raeburn  10128:                 my %lt = &selfcreation_types();
1.34      raeburn  10129:                 foreach my $type (@{$changes{'cancreate'}}) {
1.100     raeburn  10130:                     my $chgtext;
1.45      raeburn  10131:                     if ($type eq 'selfcreate') {
1.50      raeburn  10132:                         if (@{$cancreate{$type}} == 0) {
1.224     raeburn  10133:                             $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50      raeburn  10134:                         } else {
1.224     raeburn  10135:                             $chgtext .= &mt('Self-creation of a new account is permitted for:').
                   10136:                                         '<ul>';
1.50      raeburn  10137:                             foreach my $case (@{$cancreate{$type}}) {
                   10138:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                   10139:                             }
                   10140:                             $chgtext .= '</ul>';
1.100     raeburn  10141:                             if (ref($cancreate{$type}) eq 'ARRAY') {
                   10142:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
                   10143:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
                   10144:                                         if (@{$cancreate{'statustocreate'}} == 0) {
1.224     raeburn  10145:                                             $chgtext .= '<br />'.
                   10146:                                                         '<span class="LC_warning">'.
                   10147:                                                         &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10148:                                                         '</span>';
1.100     raeburn  10149:                                         }
                   10150:                                     }
                   10151:                                 }
                   10152:                             }
1.43      raeburn  10153:                         }
1.240     raeburn  10154:                     } elsif ($type eq 'shibenv') {
                   10155:                         if (keys(%{$cancreate{$type}}) == 0) {
                   10156:                             $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information'); 
                   10157:                         } else {
                   10158:                             $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
                   10159:                                         '<ul>';
                   10160:                             foreach my $field (@shibfields) {
                   10161:                                 next if ($cancreate{$type}{$field} eq '');
                   10162:                                 if ($field eq 'inststatus') {
                   10163:                                     $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
                   10164:                                 } else {
                   10165:                                     $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
                   10166:                                 }
                   10167:                             }
                   10168:                             $chgtext .= '</ul>';
                   10169:                         }  
1.93      raeburn  10170:                     } elsif ($type eq 'statustocreate') {
1.96      raeburn  10171:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
                   10172:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
                   10173:                             if (@{$cancreate{'selfcreate'}} > 0) {
                   10174:                                 if (@{$cancreate{'statustocreate'}} == 0) {
1.100     raeburn  10175:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96      raeburn  10176:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  10177:                                         $chgtext .= '<br />'.
                   10178:                                                     '<span class="LC_warning">'.
                   10179:                                                     &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
                   10180:                                                     '</span>';
                   10181:                                     }
1.96      raeburn  10182:                                 } elsif (ref($usertypes) eq 'HASH') {
                   10183:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100     raeburn  10184:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
                   10185:                                     } else {
                   10186:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
                   10187:                                     }
                   10188:                                     $chgtext .= '<ul>';
                   10189:                                     foreach my $case (@{$cancreate{$type}}) {
                   10190:                                         if ($case eq 'default') {
                   10191:                                             $chgtext .= '<li>'.$othertitle.'</li>';
                   10192:                                         } else {
                   10193:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93      raeburn  10194:                                         }
                   10195:                                     }
1.100     raeburn  10196:                                     $chgtext .= '</ul>';
                   10197:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.224     raeburn  10198:                                         $chgtext .= '<br /><span class="LC_warning">'.
                   10199:                                                     &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
                   10200:                                                     '</span>';
1.100     raeburn  10201:                                     }
                   10202:                                 }
                   10203:                             } else {
                   10204:                                 if (@{$cancreate{$type}} == 0) {
                   10205:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
                   10206:                                 } else {
                   10207:                                     $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  10208:                                 }
                   10209:                             }
                   10210:                         }
1.236     raeburn  10211:                     } elsif ($type eq 'selfcreateprocessing') {
                   10212:                         my %choices = &Apache::lonlocal::texthash (
                   10213:                                                                     automatic => 'Automatic approval',
                   10214:                                                                     approval  => 'Queued for approval',
                   10215:                                                                   );
                   10216:                         if (@statuses > 1) {
                   10217:                             $chgtext .= &mt('Processing of requests to create account with e-mail address as username set as follows:'). 
                   10218:                                         '<ul>';
                   10219:                            foreach my $type (@statuses) {
                   10220:                                if ($type eq 'default') {
                   10221:                                    $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10222:                                } else {
                   10223:                                    $chgtext .= '<li>'.$usertypes->{$type}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$type}}.'</li>';
                   10224:                                }
                   10225:                            }
                   10226:                            $chgtext .= '</ul>';
                   10227:                         } else {
                   10228:                            $chgtext .= &mt('Processing of requests to create account with e-mail address as username set to: "[_1]"',
                   10229:                                          $choices{$cancreate{'selfcreateprocessing'}{'default'}});
                   10230:                         }
1.165     raeburn  10231:                     } elsif ($type eq 'captcha') {
1.224     raeburn  10232:                         if ($savecaptcha{$type} eq 'notused') {
1.165     raeburn  10233:                             $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
                   10234:                         } else {
                   10235:                             my %captchas = &captcha_phrases();
1.224     raeburn  10236:                             if ($captchas{$savecaptcha{$type}}) {
                   10237:                                 $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165     raeburn  10238:                             } else {
1.210     raeburn  10239:                                 $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165     raeburn  10240:                             }
                   10241:                         }
                   10242:                     } elsif ($type eq 'recaptchakeys') {
                   10243:                         my ($privkey,$pubkey);
1.224     raeburn  10244:                         if (ref($savecaptcha{$type}) eq 'HASH') {
                   10245:                             $pubkey = $savecaptcha{$type}{'public'};
                   10246:                             $privkey = $savecaptcha{$type}{'private'};
1.165     raeburn  10247:                         }
                   10248:                         $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
                   10249:                         if (!$pubkey) {
                   10250:                             $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
                   10251:                         } else {
                   10252:                             $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
                   10253:                         }
                   10254:                         if (!$privkey) {
                   10255:                             $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
                   10256:                         } else {
                   10257:                             $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
                   10258:                         }
                   10259:                         $chgtext .= '</ul>';
1.269     raeburn  10260:                     } elsif ($type eq 'recaptchaversion') {
                   10261:                         if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270     raeburn  10262:                             $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269     raeburn  10263:                         }
1.224     raeburn  10264:                     } elsif ($type eq 'emailusername') {
                   10265:                         if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.228     raeburn  10266:                             if (ref($types) eq 'ARRAY') {
                   10267:                                 foreach my $type (@{$types}) {
                   10268:                                     if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
                   10269:                                         if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.245     raeburn  10270:                                             $chgtext .= &mt('When self-creating account with e-mail as username, the following information will be provided by [_1]:',"'$usertypes->{$type}'").
1.228     raeburn  10271:                                                     '<ul>';
                   10272:                                             foreach my $field (@{$infofields}) {
                   10273:                                                 if ($cancreate{'emailusername'}{$type}{$field}) {
                   10274:                                                     $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
                   10275:                                                 }
                   10276:                                             }
1.245     raeburn  10277:                                             $chgtext .= '</ul>';
                   10278:                                         } else {
                   10279:                                             $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.228     raeburn  10280:                                         }
                   10281:                                     } else {
1.245     raeburn  10282:                                         $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.224     raeburn  10283:                                     }
                   10284:                                 }
                   10285:                             }
                   10286:                         }
                   10287:                     } elsif ($type eq 'notify') {
                   10288:                         $chgtext = &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
                   10289:                         if (ref($changes{'cancreate'}) eq 'ARRAY') {
                   10290:                             if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
                   10291:                                 if ($cancreate{'notify'}{'approval'}) {
                   10292:                                     $chgtext = &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
                   10293:                                 }
                   10294:                             }
1.43      raeburn  10295:                         }
1.34      raeburn  10296:                     }
1.224     raeburn  10297:                     if ($chgtext) {
                   10298:                         $resulttext .= '<li>'.$chgtext.'</li>';
1.32      raeburn  10299:                     }
                   10300:                 }
                   10301:             }
1.43      raeburn  10302:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
                   10303:                 my ($emailrules,$emailruleorder) =
                   10304:                     &Apache::lonnet::inst_userrules($dom,'email');
                   10305:                 my $chgtext = '<ul>';
                   10306:                 foreach my $type (@email_rule) {
                   10307:                     if (ref($emailrules->{$type}) eq 'HASH') {
                   10308:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
                   10309:                     }
                   10310:                 }
                   10311:                 $chgtext .= '</ul>';
                   10312:                 if (@email_rule > 0) {
1.224     raeburn  10313:                     $resulttext .= '<li>'.
                   10314:                                    &mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').
                   10315:                                        $chgtext.
                   10316:                                    '</li>';
1.43      raeburn  10317:                 } else {
1.224     raeburn  10318:                     $resulttext .= '<li>'.
                   10319:                                    &mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').
                   10320:                                    '</li>';
1.43      raeburn  10321:                 }
                   10322:             }
1.224     raeburn  10323:             if (ref($changes{'selfcreate'}) eq 'ARRAY') {
                   10324:                 $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
                   10325:                 my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10326:                 foreach my $type (@{$changes{'selfcreate'}}) {
                   10327:                     my $typename = $type;
                   10328:                     if (ref($usertypes) eq 'HASH') {
                   10329:                         if ($usertypes->{$type} ne '') {
                   10330:                             $typename = $usertypes->{$type};
                   10331:                         }
                   10332:                     }
                   10333:                     my @modifiable;
                   10334:                     $resulttext .= '<li>'.
                   10335:                                     &mt('Self-creation of account by users with status: [_1]',
                   10336:                                         '<span class="LC_cusr_emph">'.$typename.'</span>').
                   10337:                                     ' - '.&mt('modifiable fields (if institutional data blank): ');
                   10338:                     foreach my $field (@fields) {
                   10339:                         if ($save_usermodify{'selfcreate'}{$type}{$field}) {
                   10340:                             push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28      raeburn  10341:                         }
                   10342:                     }
1.224     raeburn  10343:                     if (@modifiable > 0) {
                   10344:                         $resulttext .= join(', ',@modifiable);
1.43      raeburn  10345:                     } else {
1.224     raeburn  10346:                         $resulttext .= &mt('none');
1.43      raeburn  10347:                     }
1.224     raeburn  10348:                     $resulttext .= '</li>';
1.28      raeburn  10349:                 }
1.224     raeburn  10350:                 $resulttext .= '</ul></li>';
1.28      raeburn  10351:             }
1.27      raeburn  10352:             $resulttext .= '</ul>';
                   10353:         } else {
1.224     raeburn  10354:             $resulttext = &mt('No changes made to self-creation settings');
1.27      raeburn  10355:         }
                   10356:     } else {
                   10357:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  10358:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10359:     }
1.43      raeburn  10360:     if ($warningmsg ne '') {
                   10361:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
                   10362:     }
1.23      raeburn  10363:     return $resulttext;
                   10364: }
                   10365: 
1.165     raeburn  10366: sub process_captcha {
                   10367:     my ($container,$changes,$newsettings,$current) = @_;
                   10368:     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
                   10369:     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
                   10370:     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
                   10371:         $newsettings->{'captcha'} = 'original';
                   10372:     }
                   10373:     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210     raeburn  10374:         if ($container eq 'cancreate') {
1.169     raeburn  10375:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10376:                 push(@{$changes->{'cancreate'}},'captcha');
                   10377:             } elsif (!defined($changes->{'cancreate'})) {
                   10378:                 $changes->{'cancreate'} = ['captcha'];
                   10379:             }
                   10380:         } else {
                   10381:             $changes->{'captcha'} = 1;
1.165     raeburn  10382:         }
                   10383:     }
1.269     raeburn  10384:     my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165     raeburn  10385:     if ($newsettings->{'captcha'} eq 'recaptcha') {
                   10386:         $newpub = $env{'form.'.$container.'_recaptchapub'};
                   10387:         $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250     raeburn  10388:         $newpub =~ s/[^\w\-]//g;
                   10389:         $newpriv =~ s/[^\w\-]//g;
1.169     raeburn  10390:         $newsettings->{'recaptchakeys'} = {
                   10391:                                              public  => $newpub,
                   10392:                                              private => $newpriv,
                   10393:                                           };
1.269     raeburn  10394:         $newversion = $env{'form.'.$container.'_recaptchaversion'};
                   10395:         $newversion =~ s/\D//g;
                   10396:         if ($newversion ne '2') {
                   10397:             $newversion = 1;
                   10398:         }
                   10399:         $newsettings->{'recaptchaversion'} = $newversion;
1.165     raeburn  10400:     }
                   10401:     if (ref($current->{'recaptchakeys'}) eq 'HASH') {
                   10402:         $currpub = $current->{'recaptchakeys'}{'public'};
                   10403:         $currpriv = $current->{'recaptchakeys'}{'private'};
1.179     raeburn  10404:         unless ($newsettings->{'captcha'} eq 'recaptcha') {
                   10405:             $newsettings->{'recaptchakeys'} = {
                   10406:                                                  public  => '',
                   10407:                                                  private => '',
                   10408:                                               }
                   10409:         }
1.165     raeburn  10410:     }
1.269     raeburn  10411:     if ($current->{'captcha'} eq 'recaptcha') {
                   10412:         $currversion = $current->{'recaptchaversion'};
                   10413:         if ($currversion ne '2') {
                   10414:             $currversion = 1;
                   10415:         }
                   10416:     }
                   10417:     if ($currversion ne $newversion) {
                   10418:         if ($container eq 'cancreate') {
                   10419:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10420:                 push(@{$changes->{'cancreate'}},'recaptchaversion');
                   10421:             } elsif (!defined($changes->{'cancreate'})) {
                   10422:                 $changes->{'cancreate'} = ['recaptchaversion'];
                   10423:             }
                   10424:         } else {
                   10425:             $changes->{'recaptchaversion'} = 1;
                   10426:         }
                   10427:     }
1.165     raeburn  10428:     if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169     raeburn  10429:         if ($container eq 'cancreate') {
                   10430:             if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                   10431:                 push(@{$changes->{'cancreate'}},'recaptchakeys');
                   10432:             } elsif (!defined($changes->{'cancreate'})) {
                   10433:                 $changes->{'cancreate'} = ['recaptchakeys'];
                   10434:             }
                   10435:         } else {
1.210     raeburn  10436:             $changes->{'recaptchakeys'} = 1;
1.165     raeburn  10437:         }
                   10438:     }
                   10439:     return;
                   10440: }
                   10441: 
1.33      raeburn  10442: sub modify_usermodification {
                   10443:     my ($dom,%domconfig) = @_;
1.224     raeburn  10444:     my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33      raeburn  10445:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   10446:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224     raeburn  10447:             if ($key eq 'selfcreate') {
                   10448:                 $modifyhash{$key} = $domconfig{'usermodification'}{$key};
                   10449:             } else {  
                   10450:                 $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   10451:             }
1.33      raeburn  10452:         }
                   10453:     }
1.224     raeburn  10454:     my @contexts = ('author','course');
1.33      raeburn  10455:     my %context_title = (
                   10456:                            author => 'In author context',
                   10457:                            course => 'In course context',
                   10458:                         );
                   10459:     my @fields = ('lastname','firstname','middlename','generation',
                   10460:                   'permanentemail','id');
                   10461:     my %roles = (
                   10462:                   author => ['ca','aa'],
                   10463:                   course => ['st','ep','ta','in','cr'],
                   10464:                 );
                   10465:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   10466:     foreach my $context (@contexts) {
                   10467:         foreach my $role (@{$roles{$context}}) {
                   10468:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   10469:             foreach my $item (@fields) {
                   10470:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   10471:                     $modifyhash{$context}{$role}{$item} = 1;
                   10472:                 } else {
                   10473:                     $modifyhash{$context}{$role}{$item} = 0;
                   10474:                 }
                   10475:             }
                   10476:         }
                   10477:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   10478:             foreach my $role (@{$roles{$context}}) {
                   10479:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   10480:                     foreach my $field (@fields) {
                   10481:                         if ($modifyhash{$context}{$role}{$field} ne 
                   10482:                                 $curr_usermodification{$context}{$role}{$field}) {
                   10483:                             push(@{$changes{$context}},$role);
                   10484:                             last;
                   10485:                         }
                   10486:                     }
                   10487:                 }
                   10488:             }
                   10489:         } else {
                   10490:             foreach my $context (@contexts) {
                   10491:                 foreach my $role (@{$roles{$context}}) {
                   10492:                     push(@{$changes{$context}},$role);
                   10493:                 }
                   10494:             }
                   10495:         }
                   10496:     }
                   10497:     my %usermodification_hash =  (
                   10498:                                    usermodification => \%modifyhash,
                   10499:                                  );
                   10500:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   10501:                                              \%usermodification_hash,$dom);
                   10502:     if ($putresult eq 'ok') {
                   10503:         if (keys(%changes) > 0) {
                   10504:             $resulttext = &mt('Changes made: ').'<ul>';
                   10505:             foreach my $context (@contexts) {
                   10506:                 if (ref($changes{$context}) eq 'ARRAY') {
                   10507:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   10508:                     if (ref($changes{$context}) eq 'ARRAY') {
                   10509:                         foreach my $role (@{$changes{$context}}) {
                   10510:                             my $rolename;
1.224     raeburn  10511:                             if ($role eq 'cr') {
                   10512:                                 $rolename = &mt('Custom');
1.33      raeburn  10513:                             } else {
1.224     raeburn  10514:                                 $rolename = &Apache::lonnet::plaintext($role);
1.33      raeburn  10515:                             }
                   10516:                             my @modifiable;
1.224     raeburn  10517:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33      raeburn  10518:                             foreach my $field (@fields) {
                   10519:                                 if ($modifyhash{$context}{$role}{$field}) {
                   10520:                                     push(@modifiable,$fieldtitles{$field});
                   10521:                                 }
                   10522:                             }
                   10523:                             if (@modifiable > 0) {
                   10524:                                 $resulttext .= join(', ',@modifiable);
                   10525:                             } else {
                   10526:                                 $resulttext .= &mt('none'); 
                   10527:                             }
                   10528:                             $resulttext .= '</li>';
                   10529:                         }
                   10530:                         $resulttext .= '</ul></li>';
                   10531:                     }
                   10532:                 }
                   10533:             }
                   10534:             $resulttext .= '</ul>';
                   10535:         } else {
                   10536:             $resulttext = &mt('No changes made to user modification settings');
                   10537:         }
                   10538:     } else {
                   10539:         $resulttext = '<span class="LC_error">'.
                   10540:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10541:     }
                   10542:     return $resulttext;
                   10543: }
                   10544: 
1.43      raeburn  10545: sub modify_defaults {
1.212     raeburn  10546:     my ($dom,$lastactref,%domconfig) = @_;
1.43      raeburn  10547:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212     raeburn  10548:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141     raeburn  10549:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43      raeburn  10550:     my @authtypes = ('internal','krb4','krb5','localauth');
                   10551:     foreach my $item (@items) {
                   10552:         $newvalues{$item} = $env{'form.'.$item};
                   10553:         if ($item eq 'auth_def') {
                   10554:             if ($newvalues{$item} ne '') {
                   10555:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
                   10556:                     push(@errors,$item);
                   10557:                 }
                   10558:             }
                   10559:         } elsif ($item eq 'lang_def') {
                   10560:             if ($newvalues{$item} ne '') {
                   10561:                 if ($newvalues{$item} =~ /^(\w+)/) {
                   10562:                     my $langcode = $1;
1.103     raeburn  10563:                     if ($langcode ne 'x_chef') {
                   10564:                         if (code2language($langcode) eq '') {
                   10565:                             push(@errors,$item);
                   10566:                         }
1.43      raeburn  10567:                     }
                   10568:                 } else {
                   10569:                     push(@errors,$item);
                   10570:                 }
                   10571:             }
1.54      raeburn  10572:         } elsif ($item eq 'timezone_def') {
                   10573:             if ($newvalues{$item} ne '') {
1.62      raeburn  10574:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54      raeburn  10575:                     push(@errors,$item);   
                   10576:                 }
                   10577:             }
1.68      raeburn  10578:         } elsif ($item eq 'datelocale_def') {
                   10579:             if ($newvalues{$item} ne '') {
                   10580:                 my @datelocale_ids = DateTime::Locale->ids();
                   10581:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                   10582:                     push(@errors,$item);
                   10583:                 }
                   10584:             }
1.141     raeburn  10585:         } elsif ($item eq 'portal_def') {
                   10586:             if ($newvalues{$item} ne '') {
                   10587:                 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])\/?$/) {
                   10588:                     push(@errors,$item);
                   10589:                 }
                   10590:             }
1.43      raeburn  10591:         }
                   10592:         if (grep(/^\Q$item\E$/,@errors)) {
                   10593:             $newvalues{$item} = $domdefaults{$item};
                   10594:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
                   10595:             $changes{$item} = 1;
                   10596:         }
1.72      raeburn  10597:         $domdefaults{$item} = $newvalues{$item};
1.43      raeburn  10598:     }
                   10599:     my %defaults_hash = (
1.72      raeburn  10600:                          defaults => \%newvalues,
                   10601:                         );
1.43      raeburn  10602:     my $title = &defaults_titles();
1.236     raeburn  10603: 
                   10604:     my $currinststatus;
                   10605:     if (ref($domconfig{'inststatus'}) eq 'HASH') {
                   10606:         $currinststatus = $domconfig{'inststatus'};
                   10607:     } else {
                   10608:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
                   10609:         $currinststatus = {
                   10610:                              inststatustypes => $usertypes,
                   10611:                              inststatusorder => $types,
                   10612:                              inststatusguest => [],
                   10613:                           };
                   10614:     }
                   10615:     my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
                   10616:     my @allpos;
                   10617:     my %guests;
                   10618:     my %alltypes;
                   10619:     my ($currtitles,$currguests,$currorder);
                   10620:     if (ref($currinststatus) eq 'HASH') {
                   10621:         if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
                   10622:             foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
                   10623:                 if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
                   10624:                     if ($currinststatus->{inststatustypes}->{$type} ne '') {
                   10625:                         $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
                   10626:                     }
                   10627:                 }
                   10628:                 unless (grep(/^\Q$type\E$/,@todelete)) { 
                   10629:                     my $position = $env{'form.inststatus_pos_'.$type};
                   10630:                     $position =~ s/\D+//g;
                   10631:                     $allpos[$position] = $type;
                   10632:                     $alltypes{$type} = $env{'form.inststatus_title_'.$type};
                   10633:                     $alltypes{$type} =~ s/`//g;
                   10634:                     if ($env{'form.inststatus_guest_'.$type}) {
                   10635:                         $guests{$type} = 1;
                   10636:                     }
                   10637:                 }
                   10638:             }
                   10639:             if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
                   10640:                 $currguests = join(',',@{$currinststatus->{'inststatusguest'}});
                   10641:             }
                   10642:             $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
                   10643:             $currtitles =~ s/,$//;
                   10644:         }
                   10645:     }
                   10646:     if ($env{'form.addinststatus'}) {
                   10647:         my $newtype = $env{'form.addinststatus'};
                   10648:         $newtype =~ s/\W//g;
                   10649:         unless (exists($alltypes{$newtype})) {
                   10650:             if ($env{'form.addinststatus_guest'}) {
                   10651:                 $guests{$newtype} = 1;
                   10652:             }
                   10653:             $alltypes{$newtype} = $env{'form.addinststatus_title'};
                   10654:             $alltypes{$newtype} =~ s/`//g; 
                   10655:             my $position = $env{'form.addinststatus_pos'};
                   10656:             $position =~ s/\D+//g;
                   10657:             if ($position ne '') {
                   10658:                 $allpos[$position] = $newtype;
                   10659:             }
                   10660:         }
                   10661:     }
                   10662:     my (@orderedstatus,@orderedguests);
                   10663:     foreach my $type (@allpos) {
                   10664:         unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
                   10665:             push(@orderedstatus,$type);
                   10666:             if ($guests{$type}) {
                   10667:                 push(@orderedguests,$type);
                   10668:             }
                   10669:         }
                   10670:     }
                   10671:     foreach my $type (keys(%alltypes)) {
                   10672:         unless (grep(/^\Q$type\E$/,@orderedstatus)) {
                   10673:             delete($alltypes{$type});
                   10674:         }
                   10675:     }
                   10676:     $defaults_hash{'inststatus'} = {
                   10677:                                      inststatustypes => \%alltypes,
                   10678:                                      inststatusorder => \@orderedstatus,
                   10679:                                      inststatusguest => \@orderedguests,
                   10680:                                    };
                   10681:     if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
                   10682:         foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
                   10683:             $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
                   10684:         }
                   10685:     }
                   10686:     if ($currorder ne join(',',@orderedstatus)) {
                   10687:         $changes{'inststatus'}{'inststatusorder'} = 1;
                   10688:     }
                   10689:     if ($currguests ne join(',',@orderedguests)) {
                   10690:         $changes{'inststatus'}{'inststatusguest'} = 1;
                   10691:     }
                   10692:     my $newtitles;
                   10693:     foreach my $item (@orderedstatus) {
                   10694:         $newtitles .= $alltypes{$item}.',';
                   10695:     }
                   10696:     $newtitles =~ s/,$//;
                   10697:     if ($currtitles ne $newtitles) {
                   10698:         $changes{'inststatus'}{'inststatustypes'} = 1;
                   10699:     }
1.43      raeburn  10700:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                   10701:                                              $dom);
                   10702:     if ($putresult eq 'ok') {
                   10703:         if (keys(%changes) > 0) {
                   10704:             $resulttext = &mt('Changes made:').'<ul>';
1.212     raeburn  10705:             my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43      raeburn  10706:             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";
                   10707:             foreach my $item (sort(keys(%changes))) {
1.236     raeburn  10708:                 if ($item eq 'inststatus') {
                   10709:                     if (ref($changes{'inststatus'}) eq 'HASH') {
                   10710:                         if (($changes{'inststatus'}{'inststatustypes'}) || $changes{'inststatus'}{'inststatusorder'}) {
                   10711:                             $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
                   10712:                             foreach my $type (@orderedstatus) { 
                   10713:                                 $resulttext .= $alltypes{$type}.', ';
                   10714:                             }
                   10715:                             $resulttext =~ s/, $//;
                   10716:                             $resulttext .= '</li>';
                   10717:                         }
                   10718:                         if ($changes{'inststatus'}{'inststatusguest'}) {
                   10719:                             $resulttext .= '<li>'; 
                   10720:                             if (@orderedguests) {
                   10721:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to:').' ';
                   10722:                                 foreach my $type (@orderedguests) {
                   10723:                                     $resulttext .= $alltypes{$type}.', ';
                   10724:                                 }
                   10725:                                 $resulttext =~ s/, $//;
                   10726:                             } else {
                   10727:                                 $resulttext .= &mt('Types assignable to "non-institutional" usernames set to none.');
                   10728:                             }
                   10729:                             $resulttext .= '</li>';
                   10730:                         }
                   10731:                     }
                   10732:                 } else {
                   10733:                     my $value = $env{'form.'.$item};
                   10734:                     if ($value eq '') {
                   10735:                         $value = &mt('none');
                   10736:                     } elsif ($item eq 'auth_def') {
                   10737:                         my %authnames = &authtype_names();
                   10738:                         my %shortauth = (
                   10739:                                           internal   => 'int',
                   10740:                                           krb4       => 'krb4',
                   10741:                                           krb5       => 'krb5',
                   10742:                                           localauth  => 'loc',
                   10743:                         );
                   10744:                         $value = $authnames{$shortauth{$value}};
                   10745:                     }
                   10746:                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                   10747:                     $mailmsgtext .= "$title->{$item} set to $value\n";  
1.43      raeburn  10748:                 }
                   10749:             }
                   10750:             $resulttext .= '</ul>';
                   10751:             $mailmsgtext .= "\n";
                   10752:             my $cachetime = 24*60*60;
1.72      raeburn  10753:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  10754:             if (ref($lastactref) eq 'HASH') {
                   10755:                 $lastactref->{'domdefaults'} = 1;
                   10756:             }
1.68      raeburn  10757:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203     raeburn  10758:                 my $notify = 1;
                   10759:                 if (ref($domconfig{'contacts'}) eq 'HASH') {
                   10760:                     if ($domconfig{'contacts'}{'reportupdates'} == 0) {
                   10761:                         $notify = 0;
                   10762:                     }
                   10763:                 }
                   10764:                 if ($notify) {
                   10765:                     &Apache::lonmsg::sendemail('installrecord@loncapa.org',
                   10766:                                                "LON-CAPA Domain Settings Change - $dom",
                   10767:                                                $mailmsgtext);
                   10768:                 }
1.54      raeburn  10769:             }
1.43      raeburn  10770:         } else {
1.54      raeburn  10771:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43      raeburn  10772:         }
                   10773:     } else {
                   10774:         $resulttext = '<span class="LC_error">'.
                   10775:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   10776:     }
                   10777:     if (@errors > 0) {
                   10778:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
                   10779:         foreach my $item (@errors) {
                   10780:             $resulttext .= ' "'.$title->{$item}.'",';
                   10781:         }
                   10782:         $resulttext =~ s/,$//;
                   10783:     }
                   10784:     return $resulttext;
                   10785: }
                   10786: 
1.46      raeburn  10787: sub modify_scantron {
1.205     raeburn  10788:     my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46      raeburn  10789:     my ($resulttext,%confhash,%changes,$errors);
                   10790:     my $custom = 'custom.tab';
                   10791:     my $default = 'default.tab';
                   10792:     my $servadm = $r->dir_config('lonAdmEMail');
                   10793:     my ($configuserok,$author_ok,$switchserver) = 
                   10794:         &config_check($dom,$confname,$servadm);
                   10795:     if ($env{'form.scantronformat.filename'} ne '') {
                   10796:         my $error;
                   10797:         if ($configuserok eq 'ok') {
                   10798:             if ($switchserver) {
1.130     raeburn  10799:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46      raeburn  10800:             } else {
                   10801:                 if ($author_ok eq 'ok') {
                   10802:                     my ($result,$scantronurl) =
                   10803:                         &publishlogo($r,'upload','scantronformat',$dom,
                   10804:                                      $confname,'scantron','','',$custom);
                   10805:                     if ($result eq 'ok') {
                   10806:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48      raeburn  10807:                         $changes{'scantronformat'} = 1;
1.46      raeburn  10808:                     } else {
                   10809:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
                   10810:                     }
                   10811:                 } else {
                   10812:                     $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);
                   10813:                 }
                   10814:             }
                   10815:         } else {
                   10816:             $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);
                   10817:         }
                   10818:         if ($error) {
                   10819:             &Apache::lonnet::logthis($error);
                   10820:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
                   10821:         }
                   10822:     }
1.48      raeburn  10823:     if (ref($domconfig{'scantron'}) eq 'HASH') {
                   10824:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
                   10825:             if ($env{'form.scantronformat_del'}) {
                   10826:                 $confhash{'scantron'}{'scantronformat'} = '';
                   10827:                 $changes{'scantronformat'} = 1;
1.46      raeburn  10828:             }
                   10829:         }
                   10830:     }
                   10831:     if (keys(%confhash) > 0) {
                   10832:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
                   10833:                                                  $dom);
                   10834:         if ($putresult eq 'ok') {
                   10835:             if (keys(%changes) > 0) {
1.48      raeburn  10836:                 if (ref($confhash{'scantron'}) eq 'HASH') {
                   10837:                     $resulttext = &mt('Changes made:').'<ul>';
                   10838:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130     raeburn  10839:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48      raeburn  10840:                     } else {
1.130     raeburn  10841:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46      raeburn  10842:                     }
1.48      raeburn  10843:                     $resulttext .= '</ul>';
                   10844:                 } else {
1.130     raeburn  10845:                     $resulttext = &mt('Changes made to bubblesheet format file.');
1.46      raeburn  10846:                 }
                   10847:                 $resulttext .= '</ul>';
                   10848:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212     raeburn  10849:                 if (ref($lastactref) eq 'HASH') {
                   10850:                     $lastactref->{'domainconfig'} = 1;
                   10851:                 }
1.46      raeburn  10852:             } else {
1.130     raeburn  10853:                 $resulttext = &mt('No changes made to bubblesheet format file');
1.46      raeburn  10854:             }
                   10855:         } else {
                   10856:             $resulttext = '<span class="LC_error">'.
                   10857:                 &mt('An error occurred: [_1]',$putresult).'</span>';
                   10858:         }
                   10859:     } else {
1.130     raeburn  10860:         $resulttext = &mt('No changes made to bubblesheet format file'); 
1.46      raeburn  10861:     }
                   10862:     if ($errors) {
                   10863:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   10864:                        $errors.'</ul>';
                   10865:     }
                   10866:     return $resulttext;
                   10867: }
                   10868: 
1.48      raeburn  10869: sub modify_coursecategories {
1.239     raeburn  10870:     my ($dom,$lastactref,%domconfig) = @_;
1.57      raeburn  10871:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
                   10872:         $cathash);
1.48      raeburn  10873:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238     raeburn  10874:     my @catitems = ('unauth','auth');
                   10875:     my @cattypes = ('std','domonly','codesrch','none');
1.55      raeburn  10876:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57      raeburn  10877:         $cathash = $domconfig{'coursecategories'}{'cats'};
                   10878:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
                   10879:             $changes{'togglecats'} = 1;
                   10880:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
                   10881:         }
                   10882:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
                   10883:             $changes{'categorize'} = 1;
                   10884:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
                   10885:         }
1.120     raeburn  10886:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
                   10887:             $changes{'togglecatscomm'} = 1;
                   10888:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
                   10889:         }
                   10890:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
                   10891:             $changes{'categorizecomm'} = 1;
                   10892:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272   ! raeburn  10893: 
        !          10894:         }
        !          10895:         if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
        !          10896:             $changes{'togglecatsplace'} = 1;
        !          10897:             $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
        !          10898:         }
        !          10899:         if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
        !          10900:             $changes{'categorizeplace'} = 1;
        !          10901:             $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120     raeburn  10902:         }
1.238     raeburn  10903:         foreach my $item (@catitems) {
                   10904:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   10905:                 if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
                   10906:                     $changes{$item} = 1;
                   10907:                     $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   10908:                 }
                   10909:             }
                   10910:         }
1.57      raeburn  10911:     } else {
                   10912:         $changes{'togglecats'} = 1;
                   10913:         $changes{'categorize'} = 1;
1.124     raeburn  10914:         $changes{'togglecatscomm'} = 1;
                   10915:         $changes{'categorizecomm'} = 1;
1.272   ! raeburn  10916:         $changes{'togglecatsplace'} = 1;
        !          10917:         $changes{'categorizeplace'} = 1;
1.87      raeburn  10918:         $domconfig{'coursecategories'} = {
                   10919:                                              togglecats => $env{'form.togglecats'},
                   10920:                                              categorize => $env{'form.categorize'},
1.124     raeburn  10921:                                              togglecatscomm => $env{'form.togglecatscomm'},
                   10922:                                              categorizecomm => $env{'form.categorizecomm'},
1.272   ! raeburn  10923:                                              togglecatsplace => $env{'form.togglecatsplace'},
        !          10924:                                              categorizeplace => $env{'form.categorizeplace'},
1.120     raeburn  10925:                                          };
1.238     raeburn  10926:         foreach my $item (@catitems) {
                   10927:             if ($env{'form.coursecat_'.$item} ne 'std') {
                   10928:                 $changes{$item} = 1;
                   10929:             }
                   10930:             if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
                   10931:                 $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
                   10932:             }
                   10933:         }
1.57      raeburn  10934:     }
                   10935:     if (ref($cathash) eq 'HASH') {
                   10936:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
1.55      raeburn  10937:             push (@deletecategory,'instcode::0');
                   10938:         }
1.120     raeburn  10939:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
                   10940:             push(@deletecategory,'communities::0');
                   10941:         }
1.272   ! raeburn  10942:         if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '')  && ($env{'form.placement'} == 0)) {
        !          10943:             push(@deletecategory,'placement::0');
        !          10944:         }
1.48      raeburn  10945:     }
1.57      raeburn  10946:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
                   10947:     if (ref($cathash) eq 'HASH') {
1.48      raeburn  10948:         if (@deletecategory > 0) {
                   10949:             #FIXME Need to remove category from all courses using a deleted category 
1.57      raeburn  10950:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48      raeburn  10951:             foreach my $item (@deletecategory) {
1.57      raeburn  10952:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                   10953:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48      raeburn  10954:                     $deletions{$item} = 1;
1.57      raeburn  10955:                     &recurse_cat_deletes($item,$cathash,\%deletions);
1.48      raeburn  10956:                 }
                   10957:             }
                   10958:         }
1.57      raeburn  10959:         foreach my $item (keys(%{$cathash})) {
1.48      raeburn  10960:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57      raeburn  10961:             if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48      raeburn  10962:                 $reorderings{$item} = 1;
1.57      raeburn  10963:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48      raeburn  10964:             }
                   10965:             if ($env{'form.addcategory_name_'.$item} ne '') {
                   10966:                 my $newcat = $env{'form.addcategory_name_'.$item};
                   10967:                 my $newdepth = $depth+1;
                   10968:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  10969:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48      raeburn  10970:                 $adds{$newitem} = 1; 
                   10971:             }
                   10972:             if ($env{'form.subcat_'.$item} ne '') {
                   10973:                 my $newcat = $env{'form.subcat_'.$item};
                   10974:                 my $newdepth = $depth+1;
                   10975:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57      raeburn  10976:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48      raeburn  10977:                 $adds{$newitem} = 1;
                   10978:             }
                   10979:         }
                   10980:     }
                   10981:     if ($env{'form.instcode'} eq '1') {
1.57      raeburn  10982:         if (ref($cathash) eq 'HASH') {
1.48      raeburn  10983:             my $newitem = 'instcode::0';
1.57      raeburn  10984:             if ($cathash->{$newitem} eq '') {  
                   10985:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  10986:                 $adds{$newitem} = 1;
                   10987:             }
                   10988:         } else {
                   10989:             my $newitem = 'instcode::0';
1.57      raeburn  10990:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48      raeburn  10991:             $adds{$newitem} = 1;
                   10992:         }
                   10993:     }
1.120     raeburn  10994:     if ($env{'form.communities'} eq '1') {
                   10995:         if (ref($cathash) eq 'HASH') {
                   10996:             my $newitem = 'communities::0';
                   10997:             if ($cathash->{$newitem} eq '') {
                   10998:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   10999:                 $adds{$newitem} = 1;
                   11000:             }
                   11001:         } else {
                   11002:             my $newitem = 'communities::0';
                   11003:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
                   11004:             $adds{$newitem} = 1;
                   11005:         }
                   11006:     }
1.272   ! raeburn  11007:     if ($env{'form.placement'} eq '1') {
        !          11008:         if (ref($cathash) eq 'HASH') {
        !          11009:             my $newitem = 'placement::0';
        !          11010:             if ($cathash->{$newitem} eq '') {
        !          11011:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
        !          11012:                 $adds{$newitem} = 1;
        !          11013:             }
        !          11014:         } else {
        !          11015:             my $newitem = 'placement::0';
        !          11016:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
        !          11017:             $adds{$newitem} = 1;
        !          11018:         }
        !          11019:     }
1.48      raeburn  11020:     if ($env{'form.addcategory_name'} ne '') {
1.120     raeburn  11021:         if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272   ! raeburn  11022:             ($env{'form.addcategory_name'} ne 'communities') &&
        !          11023:             ($env{'form.addcategory_name'} ne 'placement')) {
1.120     raeburn  11024:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
                   11025:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
                   11026:             $adds{$newitem} = 1;
                   11027:         }
1.48      raeburn  11028:     }
1.57      raeburn  11029:     my $putresult;
1.48      raeburn  11030:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11031:         if (keys(%deletions) > 0) {
                   11032:             foreach my $key (keys(%deletions)) {
                   11033:                 if ($predelallitems{$key} ne '') {
                   11034:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
                   11035:                 }
                   11036:             }
                   11037:         }
                   11038:         my (@chkcats,@chktrails,%chkallitems);
1.57      raeburn  11039:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48      raeburn  11040:         if (ref($chkcats[0]) eq 'ARRAY') {
                   11041:             my $depth = 0;
                   11042:             my $chg = 0;
                   11043:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
                   11044:                 my $name = $chkcats[0][$i];
                   11045:                 my $item;
                   11046:                 if ($name eq '') {
                   11047:                     $chg ++;
                   11048:                 } else {
                   11049:                     $item = &escape($name).'::0';
                   11050:                     if ($chg) {
1.57      raeburn  11051:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48      raeburn  11052:                     }
                   11053:                     $depth ++; 
1.57      raeburn  11054:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48      raeburn  11055:                     $depth --;
                   11056:                 }
                   11057:             }
                   11058:         }
1.57      raeburn  11059:     }
                   11060:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11061:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48      raeburn  11062:         if ($putresult eq 'ok') {
1.57      raeburn  11063:             my %title = (
1.120     raeburn  11064:                          togglecats     => 'Show/Hide a course in catalog',
                   11065:                          categorize     => 'Assign a category to a course',
                   11066:                          togglecatscomm => 'Show/Hide a community in catalog',
                   11067:                          categorizecomm => 'Assign a category to a community',
1.57      raeburn  11068:                         );
                   11069:             my %level = (
1.120     raeburn  11070:                          dom  => 'set in Domain ("Modify Course/Community")',
                   11071:                          crs  => 'set in Course ("Course Configuration")',
                   11072:                          comm => 'set in Community ("Community Configuration")',
1.238     raeburn  11073:                          none     => 'No catalog',
                   11074:                          std      => 'Standard catalog',
                   11075:                          domonly  => 'Domain-only catalog',
                   11076:                          codesrch => 'Code search form',
1.57      raeburn  11077:                         );
1.48      raeburn  11078:             $resulttext = &mt('Changes made:').'<ul>';
1.57      raeburn  11079:             if ($changes{'togglecats'}) {
                   11080:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                   11081:             }
                   11082:             if ($changes{'categorize'}) {
                   11083:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48      raeburn  11084:             }
1.120     raeburn  11085:             if ($changes{'togglecatscomm'}) {
                   11086:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
                   11087:             }
                   11088:             if ($changes{'categorizecomm'}) {
                   11089:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
                   11090:             }
1.238     raeburn  11091:             if ($changes{'unauth'}) {
                   11092:                 $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
                   11093:             }
                   11094:             if ($changes{'auth'}) {
                   11095:                 $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
                   11096:             }
1.57      raeburn  11097:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   11098:                 my $cathash;
                   11099:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                   11100:                     $cathash = $domconfig{'coursecategories'}{'cats'};
                   11101:                 } else {
                   11102:                     $cathash = {};
                   11103:                 } 
                   11104:                 my (@cats,@trails,%allitems);
                   11105:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   11106:                 if (keys(%deletions) > 0) {
                   11107:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                   11108:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                   11109:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                   11110:                     }
                   11111:                     $resulttext .= '</ul></li>';
                   11112:                 }
                   11113:                 if (keys(%reorderings) > 0) {
                   11114:                     my %sort_by_trail;
                   11115:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                   11116:                     foreach my $key (keys(%reorderings)) {
                   11117:                         if ($allitems{$key} ne '') {
                   11118:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11119:                         }
1.48      raeburn  11120:                     }
1.57      raeburn  11121:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11122:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
                   11123:                     }
                   11124:                     $resulttext .= '</ul></li>';
1.48      raeburn  11125:                 }
1.57      raeburn  11126:                 if (keys(%adds) > 0) {
                   11127:                     my %sort_by_trail;
                   11128:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                   11129:                     foreach my $key (keys(%adds)) {
                   11130:                         if ($allitems{$key} ne '') {
                   11131:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                   11132:                         }
                   11133:                     }
                   11134:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                   11135:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48      raeburn  11136:                     }
1.57      raeburn  11137:                     $resulttext .= '</ul></li>';
1.48      raeburn  11138:                 }
                   11139:             }
                   11140:             $resulttext .= '</ul>';
1.239     raeburn  11141:             if ($changes{'unauth'} || $changes{'auth'}) {
1.246     raeburn  11142:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   11143:                 if ($changes{'auth'}) {
                   11144:                     $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
                   11145:                 }
                   11146:                 if ($changes{'unauth'}) {
                   11147:                     $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
                   11148:                 }
                   11149:                 my $cachetime = 24*60*60;
                   11150:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239     raeburn  11151:                 if (ref($lastactref) eq 'HASH') {
1.246     raeburn  11152:                     $lastactref->{'domdefaults'} = 1;
1.239     raeburn  11153:                 }
                   11154:             }
1.48      raeburn  11155:         } else {
                   11156:             $resulttext = '<span class="LC_error">'.
1.57      raeburn  11157:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.48      raeburn  11158:         }
                   11159:     } else {
1.120     raeburn  11160:         $resulttext = &mt('No changes made to course and community categories');
1.48      raeburn  11161:     }
                   11162:     return $resulttext;
                   11163: }
                   11164: 
1.69      raeburn  11165: sub modify_serverstatuses {
                   11166:     my ($dom,%domconfig) = @_;
                   11167:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
                   11168:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
                   11169:         %currserverstatus = %{$domconfig{'serverstatuses'}};
                   11170:     }
                   11171:     my @pages = &serverstatus_pages();
                   11172:     foreach my $type (@pages) {
                   11173:         $newserverstatus{$type}{'namedusers'} = '';
                   11174:         $newserverstatus{$type}{'machines'} = '';
                   11175:         if (defined($env{'form.'.$type.'_namedusers'})) {
                   11176:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
                   11177:             my @okusers;
                   11178:             foreach my $user (@users) {
                   11179:                 my ($uname,$udom) = split(/:/,$user);
                   11180:                 if (($udom =~ /^$match_domain$/) &&   
                   11181:                     (&Apache::lonnet::domain($udom)) &&
                   11182:                     ($uname =~ /^$match_username$/)) {
                   11183:                     if (!grep(/^\Q$user\E/,@okusers)) {
                   11184:                         push(@okusers,$user);
                   11185:                     }
                   11186:                 }
                   11187:             }
                   11188:             if (@okusers > 0) {
                   11189:                  @okusers = sort(@okusers);
                   11190:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                   11191:             }
                   11192:         }
                   11193:         if (defined($env{'form.'.$type.'_machines'})) {
                   11194:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
                   11195:             my @okmachines;
                   11196:             foreach my $ip (@machines) {
                   11197:                 my @parts = split(/\./,$ip);
                   11198:                 next if (@parts < 4);
                   11199:                 my $badip = 0;
                   11200:                 for (my $i=0; $i<4; $i++) {
                   11201:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                   11202:                         $badip = 1;
                   11203:                         last;
                   11204:                     }
                   11205:                 }
                   11206:                 if (!$badip) {
                   11207:                     push(@okmachines,$ip);     
                   11208:                 }
                   11209:             }
                   11210:             @okmachines = sort(@okmachines);
                   11211:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                   11212:         }
                   11213:     }
                   11214:     my %serverstatushash =  (
                   11215:                                 serverstatuses => \%newserverstatus,
                   11216:                             );
                   11217:     foreach my $type (@pages) {
1.83      raeburn  11218:         foreach my $setting ('namedusers','machines') {
1.84      raeburn  11219:             my (@current,@new);
1.83      raeburn  11220:             if (ref($currserverstatus{$type}) eq 'HASH') {
1.84      raeburn  11221:                 if ($currserverstatus{$type}{$setting} ne '') { 
                   11222:                     @current = split(/,/,$currserverstatus{$type}{$setting});
                   11223:                 }
                   11224:             }
                   11225:             if ($newserverstatus{$type}{$setting} ne '') {
                   11226:                 @new = split(/,/,$newserverstatus{$type}{$setting});
1.83      raeburn  11227:             }
                   11228:             if (@current > 0) {
                   11229:                 if (@new > 0) {
                   11230:                     foreach my $item (@current) {
                   11231:                         if (!grep(/^\Q$item\E$/,@new)) {
                   11232:                             $changes{$type}{$setting} = 1;
1.82      raeburn  11233:                             last;
                   11234:                         }
                   11235:                     }
1.84      raeburn  11236:                     foreach my $item (@new) {
                   11237:                         if (!grep(/^\Q$item\E$/,@current)) {
                   11238:                             $changes{$type}{$setting} = 1;
                   11239:                             last;
1.82      raeburn  11240:                         }
                   11241:                     }
                   11242:                 } else {
1.83      raeburn  11243:                     $changes{$type}{$setting} = 1;
1.69      raeburn  11244:                 }
1.83      raeburn  11245:             } elsif (@new > 0) {
                   11246:                 $changes{$type}{$setting} = 1;
1.69      raeburn  11247:             }
                   11248:         }
                   11249:     }
                   11250:     if (keys(%changes) > 0) {
1.81      raeburn  11251:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69      raeburn  11252:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   11253:                                                  \%serverstatushash,$dom);
                   11254:         if ($putresult eq 'ok') {
                   11255:             $resulttext .= &mt('Changes made:').'<ul>';
                   11256:             foreach my $type (@pages) {
1.84      raeburn  11257:                 if (ref($changes{$type}) eq 'HASH') {
1.69      raeburn  11258:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84      raeburn  11259:                     if ($changes{$type}{'namedusers'}) {
1.69      raeburn  11260:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
                   11261:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                   11262:                         } else {
                   11263:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                   11264:                         }
1.84      raeburn  11265:                     }
                   11266:                     if ($changes{$type}{'machines'}) {
1.69      raeburn  11267:                         if ($newserverstatus{$type}{'machines'} eq '') {
                   11268:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                   11269:                         } else {
                   11270:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                   11271:                         }
                   11272: 
                   11273:                     }
                   11274:                     $resulttext .= '</ul></li>';
                   11275:                 }
                   11276:             }
                   11277:             $resulttext .= '</ul>';
                   11278:         } else {
                   11279:             $resulttext = '<span class="LC_error">'.
                   11280:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
                   11281: 
                   11282:         }
                   11283:     } else {
                   11284:         $resulttext = &mt('No changes made to access to server status pages');
                   11285:     }
                   11286:     return $resulttext;
                   11287: }
                   11288: 
1.118     jms      11289: sub modify_helpsettings {
1.122     jms      11290:     my ($r,$dom,$confname,%domconfig) = @_;
1.166     raeburn  11291:     my ($resulttext,$errors,%changes,%helphash);
                   11292:     my %defaultchecked = ('submitbugs' => 'on');
                   11293:     my @offon = ('off','on');
1.118     jms      11294:     my @toggles = ('submitbugs');
                   11295:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
                   11296:         foreach my $item (@toggles) {
1.166     raeburn  11297:             if ($defaultchecked{$item} eq 'on') { 
                   11298:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   11299:                     if ($env{'form.'.$item} eq '0') {
                   11300:                         $changes{$item} = 1;
                   11301:                     }
                   11302:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   11303:                     $changes{$item} = 1;
                   11304:                 }
                   11305:             } elsif ($defaultchecked{$item} eq 'off') {
                   11306:                 if ($domconfig{'helpsettings'}{$item} eq '') {
                   11307:                     if ($env{'form.'.$item} eq '1') {
                   11308:                         $changes{$item} = 1;
                   11309:                     }
                   11310:                 } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
                   11311:                     $changes{$item} = 1;
                   11312:                 }
                   11313:             }
1.210     raeburn  11314:             if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166     raeburn  11315:                 $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
                   11316:             }
                   11317:         }
1.118     jms      11318:     }
1.123     jms      11319:     my $putresult;
                   11320:     if (keys(%changes) > 0) {
1.166     raeburn  11321:         $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168     raeburn  11322:         if ($putresult eq 'ok') {
1.166     raeburn  11323:             $resulttext = &mt('Changes made:').'<ul>';
                   11324:             foreach my $item (sort(keys(%changes))) {
                   11325:                 if ($item eq 'submitbugs') {
                   11326:                     $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
                   11327:                                               &Apache::loncommon::modal_link('http://bugs.loncapa.org',
                   11328:                                               &mt('LON-CAPA bug tracker'),600,500)).'</li>';
                   11329:                 }
                   11330:             }
                   11331:             $resulttext .= '</ul>';
                   11332:         } else {
                   11333:             $resulttext = &mt('No changes made to help settings');
1.168     raeburn  11334:             $errors .= '<li><span class="LC_error">'.
                   11335:                        &mt('An error occurred storing the settings: [_1]',
                   11336:                            $putresult).'</span></li>';
1.166     raeburn  11337:         }
1.118     jms      11338:     }
                   11339:     if ($errors) {
1.168     raeburn  11340:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118     jms      11341:                        $errors.'</ul>';
                   11342:     }
                   11343:     return $resulttext;
                   11344: }
                   11345: 
1.121     raeburn  11346: sub modify_coursedefaults {
1.212     raeburn  11347:     my ($dom,$lastactref,%domconfig) = @_;
1.121     raeburn  11348:     my ($resulttext,$errors,%changes,%defaultshash);
1.257     raeburn  11349:     my %defaultchecked = (
                   11350:                            'canuse_pdfforms' => 'off',
                   11351:                            'uselcmath'       => 'on',
                   11352:                            'usejsme'         => 'on'
                   11353:                          );
                   11354:     my @toggles = ('canuse_pdfforms','uselcmath','usejsme');
1.198     raeburn  11355:     my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.271     raeburn  11356:                    'uploadquota_community','uploadquota_textbook','uploadquota_placement');
                   11357:     my @types = ('official','unofficial','community','textbook','placement');
1.198     raeburn  11358:     my %staticdefaults = (
                   11359:                            anonsurvey_threshold => 10,
                   11360:                            uploadquota          => 500,
1.257     raeburn  11361:                            postsubmit           => 60,
1.198     raeburn  11362:                          );
1.121     raeburn  11363: 
                   11364:     $defaultshash{'coursedefaults'} = {};
                   11365: 
                   11366:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
                   11367:         if ($domconfig{'coursedefaults'} eq '') {
                   11368:             $domconfig{'coursedefaults'} = {};
                   11369:         }
                   11370:     }
                   11371: 
                   11372:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
                   11373:         foreach my $item (@toggles) {
                   11374:             if ($defaultchecked{$item} eq 'on') {
                   11375:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11376:                     ($env{'form.'.$item} eq '0')) {
                   11377:                     $changes{$item} = 1;
1.192     raeburn  11378:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121     raeburn  11379:                     $changes{$item} = 1;
                   11380:                 }
                   11381:             } elsif ($defaultchecked{$item} eq 'off') {
                   11382:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
                   11383:                     ($env{'form.'.$item} eq '1')) {
                   11384:                     $changes{$item} = 1;
                   11385:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
                   11386:                     $changes{$item} = 1;
                   11387:                 }
                   11388:             }
                   11389:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
                   11390:         }
1.198     raeburn  11391:         foreach my $item (@numbers) {
                   11392:             my ($currdef,$newdef);
1.208     raeburn  11393:             $newdef = $env{'form.'.$item};
1.198     raeburn  11394:             if ($item eq 'anonsurvey_threshold') {
                   11395:                 $currdef = $domconfig{'coursedefaults'}{$item};
                   11396:                 $newdef =~ s/\D//g;
                   11397:                 if ($newdef eq '' || $newdef < 1) {
                   11398:                     $newdef = 1;
                   11399:                 }
                   11400:                 $defaultshash{'coursedefaults'}{$item} = $newdef;
                   11401:             } else {
                   11402:                 my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
                   11403:                 if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   11404:                     $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
                   11405:                 }
                   11406:                 $newdef =~ s/[^\w.\-]//g;
                   11407:                 $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
                   11408:             }
                   11409:             if ($currdef ne $newdef) {
                   11410:                 my $staticdef;
                   11411:                 if ($item eq 'anonsurvey_threshold') {
                   11412:                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                   11413:                         $changes{$item} = 1;
                   11414:                     }
                   11415:                 } else {
                   11416:                     unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
                   11417:                         $changes{'uploadquota'} = 1;
                   11418:                     }
                   11419:                 }
1.139     raeburn  11420:             }
                   11421:         }
1.264     raeburn  11422:         my $currclone = $domconfig{'coursedefaults'}{'canclone'};
                   11423:         my @currclonecode;
                   11424:         if (ref($currclone) eq 'HASH') {
                   11425:             if (ref($currclone->{'instcode'}) eq 'ARRAY') {
                   11426:                 @currclonecode = @{$currclone->{'instcode'}};
                   11427:             }
                   11428:         }
                   11429:         my $newclone;
                   11430:         if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) { 
                   11431:             $newclone = $env{'form.canclone'};
                   11432:         }
                   11433:         if ($newclone eq 'instcode') {
                   11434:             my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
                   11435:             my (%codedefaults,@code_order,@clonecode);
                   11436:             &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
                   11437:                                                     \@code_order);
                   11438:             foreach my $item (@code_order) {
                   11439:                 if (grep(/^\Q$item\E$/,@newcodes)) {
                   11440:                     push(@clonecode,$item);
                   11441:                 }
                   11442:             }
                   11443:             if (@clonecode) {
                   11444:                 $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
                   11445:                 my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
                   11446:                 if (@diffs) {
                   11447:                     $changes{'canclone'} = 1;
                   11448:                 }
                   11449:             } else {
                   11450:                 $newclone eq '';
                   11451:             }
                   11452:         } elsif ($newclone ne '') {
                   11453:             $defaultshash{'coursedefaults'}{'canclone'} = $newclone; 
                   11454:         } 
                   11455:         if ($newclone ne $currclone) {
                   11456:             $changes{'canclone'} = 1;
                   11457:         }
1.257     raeburn  11458:         my %credits;
                   11459:         foreach my $type (@types) {
                   11460:             unless ($type eq 'community') {
                   11461:                 $credits{$type} = $env{'form.'.$type.'_credits'};
                   11462:                 $credits{$type} =~ s/[^\d.]+//g;
                   11463:             }
                   11464:         }
                   11465:         if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
                   11466:             ($env{'form.coursecredits'} eq '1')) {
                   11467:             $changes{'coursecredits'} = 1;
                   11468:             foreach my $type (keys(%credits)) {
                   11469:                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   11470:             }
                   11471:         } else {
                   11472:             if ($env{'form.coursecredits'} eq '1') { 
                   11473:                 foreach my $type (@types) {
                   11474:                     unless ($type eq 'community') {
                   11475:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {        
                   11476:                             $changes{'coursecredits'} = 1;
                   11477:                         }
                   11478:                         $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
                   11479:                     }
                   11480:                 }
                   11481:             } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   11482:                 foreach my $type (@types) {
                   11483:                     unless ($type eq 'community') {
                   11484:                         if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
                   11485:                             $changes{'coursecredits'} = 1;
                   11486:                             last;
                   11487:                         }
                   11488:                     }
                   11489:                 }
                   11490:             }
                   11491:         }
                   11492:         if ($env{'form.postsubmit'} eq '1') {
                   11493:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
                   11494:             my %currtimeout;
                   11495:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11496:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
                   11497:                     $changes{'postsubmit'} = 1;
                   11498:                 }
                   11499:                 if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   11500:                     %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
                   11501:                 }
                   11502:             } else {
                   11503:                 $changes{'postsubmit'} = 1;
                   11504:             }
                   11505:             foreach my $type (@types) {
                   11506:                 my $timeout = $env{'form.'.$type.'_timeout'};
                   11507:                 $timeout =~ s/\D//g;
                   11508:                 if ($timeout == $staticdefaults{'postsubmit'}) {
                   11509:                     $timeout = '';
                   11510:                 } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
                   11511:                     $timeout = '0';
                   11512:                 }
                   11513:                 unless ($timeout eq '') {
                   11514:                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
                   11515:                 }
                   11516:                 if (exists($currtimeout{$type})) {
                   11517:                     if ($timeout ne $currtimeout{$type}) {
                   11518:                         $changes{'postsubmit'} = 1; 
                   11519:                     }
                   11520:                 } elsif ($timeout ne '') {
                   11521:                     $changes{'postsubmit'} = 1;
                   11522:                 }
                   11523:             }
                   11524:         } else {
                   11525:             $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
                   11526:             if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11527:                 if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
                   11528:                     $changes{'postsubmit'} = 1;
                   11529:                 }
                   11530:             } else {
                   11531:                 $changes{'postsubmit'} = 1;
                   11532:             }
1.192     raeburn  11533:         }
1.121     raeburn  11534:     }
                   11535:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   11536:                                              $dom);
                   11537:     if ($putresult eq 'ok') {
                   11538:         if (keys(%changes) > 0) {
1.213     raeburn  11539:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257     raeburn  11540:             if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264     raeburn  11541:                 ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
                   11542:                 ($changes{'canclone'})) {
1.257     raeburn  11543:                 foreach my $item ('canuse_pdfforms','uselcmath','usejsme') { 
                   11544:                     if ($changes{$item}) {
                   11545:                         $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
                   11546:                     }
                   11547:                 } 
1.192     raeburn  11548:                 if ($changes{'coursecredits'}) {
                   11549:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257     raeburn  11550:                         foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
                   11551:                             $domdefaults{$type.'credits'} =
                   11552:                                 $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
                   11553:                         }
                   11554:                     }
                   11555:                 }
                   11556:                 if ($changes{'postsubmit'}) {
                   11557:                     if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
                   11558:                         $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
                   11559:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   11560:                             foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
                   11561:                                 $domdefaults{$type.'postsubtimeout'} =
                   11562:                                     $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   11563:                             }
                   11564:                         }
1.192     raeburn  11565:                     }
                   11566:                 }
1.198     raeburn  11567:                 if ($changes{'uploadquota'}) {
                   11568:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   11569:                         foreach my $type (@types) {
                   11570:                             $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
                   11571:                         }
                   11572:                     }
                   11573:                 }
1.264     raeburn  11574:                 if ($changes{'canclone'}) {
                   11575:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   11576:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   11577:                             my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
                   11578:                             if (@clonecodes) {
                   11579:                                 $domdefaults{'canclone'} = join('+',@clonecodes);
                   11580:                             }
                   11581:                         }
                   11582:                     } else {
                   11583:                         $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
                   11584:                     }
                   11585:                 }
1.121     raeburn  11586:                 my $cachetime = 24*60*60;
                   11587:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  11588:                 if (ref($lastactref) eq 'HASH') {
                   11589:                     $lastactref->{'domdefaults'} = 1;
                   11590:                 }
1.121     raeburn  11591:             }
                   11592:             $resulttext = &mt('Changes made:').'<ul>';
                   11593:             foreach my $item (sort(keys(%changes))) {
                   11594:                 if ($item eq 'canuse_pdfforms') {
                   11595:                     if ($env{'form.'.$item} eq '1') {
                   11596:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
                   11597:                     } else {
                   11598:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
                   11599:                     }
1.257     raeburn  11600:                 } elsif ($item eq 'uselcmath') {
                   11601:                     if ($env{'form.'.$item} eq '1') {
                   11602:                         $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
                   11603:                     } else {
                   11604:                         $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
                   11605:                     }
                   11606:                 } elsif ($item eq 'usejsme') {
                   11607:                     if ($env{'form.'.$item} eq '1') {
                   11608:                         $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
                   11609:                     } else {
                   11610:                         $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>'; 
                   11611:                     }
1.139     raeburn  11612:                 } elsif ($item eq 'anonsurvey_threshold') {
1.192     raeburn  11613:                     $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198     raeburn  11614:                 } elsif ($item eq 'uploadquota') {
                   11615:                     if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
                   11616:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
                   11617:                                        '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
                   11618:                                        '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216     raeburn  11619:                                        '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271     raeburn  11620:                                        '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'. 
1.198     raeburn  11621:                                        '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
                   11622:                                        '</ul>'.
                   11623:                                        '</li>';
                   11624:                     } else {
                   11625:                         $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
                   11626:                     }
1.257     raeburn  11627:                 } elsif ($item eq 'postsubmit') {
                   11628:                     if ($domdefaults{'postsubmit'} eq 'off') {
                   11629:                         $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
                   11630:                     } else {
                   11631:                         $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
                   11632:                         if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') { 
                   11633:                             $resulttext .= &mt('durations:').'<ul>';
                   11634:                             foreach my $type (@types) {
                   11635:                                 $resulttext .= '<li>';
                   11636:                                 my $timeout;
                   11637:                                 if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
                   11638:                                     $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
                   11639:                                 }
                   11640:                                 my $display;
                   11641:                                 if ($timeout eq '0') {
                   11642:                                     $display = &mt('unlimited');
                   11643:                                 } elsif ($timeout eq '') {
                   11644:                                     $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
                   11645:                                 } else {
                   11646:                                     $display = &mt('[quant,_1,second]',$timeout);
                   11647:                                 }
                   11648:                                 if ($type eq 'community') {
                   11649:                                     $resulttext .= &mt('Communities');
                   11650:                                 } elsif ($type eq 'official') {
                   11651:                                     $resulttext .= &mt('Official courses');
                   11652:                                 } elsif ($type eq 'unofficial') {
                   11653:                                     $resulttext .= &mt('Unofficial courses');
                   11654:                                 } elsif ($type eq 'textbook') {
                   11655:                                     $resulttext .= &mt('Textbook courses');
1.271     raeburn  11656:                                 } elsif ($type eq 'placement') {
                   11657:                                     $resulttext .= &mt('Placement tests');
1.257     raeburn  11658:                                 }
                   11659:                                 $resulttext .= ' -- '.$display.'</li>';
                   11660:                             }
                   11661:                             $resulttext .= '</ul>';
                   11662:                         }
                   11663:                         $resulttext .= '</li>';    
                   11664:                     }
1.192     raeburn  11665:                 } elsif ($item eq 'coursecredits') {
                   11666:                     if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
                   11667:                         if (($domdefaults{'officialcredits'} eq '') &&
1.216     raeburn  11668:                             ($domdefaults{'unofficialcredits'} eq '') &&
                   11669:                             ($domdefaults{'textbookcredits'} eq '')) {
1.192     raeburn  11670:                             $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   11671:                         } else {
                   11672:                             $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
                   11673:                                            '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
                   11674:                                            '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216     raeburn  11675:                                            '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192     raeburn  11676:                                            '</ul>'.
                   11677:                                            '</li>';
                   11678:                         }
                   11679:                     } else {
                   11680:                         $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
                   11681:                     }
1.264     raeburn  11682:                 } elsif ($item eq 'canclone') {
                   11683:                     if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
                   11684:                         if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
                   11685:                             my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
                   11686:                             $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
                   11687:                         }
                   11688:                     } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
                   11689:                         $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
                   11690:                     } else {
                   11691:                         $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>'; 
                   11692:                     }
1.140     raeburn  11693:                 }
1.121     raeburn  11694:             }
                   11695:             $resulttext .= '</ul>';
                   11696:         } else {
                   11697:             $resulttext = &mt('No changes made to course defaults');
                   11698:         }
                   11699:     } else {
                   11700:         $resulttext = '<span class="LC_error">'.
                   11701:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11702:     }
                   11703:     return $resulttext;
                   11704: }
                   11705: 
1.231     raeburn  11706: sub modify_selfenrollment {
                   11707:     my ($dom,$lastactref,%domconfig) = @_;
                   11708:     my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271     raeburn  11709:     my @types = ('official','unofficial','community','textbook','placement');
1.231     raeburn  11710:     my %titles = &tool_titles();
1.232     raeburn  11711:     my %descs = &Apache::lonuserutils::selfenroll_default_descs();
                   11712:     ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231     raeburn  11713:     $ordered{'default'} = ['types','registered','approval','limit'];
                   11714: 
                   11715:     my (%roles,%shown,%toplevel);
                   11716:     $roles{'0'} = &Apache::lonnet::plaintext('dc');
                   11717: 
                   11718:     if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
                   11719:         if ($domconfig{'selfenrollment'} eq '') {
                   11720:             $domconfig{'selfenrollment'} = {};
                   11721:         }
                   11722:     }
                   11723:     %toplevel = (
                   11724:                   admin      => 'Configuration Rights',
                   11725:                   default    => 'Default settings',
                   11726:                   validation => 'Validation of self-enrollment requests',
                   11727:                 );
1.233     raeburn  11728:     my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231     raeburn  11729: 
                   11730:     if (ref($ordered{'admin'}) eq 'ARRAY') {
                   11731:         foreach my $item (@{$ordered{'admin'}}) {
                   11732:             foreach my $type (@types) {
                   11733:                 if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
                   11734:                     $selfenrollhash{'admin'}{$type}{$item} = 1;
                   11735:                 } else {
                   11736:                     $selfenrollhash{'admin'}{$type}{$item} = 0;
                   11737:                 }
                   11738:                 if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
                   11739:                     if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
                   11740:                         if ($selfenrollhash{'admin'}{$type}{$item} ne
                   11741:                             $domconfig{'selfenrollment'}{'admin'}{$type}{$item})  {
                   11742:                             push(@{$changes{'admin'}{$type}},$item);
                   11743:                         }
                   11744:                     } else {
                   11745:                         if (!$selfenrollhash{'admin'}{$type}{$item}) {
                   11746:                             push(@{$changes{'admin'}{$type}},$item);
                   11747:                         }
                   11748:                     }
                   11749:                 } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
                   11750:                     push(@{$changes{'admin'}{$type}},$item);
                   11751:                 }
                   11752:             }
                   11753:         }
                   11754:     }
                   11755: 
                   11756:     foreach my $item (@{$ordered{'default'}}) {
                   11757:         foreach my $type (@types) {
                   11758:             my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
                   11759:             if ($item eq 'types') {
                   11760:                 unless (($value eq 'all') || ($value eq 'dom')) {
                   11761:                     $value = '';
                   11762:                 }
                   11763:             } elsif ($item eq 'registered') {
                   11764:                 unless ($value eq '1') {
                   11765:                     $value = 0;
                   11766:                 }
                   11767:             } elsif ($item eq 'approval') {
                   11768:                 unless ($value =~ /^[012]$/) {
                   11769:                     $value = 0;
                   11770:                 }
                   11771:             } else {
                   11772:                 unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   11773:                     $value = 'none';
                   11774:                 }
                   11775:             }
                   11776:             $selfenrollhash{'default'}{$type}{$item} = $value;
                   11777:             if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
                   11778:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   11779:                     if ($selfenrollhash{'default'}{$type}{$item} ne
                   11780:                          $domconfig{'selfenrollment'}{'default'}{$type}{$item})  {
                   11781:                          push(@{$changes{'default'}{$type}},$item);
                   11782:                     }
                   11783:                 } else {
                   11784:                     push(@{$changes{'default'}{$type}},$item);
                   11785:                 }
                   11786:             } else {
                   11787:                 push(@{$changes{'default'}{$type}},$item);
                   11788:             }
                   11789:             if ($item eq 'limit') {
                   11790:                 if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
                   11791:                     $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
                   11792:                     if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
                   11793:                         $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
                   11794:                     }
                   11795:                 } else {
                   11796:                     $selfenrollhash{'default'}{$type}{'cap'} = '';
                   11797:                 }
                   11798:                 if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
                   11799:                     if ($selfenrollhash{'default'}{$type}{'cap'} ne
                   11800:                          $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'})  {
                   11801:                          push(@{$changes{'default'}{$type}},'cap');
                   11802:                     }
                   11803:                 } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
                   11804:                     push(@{$changes{'default'}{$type}},'cap');
                   11805:                 }
                   11806:             }
                   11807:         }
                   11808:     }
                   11809: 
                   11810:     foreach my $item (@{$itemsref}) {
                   11811:         if ($item eq 'fields') {
                   11812:             my @changed;
                   11813:             @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
                   11814:             if (@{$selfenrollhash{'validation'}{$item}} > 0) {
                   11815:                 @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
                   11816:             }
                   11817:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   11818:                 if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
                   11819:                     @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
                   11820:                                                                   $domconfig{'selfenrollment'}{'validation'}{$item});
                   11821:                 } else {
                   11822:                     @changed = @{$selfenrollhash{'validation'}{$item}};
                   11823:                 }
                   11824:             } else {
                   11825:                 @changed = @{$selfenrollhash{'validation'}{$item}};
                   11826:             }
                   11827:             if (@changed) {
                   11828:                 if ($selfenrollhash{'validation'}{$item}) { 
                   11829:                     $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
                   11830:                 } else {
                   11831:                     $changes{'validation'}{$item} = &mt('None');
                   11832:                 }
                   11833:             }
                   11834:         } else {
                   11835:             $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
                   11836:             if ($item eq 'markup') {
                   11837:                if ($env{'form.selfenroll_validation_'.$item}) {
                   11838:                    $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
                   11839:                }
                   11840:             }
                   11841:             if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
                   11842:                 if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
                   11843:                     $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
                   11844:                 }
                   11845:             }
                   11846:         }
                   11847:     }
                   11848: 
                   11849:     my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
                   11850:                                              $dom);
                   11851:     if ($putresult eq 'ok') {
                   11852:         if (keys(%changes) > 0) {
                   11853:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
                   11854:             $resulttext = &mt('Changes made:').'<ul>';
                   11855:             foreach my $key ('admin','default','validation') {
                   11856:                 if (ref($changes{$key}) eq 'HASH') {
                   11857:                     $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
                   11858:                     if ($key eq 'validation') {
                   11859:                         foreach my $item (@{$itemsref}) {
                   11860:                             if (exists($changes{$key}{$item})) {
                   11861:                                 if ($item eq 'markup') {
                   11862:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   11863:                                                               '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
                   11864:                                 } else {  
                   11865:                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
                   11866:                                                               '<b>'.$changes{$key}{$item}.'</b>').'</li>';
                   11867:                                 }
                   11868:                             }
                   11869:                         }
                   11870:                     } else {
                   11871:                         foreach my $type (@types) {
                   11872:                             if ($type eq 'community') {
                   11873:                                 $roles{'1'} = &mt('Community personnel');
                   11874:                             } else {
                   11875:                                 $roles{'1'} = &mt('Course personnel');
                   11876:                             }
                   11877:                             if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232     raeburn  11878:                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
                   11879:                                     if ($key eq 'admin') {
                   11880:                                         my @mgrdc = ();
                   11881:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   11882:                                             foreach my $item (@{$ordered{'admin'}}) {
                   11883:                                                 if (ref($selfenrollhash{$key}{$type}) eq 'HASH') { 
                   11884:                                                     if ($selfenrollhash{$key}{$type}{$item} eq '0') {
                   11885:                                                         push(@mgrdc,$item);
                   11886:                                                     }
                   11887:                                                 }
                   11888:                                             }
                   11889:                                             if (@mgrdc) {
                   11890:                                                 $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
                   11891:                                             } else {
                   11892:                                                 delete($domdefaults{$type.'selfenrolladmdc'});
                   11893:                                             }
                   11894:                                         }
                   11895:                                     } else {
                   11896:                                         if (ref($ordered{$key}) eq 'ARRAY') {
                   11897:                                             foreach my $item (@{$ordered{$key}}) {
                   11898:                                                 if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   11899:                                                     $domdefaults{$type.'selfenroll'.$item} =
                   11900:                                                         $selfenrollhash{$key}{$type}{$item};
                   11901:                                                 }
                   11902:                                             }
                   11903:                                         }
                   11904:                                     }
                   11905:                                 }
1.231     raeburn  11906:                                 $resulttext .= '<li>'.$titles{$type}.'<ul>';
                   11907:                                 foreach my $item (@{$ordered{$key}}) {
                   11908:                                     if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
                   11909:                                         $resulttext .= '<li>';
                   11910:                                         if ($key eq 'admin') {
                   11911:                                             $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
                   11912:                                                                '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
                   11913:                                         } else {
                   11914:                                             $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
                   11915:                                                                '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
                   11916:                                         }
                   11917:                                         $resulttext .= '</li>';
                   11918:                                     }
                   11919:                                 }
                   11920:                                 $resulttext .= '</ul></li>';
                   11921:                             }
                   11922:                         }
                   11923:                         $resulttext .= '</ul></li>'; 
                   11924:                     }
                   11925:                 }
1.232     raeburn  11926:                 if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
                   11927:                     my $cachetime = 24*60*60;
                   11928:                     &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                   11929:                     if (ref($lastactref) eq 'HASH') {
                   11930:                         $lastactref->{'domdefaults'} = 1;
                   11931:                     }
                   11932:                 }
1.231     raeburn  11933:             }
                   11934:             $resulttext .= '</ul>';
                   11935:         } else {
                   11936:             $resulttext = &mt('No changes made to self-enrollment settings');
                   11937:         }
                   11938:     } else {
                   11939:         $resulttext = '<span class="LC_error">'.
                   11940:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   11941:     }
                   11942:     return $resulttext;
                   11943: }
                   11944: 
1.137     raeburn  11945: sub modify_usersessions {
1.212     raeburn  11946:     my ($dom,$lastactref,%domconfig) = @_;
1.145     raeburn  11947:     my @hostingtypes = ('version','excludedomain','includedomain');
                   11948:     my @offloadtypes = ('primary','default');
                   11949:     my %types = (
                   11950:                   remote => \@hostingtypes,
                   11951:                   hosted => \@hostingtypes,
                   11952:                   spares => \@offloadtypes,
                   11953:                 );
                   11954:     my @prefixes = ('remote','hosted','spares');
1.137     raeburn  11955:     my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138     raeburn  11956:     my (%by_ip,%by_location,@intdoms);
                   11957:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
                   11958:     my @locations = sort(keys(%by_location));
1.137     raeburn  11959:     my (%defaultshash,%changes);
                   11960:     foreach my $prefix (@prefixes) {
                   11961:         $defaultshash{'usersessions'}{$prefix} = {};
                   11962:     }
1.212     raeburn  11963:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137     raeburn  11964:     my $resulttext;
1.138     raeburn  11965:     my %iphost = &Apache::lonnet::get_iphost();
1.137     raeburn  11966:     foreach my $prefix (@prefixes) {
1.145     raeburn  11967:         next if ($prefix eq 'spares');
                   11968:         foreach my $type (@{$types{$prefix}}) {
1.137     raeburn  11969:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
                   11970:             if ($type eq 'version') {
                   11971:                 my $value = $env{'form.'.$prefix.'_'.$type};
                   11972:                 my $okvalue;
                   11973:                 if ($value ne '') {
                   11974:                     if (grep(/^\Q$value\E$/,@lcversions)) {
                   11975:                         $okvalue = $value;
                   11976:                     }
                   11977:                 }
                   11978:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   11979:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   11980:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
                   11981:                             if ($inuse == 0) {
                   11982:                                 $changes{$prefix}{$type} = 1;
                   11983:                             } else {
                   11984:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
                   11985:                                     $changes{$prefix}{$type} = 1;
                   11986:                                 }
                   11987:                                 if ($okvalue ne '') {
                   11988:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   11989:                                 } 
                   11990:                             }
                   11991:                         } else {
                   11992:                             if (($inuse == 1) && ($okvalue ne '')) {
                   11993:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   11994:                                 $changes{$prefix}{$type} = 1;
                   11995:                             }
                   11996:                         }
                   11997:                     } else {
                   11998:                         if (($inuse == 1) && ($okvalue ne '')) {
                   11999:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12000:                             $changes{$prefix}{$type} = 1;
                   12001:                         }
                   12002:                     }
                   12003:                 } else {
                   12004:                     if (($inuse == 1) && ($okvalue ne '')) {
                   12005:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
                   12006:                         $changes{$prefix}{$type} = 1;
                   12007:                     }
                   12008:                 }
                   12009:             } else {
                   12010:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
                   12011:                 my @okvals;
                   12012:                 foreach my $val (@vals) {
1.138     raeburn  12013:                     if ($val =~ /:/) {
                   12014:                         my @items = split(/:/,$val);
                   12015:                         foreach my $item (@items) {
                   12016:                             if (ref($by_location{$item}) eq 'ARRAY') {
                   12017:                                 push(@okvals,$item);
                   12018:                             }
                   12019:                         }
                   12020:                     } else {
                   12021:                         if (ref($by_location{$val}) eq 'ARRAY') {
                   12022:                             push(@okvals,$val);
                   12023:                         }
1.137     raeburn  12024:                     }
                   12025:                 }
                   12026:                 @okvals = sort(@okvals);
                   12027:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12028:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
                   12029:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12030:                             if ($inuse == 0) {
                   12031:                                 $changes{$prefix}{$type} = 1; 
                   12032:                             } else {
                   12033:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12034:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
                   12035:                                 if (@changed > 0) {
                   12036:                                     $changes{$prefix}{$type} = 1;
                   12037:                                 }
                   12038:                             }
                   12039:                         } else {
                   12040:                             if ($inuse == 1) {
                   12041:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12042:                                 $changes{$prefix}{$type} = 1;
                   12043:                             }
                   12044:                         } 
                   12045:                     } else {
                   12046:                         if ($inuse == 1) {
                   12047:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12048:                             $changes{$prefix}{$type} = 1;
                   12049:                         }
                   12050:                     }
                   12051:                 } else {
                   12052:                     if ($inuse == 1) {
                   12053:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
                   12054:                         $changes{$prefix}{$type} = 1;
                   12055:                     }
                   12056:                 }
                   12057:             }
                   12058:         }
                   12059:     }
1.145     raeburn  12060: 
                   12061:     my @alldoms = &Apache::lonnet::all_domains();
1.149     raeburn  12062:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145     raeburn  12063:     my %spareid = &current_offloads_to($dom,$domconfig{'usersessions'},\%servers);
                   12064:     my $savespares;
                   12065: 
                   12066:     foreach my $lonhost (sort(keys(%servers))) {
                   12067:         my $serverhomeID =
                   12068:             &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152     raeburn  12069:         my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145     raeburn  12070:         $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
                   12071:         my %spareschg;
                   12072:         foreach my $type (@{$types{'spares'}}) {
                   12073:             my @okspares;
                   12074:             my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
                   12075:             foreach my $server (@checked) {
1.152     raeburn  12076:                 if (&Apache::lonnet::hostname($server) ne '') {
                   12077:                     unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
                   12078:                         unless (grep(/^\Q$server\E$/,@okspares)) {
                   12079:                             push(@okspares,$server);
                   12080:                         }
1.145     raeburn  12081:                     }
                   12082:                 }
                   12083:             }
                   12084:             my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
                   12085:             my $newspare;
1.152     raeburn  12086:             if (($new ne '') && (&Apache::lonnet::hostname($new))) {
                   12087:                 unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145     raeburn  12088:                     $newspare = $new;
                   12089:                 }
                   12090:             }
1.152     raeburn  12091:             my @spares;
                   12092:             if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
                   12093:                 @spares = sort(@okspares,$newspare);
                   12094:             } else {
                   12095:                 @spares = sort(@okspares);
                   12096:             }
                   12097:             $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145     raeburn  12098:             if (ref($spareid{$lonhost}) eq 'HASH') {
                   12099:                 if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152     raeburn  12100:                     my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145     raeburn  12101:                     if (@diffs > 0) {
                   12102:                         $spareschg{$type} = 1;
                   12103:                     }
                   12104:                 }
                   12105:             }
                   12106:         }
                   12107:         if (keys(%spareschg) > 0) {
                   12108:             $changes{'spares'}{$lonhost} = \%spareschg;
                   12109:         }
                   12110:     }
1.261     raeburn  12111:     $defaultshash{'usersessions'}{'offloadnow'} = {};
                   12112:     my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
                   12113:     my @okoffload;
                   12114:     if (@offloadnow) {
                   12115:         foreach my $server (@offloadnow) {
                   12116:             if (&Apache::lonnet::hostname($server) ne '') {
                   12117:                 unless (grep(/^\Q$server\E$/,@okoffload)) {
                   12118:                     push(@okoffload,$server);
                   12119:                 }
                   12120:             }
                   12121:         }
                   12122:         if (@okoffload) {
                   12123:             foreach my $lonhost (@okoffload) {
                   12124:                 $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
                   12125:             }
                   12126:         }
                   12127:     }
1.145     raeburn  12128:     if (ref($domconfig{'usersessions'}) eq 'HASH') {
                   12129:         if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
                   12130:             if (ref($changes{'spares'}) eq 'HASH') {
                   12131:                 if (keys(%{$changes{'spares'}}) > 0) {
                   12132:                     $savespares = 1;
                   12133:                 }
                   12134:             }
                   12135:         } else {
                   12136:             $savespares = 1;
                   12137:         }
1.261     raeburn  12138:         if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12139:             foreach my $lonhost (keys(%{$domconfig{'usersessions'}{'offloadnow'}})) {
                   12140:                 unless ($defaultshash{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12141:                     $changes{'offloadnow'} = 1;
                   12142:                     last;
                   12143:                 }
                   12144:             }
                   12145:             unless ($changes{'offloadnow'}) {
                   12146:                 foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{'offloadnow'}})) { 
                   12147:                     unless ($domconfig{'usersessions'}{'offloadnow'}{$lonhost}) {
                   12148:                         $changes{'offloadnow'} = 1;
                   12149:                         last;
                   12150:                     }
                   12151:                 }
                   12152:             }
                   12153:         } elsif (@okoffload) {
                   12154:             $changes{'offloadnow'} = 1;
                   12155:         }
                   12156:     } elsif (@okoffload) {
                   12157:         $changes{'offloadnow'} = 1;
1.145     raeburn  12158:     }
1.147     raeburn  12159:     my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
                   12160:     if ((keys(%changes) > 0) || ($savespares)) {
1.137     raeburn  12161:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
                   12162:                                                  $dom);
                   12163:         if ($putresult eq 'ok') {
                   12164:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12165:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
                   12166:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
                   12167:                 }
                   12168:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
                   12169:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
                   12170:                 }
1.261     raeburn  12171:                 if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12172:                     $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
                   12173:                 }
1.137     raeburn  12174:             }
                   12175:             my $cachetime = 24*60*60;
                   12176:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212     raeburn  12177:             if (ref($lastactref) eq 'HASH') {
                   12178:                 $lastactref->{'domdefaults'} = 1;
                   12179:             }
1.147     raeburn  12180:             if (keys(%changes) > 0) {
                   12181:                 my %lt = &usersession_titles();
                   12182:                 $resulttext = &mt('Changes made:').'<ul>';
                   12183:                 foreach my $prefix (@prefixes) {
                   12184:                     if (ref($changes{$prefix}) eq 'HASH') {
                   12185:                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                   12186:                         if ($prefix eq 'spares') {
                   12187:                             if (ref($changes{$prefix}) eq 'HASH') {
                   12188:                                 foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
                   12189:                                     $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148     raeburn  12190:                                     my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211     raeburn  12191:                                     my $cachekey = &escape('spares').':'.&escape($lonhostdom);
                   12192:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147     raeburn  12193:                                     if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
                   12194:                                         foreach my $type (@{$types{$prefix}}) {
                   12195:                                             if ($changes{$prefix}{$lonhost}{$type}) {
                   12196:                                                 my $offloadto = &mt('None');
                   12197:                                                 if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
                   12198:                                                     if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {   
                   12199:                                                         $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
                   12200:                                                     }
1.145     raeburn  12201:                                                 }
1.147     raeburn  12202:                                                 $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).('&nbsp;'x3);
1.145     raeburn  12203:                                             }
1.137     raeburn  12204:                                         }
                   12205:                                     }
1.147     raeburn  12206:                                     $resulttext .= '</li>';
1.137     raeburn  12207:                                 }
                   12208:                             }
1.147     raeburn  12209:                         } else {
                   12210:                             foreach my $type (@{$types{$prefix}}) {
                   12211:                                 if (defined($changes{$prefix}{$type})) {
                   12212:                                     my $newvalue;
                   12213:                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                   12214:                                         if (ref($defaultshash{'usersessions'}{$prefix})) {
                   12215:                                             if ($type eq 'version') {
                   12216:                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                   12217:                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                   12218:                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                   12219:                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                   12220:                                                 }
1.145     raeburn  12221:                                             }
                   12222:                                         }
                   12223:                                     }
1.147     raeburn  12224:                                     if ($newvalue eq '') {
                   12225:                                         if ($type eq 'version') {
                   12226:                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                   12227:                                         } else {
                   12228:                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                   12229:                                         }
1.145     raeburn  12230:                                     } else {
1.147     raeburn  12231:                                         if ($type eq 'version') {
                   12232:                                             $newvalue .= ' '.&mt('(or later)'); 
                   12233:                                         }
                   12234:                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145     raeburn  12235:                                     }
1.137     raeburn  12236:                                 }
                   12237:                             }
                   12238:                         }
1.147     raeburn  12239:                         $resulttext .= '</ul>';
1.137     raeburn  12240:                     }
                   12241:                 }
1.261     raeburn  12242:                 if ($changes{'offloadnow'}) {
                   12243:                     if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
                   12244:                         if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
                   12245:                             $resulttext .= '<li>'.&mt('Switch active users on next access, for server(s):').'<ul>';
                   12246:                             foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
                   12247:                                 $resulttext .= '<li>'.$lonhost.'</li>';
                   12248:                             }
                   12249:                             $resulttext .= '</ul>';
                   12250:                         } else {
                   12251:                             $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.');
                   12252:                         }
                   12253:                     } else {
                   12254:                         $resulttext .= '<li>'.&mt('No servers now set to switch active users on next access.').'</li>';
                   12255:                     }
                   12256:                 }
1.147     raeburn  12257:                 $resulttext .= '</ul>';
                   12258:             } else {
                   12259:                 $resulttext = $nochgmsg;
1.137     raeburn  12260:             }
                   12261:         } else {
                   12262:             $resulttext = '<span class="LC_error">'.
                   12263:                           &mt('An error occurred: [_1]',$putresult).'</span>';
                   12264:         }
                   12265:     } else {
1.147     raeburn  12266:         $resulttext = $nochgmsg;
1.137     raeburn  12267:     }
                   12268:     return $resulttext;
                   12269: }
                   12270: 
1.150     raeburn  12271: sub modify_loadbalancing {
                   12272:     my ($dom,%domconfig) = @_;
                   12273:     my $primary_id = &Apache::lonnet::domain($dom,'primary');
                   12274:     my $intdom = &Apache::lonnet::internet_dom($primary_id);
                   12275:     my ($othertitle,$usertypes,$types) =
                   12276:         &Apache::loncommon::sorted_inst_types($dom);
                   12277:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253     raeburn  12278:     my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150     raeburn  12279:     my @sparestypes = ('primary','default');
                   12280:     my %typetitles = &sparestype_titles();
                   12281:     my $resulttext;
1.171     raeburn  12282:     my (%currbalancer,%currtargets,%currrules,%existing);
                   12283:     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   12284:         %existing = %{$domconfig{'loadbalancing'}};
                   12285:     }
                   12286:     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                   12287:                               \%currtargets,\%currrules);
                   12288:     my ($saveloadbalancing,%defaultshash,%changes);
                   12289:     my ($alltypes,$othertypes,$titles) =
                   12290:         &loadbalancing_titles($dom,$intdom,$usertypes,$types);
                   12291:     my %ruletitles = &offloadtype_text();
                   12292:     my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
                   12293:     for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
                   12294:         my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
                   12295:         if ($balancer eq '') {
                   12296:             next;
                   12297:         }
1.210     raeburn  12298:         if (!exists($servers{$balancer})) {
1.171     raeburn  12299:             if (exists($currbalancer{$balancer})) {
                   12300:                 push(@{$changes{'delete'}},$balancer);
1.150     raeburn  12301:             }
1.171     raeburn  12302:             next;
                   12303:         }
                   12304:         if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
                   12305:             push(@{$changes{'delete'}},$balancer);
                   12306:             next;
                   12307:         }
                   12308:         if (!exists($currbalancer{$balancer})) {
                   12309:             push(@{$changes{'add'}},$balancer);
                   12310:         }
                   12311:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
                   12312:         $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
                   12313:         $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
                   12314:         unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
                   12315:             $saveloadbalancing = 1;
                   12316:         }
                   12317:         foreach my $sparetype (@sparestypes) {
                   12318:             my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
                   12319:             my @offloadto;
                   12320:             foreach my $target (@targets) {
                   12321:                 if (($servers{$target}) && ($target ne $balancer)) {
                   12322:                     if ($sparetype eq 'default') {
                   12323:                         if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
                   12324:                             next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150     raeburn  12325:                         }
                   12326:                     }
1.171     raeburn  12327:                     unless(grep(/^\Q$target\E$/,@offloadto)) {
                   12328:                         push(@offloadto,$target);
                   12329:                     }
1.150     raeburn  12330:                 }
1.171     raeburn  12331:                 $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150     raeburn  12332:             }
                   12333:         }
1.171     raeburn  12334:         if (ref($currtargets{$balancer}) eq 'HASH') {
1.150     raeburn  12335:             foreach my $sparetype (@sparestypes) {
1.171     raeburn  12336:                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
                   12337:                     my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150     raeburn  12338:                     if (@targetdiffs > 0) {
1.171     raeburn  12339:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  12340:                     }
1.171     raeburn  12341:                 } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12342:                     if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12343:                         $changes{'curr'}{$balancer}{'targets'} = 1;
1.150     raeburn  12344:                     }
                   12345:                 }
                   12346:             }
                   12347:         } else {
1.171     raeburn  12348:             if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210     raeburn  12349:                 foreach my $sparetype (@sparestypes) {
1.171     raeburn  12350:                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12351:                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12352:                             $changes{'curr'}{$balancer}{'targets'} = 1;
                   12353:                         }
1.150     raeburn  12354:                     }
                   12355:                 }
1.210     raeburn  12356:             }
1.150     raeburn  12357:         }
                   12358:         my $ishomedom;
1.171     raeburn  12359:         if (&Apache::lonnet::host_domain($balancer) eq $dom) {
                   12360:             $ishomedom = 1;
1.150     raeburn  12361:         }
                   12362:         if (ref($alltypes) eq 'ARRAY') {
                   12363:             foreach my $type (@{$alltypes}) {
                   12364:                 my $rule;
1.210     raeburn  12365:                 unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150     raeburn  12366:                          (!$ishomedom)) {
1.171     raeburn  12367:                     $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
                   12368:                 }
                   12369:                 if ($rule eq 'specific') {
1.255     raeburn  12370:                     my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
                   12371:                     if (exists($servers{$specifiedhost})) { 
                   12372:                         $rule = $specifiedhost;
                   12373:                     }
1.150     raeburn  12374:                 }
1.171     raeburn  12375:                 $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
                   12376:                 if (ref($currrules{$balancer}) eq 'HASH') {
                   12377:                     if ($rule ne $currrules{$balancer}{$type}) {
                   12378:                         $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  12379:                     }
                   12380:                 } elsif ($rule ne '') {
1.171     raeburn  12381:                     $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150     raeburn  12382:                 }
                   12383:             }
                   12384:         }
1.171     raeburn  12385:     }
                   12386:     my $nochgmsg = &mt('No changes made to Load Balancer settings.');
                   12387:     if ((keys(%changes) > 0) || ($saveloadbalancing)) {
                   12388:         unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
                   12389:             $defaultshash{'loadbalancing'} = {};
                   12390:         }
                   12391:         my $putresult = &Apache::lonnet::put_dom('configuration',
                   12392:                                                  \%defaultshash,$dom);
                   12393:         if ($putresult eq 'ok') {
                   12394:             if (keys(%changes) > 0) {
1.252     raeburn  12395:                 my %toupdate;
1.171     raeburn  12396:                 if (ref($changes{'delete'}) eq 'ARRAY') {
                   12397:                     foreach my $balancer (sort(@{$changes{'delete'}})) {
                   12398:                         $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252     raeburn  12399:                         $toupdate{$balancer} = 1;
1.150     raeburn  12400:                     }
1.171     raeburn  12401:                 }
                   12402:                 if (ref($changes{'add'}) eq 'ARRAY') {
1.210     raeburn  12403:                     foreach my $balancer (sort(@{$changes{'add'}})) {
1.171     raeburn  12404:                         $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252     raeburn  12405:                         $toupdate{$balancer} = 1;
1.171     raeburn  12406:                     }
                   12407:                 }
                   12408:                 if (ref($changes{'curr'}) eq 'HASH') {
                   12409:                     foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253     raeburn  12410:                         $toupdate{$balancer} = 1;
1.171     raeburn  12411:                         if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
                   12412:                             if ($changes{'curr'}{$balancer}{'targets'}) {
                   12413:                                 my %offloadstr;
                   12414:                                 foreach my $sparetype (@sparestypes) {
                   12415:                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12416:                                         if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
                   12417:                                             $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   12418:                                         }
                   12419:                                     }
1.150     raeburn  12420:                                 }
1.171     raeburn  12421:                                 if (keys(%offloadstr) == 0) {
                   12422:                                     $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150     raeburn  12423:                                 } else {
1.171     raeburn  12424:                                     my $showoffload;
                   12425:                                     foreach my $sparetype (@sparestypes) {
                   12426:                                         $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>:&nbsp;';
                   12427:                                         if (defined($offloadstr{$sparetype})) {
                   12428:                                             $showoffload .= $offloadstr{$sparetype};
                   12429:                                         } else {
                   12430:                                             $showoffload .= &mt('None');
                   12431:                                         }
                   12432:                                         $showoffload .= ('&nbsp;'x3);
                   12433:                                     }
                   12434:                                     $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150     raeburn  12435:                                 }
                   12436:                             }
                   12437:                         }
1.171     raeburn  12438:                         if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
                   12439:                             if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
                   12440:                                 foreach my $type (@{$alltypes}) {
                   12441:                                     if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
                   12442:                                         my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   12443:                                         my $balancetext;
                   12444:                                         if ($rule eq '') {
                   12445:                                             $balancetext =  $ruletitles{'default'};
1.209     raeburn  12446:                                         } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.254     raeburn  12447:                                                  ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) { 
                   12448:                                             if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252     raeburn  12449:                                                 foreach my $sparetype (@sparestypes) {
                   12450:                                                     if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
                   12451:                                                         map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
                   12452:                                                     }
                   12453:                                                 }
1.253     raeburn  12454:                                                 foreach my $item (@{$alltypes}) {
                   12455:                                                     next if ($item =~  /^_LC_ipchange/);
                   12456:                                                     my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
                   12457:                                                     if ($hasrule eq 'homeserver') {
                   12458:                                                         map { $toupdate{$_} = 1; } (keys(%libraryservers));
                   12459:                                                     } else {
                   12460:                                                         unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
                   12461:                                                             if ($servers{$hasrule}) {
                   12462:                                                                 $toupdate{$hasrule} = 1;
                   12463:                                                             }
                   12464:                                                         }
                   12465:                                                     }
                   12466:                                                 }
1.254     raeburn  12467:                                                 if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
                   12468:                                                     $balancetext =  $ruletitles{$rule};
                   12469:                                                 } else {
                   12470:                                                     my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
                   12471:                                                     $balancetext = $ruletitles{'particular'}.' '.$receiver;
                   12472:                                                     if ($receiver) {
                   12473:                                                         $toupdate{$receiver};
                   12474:                                                     }
                   12475:                                                 }
                   12476:                                             } else {
                   12477:                                                 $balancetext =  $ruletitles{$rule};
1.252     raeburn  12478:                                             }
1.171     raeburn  12479:                                         } else {
                   12480:                                             $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
                   12481:                                         }
1.210     raeburn  12482:                                         $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150     raeburn  12483:                                     }
                   12484:                                 }
                   12485:                             }
                   12486:                         }
1.252     raeburn  12487:                         if (keys(%toupdate)) {
                   12488:                             my %thismachine;
                   12489:                             my $updatedhere;
                   12490:                             my $cachetime = 60*60*24;
                   12491:                             map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
                   12492:                             foreach my $lonhost (keys(%toupdate)) {
                   12493:                                 if ($thismachine{$lonhost}) {
                   12494:                                     unless ($updatedhere) {
                   12495:                                         &Apache::lonnet::do_cache_new('loadbalancing',$dom,
                   12496:                                                                       $defaultshash{'loadbalancing'},
                   12497:                                                                       $cachetime);
                   12498:                                         $updatedhere = 1;
                   12499:                                     }
                   12500:                                 } else {
                   12501:                                     my $cachekey = &escape('loadbalancing').':'.&escape($dom);
                   12502:                                     &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
                   12503:                                 }
                   12504:                             }
                   12505:                         }
1.150     raeburn  12506:                     }
1.171     raeburn  12507:                 }
                   12508:                 if ($resulttext ne '') {
                   12509:                     $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150     raeburn  12510:                 } else {
                   12511:                     $resulttext = $nochgmsg;
                   12512:                 }
                   12513:             } else {
1.171     raeburn  12514:                 $resulttext = $nochgmsg;
1.150     raeburn  12515:             }
                   12516:         } else {
1.171     raeburn  12517:             $resulttext = '<span class="LC_error">'.
                   12518:                           &mt('An error occurred: [_1]',$putresult).'</span>';
1.150     raeburn  12519:         }
                   12520:     } else {
1.171     raeburn  12521:         $resulttext = $nochgmsg;
1.150     raeburn  12522:     }
                   12523:     return $resulttext;
                   12524: }
                   12525: 
1.48      raeburn  12526: sub recurse_check {
                   12527:     my ($chkcats,$categories,$depth,$name) = @_;
                   12528:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
                   12529:         my $chg = 0;
                   12530:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
                   12531:             my $category = $chkcats->[$depth]{$name}[$j];
                   12532:             my $item;
                   12533:             if ($category eq '') {
                   12534:                 $chg ++;
                   12535:             } else {
                   12536:                 my $deeper = $depth + 1;
                   12537:                 $item = &escape($category).':'.&escape($name).':'.$depth;
                   12538:                 if ($chg) {
                   12539:                     $categories->{$item} -= $chg;
                   12540:                 }
                   12541:                 &recurse_check($chkcats,$categories,$deeper,$category);
                   12542:                 $deeper --;
                   12543:             }
                   12544:         }
                   12545:     }
                   12546:     return;
                   12547: }
                   12548: 
                   12549: sub recurse_cat_deletes {
                   12550:     my ($item,$coursecategories,$deletions) = @_;
                   12551:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   12552:     my $subdepth = $depth + 1;
                   12553:     if (ref($coursecategories) eq 'HASH') {
                   12554:         foreach my $subitem (keys(%{$coursecategories})) {
                   12555:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
                   12556:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
                   12557:                 delete($coursecategories->{$subitem});
                   12558:                 $deletions->{$subitem} = 1;
                   12559:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168     raeburn  12560:             }
1.48      raeburn  12561:         }
                   12562:     }
                   12563:     return;
                   12564: }
                   12565: 
1.125     raeburn  12566: sub get_active_dcs {
                   12567:     my ($dom) = @_;
1.191     raeburn  12568:     my $now = time;
                   12569:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125     raeburn  12570:     my %domcoords;
                   12571:     my $numdcs = 0;
                   12572:     foreach my $server (keys(%dompersonnel)) {
                   12573:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
                   12574:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191     raeburn  12575:             $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125     raeburn  12576:         }
                   12577:     }
                   12578:     return %domcoords;
                   12579: }
                   12580: 
                   12581: sub active_dc_picker {
1.191     raeburn  12582:     my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.235     raeburn  12583:     my %domcoords = &get_active_dcs($dom);
1.191     raeburn  12584:     my @domcoord = keys(%domcoords);
                   12585:     if (keys(%currhash)) {
                   12586:         foreach my $dc (keys(%currhash)) {
                   12587:             unless (exists($domcoords{$dc})) {
                   12588:                 push(@domcoord,$dc);
                   12589:             }
                   12590:         }
                   12591:     }
                   12592:     @domcoord = sort(@domcoord);
1.210     raeburn  12593:     my $numdcs = scalar(@domcoord);
1.191     raeburn  12594:     my $rows = 0;
                   12595:     my $table;
1.125     raeburn  12596:     if ($numdcs > 1) {
1.191     raeburn  12597:         $table = '<table>';
                   12598:         for (my $i=0; $i<@domcoord; $i++) {
1.125     raeburn  12599:             my $rem = $i%($numinrow);
                   12600:             if ($rem == 0) {
                   12601:                 if ($i > 0) {
1.191     raeburn  12602:                     $table .= '</tr>';
1.125     raeburn  12603:                 }
1.191     raeburn  12604:                 $table .= '<tr>';
                   12605:                 $rows ++;
1.125     raeburn  12606:             }
1.191     raeburn  12607:             my $check = '';
                   12608:             if ($inputtype eq 'radio') {
                   12609:                 if (keys(%currhash) == 0) {
                   12610:                     if (!$i) {
                   12611:                         $check = ' checked="checked"';
                   12612:                     }
                   12613:                 } elsif (exists($currhash{$domcoord[$i]})) {
                   12614:                     $check = ' checked="checked"';
                   12615:                 }
                   12616:             } else {
                   12617:                 if (exists($currhash{$domcoord[$i]})) {
                   12618:                     $check = ' checked="checked"';
1.125     raeburn  12619:                 }
                   12620:             }
1.191     raeburn  12621:             if ($i == @domcoord - 1) {
1.125     raeburn  12622:                 my $colsleft = $numinrow - $rem;
                   12623:                 if ($colsleft > 1) {
1.191     raeburn  12624:                     $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125     raeburn  12625:                 } else {
1.191     raeburn  12626:                     $table .= '<td class="LC_left_item">';
1.125     raeburn  12627:                 }
                   12628:             } else {
1.191     raeburn  12629:                 $table .= '<td class="LC_left_item">';
                   12630:             }
                   12631:             my ($dcname,$dcdom) = split(':',$domcoord[$i]);
                   12632:             my $user = &Apache::loncommon::plainname($dcname,$dcdom);
                   12633:             $table .= '<span class="LC_nobreak"><label>'.
                   12634:                       '<input type="'.$inputtype.'" name="'.$name.'"'.
                   12635:                       ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
                   12636:             if ($user ne $dcname.':'.$dcdom) {
1.219     raeburn  12637:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.191     raeburn  12638:             }
1.219     raeburn  12639:             $table .= '</label></span></td>';
1.191     raeburn  12640:         }
                   12641:         $table .= '</tr></table>';
                   12642:     } elsif ($numdcs == 1) {
1.219     raeburn  12643:         my ($dcname,$dcdom) = split(':',$domcoord[0]);
                   12644:         my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191     raeburn  12645:         if ($inputtype eq 'radio') {
1.247     raeburn  12646:             $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219     raeburn  12647:             if ($user ne $dcname.':'.$dcdom) {
                   12648:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
                   12649:             }
1.191     raeburn  12650:         } else {
                   12651:             my $check;
                   12652:             if (exists($currhash{$domcoord[0]})) {
                   12653:                 $check = ' checked="checked"';
1.125     raeburn  12654:             }
1.247     raeburn  12655:             $table = '<span class="LC_nobreak"><label>'.
                   12656:                      '<input type="checkbox" name="'.$name.'" '.
                   12657:                      'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219     raeburn  12658:             if ($user ne $dcname.':'.$dcdom) {
1.220     raeburn  12659:                 $table .=  ' ('.$dcname.':'.$dcdom.')';
1.219     raeburn  12660:             }
1.220     raeburn  12661:             $table .= '</label></span>';
1.191     raeburn  12662:             $rows ++;
1.125     raeburn  12663:         }
                   12664:     }
1.191     raeburn  12665:     return ($numdcs,$table,$rows);
1.125     raeburn  12666: }
                   12667: 
1.137     raeburn  12668: sub usersession_titles {
                   12669:     return &Apache::lonlocal::texthash(
                   12670:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
                   12671:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145     raeburn  12672:                spares => 'Servers offloaded to, when busy',
1.137     raeburn  12673:                version => 'LON-CAPA version requirement',
1.138     raeburn  12674:                excludedomain => 'Allow all, but exclude specific domains',
                   12675:                includedomain => 'Deny all, but include specific domains',
1.145     raeburn  12676:                primary => 'Primary (checked first)',
1.154     raeburn  12677:                default => 'Default',
1.137     raeburn  12678:            );
                   12679: }
                   12680: 
1.152     raeburn  12681: sub id_for_thisdom {
                   12682:     my (%servers) = @_;
                   12683:     my %altids;
                   12684:     foreach my $server (keys(%servers)) {
                   12685:         my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
                   12686:         if ($serverhome ne $server) {
                   12687:             $altids{$serverhome} = $server;
                   12688:         }
                   12689:     }
                   12690:     return %altids;
                   12691: }
                   12692: 
1.150     raeburn  12693: sub count_servers {
                   12694:     my ($currbalancer,%servers) = @_;
                   12695:     my (@spares,$numspares);
                   12696:     foreach my $lonhost (sort(keys(%servers))) {
                   12697:         next if ($currbalancer eq $lonhost);
                   12698:         push(@spares,$lonhost);
                   12699:     }
                   12700:     if ($currbalancer) {
                   12701:         $numspares = scalar(@spares);
                   12702:     } else {
                   12703:         $numspares = scalar(@spares) - 1;
                   12704:     }
                   12705:     return ($numspares,@spares);
                   12706: }
                   12707: 
                   12708: sub lonbalance_targets_js {
1.171     raeburn  12709:     my ($dom,$types,$servers,$settings) = @_;
1.150     raeburn  12710:     my $select = &mt('Select');
                   12711:     my ($alltargets,$allishome,$allinsttypes,@alltypes);
                   12712:     if (ref($servers) eq 'HASH') {
                   12713:         $alltargets = join("','",sort(keys(%{$servers})));
                   12714:         my @homedoms;
                   12715:         foreach my $server (sort(keys(%{$servers}))) {
                   12716:             if (&Apache::lonnet::host_domain($server) eq $dom) {
                   12717:                 push(@homedoms,'1');
                   12718:             } else {
                   12719:                 push(@homedoms,'0');
                   12720:             }
                   12721:         }
                   12722:         $allishome = join("','",@homedoms);
                   12723:     }
                   12724:     if (ref($types) eq 'ARRAY') {
                   12725:         if (@{$types} > 0) {
                   12726:             @alltypes = @{$types};
                   12727:         }
                   12728:     }
                   12729:     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
                   12730:     $allinsttypes = join("','",@alltypes);
1.171     raeburn  12731:     my (%currbalancer,%currtargets,%currrules,%existing);
                   12732:     if (ref($settings) eq 'HASH') {
                   12733:         %existing = %{$settings};
                   12734:     }
                   12735:     &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                   12736:                               \%currtargets,\%currrules);
1.210     raeburn  12737:     my $balancers = join("','",sort(keys(%currbalancer)));
1.150     raeburn  12738:     return <<"END";
                   12739: 
                   12740: <script type="text/javascript">
                   12741: // <![CDATA[
                   12742: 
1.171     raeburn  12743: currBalancers = new Array('$balancers');
                   12744: 
                   12745: function toggleTargets(balnum) {
                   12746:     var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   12747:     var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
                   12748:     var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
                   12749:     var prevbalancer = prevhostitem.value;
                   12750:     var baltotal = document.getElementById('loadbalancing_total').value;
                   12751:     prevhostitem.value = balancer;
                   12752:     if (prevbalancer != '') {
                   12753:         var prevIdx = currBalancers.indexOf(prevbalancer);
                   12754:         if (prevIdx != -1) {
                   12755:             currBalancers.splice(prevIdx,1);
                   12756:         }
                   12757:     }
1.150     raeburn  12758:     if (balancer == '') {
1.171     raeburn  12759:         hideSpares(balnum);
1.150     raeburn  12760:     } else {
1.171     raeburn  12761:         var currIdx = currBalancers.indexOf(balancer);
                   12762:         if (currIdx == -1) {
                   12763:             currBalancers.push(balancer);
                   12764:         }
1.150     raeburn  12765:         var homedoms = new Array('$allishome');
1.171     raeburn  12766:         var ishomedom = homedoms[lonhostitem.selectedIndex];
                   12767:         showSpares(balancer,ishomedom,balnum);
1.150     raeburn  12768:     }
1.171     raeburn  12769:     balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150     raeburn  12770:     return;
                   12771: }
                   12772: 
1.171     raeburn  12773: function showSpares(balancer,ishomedom,balnum) {
1.150     raeburn  12774:     var alltargets = new Array('$alltargets');
                   12775:     var insttypes = new Array('$allinsttypes');
1.151     raeburn  12776:     var offloadtypes = new Array('primary','default');
                   12777: 
1.171     raeburn  12778:     document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
                   12779:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152     raeburn  12780:  
1.151     raeburn  12781:     for (var i=0; i<offloadtypes.length; i++) {
                   12782:         var count = 0;
                   12783:         for (var j=0; j<alltargets.length; j++) {
                   12784:             if (alltargets[j] != balancer) {
1.171     raeburn  12785:                 var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
                   12786:                 item.value = alltargets[j];
                   12787:                 item.style.textAlign='left';
                   12788:                 item.style.textFace='normal';
                   12789:                 document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
                   12790:                 if (currBalancers.indexOf(alltargets[j]) == -1) {
                   12791:                     item.disabled = '';
                   12792:                 } else {
                   12793:                     item.disabled = 'disabled';
                   12794:                     item.checked = false;
                   12795:                 }
1.151     raeburn  12796:                 count ++;
                   12797:             }
1.150     raeburn  12798:         }
                   12799:     }
1.151     raeburn  12800:     for (var k=0; k<insttypes.length; k++) {
                   12801:         if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150     raeburn  12802:             if (ishomedom == 1) {
1.171     raeburn  12803:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   12804:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  12805:             } else {
1.171     raeburn  12806:                 document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   12807:                 document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150     raeburn  12808:             }
                   12809:         } else {
1.171     raeburn  12810:             document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
                   12811:             document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150     raeburn  12812:         }
1.151     raeburn  12813:         if ((insttypes[k] != '_LC_external') && 
                   12814:             ((insttypes[k] != '_LC_internetdom') ||
                   12815:              ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171     raeburn  12816:             var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
                   12817:             item.options.length = 0;
                   12818:             item.options[0] = new Option("","",true,true);
1.210     raeburn  12819:             var idx = 0;
1.151     raeburn  12820:             for (var m=0; m<alltargets.length; m++) {
1.171     raeburn  12821:                 if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
                   12822:                     idx ++;
                   12823:                     item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150     raeburn  12824:                 }
                   12825:             }
                   12826:         }
                   12827:     }
                   12828:     return;
                   12829: }
                   12830: 
1.171     raeburn  12831: function hideSpares(balnum) {
1.150     raeburn  12832:     var alltargets = new Array('$alltargets');
                   12833:     var insttypes = new Array('$allinsttypes');
                   12834:     var offloadtypes = new Array('primary','default');
                   12835: 
1.171     raeburn  12836:     document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
                   12837:     document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150     raeburn  12838: 
                   12839:     var total = alltargets.length - 1;
                   12840:     for (var i=0; i<offloadtypes; i++) {
                   12841:         for (var j=0; j<total; j++) {
1.171     raeburn  12842:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
                   12843:            document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
                   12844:            document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151     raeburn  12845:         }
1.150     raeburn  12846:     }
                   12847:     for (var k=0; k<insttypes.length; k++) {
1.171     raeburn  12848:         document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
                   12849:         document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151     raeburn  12850:         if (insttypes[k] != '_LC_external') {
1.171     raeburn  12851:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
                   12852:             document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150     raeburn  12853:         }
                   12854:     }
                   12855:     return;
                   12856: }
                   12857: 
1.171     raeburn  12858: function checkOffloads(item,balnum,type) {
1.150     raeburn  12859:     var alltargets = new Array('$alltargets');
                   12860:     var offloadtypes = new Array('primary','default');
                   12861:     if (item.checked) {
                   12862:         var total = alltargets.length - 1;
                   12863:         var other;
                   12864:         if (type == offloadtypes[0]) {
1.151     raeburn  12865:             other = offloadtypes[1];
1.150     raeburn  12866:         } else {
1.151     raeburn  12867:             other = offloadtypes[0];
1.150     raeburn  12868:         }
                   12869:         for (var i=0; i<total; i++) {
1.171     raeburn  12870:             var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150     raeburn  12871:             if (server == item.value) {
1.171     raeburn  12872:                 if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
                   12873:                     document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150     raeburn  12874:                 }
                   12875:             }
                   12876:         }
                   12877:     }
                   12878:     return;
                   12879: }
                   12880: 
1.171     raeburn  12881: function singleServerToggle(balnum,type) {
                   12882:     var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150     raeburn  12883:     if (offloadtoSelIdx == 0) {
1.171     raeburn  12884:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
                   12885:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  12886: 
                   12887:     } else {
1.171     raeburn  12888:         document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
                   12889:         document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150     raeburn  12890:     }
                   12891:     return;
                   12892: }
                   12893: 
1.171     raeburn  12894: function balanceruleChange(formname,balnum,type) {
1.150     raeburn  12895:     if (type == '_LC_external') {
1.171     raeburn  12896:         return;
1.150     raeburn  12897:     }
1.171     raeburn  12898:     var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150     raeburn  12899:     for (var i=0; i<typesRules.length; i++) {
                   12900:         if (formname.elements[typesRules[i]].checked) {
                   12901:             if (formname.elements[typesRules[i]].value != 'specific') {
1.171     raeburn  12902:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
                   12903:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150     raeburn  12904:             } else {
1.171     raeburn  12905:                 document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
                   12906:             }
                   12907:         }
                   12908:     }
                   12909:     return;
                   12910: }
                   12911: 
                   12912: function balancerDeleteChange(balnum) {
                   12913:     var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
                   12914:     var baltotal = document.getElementById('loadbalancing_total').value;
                   12915:     var addtarget;
                   12916:     var removetarget;
                   12917:     var action = 'delete';
                   12918:     if (document.getElementById('loadbalancing_delete_'+balnum)) {
                   12919:         var lonhost = hostitem.value;
                   12920:         var currIdx = currBalancers.indexOf(lonhost);
                   12921:         if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
                   12922:             if (currIdx != -1) {
                   12923:                 currBalancers.splice(currIdx,1);
                   12924:             }
                   12925:             addtarget = lonhost;
                   12926:         } else {
                   12927:             if (currIdx == -1) {
                   12928:                 currBalancers.push(lonhost);
                   12929:             }
                   12930:             removetarget = lonhost;
                   12931:             action = 'undelete';
                   12932:         }
                   12933:         balancerChange(balnum,baltotal,action,addtarget,removetarget);
                   12934:     }
                   12935:     return;
                   12936: }
                   12937: 
                   12938: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
                   12939:     if (baltotal > 1) {
                   12940:         var offloadtypes = new Array('primary','default');
                   12941:         var alltargets = new Array('$alltargets');
                   12942:         var insttypes = new Array('$allinsttypes');
                   12943:         for (var i=0; i<baltotal; i++) {
                   12944:             if (i != balnum) {
                   12945:                 for (var j=0; j<offloadtypes.length; j++) {
                   12946:                     var total = alltargets.length - 1;
                   12947:                     for (var k=0; k<total; k++) {
                   12948:                         var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
                   12949:                         var server = serveritem.value;
                   12950:                         if ((action == 'delete') || (action == 'change' && addtarget != ''))  {
                   12951:                             if (server == addtarget) {
                   12952:                                 serveritem.disabled = '';
                   12953:                             }
                   12954:                         }
                   12955:                         if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   12956:                             if (server == removetarget) {
                   12957:                                 serveritem.disabled = 'disabled';
                   12958:                                 serveritem.checked = false;
                   12959:                             }
                   12960:                         }
                   12961:                     }
                   12962:                 }
                   12963:                 for (var j=0; j<insttypes.length; j++) {
                   12964:                     if (insttypes[j] != '_LC_external') {
                   12965:                         if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
                   12966:                             var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
                   12967:                             var currSel = singleserver.selectedIndex;
                   12968:                             var currVal = singleserver.options[currSel].value;
                   12969:                             if ((action == 'delete') || (action == 'change' && addtarget != '')) {
                   12970:                                 var numoptions = singleserver.options.length;
                   12971:                                 var needsnew = 1;
                   12972:                                 for (var k=0; k<numoptions; k++) {
                   12973:                                     if (singleserver.options[k] == addtarget) {
                   12974:                                         needsnew = 0;
                   12975:                                         break;
                   12976:                                     }
                   12977:                                 }
                   12978:                                 if (needsnew == 1) {
                   12979:                                     singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
                   12980:                                 }
                   12981:                             }
                   12982:                             if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
                   12983:                                 singleserver.options.length = 0;
                   12984:                                 if ((currVal) && (currVal != removetarget)) {
                   12985:                                     singleserver.options[0] = new Option("","",false,false);
                   12986:                                 } else {
                   12987:                                     singleserver.options[0] = new Option("","",true,true);
                   12988:                                 }
                   12989:                                 var idx = 0;
                   12990:                                 for (var m=0; m<alltargets.length; m++) {
                   12991:                                     if (currBalancers.indexOf(alltargets[m]) == -1) {
                   12992:                                         idx ++;
                   12993:                                         if (currVal == alltargets[m]) {
                   12994:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
                   12995:                                         } else {
                   12996:                                             singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
                   12997:                                         }
                   12998:                                     }
                   12999:                                 }
                   13000:                             }
                   13001:                         }
                   13002:                     }
                   13003:                 }
1.150     raeburn  13004:             }
                   13005:         }
                   13006:     }
                   13007:     return;
                   13008: }
                   13009: 
1.152     raeburn  13010: // ]]>
                   13011: </script>
                   13012: 
                   13013: END
                   13014: }
                   13015: 
                   13016: sub new_spares_js {
                   13017:     my @sparestypes = ('primary','default');
                   13018:     my $types = join("','",@sparestypes);
                   13019:     my $select = &mt('Select');
                   13020:     return <<"END";
                   13021: 
                   13022: <script type="text/javascript">
                   13023: // <![CDATA[
                   13024: 
                   13025: function updateNewSpares(formname,lonhost) {
                   13026:     var types = new Array('$types');
                   13027:     var include = new Array();
                   13028:     var exclude = new Array();
                   13029:     for (var i=0; i<types.length; i++) {
                   13030:         var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
                   13031:         for (var j=0; j<spareboxes.length; j++) {
                   13032:             if (formname.elements[spareboxes[j]].checked) {
                   13033:                 exclude.push(formname.elements[spareboxes[j]].value);
                   13034:             } else {
                   13035:                 include.push(formname.elements[spareboxes[j]].value);
                   13036:             }
                   13037:         }
                   13038:     }
                   13039:     for (var i=0; i<types.length; i++) {
                   13040:         var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
                   13041:         var selIdx = newSpare.selectedIndex;
                   13042:         var currnew = newSpare.options[selIdx].value;
                   13043:         var okSpares = new Array();
                   13044:         for (var j=0; j<newSpare.options.length; j++) {
                   13045:             var possible = newSpare.options[j].value;
                   13046:             if (possible != '') {
                   13047:                 if (exclude.indexOf(possible) == -1) {
                   13048:                     okSpares.push(possible);
                   13049:                 } else {
                   13050:                     if (currnew == possible) {
                   13051:                         selIdx = 0;
                   13052:                     }
                   13053:                 }
                   13054:             }
                   13055:         }
                   13056:         for (var k=0; k<include.length; k++) {
                   13057:             if (okSpares.indexOf(include[k]) == -1) {
                   13058:                 okSpares.push(include[k]);
                   13059:             }
                   13060:         }
                   13061:         okSpares.sort();
                   13062:         newSpare.options.length = 0;
                   13063:         if (selIdx == 0) {
                   13064:             newSpare.options[0] = new Option("$select","",true,true);
                   13065:         } else {
                   13066:             newSpare.options[0] = new Option("$select","",false,false);
                   13067:         }
                   13068:         for (var m=0; m<okSpares.length; m++) {
                   13069:             var idx = m+1;
                   13070:             var selThis = 0;
                   13071:             if (selIdx != 0) {
                   13072:                 if (okSpares[m] == currnew) {
                   13073:                     selThis = 1;
                   13074:                 }
                   13075:             }
                   13076:             if (selThis == 1) {
                   13077:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
                   13078:             } else {
                   13079:                 newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
                   13080:             }
                   13081:         }
                   13082:     }
                   13083:     return;
                   13084: }
                   13085: 
                   13086: function checkNewSpares(lonhost,type) {
                   13087:     var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
                   13088:     var chosen =  newSpare.options[newSpare.selectedIndex].value;
                   13089:     if (chosen != '') { 
                   13090:         var othertype;
                   13091:         var othernewSpare;
                   13092:         if (type == 'primary') {
                   13093:             othernewSpare = document.getElementById('newspare_default_'+lonhost);
                   13094:         }
                   13095:         if (type == 'default') {
                   13096:             othernewSpare = document.getElementById('newspare_primary_'+lonhost);
                   13097:         }
                   13098:         if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
                   13099:             othernewSpare.selectedIndex = 0;
                   13100:         }
                   13101:     }
                   13102:     return;
                   13103: }
                   13104: 
                   13105: // ]]>
                   13106: </script>
                   13107: 
                   13108: END
                   13109: 
                   13110: }
                   13111: 
                   13112: sub common_domprefs_js {
                   13113:     return <<"END";
                   13114: 
                   13115: <script type="text/javascript">
                   13116: // <![CDATA[
                   13117: 
1.150     raeburn  13118: function getIndicesByName(formname,item) {
1.152     raeburn  13119:     var group = new Array();
1.150     raeburn  13120:     for (var i=0;i<formname.elements.length;i++) {
                   13121:         if (formname.elements[i].name == item) {
1.152     raeburn  13122:             group.push(formname.elements[i].id);
1.150     raeburn  13123:         }
                   13124:     }
1.152     raeburn  13125:     return group;
1.150     raeburn  13126: }
                   13127: 
                   13128: // ]]>
                   13129: </script>
                   13130: 
                   13131: END
1.152     raeburn  13132: 
1.150     raeburn  13133: }
                   13134: 
1.165     raeburn  13135: sub recaptcha_js {
                   13136:     my %lt = &captcha_phrases();
                   13137:     return <<"END";
                   13138: 
                   13139: <script type="text/javascript">
                   13140: // <![CDATA[
                   13141: 
                   13142: function updateCaptcha(caller,context) {
                   13143:     var privitem;
                   13144:     var pubitem;
                   13145:     var privtext;
                   13146:     var pubtext;
1.269     raeburn  13147:     var versionitem;
                   13148:     var versiontext;
1.165     raeburn  13149:     if (document.getElementById(context+'_recaptchapub')) {
                   13150:         pubitem = document.getElementById(context+'_recaptchapub');
                   13151:     } else {
                   13152:         return;
                   13153:     }
                   13154:     if (document.getElementById(context+'_recaptchapriv')) {
                   13155:         privitem = document.getElementById(context+'_recaptchapriv');
                   13156:     } else {
                   13157:         return;
                   13158:     }
                   13159:     if (document.getElementById(context+'_recaptchapubtxt')) {
                   13160:         pubtext = document.getElementById(context+'_recaptchapubtxt');
                   13161:     } else {
                   13162:         return;
                   13163:     }
                   13164:     if (document.getElementById(context+'_recaptchaprivtxt')) {
                   13165:         privtext = document.getElementById(context+'_recaptchaprivtxt');
                   13166:     } else {
                   13167:         return;
                   13168:     }
1.269     raeburn  13169:     if (document.getElementById(context+'_recaptchaversion')) {
                   13170:         versionitem = document.getElementById(context+'_recaptchaversion');
                   13171:     } else {
                   13172:         return;
                   13173:     }
                   13174:     if (document.getElementById(context+'_recaptchavertxt')) {
                   13175:         versiontext = document.getElementById(context+'_recaptchavertxt');
                   13176:     } else {
                   13177:         return;
                   13178:     }
1.165     raeburn  13179:     if (caller.checked) {
                   13180:         if (caller.value == 'recaptcha') {
                   13181:             pubitem.type = 'text';
                   13182:             privitem.type = 'text';
                   13183:             pubitem.size = '40';
                   13184:             privitem.size = '40';
                   13185:             pubtext.innerHTML = "$lt{'pub'}";
                   13186:             privtext.innerHTML = "$lt{'priv'}";
1.269     raeburn  13187:             versionitem.type = 'text';
                   13188:             versionitem.size = '3';
                   13189:             versiontext.innerHTML = "$lt{'ver'}"; 
1.165     raeburn  13190:         } else {
                   13191:             pubitem.type = 'hidden';
                   13192:             privitem.type = 'hidden';
1.269     raeburn  13193:             versionitem.type = 'hidden';
1.165     raeburn  13194:             pubtext.innerHTML = '';
                   13195:             privtext.innerHTML = '';
1.269     raeburn  13196:             versiontext.innerHTML = '';
1.165     raeburn  13197:         }
                   13198:     }
                   13199:     return;
                   13200: }
                   13201: 
                   13202: // ]]>
                   13203: </script>
                   13204: 
                   13205: END
                   13206: 
                   13207: }
                   13208: 
1.236     raeburn  13209: sub toggle_display_js {
1.192     raeburn  13210:     return <<"END";
                   13211: 
                   13212: <script type="text/javascript">
                   13213: // <![CDATA[
                   13214: 
1.236     raeburn  13215: function toggleDisplay(domForm,caller) {
                   13216:     if (document.getElementById(caller)) {
                   13217:         var divitem = document.getElementById(caller);
                   13218:         var optionsElement = domForm.coursecredits;
1.264     raeburn  13219:         var checkval = 1;
                   13220:         var dispval = 'block';
1.236     raeburn  13221:         if (caller == 'emailoptions') {
                   13222:             optionsElement = domForm.cancreate_email; 
                   13223:         }
1.257     raeburn  13224:         if (caller == 'studentsubmission') {
                   13225:             optionsElement = domForm.postsubmit;
                   13226:         }
1.264     raeburn  13227:         if (caller == 'cloneinstcode') {
                   13228:             optionsElement = domForm.canclone;
                   13229:             checkval = 'instcode';
                   13230:         }
1.236     raeburn  13231:         if (optionsElement.length) {
1.192     raeburn  13232:             var currval;
1.236     raeburn  13233:             for (var i=0; i<optionsElement.length; i++) {
                   13234:                 if (optionsElement[i].checked) {
                   13235:                    currval = optionsElement[i].value;
1.192     raeburn  13236:                 }
                   13237:             }
1.264     raeburn  13238:             if (currval == checkval) {
                   13239:                 divitem.style.display = dispval;
1.192     raeburn  13240:             } else {
1.236     raeburn  13241:                 divitem.style.display = 'none';
1.192     raeburn  13242:             }
                   13243:         }
                   13244:     }
                   13245:     return;
                   13246: }
                   13247: 
                   13248: // ]]>
                   13249: </script>
                   13250: 
                   13251: END
                   13252: 
                   13253: }
                   13254: 
1.165     raeburn  13255: sub captcha_phrases {
                   13256:     return &Apache::lonlocal::texthash (
                   13257:                  priv => 'Private key',
                   13258:                  pub  => 'Public key',
                   13259:                  original  => 'original (CAPTCHA)',
                   13260:                  recaptcha => 'successor (ReCAPTCHA)',
                   13261:                  notused   => 'unused',
1.269     raeburn  13262:                  ver => 'ReCAPTCHA version (1 or 2)', 
1.165     raeburn  13263:     );
                   13264: }
                   13265: 
1.205     raeburn  13266: sub devalidate_remote_domconfs {
1.212     raeburn  13267:     my ($dom,$cachekeys) = @_;
                   13268:     return unless (ref($cachekeys) eq 'HASH');
1.205     raeburn  13269:     my %servers = &Apache::lonnet::internet_dom_servers($dom);
                   13270:     my %thismachine;
                   13271:     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.267     raeburn  13272:     my @posscached = ('domainconfig','domdefaults','ltitools');
1.260     raeburn  13273:     if (keys(%servers)) {
1.205     raeburn  13274:         foreach my $server (keys(%servers)) {
                   13275:             next if ($thismachine{$server});
1.212     raeburn  13276:             my @cached;
                   13277:             foreach my $name (@posscached) {
                   13278:                 if ($cachekeys->{$name}) {
                   13279:                     push(@cached,&escape($name).':'.&escape($dom));
                   13280:                 }
                   13281:             }
                   13282:             if (@cached) {
                   13283:                 &Apache::lonnet::remote_devalidate_cache($server,\@cached);
                   13284:             }
1.205     raeburn  13285:         }
                   13286:     }
                   13287:     return;
                   13288: }
                   13289: 
1.3       raeburn  13290: 1;

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